1.新增自动构建脚本。

This commit is contained in:
MacRsh
2023-12-17 03:09:20 +08:00
parent 83dba00f6c
commit a635e6facd
20 changed files with 155 additions and 196 deletions

99
Kconfig
View File

@@ -8,98 +8,105 @@ menu "Device configure"
help help
"Size of dynamic memory for system." "Size of dynamic memory for system."
config MR_CFG_PRINTF_BUFSZ
int "Printf buffer size"
default 128
range 32 2147483647
help
"Size of the buffer used by the printf function."
config MR_USING_ASSERT config MR_USING_ASSERT
bool "Enable assert" bool "Use assert"
default y default y
help help
"Enabling this option allows the use of assert statements in the code." "Use this option allows the use of assert statements in the code."
config MR_USING_LOG
bool "Use log"
default y
help
"Use this option allows for the use of log."
menu "Logging configure" menu "Logging configure"
depends on MR_USING_LOG
config MR_USING_LOG_ERROR config MR_USING_LOG_ERROR
bool "Enable error log" bool "Use error log"
default y default y
help help
"Enabling this option allows for the use of error log." "Use this option allows for the use of error log."
config MR_USING_LOG_WARN config MR_USING_LOG_WARN
bool "Enable warning log" bool "Use warning log"
default y default y
help help
"Enabling this option allows for the use of warning log." "Use this option allows for the use of warning log."
config MR_USING_LOG_INFO config MR_USING_LOG_INFO
bool "Enable info log" bool "Use info log"
default y default y
help help
"Enabling this option allows for the use of info log." "Use this option allows for the use of info log."
config MR_USING_LOG_DEBUG config MR_USING_LOG_DEBUG
bool "Enable debug log" bool "Use debug log"
default y default y
help help
"Enabling this option allows for the use of debug log." "Use this option allows for the use of debug log."
endmenu endmenu
config MR_CFG_NAME_MAX config MR_CFG_NAME_MAX
int "Max length of device name" int "Name max length"
default 8 default 8
range 4 1024 range 4 1024
help help
"Maximum length of name" "Maximum length of device name"
config MR_CFG_DESC_MAX config MR_CFG_DESC_MAX
int "Max number of descriptors" int "Descriptors max number"
default 64 default 64
range 16 1024 range 16 1024
help help
"Maximum number of descriptors" "Maximum number of descriptors"
config MR_USING_RDWR_CTL config MR_USING_RDWR_CTL
bool "Enable read/write control" bool "Use read/write control"
default y default y
help help
"Enabling this option allows for read and write control of devices." "Use this option allows for read and write control of devices."
config MR_USING_CONSOLE config MR_USING_CONSOLE
bool "Enable console" bool "Use console"
default y default y
help help
"Enabling this option allows for the use of the console device." "Use this option allows for the use of the console device."
menu "Console configure" menu "Console configure"
depends on MR_USING_CONSOLE depends on MR_USING_CONSOLE
config MR_CFG_CONSOLE_NAME config MR_CFG_CONSOLE_NAME
string "Console device name" string "Console name"
default "serial1" default "serial1"
help help
"This option sets the name of the console device." "Name of the console device."
config MR_USING_CONSOLE_NONBLOCK config MR_USING_CONSOLE_NONBLOCK
bool "Console device non-blocking read/write" bool "Use console non-blocking"
default n default n
help help
"Enable or disable non-blocking read/write for the console device." "Use this option allows for the use of the console device in non-blocking mode."
endmenu endmenu
config MR_CFG_PRINTF_BUFSZ
int "Size of printf buffer"
default 128
range 32 2147483647
help
"This option sets the size of the buffer used for printf operations."
config MR_USING_ADC config MR_USING_ADC
bool "Enable ADC device" bool "Use ADC device"
default n default n
help help
"Enabling this option allows for the use of ADC (Analog-to-Digital Converter) devices." "Use this option allows for the use of ADC (Analog-to-Digital Converter) devices."
config MR_USING_CAN config MR_USING_CAN
bool "Enable CAN device" bool "Use CAN device"
default n default n
help help
"Enabling this option allows for the use of CAN (Controller Area Network) devices." "Use this option allows for the use of CAN (Controller Area Network) devices."
menu "CAN configure" menu "CAN configure"
depends on MR_USING_CAN depends on MR_USING_CAN
@@ -113,16 +120,16 @@ menu "Device configure"
endmenu endmenu
config MR_USING_DAC config MR_USING_DAC
bool "Enable DAC device" bool "Use DAC device"
default n default n
help help
"Enabling this option allows for the use of DAC (Digital-to-Analog Converter) devices." "Use this option allows for the use of DAC (Digital-to-Analog Converter) devices."
config MR_USING_I2C config MR_USING_I2C
bool "Enable I2C device" bool "Use I2C device"
default n default n
help help
"Enabling this option allows for the use of I2C (Inter-Integrated Circuit) devices." "Use this option allows for the use of I2C (Inter-Integrated Circuit) devices."
menu "I2C configure" menu "I2C configure"
depends on MR_USING_I2C depends on MR_USING_I2C
@@ -136,23 +143,23 @@ menu "Device configure"
config MR_USING_SOFT_I2C config MR_USING_SOFT_I2C
depends on MR_USING_PIN depends on MR_USING_PIN
bool "Enable soft I2C" bool "Use Soft I2C"
default n default n
help help
"Enabling this option allows for the use of soft I2C." "Use this option allows for the use of soft I2C."
endmenu endmenu
config MR_USING_PIN config MR_USING_PIN
bool "Enable Pin device" bool "Use Pin device"
default n default n
help help
"Enabling this option allows for the use of Pin devices." "Use this option allows for the use of Pin devices."
config MR_USING_SERIAL config MR_USING_SERIAL
bool "Enable Serial device" bool "Use Serial device"
default n default n
help help
"Enabling this option allows for the use of Serial devices." "Use this option allows for the use of Serial devices."
menu "Serial configure" menu "Serial configure"
depends on MR_USING_SERIAL depends on MR_USING_SERIAL
@@ -173,10 +180,10 @@ menu "Device configure"
endmenu endmenu
config MR_USING_SPI config MR_USING_SPI
bool "Enable SPI device" bool "Use SPI device"
default n default n
help help
"Enabling this option allows for the use of SPI (Serial Peripheral Interface) devices." "Use this option allows for the use of SPI (Serial Peripheral Interface) devices."
menu "SPI configure" menu "SPI configure"
depends on MR_USING_SPI depends on MR_USING_SPI
@@ -190,10 +197,10 @@ menu "Device configure"
endmenu endmenu
config MR_USING_TIMER config MR_USING_TIMER
bool "Enable Timer device" bool "Use Timer device"
default n default n
help help
"Enabling this option allows for the use of Timer devices." "Use this option allows for the use of Timer devices."
endmenu endmenu
source "driver/Kconfig" source "driver/Kconfig"

View File

@@ -14,11 +14,9 @@
* [目录结构](#目录结构) * [目录结构](#目录结构)
* [设备/组件支持一览表](#设备组件支持一览表) * [设备/组件支持一览表](#设备组件支持一览表)
* [开始使用](#开始使用) * [开始使用](#开始使用)
* [配置 `Kconfig` 环境](#配置-kconfig-环境) * [验证Python环境](#验证python环境)
* [框架导入工程](#将框架导入工程) * [项目导入工程](#将项目导入工程)
* [配置菜单选项](#配置菜单选项) * [配置菜单选项](#配置菜单选项)
* [生成配置文件](#生成配置文件)
* [添加包含路径](#添加包含路径)
* [先来点个灯吧](#先来点个灯吧) * [先来点个灯吧](#先来点个灯吧)
* [Hello World](#hello-world) * [Hello World](#hello-world)
* [现在您已经完成了入门教程开始使用MR库吧](#现在您已经完成了入门教程开始使用mr库吧) * [现在您已经完成了入门教程开始使用MR库吧](#现在您已经完成了入门教程开始使用mr库吧)
@@ -106,9 +104,9 @@ int main(void)
`Kconfig` 会根据配置文件自动生成配置选项界面。开发者可以通过简单的操作来选择需要启用的功能组件和设置相关参数。 `Kconfig` 会根据配置文件自动生成配置选项界面。开发者可以通过简单的操作来选择需要启用的功能组件和设置相关参数。
![配置工具](document/picture/readme/README_Kconfig.png) ![配置工具1](document/picture/readme/kconfig_main1.png)
![配置工具1](document/picture/readme/README_Kconfig1.png) ![配置工具2](document/picture/readme/kconfig_main2.png)
通过修改参数,快速裁剪所需功能。配置完成后通过 `Python` 脚本自动生成配置文件。 通过修改参数,快速裁剪所需功能。配置完成后通过 `Python` 脚本自动生成配置文件。
@@ -152,66 +150,33 @@ int main(void)
# 开始使用 # 开始使用
## 配置 `Kconfig` 环境 ## 验证Python环境
注:`Kconfig` 并非必须的,但是推荐使用(安装和配置非常快捷,后续教程也是以应用 `Kconfig` 为例)。 验证系统是否安装Python环境。在命令行中运行 `python --version` 检查Python版本`MR` 脚本工具依赖Python 若无Python环境请自行安装)。
1. 验证系统是否安装Python环境。在命令行中运行 `python --version` 检查Python版本`Kconfig` 依赖于 ` python`,若无 ` python` ## 将项目导入工程
环境请自行安装)。
2. 在命令行中使用所示命令安装 `Kconfig`
```cmd
python -m pip install windows-curses
python -m pip install kconfiglib
```
3. 在命令行中运行 `menuconfig -h` 验证安装是否成功。
## 将框架导入工程
1.`Gitee``Github` 仓库下载最新版本源码到本地。 1.`Gitee``Github` 仓库下载最新版本源码到本地。
2. 将源码导入到您工程所在的目录。以STM32工程为例: 2. 将源码复制到您工程所在的目录。以 `MDK` 工程CubeMX生成的标准工程为例:
![工程目录](document/picture/readme/README_Build.png) ![CubeMX工程](document/picture/readme/cubemx_project.png)
3. 如使用的芯片已经做了 `BSP` 适配请参考芯片对应 `BSP` 中的配置教程,完成 `BSP` 配置。 3.`bsp` 目录中对应芯片的驱动复制到 `driver`
4. 移除不需要的文件 `bsp`、`document`、`module` 目录(如不需要`GIT`也可以移除`.git`文件删除)。完成后,目录结构如下所示:
![工程目录1](document/picture/readme/README_Build1.png) ![Driver目录](document/picture/readme/driver.png)
5. 将文件加入到IDE中大部分IDE都能自动识别工程路径下的文件无需进行此步骤。以 `keil` 为例: 4. 移除不需要的文件 `bsp``document``module` 目录(如不需要`GIT`也可以移除`.git`文件)。完成后,目录结构如下所示:
![工程目录Keil](document/picture/readme/README_Keil.png) ![工程目录](document/picture/readme/project.png)
添加 `source`、`device`、`driver` 目录下的所有文件。 5. 将文件加入到IDE中大部分IDE都能自动识别工程路径下的文件无需进行此步骤。编译器中添加 `mr-library`
的包含路径。配置GNU语法。如果您使用的是非 `GCC` 编译器请使能GNU语法。
## 配置菜单选项 `MR` 配置脚本支持 `MDK` 工程自动配置。在 `mr-library` 路径下,打开命令行工具,运行 `python build.py -mdk` 自动完成配置(完成后跳过剩余步骤至 `配置菜单选项`)。
1. 在 `mr-library` 目录下打开命令行工具,运行 `menuconfig` 进行菜单配置。 ![MDK自动构建](document/picture/readme/build_mdk.png)
![工程目录2](document/picture/readme/README_Build2.png) 6. 配置自动初始化GCC环境查找您工程下以 `.ld` 为后缀的连接脚本文件(通常为 `link.ld`),在脚本文件中添加代码(如使用 `MDK` 等能自动生成链接脚本的环境,请跳过此步骤):
注:当添加对应芯片驱动的后,将显示 `Device configure` 和 `Driver configure`。对应 `Driver configure` 请参考 `BSP` 下教程。
2. 选中 `Device configure` 回车进入菜单,按照需要配置功能。
![工程目录3](document/picture/readme/README_Build3.png)
3. 配置完成后,按 `Q` 退出菜单配置界面,按`Y` 保存配置。
## 生成配置文件
1. 在 `mr-library` 目录下打开命令行工具,运行 `python kconfig.py`,自动生成配置文件 `mr_config.h`。
## 添加包含路径
1. 在编译器中添加 `mr-library` 的包含路径,以 `keil` 为例:
![工程目录4](document/picture/readme/README_Build4.png)
2. 配置自动初始化GCC环境查找您工程下以 `.ld` 为后缀的连接脚本文件(通常为 `link.ld`),在脚本文件中添加代码:
注:如果您的是在 `keil` 等,能够自动生成链接脚本的环境下,请跳过此步骤。
```c ```c
/* mr-library auto init */ /* mr-library auto init */
@@ -221,22 +186,25 @@ int main(void)
_mr_auto_init_end = .; _mr_auto_init_end = .;
``` ```
示例: ![Ld](document/picture/readme/ld.png)
![工程目录5](document/picture/readme/README_Build5.png) ## 配置菜单选项
3. 配置GNU语法。如果您使用的是非 `GCC` 编译器请使能GNU语法。以 `keil` 为例: 1. 在 `mr-library` 目录下打开命令行工具,运行 `python build.py -m` 进行菜单配置。
AC5: ![配置工具1](document/picture/readme/kconfig_main1.png)
![工程目录6](document/picture/readme/README_Build6.png) 注:当添加对应芯片驱动的后,将显示 `Device configure` 和 `Driver configure`。对应 `Driver configure` 请参考 `bsp` 下文档。
AC6: 2. 选中 `Device configure` 回车进入菜单,按照需要配置功能。
![工程目录7](document/picture/readme/README_AC6.png) ![配置工具2](document/picture/readme/kconfig_main2.png)
4. 在您的工程中引入 `#include "include/mr_lib.h"` 3. 配置完成后,按 `Q` 退出菜单配置界面,按`Y` 保存配置,脚本将自动生成配置文件
5. 在 `main` 函数中添加 `mr_auto_init();` 自动初始化函数。
![自动配置工具](document/picture/readme/build_m.png)
4. 工程中引入 `#include "include/mr_lib.h"` 并在 `main` 函数中添加 `mr_auto_init();` 自动初始化函数,即可开始使用。
---------- ----------

View File

@@ -14,12 +14,10 @@
* [Directory structure](#directory-structure) * [Directory structure](#directory-structure)
* [Device/Component Support Overview](#devicecomponent-support-overview) * [Device/Component Support Overview](#devicecomponent-support-overview)
* [Get Started](#get-started) * [Get Started](#get-started)
* [Configure the Kconfig Environment](#configure-the-kconfig-environment) * [Verifying Python environment](#verifying-python-environment)
* [Import the Framework into the Project](#import-the-framework-into-the-project) * [Import the project into the workspace](#import-the-project-into-the-workspace)
* [Configure Menu Options](#configure-menu-options) * [Configure Menu Options](#configure-menu-options)
* [Generate Configuration File](#generate-configuration-file) * [Let`s Light an LED](#lets-light-an-led)
* [Add Include Paths](#add-include-paths)
* [Let's Light an LED](#lets-light-an-led)
* [Hello World](#hello-world) * [Hello World](#hello-world)
* [Now that you have completed the introductory tutorial, start using the MR Library.](#now-that-you-have-completed-the-introductory-tutorial-start-using-the-mr-library) * [Now that you have completed the introductory tutorial, start using the MR Library.](#now-that-you-have-completed-the-introductory-tutorial-start-using-the-mr-library)
<!-- TOC --> <!-- TOC -->
@@ -115,9 +113,9 @@ code.
`Kconfig` will automatically generate the configuration options interface based on the configuration file. Developers `Kconfig` will automatically generate the configuration options interface based on the configuration file. Developers
can select the functional components that need to be enabled and set relevant parameters through simple operations. can select the functional components that need to be enabled and set relevant parameters through simple operations.
![Tool](document/picture/readme/README_Kconfig.png) ![Tool1](document/picture/readme/kconfig_main1.png)
![Tool1](document/picture/readme/README_Kconfig1.png) ![Tool1](document/picture/readme/kconfig_main2.png)
By modifying parameters, you can quickly tailor the required functions. After the configuration is complete, By modifying parameters, you can quickly tailor the required functions. After the configuration is complete,
the `Python` script automatically generates the configuration file. the `Python` script automatically generates the configuration file.
@@ -162,74 +160,41 @@ the `Python` script automatically generates the configuration file.
# Get Started # Get Started
## Configure the Kconfig Environment ## Verifying Python environment
Note: Kconfig is not mandatory, but recommended (installation and configuration are very quick, and the following Verify that the Python environment is installed. Run `python --version` on the command line to check the Python
tutorials are based on applying Kconfig). version (the `MR` scripting tool relies on Python, install it yourself if there is no Python environment).
1. Verify that the system has a Python environment installed. Run `python --version` in the command line to check the ## Import the project into the workspace
Python version (Kconfig depends on python, please install python if it is not available).
2. Use the following commands to install Kconfig in the command line: 1. Download the latest version source code from the `Gitee` or `GitHub` repository to the local.
2. Copy the source code to the directory where your project is located. Take the `MDK` project (CubeMX-generated
standard project) as an example:
```cmd ![CubeMX project](document/picture/readme/cubemx_project.png)
python -m pip install windows-curses
python -m pip install kconfiglib
```
3. Run `menuconfig -h` in the command line to verify successful installation. 3. Copy the driver of the corresponding chip in the `bsp` directory to `driver`:
## Import the Framework into the Project ![Driver directory](document/picture/readme/driver.png)
1. Download the latest version source code from the Gitee or Github repository to the local. 4. Remove unnecessary files` bsp `, `document`, `module` directories (you can also remove `.git `files if you don`t
2. Import the source code into the directory where your project is located. Taking an STM32 project as an example: need` git `). When complete, the directory structure looks like this:
![project directory](document/picture/readme/README_Build.png) ![project directory](document/picture/readme/project.png)
3. If the used chip has BSP adaptation, please refer to the chip's corresponding BSP configuration tutorial to complete
the BSP configuration.
4. Remove unnecessary files such as `bsp`、`document`、`module` directories (you can also remove the `.git` file to delete
GIT if not needed). The directory structure is shown below after completion:
![project directory1](document/picture/readme/README_Build1.png)
5. Add the files to the IDE (most ides automatically recognize the files in the project path, eliminating the need for 5. Add the files to the IDE (most ides automatically recognize the files in the project path, eliminating the need for
this step). Take `keil` for example: this step). Add `mr-library` to the compiler
Contains the path. Configure the GNU syntax. If you are using a non-gcc compiler, enable GNU syntax.
![project directory1 Keil](document/picture/readme/README_Keil.png) The `MR` configuration script supports the `MDK` project automatic configuration. In the `mr-library` path, open the
command line tool and run `python build.py -mdk` to complete the configuration automatically (when done, skip the
remaining steps to `Configuration menu options`).
Add all files in the `source`, `device`, `driver` directories. ![MDK auto build](document/picture/readme/build_mdk.png)
## Configure Menu Options 6. Configure automatic initialization (GCC environment), find the connection script file with suffix `.ld `under your
project (usually` link.ld `), and add code to the script file (such as using the environment that can automatically
1. Open the command line tool in the `mr-library` directory and run `menuconfig` to configure the menu. generate link scripts such as` MDK `, please skip this step) :
![project directory2](document/picture/readme/README_Build2.png)
Note: When the corresponding chip driver is added, `Device configure` and `Driver configure` will be displayed.
Please refer to the tutorial under `BSP` for `Driver configure`.
2. Enter the menu by pressing the Enter key on `Device configure`, and configure the desired functions according to
needs.
![project directory3](document/picture/readme/README_Build3.png)
3. After configuration is complete, press `Q` to exit the menu configuration interface, press `Y` to save the
configuration.
## Generate Configuration File
1. Run `python kconfig.py` in the command line tool under `mr-library` directory to automatically generate the
configuration file `mr_config.h`.
## Add Include Paths
1. Add the include paths of `mr-library` in the compiler, taking `keil` as an example:
![project directory4](document/picture/readme/README_Build4.png)
2. Configure automatic initialization (GCC environment), find the link script file with suffix `.ld` in your project
directory (usually `link.ld`), and add the following code to the script file:
```c ```c
/* mr-library auto init */ /* mr-library auto init */
@@ -239,26 +204,33 @@ tutorials are based on applying Kconfig).
_mr_auto_init_end = .; _mr_auto_init_end = .;
``` ```
Example: ![Ld](document/picture/readme/ld.png)
![project directory5](document/picture/readme/README_Build5.png) ## Configure Menu Options
3. Configure the GNU syntax. If you are using a non-gcc compiler, enable GNU syntax. Take `keil` for example: 1. Open the command line tool in the `mr-library` directory and run `python build.py -m` for menu configuration.
AC5: ![Tool1](document/picture/readme/kconfig_main1.png)
![project directory6](document/picture/readme/README_Build6.png) Note: When the corresponding chip driver is added, `Device configure` and `Driver configure` will be displayed.
For `Driver configure` please refer to the documentation under `bsp`.
AC6: 2. Enter the menu by pressing the Enter key on `Device configure`, and configure the desired functions according to
needs.
![project directory7](document/picture/readme/README_AC6.png) ![Tool2](document/picture/readme/kconfig_main2.png)
4. Include `#include "include/mr_lib.h"` in your project. 3. After configuration is complete, press `Q` to exit the menu configuration interface, press `Y` to save the
5. Add the automatic initialization function `mr_auto_init();` in the main function. configuration.
![Automatic configuration tool](document/picture/readme/build_m.png)
4. In the project, introduce `#include` include/mr_lib.h `and add` mr_auto_init() `to` main `function; `
Automatically initialize the function and start using it.
---------- ----------
# Let's Light an LED # Let`s Light an LED
```c ```c
#include "include/mr_lib.h" #include "include/mr_lib.h"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -1,16 +1,27 @@
import argparse #!/usr/bin/env python
import os
import re import re
import sys import pip
import textwrap
from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \
TRISTATE, TRI_TO_STR, AND, OR
def generate_config(kconfig_file,config_in, config_out, header_out): def install_package(package):
pip.main(['install', package])
try:
from kconfiglib import Kconfig
except ImportError:
install_package('kconfiglib')
try:
import curses
except ImportError:
install_package('windows-curses')
def generate_config(kconfig_file, config_in, config_out, header_out):
print("Parsing " + kconfig_file) print("Parsing " + kconfig_file)
kconf = Kconfig(kconfig_file, warn_to_stderr=False, kconf = Kconfig(kconfig_file, warn_to_stderr=False,
suppress_traceback=True) suppress_traceback=True)
# Load config files # Load config files
@@ -18,26 +29,25 @@ def generate_config(kconfig_file,config_in, config_out, header_out):
# Write merged config # Write merged config
print(kconf.write_config(config_out)) print(kconf.write_config(config_out))
# Write headers # Write headers
print(kconf.write_autoconf(header_out)) print(kconf.write_autoconf(header_out))
with open(header_out, 'r+') as header_file: with open(header_out, 'r+') as header_file:
content = header_file.read() content = header_file.read()
header_file.truncate(0) header_file.truncate(0)
header_file.seek(0) header_file.seek(0)
# Remove CONFIG_ and MR_USING_XXX following number # Remove CONFIG_ and MR_USING_XXX following number
content = content.replace("#define CONFIG_", "#define ") content = content.replace("#define CONFIG_", "#define ")
content = re.sub(r'#define MR_USING_(\w+) (\d+)', r'#define MR_USING_\1', content) content = re.sub(r'#define MR_USING_(\w+) (\d+)', r'#define MR_USING_\1', content)
# Add the micro # Add the micro
header_file.write("#ifndef _MR_CONFIG_H_\n") header_file.write("#ifndef _MR_CONFIG_H_\n")
header_file.write("#define _MR_CONFIG_H_\n\n") header_file.write("#define _MR_CONFIG_H_\n\n")
header_file.write("#ifdef __cplusplus\n") header_file.write("#ifdef __cplusplus\n")
header_file.write("extern \"C\" {\n") header_file.write("extern \"C\" {\n")
header_file.write("#endif /* __cplusplus */\n\n") header_file.write("#endif /* __cplusplus */\n\n")
# Write back the original data # Write back the original data
@@ -49,12 +59,14 @@ def generate_config(kconfig_file,config_in, config_out, header_out):
header_file.write("#endif /* __cplusplus */\n\n") header_file.write("#endif /* __cplusplus */\n\n")
header_file.write("#endif /* _MR_CONFIG_H_ */\n") header_file.write("#endif /* _MR_CONFIG_H_ */\n")
def main(): def main():
kconfig_file = 'Kconfig' kconfig_file = 'Kconfig'
config_in = '.config' config_in = '.config'
config_out = '.config' config_out = '.config'
header_out = 'include/mr_config.h' header_out = 'include/mr_config.h'
generate_config(kconfig_file, config_in, config_out, header_out) generate_config(kconfig_file, config_in, config_out, header_out)
if __name__ == "__main__": if __name__ == "__main__":
main() main()