Skip to content

Commit df1c633

Browse files
committed
Update.
1 parent 9e6a3b8 commit df1c633

File tree

26 files changed

+657
-23
lines changed

26 files changed

+657
-23
lines changed

docs/code_gen/stm32/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ xr_cubemx_cfg -d .
3434
[INFO] LibXR submodule already exists. Checking for updates...
3535
[INFO] [OK] cd . && git submodule update --init --recursive
3636
[INFO] LibXR submodule updated.
37-
Found .ioc file: .\atom.ioc
37+
Found .ioc file: ./atom.ioc
3838
Parsing .ioc file...
39-
[INFO] [OK] xr_parse_ioc -d . -o .\.config.yaml
39+
[INFO] [OK] xr_parse_ioc -d . -o ./.config.yaml
4040
Generating C++ code...
41-
[INFO] [OK] xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp
41+
[INFO] [OK] xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp
4242
Modifying STM32 interrupt files...
43-
[INFO] [OK] xr_stm32_it .\Core/Src
43+
[INFO] [OK] xr_stm32_it ./Core/Src
4444
[INFO] [OK] xr_stm32_cmake .
4545
[INFO] [Pass] All tasks completed successfully!
4646
```
@@ -62,7 +62,7 @@ Modifying STM32 interrupt files...
6262
├── Core/Src/stm32f1xx_it.c # 补丁后的中断处理函数
6363
├── cmake/LibXR.CMake # LibXR 构建配置
6464
├── CMakeLists.txt # 自动集成 LibXR
65-
└── Middlewares\Third_Party\LibXR # Git 子模块:LibXR 本体
65+
└── Middlewares/Third_Party/LibXR # Git 子模块:LibXR 本体
6666
```
6767

6868
---

docs/code_gen/stm32/adc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ ADC:
4343
可直接修改该文件。如需应用更新配置,请执行以下任一命令以重新生成代码:
4444
`xr_cubemx_cfg -d .`
4545
46-
`xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp`
46+
`xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp`

docs/code_gen/stm32/can.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ FDCAN:
3636
可直接修改该配置文件。如需应用更改,请执行以下命令重新生成代码:
3737
`xr_cubemx_cfg -d .`
3838
39-
`xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp`
39+
`xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp`

docs/code_gen/stm32/i2c.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ I2C:
3333
可直接修改该文件。如需应用更新配置,请执行以下任一命令以重新生成代码:
3434
`xr_cubemx_cfg -d .`
3535
36-
`xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp`
36+
`xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp`

docs/code_gen/stm32/spi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ SPI:
3131
可直接修改该文件。如需应用更新配置,请执行以下任一命令以重新生成代码:
3232
`xr_cubemx_cfg -d .`
3333
34-
`xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp`
34+
`xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp`

docs/code_gen/stm32/timer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PlatformInit(2, 512);
4242

4343
## 配置文件
4444

45-
对于非裸机环境,会在`User\libxr_config.yaml`中生成如下配置:
45+
对于非裸机环境,会在`User/libxr_config.yaml`中生成如下配置:
4646

4747
```yaml
4848
software_timer:
@@ -53,4 +53,4 @@ software_timer:
5353
可直接修改该文件。如需应用更新配置,请执行以下任一命令以重新生成代码:
5454
`xr_cubemx_cfg -d .`
5555
56-
`xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp`
56+
`xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp`

docs/code_gen/stm32/uart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ USB:
6464
可直接修改该文件。如需应用更新配置,请执行以下任一命令以重新生成代码:
6565
`xr_cubemx_cfg -d .`
6666
67-
`xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp`
67+
`xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp`

docs/code_gen/xrobot_inter.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
id: code-gen-xrobot-inter
3+
title: 与XRobot集成
4+
sidebar_position: 2
5+
---
6+
7+
# 与XRobot集成
8+
9+
在代码生成时加入`--xrobot`选项,可以生成对应的硬件容器(LibXR::HardwareContainer)以供XRobot初始化。
10+
11+
## 示例
12+
13+
```bash
14+
xr_gen_code_stm32 -i .\.config.yaml -o .\User\app_main.cpp --xrobot
15+
[INFO] Detected FreeRTOS configuration
16+
[INFO] FlashLayout is generated and injected, MCU: STM32G431KBU6
17+
[INFO] Flash layout map written to: .\User\flash_map.hpp
18+
[INFO] Successfully generated: .\User
19+
[INFO] Generated header file: app_main.h
20+
```
21+
22+
会在app_main.cpp中额外生成以下代码:
23+
24+
```cpp
25+
LibXR::HardwareContainer<
26+
LibXR::Entry<LibXR::PowerManager>,
27+
...
28+
> peripherals{
29+
LibXR::Entry<LibXR::PowerManager>(power_manager)
30+
...
31+
};
32+
33+
XRobotMain(peripherals);
34+
```
35+
36+
同时在libxr_config.yaml中添加外设别名,上层代码可依靠这些别名访问外设:
37+
38+
```yaml
39+
device_aliases:
40+
power_manager:
41+
type: PowerManager
42+
aliases:
43+
- power_manager
44+
LED:
45+
type: GPIO
46+
aliases:
47+
- LED
48+
- led_red
49+
...
50+
```

docs/proj_man/add_mod.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
id: proj-man-add-mod
3+
title: 添加模块
4+
sidebar_position: 4
5+
---
6+
7+
# 添加模块
8+
9+
通过`xrobot_add_mod`工具可以快速添加一个新模块到仓库,或者从仓库中选择一个模块创建实例。
10+
11+
## 使用方法
12+
13+
### 添加远程模块到仓库
14+
15+
--version可以省略,使用时要确保对应分支存在。
16+
17+
```bash
18+
$ xrobot_add_mod https://github.com/yourorg/BlinkLED.git --version main
19+
[SUCCESS] Added repo module 'BlinkLED' to Modules/modules.yaml
20+
```
21+
22+
然后拉取模块:
23+
24+
```bash
25+
$ xrobot_init_mod
26+
[INFO] Cloning new module: BlinkLED
27+
Cloning into 'Modules/BlinkLED'...
28+
remote: Enumerating objects: 22, done.
29+
remote: Counting objects: 100% (22/22), done.
30+
remote: Compressing objects: 100% (15/15), done.
31+
remote: Total 22 (delta 7), reused 22 (delta 7), pack-reused 0 (from 0)
32+
Receiving objects: 100% (22/22), done.
33+
Resolving deltas: 100% (7/7), done.
34+
[SUCCESS] All modules processed
35+
```
36+
37+
### 创建模块实例
38+
39+
```bash
40+
$ xrobot_add_mod BlinkLED
41+
[SUCCESS] Appended module instance 'BlinkLED' to User/xrobot.yaml
42+
43+
# 重新生成代码
44+
$ xrobot_gen_main
45+
...
46+
```

docs/proj_man/create_mod.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
id: proj-man-create-mod
3+
title: 快速创建模块
4+
sidebar_position: 3
5+
---
6+
7+
XRobot 提供了快速创建模块的工具 `xrobot_create_mod`,可以从模板中快速创建一个新模块,用于快速开发模块,无需手动创建模块仓库和模块头文件。
8+
9+
## 使用方法
10+
11+
```bash
12+
$ xrobot_create_mod MySensor --desc "IMU interface module" --hw imu scl sda
13+
[OK] Module MySensor generated at Modules/MySensor
14+
```
15+
16+
通过xrobot_mod_parser查看模块信息:
17+
18+
```bash
19+
$ xrobot_mod_parser --path ./Modules/MySensor/
20+
21+
=== Module: MySensor ===
22+
Description : IMU interface module
23+
24+
Constructor Args :
25+
- name = your_arg_name_here
26+
27+
Required Hardware : imu scl sda
28+
```
29+
30+
模块的目录结构如下:
31+
32+
```bash
33+
Modules/
34+
└── BlinkLED/
35+
├── BlinkLED.hpp # 带 manifest 的头文件
36+
├── README.md # 模块文档
37+
└── CMakeLists.txt # 构建配置
38+
```
39+
40+
标准的MANIFEST(模块信息)格式如下:
41+
42+
```yaml
43+
// clang-format off
44+
/* === MODULE MANIFEST ===
45+
module_name: BlinkLED
46+
module_description: 控制 LED 闪烁的简单模块 / A simple module to control LED blinking
47+
constructor_args:
48+
- blink_cycle: 250
49+
required_hardware: led/LED/led1/LED1
50+
repository: https://github.com/xrobot-org/BlinkLED
51+
=== END MANIFEST === */
52+
// clang-format on
53+
```

docs/proj_man/gen_main.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
id: proj-man-gen-main
3+
title: 生成主函数
4+
sidebar_position: 2
5+
---
6+
7+
XRobot 提供了自动主函数生成工具 `gen_xrobot_main.py`,可根据每个模块头文件中的 MANIFEST 信息,自动提取构造参数并生成统一入口函数 `XRobotMain`,用于快速搭建完整的嵌入式应用框架。
8+
9+
## 基本用法
10+
11+
### 无配置文件
12+
13+
会创建一个模板yaml文件,并在当前目录下生成函数入口文件。模板文件会为当前所有模块创建一个实例,并填入默认参数。
14+
15+
```bash
16+
$ xrobot_gen_main
17+
Discovered modules: BlinkLED
18+
[INFO] Successfully parsed manifest for BlinkLED
19+
[INFO] Writing configuration to User/xrobot.yaml
20+
[SUCCESS] Generated entry file: User/xrobot_main.hpp
21+
```
22+
23+
User/xrobot.yaml如下所示,可以直接修改此文件并重新生成代码:
24+
25+
```yaml
26+
global_settings:
27+
monitor_sleep_ms: 1000
28+
modules:
29+
- name: BlinkLED
30+
constructor_args:
31+
blink_cycle: 250
32+
```
33+
34+
生成的xrobot_main.hpp如下所示:
35+
36+
```cpp
37+
#include "app_framework.hpp"
38+
#include "libxr.hpp"
39+
40+
// Module headers
41+
#include "BlinkLED.hpp"
42+
43+
template <typename HardwareContainer>
44+
static void XRobotMain(HardwareContainer &hw) {
45+
using namespace LibXR;
46+
ApplicationManager appmgr;
47+
48+
// Auto-generated module instantiations
49+
static BlinkLED<HardwareContainer> blinkled(hw, appmgr, 250);
50+
51+
while (true) {
52+
appmgr.MonitorAll();
53+
Thread::Sleep(1000);
54+
}
55+
}
56+
```
57+
58+
### 存在配置文件
59+
60+
会直接读取配置文件,并生成函数入口文件。
61+
62+
```bash
63+
$ xrobot_gen_main --config User/xrobot.yaml
64+
[INFO] Using existing configuration file: User/xrobot.yaml
65+
[SUCCESS] Generated entry file: User/xrobot_main.hpp
66+
```

docs/proj_man/init_mod.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
id: proj-man-init-mod
3+
title: 初始化模块仓库
4+
sidebar_position: 1
5+
---
6+
7+
# 初始化模块仓库
8+
9+
XRobot提供了模块初始化工具`xrobot_init_mod`,可以通过本地或远程yaml文件初始化模块仓库。
10+
11+
## 使用方法
12+
13+
### 无本地/远程配置文件
14+
15+
```bash
16+
# 第一次运行会创建一个模板yaml文件
17+
$ xrobot_init_mod
18+
[WARN] Configuration file not found, creating template: Modules/modules.yaml
19+
[INFO] Please edit the configuration file and rerun this script.
20+
21+
# 第二次运行会根据配置文件初始化模块仓库
22+
$ xrobot_init_mod
23+
[INFO] Cloning new module: BlinkLED
24+
Cloning into 'Modules/BlinkLED'...
25+
remote: Enumerating objects: 22, done.
26+
remote: Counting objects: 100% (22/22), done.
27+
remote: Compressing objects: 100% (15/15), done.
28+
remote: Total 22 (delta 7), reused 22 (delta 7), pack-reused 0 (from 0)
29+
Receiving objects: 100% (22/22), done.
30+
Resolving deltas: 100% (7/7), done.
31+
[SUCCESS] All modules processed
32+
```
33+
34+
### 本地配置文件
35+
36+
使用--config选项指定本地配置文件,初始化模块仓库。
37+
38+
```bash
39+
$ xrobot_init_mod --config Modules/modules.yaml
40+
[INFO] Updating module: BlinkLED
41+
Already up to date.
42+
Already on 'master'
43+
Your branch is up to date with 'origin/master'.
44+
[SUCCESS] All modules processed
45+
```
46+
47+
### 远程配置文件
48+
49+
使用--config选项指定远程配置文件,初始化模块仓库。
50+
51+
```bash
52+
$ xrobot_init_mod --config https://raw.githubusercontent.com/${user_or_org_name}/${repo_name}/refs/heads/${branch_name}/${yaml_file_name}.yaml
53+
[INFO] Cloning new module: BlinkLED
54+
Cloning into 'Modules/BlinkLED'...
55+
remote: Enumerating objects: 22, done.
56+
remote: Counting objects: 100% (22/22), done.
57+
remote: Compressing objects: 100% (15/15), done.
58+
remote: Total 22 (delta 7), reused 22 (delta 7), pack-reused 0 (from 0)
59+
Receiving objects: 100% (22/22), done.
60+
Resolving deltas: 100% (7/7), done.
61+
[SUCCESS] All modules processed
62+
```
63+
64+
## CMakeLists.txt 集成 XRobot
65+
66+
在工程的CMakeLists.txt文件中添加:
67+
68+
```cmake
69+
# Add XRobot Modules
70+
include(${CMAKE_CURRENT_LIST_DIR}/Modules/CMakeLists.txt)
71+
```

docs/proj_man/setup.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
id: proj-man-setup
3+
title: 一键配置
4+
sidebar_position: 5
5+
---
6+
7+
# 一键配置
8+
9+
XRobot 提供了一键配置的工具 `xrobot_setup`,可以快速配置项目,包括模块拉取、配置和主函数生成等。
10+
11+
## 使用方法
12+
13+
```bash
14+
$ xrobot_setup
15+
Starting XRobot auto-configuration
16+
[EXEC] xrobot_init_mod --config Modules/modules.yaml --dir Modules
17+
[INFO] Updating module: BlinkLED
18+
Already up to date.
19+
Already on 'master'
20+
Your branch is up to date with 'origin/master'.
21+
[SUCCESS] All modules processed
22+
[INFO] Generated default Modules/CMakeLists.txt at: Modules/CMakeLists.txt
23+
[EXEC] xrobot_gen_main --output User/xrobot_main.hpp --config User/xrobot.yaml
24+
Discovered modules: BlinkLED
25+
[INFO] Using existing configuration file: User/xrobot.yaml
26+
[SUCCESS] Generated entry file: User/xrobot_main.hpp
27+
```

0 commit comments

Comments
 (0)