libxr


Namelibxr JSON
Version 0.4.1 PyPI version JSON
download
home_pageNone
SummaryC++ code generator for LibXR-based embedded systems, supporting STM32 and modular robotics applications.
upload_time2025-07-08 15:29:10
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache-2.0
keywords code generation embedded systems automation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">
<img src="https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/raw/main/imgs/XRobot.jpeg" width="300">
</h1><br>

[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
[![GitHub Repo](https://img.shields.io/github/stars/Jiu-xiao/libxr?style=social)](https://github.com/Jiu-xiao/libxr)
[![Documentation](https://img.shields.io/badge/docs-online-brightgreen)](https://jiu-xiao.github.io/libxr/)
[![GitHub Issues](https://img.shields.io/github/issues/Jiu-xiao/LibXR_CppCodeGenerator)](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/issues)
[![CI/CD - Python Package](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/actions/workflows/python-publish.yml)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator?ref=badge_shield)

`libxr` 是一个 Python 包,用于自动化嵌入式系统开发。它通过解析硬件配置文件并生成对应的 C++ 工程代码,显著降低嵌入式开发中的重复性工作。目前默认支持 STM32 平台,后续将扩展至更多硬件体系结构。

`libxr` is a Python package for automating embedded system development. It parses hardware configuration files and generates corresponding C++ project code, significantly reducing repetitive manual work. STM32 is supported by default, with more hardware architectures planned.

## 🌟 Features 功能亮点

- 🧠 自动生成设备驱动和应用程序框架。  
  Automatically generates device drivers and application scaffolding.

- ⚙️ 支持多种后端架构,默认支持 STM32 平台。  
  Supports multiple backends; STM32 is the default.

- 🔌 支持多重别名注册与查找。  
  Supports multi-alias registration and lookup.

- 📦 可与 XRobot 框架集成,实现模块自动注册与调度管理。  
  Enables integration with the XRobot application framework.

## 📥 Installation 安装

### 使用pipx安装 (Install via `pipx`)

windows

```ps
python -m pip install --user pipx
python -m pipx ensurepath
pipx install libxr
pipx ensurepath
# Restart your terminal
```

linux

```bash
sudo apt install pipx
pipx install libxr
pipx ensurepath
# Restart your terminal
```

### 使用 pip 安装 (Install via `pip`)

```bash
pip install libxr
```

### 从源码安装 (Install from source)

```bash
git clone https://github.com/Jiu-xiao/LibXR_CppCodeGenerator.git
cd LibXR_CppCodeGenerator
python3 ./scripts/gen_libxr_version.py
pip install -e .
```

---

## 🔧 General 通用命令(跨平台支持)

以下命令适用于所有平台(如 STM32 及未来支持的架构)。  
These commands work across platforms (STM32 and others):

### `xr_parse`

```bash
xr_parse -i config.yaml
```

解析通用的 YAML 硬件配置文件,提取外设定义。  
Parses a generic YAML hardware configuration and extracts peripheral definitions.

### `xr_gen_code`

```bash
xr_gen_code -i config.yaml [--xrobot]
```

根据 YAML 配置生成平台无关的 C++ 硬件抽象层代码,可选生成 XRobot 集成代码。  
Generates platform-agnostic C++ hardware abstraction code from YAML.

---

## STM32 工程工具 (STM32 Project Tools)

### `xr_cubemx_cfg`

自动配置 STM32CubeMX 工程  
Automatically configures an STM32CubeMX project.

```bash
usage: xr_cubemx_cfg [-h] -d DIRECTORY [-t TERMINAL] [-c] [--xrobot]
```

解析 `.ioc` 文件,生成 YAML 和 C++ 驱动代码,补丁中断处理函数,并初始化项目结构  
Parses `.ioc`, generates YAML and C++ code, patches interrupt handlers, and initializes the project structure.

#### 🔧 必选参数 (Required)

- `-d, --directory <DIRECTORY>`:

  STM32CubeMX 工程路径  
  Path to the STM32CubeMX project.

#### ⚙️ 可选参数 (Optional)

- `-t, --terminal <TERMINAL>`:
  
  串口设备名称(如 `usart1` `usb`)  
  Terminal device name (e.g. `usart1` `usb`).

- `-c, --clang`:

  启用 Clang 构建支持  
  Enable Clang build support.

- `--xrobot`:

  生成 XRobot Glue 代码  
  Enable XRobot glue code generation.

- `--commit`
  
  指定 LibXR 仓库commit版本  
  Specify the LibXR repository commit version

#### 📦 输出内容 (Outputs)

- `.config.yaml`:

  自动生成的 C++ 驱动代码(如 `app_main.cpp`  
  Generated C++ driver code (e.g. `app_main.cpp`)

- 补丁后的中断处理函数(如 `stm32xx_it.c`)  
  Patched interrupt handlers (e.g. `stm32xx_it.c`)

- `CMakeLists.txt`、`.gitignore`  

- 初始化的 Git 仓库及 LibXR 子模块  
  Initialized Git repository and LibXR submodule

---

### `xr_parse_ioc`

自动解析 STM32CubeMX 工程配置  
Parses `.ioc` files from STM32CubeMX projects and exports structured YAML.

```bash
usage: xr_parse_ioc [-h] -d DIRECTORY [-o OUTPUT] [--verbose]
```

解析 `.ioc` 文件为 `.config.yaml`,并在终端输出解析摘要  
Parses `.ioc` files and creates `.config.yaml` with a readable summary.

#### 🔧 必选参数 (Required)

- `-d, --directory <DIRECTORY>`  
  `.ioc` 文件所在目录路径  
  Path to the input directory containing `.ioc` files.

#### ⚙️ 可选参数 (Optional)

- `-o, --output <FILE>`  
  自定义 YAML 输出路径(默认与 `.ioc` 同名)  
  Custom YAML output path (default: `<input_file>.yaml`).

- `--verbose`  
  启用调试日志,输出详细解析过程  
  Enable verbose logging.

#### 📦 输出内容 (Outputs)

- `.config.yaml`:

  包含 GPIO、外设、DMA、FreeRTOS、MCU 等配置  
  YAML file containing GPIO, peripheral, DMA, FreeRTOS, and MCU configurations.

- 控制台摘要:MCU 信息、GPIO 数量、外设统计等  
  Console summary: MCU information, GPIO count, peripheral statistics, etc.

---

### `xr_gen_code_stm32`

根据 YAML 配置生成 STM32 硬件抽象层代码,可选生成 XRobot 集成代码。  
Generates STM32 application code from YAML.

```bash
usage: xr_gen_code_stm32 [-h] -i INPUT -o OUTPUT [--xrobot] [--libxr-config LIBXR_CONFIG]
```

#### 🔧 Required

- `-i`:

  `.config.yaml` 配置文件路径  
  Path to `.config.yaml`

- `-o`:

  生成代码输出目录  
  Output directory

#### ⚙️ Optional

- `--xrobot`:

  启用 XRobot glue 代码生成  
  Enable XRobot glue generation

- `--libxr-config`:

  自定义 libxr_config.yaml 路径(可为本地或远程)  
  Path or URL to runtime config YAML

#### 📦 Outputs

- `app_main.cpp`:  
  主入口文件,包含所有初始化逻辑  
  Main entry point with all initialization logic

- `libxr_config.yaml`:  
  运行时配置文件,可自定义缓冲区大小、队列等参数  
  Runtime config YAML, can be customized with buffer size, queue, etc.

- `flash_map.hpp`:  
  自动生成的 Flash 扇区表,供 Flash 抽象层使用  
  Auto-generated flash sector layout for use with Flash abstraction layer

---

### `xr_stm32_flash`

解析 STM32 型号,生成 Flash 扇区信息表(YAML 格式输出)。  
Parses STM32 model name and generates flash layout info (YAML output).

```bash
usage: xr_stm32_flash <STM32_MODEL>
```

### 🧠 功能说明 (Functionality)

- 根据 STM32 型号名称自动推导 Flash 大小  
  Automatically infers flash size from the STM32 model string

- 根据芯片系列(如 F1/F4/H7/U5 等)生成对应的扇区布局  
  Generates sector layout depending on the chip series (e.g., F1/F4/H7/U5)

- 输出包括每个扇区的地址、大小和索引  
  Output includes address, size, and index of each sector

### 📦 输出内容 (Outputs)

- YAML 格式的 Flash 信息  
  Flash info in YAML format:

```yaml
model: STM32F103C8
flash_base: '0x08000000'
flash_size_kb: 64
sectors:
- index: 0
  address: '0x08000000'
  size_kb: 1.0
- index: 1
  address: '0x08000400'
  size_kb: 1.0
  ...
```

---

### `xr_stm32_it`

批量修改 STM32 中断处理文件,插入 UART IDLE 回调和 USB F1 回调支持。
Modifies STM32 interrupt handlers to add UART IDLE callback and USB F1 callback support for LibXR.

```bash
usage: xr_stm32_it [-h] input_dir
```

#### 🔧 必选参数 (Required)

- `input_dir`:

  包含 `*_it.c` 文件的文件夹路径  
  Directory containing the `*_it.c` source files.

#### ⚙️ 功能说明 (Functionality)

- 查找每个 `*_it.c` 文件中的 `HAL_UART_IRQHandler(&huartX)` 调用  
  Find `HAL_UART_IRQHandler(&huartX)` calls in each `*_it.c` file

- 查找 `USB_HP_CAN1_TX_IRQHandler` 和 `USB_LP_CAN1_RX0_IRQHandler` 中断函数  
  Find `USB_HP_CAN1_TX_IRQHandler` and `USB_LP_CAN1_RX0_IRQHandler` handlers

- 向对应中断函数的 `/* USER CODE BEGIN XXX_IRQn 0/1 */` 区域插入:  
  Add to the `/* USER CODE BEGIN XXX_IRQn 0/1 */` section of the corresponding interrupt function
  
```c
  /* LibXR UART IDLE callback (Auto-generated) */
#ifdef HAL_UART_MODULE_ENABLED
  STM32_UART_ISR_Handler_IDLE(&huartX);
#endif
```

- 对于 USB 中断(仅 STM32F1,且启用 HAL_PCD_MODULE),插入:  
  For USB interrupts (STM32F1 only, with HAL_PCD_MODULE enabled)

```c
/* LibXR USB Tx Cplt callback (Auto-generated, For STM32F1) */
#if defined(STM32F1) && defined(HAL_PCD_MODULE_ENABLED)
  STM32_USB_ISR_Handler_F1();
#endif
```

- 若未定义 `STM32_UART_ISR_Handler_IDLE`和 `STM32_USB_ISR_Handler_F1`的 `extern` 声明,将插入至 `/* USER CODE BEGIN 0 */` 区域下  
  Insert at `/* USER CODE BEGIN 0 */` if `STM32_UART_ISR_Handler_IDLE` and `STM32_USB_ISR_Handler_F1` is not defined

- 支持多个 UART 和 USB 接口  
  Support for multiple UART and USB interfaces

#### 📦 输出内容 (Outputs)

- 被修改的 `*_it.c` 文件  
  Modified `*_it.c` files

- 控制台输出修改摘要,包括修改的文件与函数名称  
  Console output summary, including modified files and function names

---

### `xr_stm32_clang`

自动修改 STM32 工程,适配 Clang 编译工具链。  
Creates Clang-compatible toolchain file.

```bash
usage: xr_stm32_clang [-h] input_dir
```

#### 🔧 必选参数 (Required)

- `input_dir`:

  包含 `gcc-arm-none-eabi.cmake` 的 STM32 工程目录路径  
  Directory containing `gcc-arm-none-eabi.cmake` for the STM32 project

#### ⚙️ 功能说明 (Functionality)

- 在 `{input_dir}/cmake/` 中查找 `gcc-arm-none-eabi.cmake` 文件  
  Locate `gcc-arm-none-eabi.cmake` inside `{input_dir}/cmake/`

- 解析其中的 `linker_script` 路径与 `-mcpu` 编译器参数  
  Extract `linker_script` path and `-mcpu` target flag

- 自动生成 `gcc-arm-none-eabi.cmake` 文件,适配 Clang 编译工具链  
  Generate Clang-compatible `gcc-arm-none-eabi.cmake` toolchain file

- 自动修改 `CMakeLists.txt` 文件,插入  
  Automatically modify `CMakeLists.txt` to include:
  
  ```cmake
  include("cmake/gcc-arm-none-eabi.cmake")
  ```

#### 📦 输出内容 (Outputs)

- 覆盖原有 `gcc-arm-none-eabi.cmake` 文件  
  Overwrites original `gcc-arm-none-eabi.cmake` file

- 自动添加或更新 `CMakeLists.txt` 文件中的 include 指令  
  Auto-updates `CMakeLists.txt` to include the toolchain file

---

### `xr_libxr_cmake`

为 STM32CubeMX 工程生成 `LibXR.CMake` 配置,并自动集成至 `CMakeLists.txt`。  
Generates `LibXR.CMake` file and injects it into the STM32CubeMX CMake project.

```bash
usage: xr_libxr_cmake [-h] input_dir
```

#### 🔧 必选参数 (Required)

- `input_dir`:

  指定 CubeMX 生成的 CMake 工程根目录  
  Path to the CubeMX-generated CMake project root

#### ⚙️ 功能说明 (Functionality)

- 自动生成 `cmake/LibXR.CMake` 文件,内容包括:  
  Generate `cmake/LibXR.CMake` containing:
  
  - 添加 `LibXR` 子目录  
    Add `LibXR` as a subdirectory
  
  - 链接 `xr` 静态库  
    Link the `xr` static library
  
  - 添加 `Core/Inc`、`User` 目录为包含路径  
    Include `Core/Inc` and `User` directories
  
  - 添加 `User/*.cpp` 为源文件  
    Add `User/*.cpp` to project sources

- 自动检测是否启用 FreeRTOS:  
  Auto-detect FreeRTOS configuration:
  
  - 存在 `Core/Inc/FreeRTOSConfig.h` → `LIBXR_SYSTEM=FreeRTOS`
  - 否则设置为 `None`

- 自动删除旧的 `build/` 目录(如存在)  
  Automatically deletes existing `build/` directory if found

- 自动向主 `CMakeLists.txt` 添加以下指令(若尚未包含):  
  Auto-appends the following line to `CMakeLists.txt` if missing:

  ```cmake
  include(${CMAKE_CURRENT_LIST_DIR}/cmake/LibXR.CMake)
  ```

#### 📦 输出内容 (Outputs)

- 生成 `cmake/LibXR.CMake` 文件  
  Generates `cmake/LibXR.CMake` file

- 修改主工程的 `CMakeLists.txt`,插入 `include(...)`  
  Updates `CMakeLists.txt` to include `LibXR.CMake`

- 删除原有构建缓存目录 `build/`(如存在)  
  Deletes the old `build/` directory if present

---

### STM32 工程要求  (STM32 Project Requirements)

#### 📁 项目结构要求(Project Structure)

- 必须为 **STM32CubeMX 导出的 CMake 工程**  
  Must be a CMake project exported from STM32CubeMX

- 项目应包含以下路径:  
  Project should contain the following directories:

  - `xx.ioc`
  - `CMakeLists.txt`
  - `cmake/gcc-arm-none-eabi.cmake`
  - `Core/Inc`, `Core/Src`

#### ⚙️ 配置要求(Peripheral & Middleware)

- 所有 **UART / SPI / I2C** 外设必须启用 **DMA**  
  All **UART / SPI / I2C** peripherals must have **DMA** enabled

- 如果ADC启用了DMA,请开启连续转换模式  
  If ADC has DMA enabled, enable continuous mode

- 推荐启用 **FreeRTOS**,自动生成 `FreeRTOSConfig.h`  
  Recommended to enable **FreeRTOS** and generate `FreeRTOSConfig.h`

- 若使用 USB 作为终端:  
  If using USB as a terminal:

  - 启用 `USB_DEVICE` 中间件,并选择 `Communication Device Class (CDC)`  
    Enable `USB_DEVICE` middleware and select `Communication Device Class (CDC)`

#### ⏱️ Timebase 配置建议(Timebase Configuration)

> ✅ 强烈推荐使用 `TIM6`/`TIM7` 等 Timer 作为 Timebase  
    Strongly recommended to use `TIM6`/`TIM7` Timers as Timebase  
> ✅ 并将该中断优先级设置为 **最高(0)**  
    And set the interrupt priority to **highest (0)**

---

## 🧩 代码生成后操作 (After Code Generation)

生成代码后,你需要**手动添加**以下内容:  
After generating code, you must **manually add** the following:  

```cpp
#include "app_main.h"
```

并在合适位置调用 `app_main();`:  
And call `app_main();` in the appropriate location:

| 场景 (Scenario)       | 添加位置        |Where to add|
|-----------------------|------------------------------------| -----------|
| 🟢 Bare metal 裸机工程 | `main()` 函数末尾   | End of `main()` |
| 🔵 FreeRTOS 工程       | 线程入口       | Thread entry function |

---

## LibXR / LibXR_CppCodeGenerator / XRobot Relationship

LibXR、LibXR_CppCodeGenerator 与 XRobot 三者形成了一套完整的嵌入式与机器人软件开发体系,分工明确,协同紧密。  
LibXR, LibXR_CppCodeGenerator and XRobot together form a complete software ecosystem for embedded and robotics development, with clear separation of concerns and tight integration.

---

### 🧠 LibXR

**LibXR 是跨平台的驱动抽象与工具库**,支持 STM32、Linux 等平台,包含:  
LibXR is a cross-platform driver abstraction and utility library supporting STM32, Linux, and more. It provides:

- 通用外设接口封装  
  Unified peripheral interface abstraction  
- 嵌入式组件(如 Terminal、PowerManager、Database 等)  
  Embedded modules like Terminal, PowerManager, Database, etc.  
- FreeRTOS / bare-metal 支持  
  FreeRTOS and bare-metal support  
- 机器人运动学与导航  
  Kinematics and navigation libraries for robotics  
- 自动代码生成支持  
  Code generation support

#### 🔗 Links

- **Repository**: [libxr](https://github.com/Jiu-xiao/libxr)  
- **API Documentation**: [API](https://jiu-xiao.github.io/libxr/)  
- **Issues**: [Issue Tracker](https://github.com/Jiu-xiao/libxr/issues)

---

### 🔧 LibXR_CppCodeGenerator

**LibXR_CppCodeGenerator 是用于 LibXR 的代码生成工具链**,当前支持 STM32 + CubeMX,未来将扩展至 Zephyr、ESP-IDF 等平台。  
LibXR_CppCodeGenerator is a code generation toolchain for LibXR. It currently supports STM32 with CubeMX, and is planned to support Zephyr, ESP-IDF, and more.

- 从不同平台的工程文件生成 `.yaml` 配置  
  Parse project files from different platforms to generate `.yaml` configurations
- 基于 `.yaml` 自动生成 `app_main.cpp`、中断、CMake 等  
  Generate `app_main.cpp`, interrupt handlers, and CMake integration  
- 支持 `XRobot` glue 层集成  
  Supports optional integration with XRobot framework  
- 支持用户代码保留与多文件结构  
  Preserves user code blocks and supports modular output

#### 🔗 Links

- **Repository**: [LibXR_CppCodeGenerator](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator)  
- **Documentation and Releases**: [PyPI](https://pypi.org/project/libxr/)  
- **Issues**: [Issue Tracker](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/issues)

---

### 🤖 XRobot

XRobot 是一个轻量级的模块化应用管理框架,专为嵌入式设备而设计。它本身不包含任何驱动或业务代码,专注于模块的注册、调度、生命周期管理、事件处理与参数配置。  
**XRobot is a lightweight modular application management framework designed for embedded systems.**  
It does not include any drivers or business logic by itself. Instead, it focuses on module registration, scheduling, lifecycle management, event handling, and parameter configuration.

- 模块注册与生命周期管理  
  Module registration and lifecycle management  
- 参数管理 / 配置系统 / 事件系统  
  Parameter management, configuration system, and event system  
- ApplicationRunner / ThreadManager 等应用调度器  
  ApplicationRunner and ThreadManager for runtime coordination  
- 不直接访问硬件,依赖 LibXR 的 PeripheralManager  
  Does not access hardware directly, relies on LibXR's PeripheralManager

---

#### ✅ Recommended For 推荐使用场景

- 拥有多个子模块(如传感器、通信、控制器)且希望统一管理初始化、调度与资源依赖  
  For projects with multiple submodules (e.g., sensors, communication, controllers) needing unified lifecycle and dependency management.

- 希望构建平台无关的应用层逻辑,与底层驱动解耦  
  For building platform-independent application logic decoupled from hardware drivers.

- 与 **LibXR** 结合使用,实现自动注册硬件对象(通过 `HardwareContainer`)  
  When used with **LibXR**, supports automatic hardware registration via `HardwareContainer`.

- 支持生成模块入口代码、配置逻辑名与硬件名的映射,便于快速适配不同硬件配置  
  Supports generating module entry code and logical-to-physical hardware name mapping for quick adaptation to different platforms.

#### 🔗 Links

- **Repository**: [XRobot](https://github.com/xrobot-org/XRobot)  
- **Documentation**: [GitHub Pages](https://xrobot-org.github.io)  
- **Releases**: [PyPI](https://pypi.org/project/xrobot)  
- **Issues**: [Issue Tracker](https://github.com/xrobot-org/XRobot/issues)

---

## 📄 License

Licensed under **Apache-2.0**. See [LICENSE](LICENSE).


[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator?ref=badge_large)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "libxr",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Xiao <2592509183@qq.com>",
    "keywords": "code generation, embedded systems, automation",
    "author": null,
    "author_email": "Xiao <2592509183@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/dc/85/7b04df7844cd50246692c4b2e3e191763e3a755394258820553090b86287/libxr-0.4.1.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">\r\n<img src=\"https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/raw/main/imgs/XRobot.jpeg\" width=\"300\">\r\n</h1><br>\r\n\r\n[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)\r\n[![GitHub Repo](https://img.shields.io/github/stars/Jiu-xiao/libxr?style=social)](https://github.com/Jiu-xiao/libxr)\r\n[![Documentation](https://img.shields.io/badge/docs-online-brightgreen)](https://jiu-xiao.github.io/libxr/)\r\n[![GitHub Issues](https://img.shields.io/github/issues/Jiu-xiao/LibXR_CppCodeGenerator)](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/issues)\r\n[![CI/CD - Python Package](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/actions/workflows/python-publish.yml)\r\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator?ref=badge_shield)\r\n\r\n`libxr` \u662f\u4e00\u4e2a Python \u5305\uff0c\u7528\u4e8e\u81ea\u52a8\u5316\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u3002\u5b83\u901a\u8fc7\u89e3\u6790\u786c\u4ef6\u914d\u7f6e\u6587\u4ef6\u5e76\u751f\u6210\u5bf9\u5e94\u7684 C++ \u5de5\u7a0b\u4ee3\u7801\uff0c\u663e\u8457\u964d\u4f4e\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u7684\u91cd\u590d\u6027\u5de5\u4f5c\u3002\u76ee\u524d\u9ed8\u8ba4\u652f\u6301 STM32 \u5e73\u53f0\uff0c\u540e\u7eed\u5c06\u6269\u5c55\u81f3\u66f4\u591a\u786c\u4ef6\u4f53\u7cfb\u7ed3\u6784\u3002\r\n\r\n`libxr` is a Python package for automating embedded system development. It parses hardware configuration files and generates corresponding C++ project code, significantly reducing repetitive manual work. STM32 is supported by default, with more hardware architectures planned.\r\n\r\n## \ud83c\udf1f Features \u529f\u80fd\u4eae\u70b9\r\n\r\n- \ud83e\udde0 \u81ea\u52a8\u751f\u6210\u8bbe\u5907\u9a71\u52a8\u548c\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\u3002  \r\n  Automatically generates device drivers and application scaffolding.\r\n\r\n- \u2699\ufe0f \u652f\u6301\u591a\u79cd\u540e\u7aef\u67b6\u6784\uff0c\u9ed8\u8ba4\u652f\u6301 STM32 \u5e73\u53f0\u3002  \r\n  Supports multiple backends; STM32 is the default.\r\n\r\n- \ud83d\udd0c \u652f\u6301\u591a\u91cd\u522b\u540d\u6ce8\u518c\u4e0e\u67e5\u627e\u3002  \r\n  Supports multi-alias registration and lookup.\r\n\r\n- \ud83d\udce6 \u53ef\u4e0e XRobot \u6846\u67b6\u96c6\u6210\uff0c\u5b9e\u73b0\u6a21\u5757\u81ea\u52a8\u6ce8\u518c\u4e0e\u8c03\u5ea6\u7ba1\u7406\u3002  \r\n  Enables integration with the XRobot application framework.\r\n\r\n## \ud83d\udce5 Installation \u5b89\u88c5\r\n\r\n### \u4f7f\u7528pipx\u5b89\u88c5 (Install via `pipx`)\r\n\r\nwindows\r\n\r\n```ps\r\npython -m pip install --user pipx\r\npython -m pipx ensurepath\r\npipx install libxr\r\npipx ensurepath\r\n# Restart your terminal\r\n```\r\n\r\nlinux\r\n\r\n```bash\r\nsudo apt install pipx\r\npipx install libxr\r\npipx ensurepath\r\n# Restart your terminal\r\n```\r\n\r\n### \u4f7f\u7528 pip \u5b89\u88c5 (Install via `pip`)\r\n\r\n```bash\r\npip install libxr\r\n```\r\n\r\n### \u4ece\u6e90\u7801\u5b89\u88c5 (Install from source)\r\n\r\n```bash\r\ngit clone https://github.com/Jiu-xiao/LibXR_CppCodeGenerator.git\r\ncd LibXR_CppCodeGenerator\r\npython3 ./scripts/gen_libxr_version.py\r\npip install -e .\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udd27 General \u901a\u7528\u547d\u4ee4(\u8de8\u5e73\u53f0\u652f\u6301)\r\n\r\n\u4ee5\u4e0b\u547d\u4ee4\u9002\u7528\u4e8e\u6240\u6709\u5e73\u53f0(\u5982 STM32 \u53ca\u672a\u6765\u652f\u6301\u7684\u67b6\u6784)\u3002  \r\nThese commands work across platforms (STM32 and others):\r\n\r\n### `xr_parse`\r\n\r\n```bash\r\nxr_parse -i config.yaml\r\n```\r\n\r\n\u89e3\u6790\u901a\u7528\u7684 YAML \u786c\u4ef6\u914d\u7f6e\u6587\u4ef6\uff0c\u63d0\u53d6\u5916\u8bbe\u5b9a\u4e49\u3002  \r\nParses a generic YAML hardware configuration and extracts peripheral definitions.\r\n\r\n### `xr_gen_code`\r\n\r\n```bash\r\nxr_gen_code -i config.yaml [--xrobot]\r\n```\r\n\r\n\u6839\u636e YAML \u914d\u7f6e\u751f\u6210\u5e73\u53f0\u65e0\u5173\u7684 C++ \u786c\u4ef6\u62bd\u8c61\u5c42\u4ee3\u7801\uff0c\u53ef\u9009\u751f\u6210 XRobot \u96c6\u6210\u4ee3\u7801\u3002  \r\nGenerates platform-agnostic C++ hardware abstraction code from YAML.\r\n\r\n---\r\n\r\n## STM32 \u5de5\u7a0b\u5de5\u5177 (STM32 Project Tools)\r\n\r\n### `xr_cubemx_cfg`\r\n\r\n\u81ea\u52a8\u914d\u7f6e STM32CubeMX \u5de5\u7a0b  \r\nAutomatically configures an STM32CubeMX project.\r\n\r\n```bash\r\nusage: xr_cubemx_cfg [-h] -d DIRECTORY [-t TERMINAL] [-c] [--xrobot]\r\n```\r\n\r\n\u89e3\u6790 `.ioc` \u6587\u4ef6\uff0c\u751f\u6210 YAML \u548c C++ \u9a71\u52a8\u4ee3\u7801\uff0c\u8865\u4e01\u4e2d\u65ad\u5904\u7406\u51fd\u6570\uff0c\u5e76\u521d\u59cb\u5316\u9879\u76ee\u7ed3\u6784  \r\nParses `.ioc`, generates YAML and C++ code, patches interrupt handlers, and initializes the project structure.\r\n\r\n#### \ud83d\udd27 \u5fc5\u9009\u53c2\u6570 (Required)\r\n\r\n- `-d, --directory <DIRECTORY>`\uff1a\r\n\r\n  STM32CubeMX \u5de5\u7a0b\u8def\u5f84  \r\n  Path to the STM32CubeMX project.\r\n\r\n#### \u2699\ufe0f \u53ef\u9009\u53c2\u6570 (Optional)\r\n\r\n- `-t, --terminal <TERMINAL>`\uff1a\r\n  \r\n  \u4e32\u53e3\u8bbe\u5907\u540d\u79f0(\u5982 `usart1` `usb`)  \r\n  Terminal device name (e.g. `usart1` `usb`).\r\n\r\n- `-c, --clang`\uff1a\r\n\r\n  \u542f\u7528 Clang \u6784\u5efa\u652f\u6301  \r\n  Enable Clang build support.\r\n\r\n- `--xrobot`\uff1a\r\n\r\n  \u751f\u6210 XRobot Glue \u4ee3\u7801  \r\n  Enable XRobot glue code generation.\r\n\r\n- `--commit`\r\n  \r\n  \u6307\u5b9a LibXR \u4ed3\u5e93commit\u7248\u672c  \r\n  Specify the LibXR repository commit version\r\n\r\n#### \ud83d\udce6 \u8f93\u51fa\u5185\u5bb9 (Outputs)\r\n\r\n- `.config.yaml`:\r\n\r\n  \u81ea\u52a8\u751f\u6210\u7684 C++ \u9a71\u52a8\u4ee3\u7801(\u5982 `app_main.cpp`  \r\n  Generated C++ driver code (e.g. `app_main.cpp`)\r\n\r\n- \u8865\u4e01\u540e\u7684\u4e2d\u65ad\u5904\u7406\u51fd\u6570(\u5982 `stm32xx_it.c`)  \r\n  Patched interrupt handlers (e.g. `stm32xx_it.c`)\r\n\r\n- `CMakeLists.txt`\u3001`.gitignore`  \r\n\r\n- \u521d\u59cb\u5316\u7684 Git \u4ed3\u5e93\u53ca LibXR \u5b50\u6a21\u5757  \r\n  Initialized Git repository and LibXR submodule\r\n\r\n---\r\n\r\n### `xr_parse_ioc`\r\n\r\n\u81ea\u52a8\u89e3\u6790 STM32CubeMX \u5de5\u7a0b\u914d\u7f6e  \r\nParses `.ioc` files from STM32CubeMX projects and exports structured YAML.\r\n\r\n```bash\r\nusage: xr_parse_ioc [-h] -d DIRECTORY [-o OUTPUT] [--verbose]\r\n```\r\n\r\n\u89e3\u6790 `.ioc` \u6587\u4ef6\u4e3a `.config.yaml`\uff0c\u5e76\u5728\u7ec8\u7aef\u8f93\u51fa\u89e3\u6790\u6458\u8981  \r\nParses `.ioc` files and creates `.config.yaml` with a readable summary.\r\n\r\n#### \ud83d\udd27 \u5fc5\u9009\u53c2\u6570 (Required)\r\n\r\n- `-d, --directory <DIRECTORY>`  \r\n  `.ioc` \u6587\u4ef6\u6240\u5728\u76ee\u5f55\u8def\u5f84  \r\n  Path to the input directory containing `.ioc` files.\r\n\r\n#### \u2699\ufe0f \u53ef\u9009\u53c2\u6570 (Optional)\r\n\r\n- `-o, --output <FILE>`  \r\n  \u81ea\u5b9a\u4e49 YAML \u8f93\u51fa\u8def\u5f84(\u9ed8\u8ba4\u4e0e `.ioc` \u540c\u540d)  \r\n  Custom YAML output path (default: `<input_file>.yaml`).\r\n\r\n- `--verbose`  \r\n  \u542f\u7528\u8c03\u8bd5\u65e5\u5fd7\uff0c\u8f93\u51fa\u8be6\u7ec6\u89e3\u6790\u8fc7\u7a0b  \r\n  Enable verbose logging.\r\n\r\n#### \ud83d\udce6 \u8f93\u51fa\u5185\u5bb9 (Outputs)\r\n\r\n- `.config.yaml`\uff1a\r\n\r\n  \u5305\u542b GPIO\u3001\u5916\u8bbe\u3001DMA\u3001FreeRTOS\u3001MCU \u7b49\u914d\u7f6e  \r\n  YAML file containing GPIO, peripheral, DMA, FreeRTOS, and MCU configurations.\r\n\r\n- \u63a7\u5236\u53f0\u6458\u8981\uff1aMCU \u4fe1\u606f\u3001GPIO \u6570\u91cf\u3001\u5916\u8bbe\u7edf\u8ba1\u7b49  \r\n  Console summary: MCU information, GPIO count, peripheral statistics, etc.\r\n\r\n---\r\n\r\n### `xr_gen_code_stm32`\r\n\r\n\u6839\u636e YAML \u914d\u7f6e\u751f\u6210 STM32 \u786c\u4ef6\u62bd\u8c61\u5c42\u4ee3\u7801\uff0c\u53ef\u9009\u751f\u6210 XRobot \u96c6\u6210\u4ee3\u7801\u3002  \r\nGenerates STM32 application code from YAML.\r\n\r\n```bash\r\nusage: xr_gen_code_stm32 [-h] -i INPUT -o OUTPUT [--xrobot] [--libxr-config LIBXR_CONFIG]\r\n```\r\n\r\n#### \ud83d\udd27 Required\r\n\r\n- `-i`\uff1a\r\n\r\n  `.config.yaml` \u914d\u7f6e\u6587\u4ef6\u8def\u5f84  \r\n  Path to `.config.yaml`\r\n\r\n- `-o`\uff1a\r\n\r\n  \u751f\u6210\u4ee3\u7801\u8f93\u51fa\u76ee\u5f55  \r\n  Output directory\r\n\r\n#### \u2699\ufe0f Optional\r\n\r\n- `--xrobot`\uff1a\r\n\r\n  \u542f\u7528 XRobot glue \u4ee3\u7801\u751f\u6210  \r\n  Enable XRobot glue generation\r\n\r\n- `--libxr-config`\uff1a\r\n\r\n  \u81ea\u5b9a\u4e49 libxr_config.yaml \u8def\u5f84(\u53ef\u4e3a\u672c\u5730\u6216\u8fdc\u7a0b)  \r\n  Path or URL to runtime config YAML\r\n\r\n#### \ud83d\udce6 Outputs\r\n\r\n- `app_main.cpp`\uff1a  \r\n  \u4e3b\u5165\u53e3\u6587\u4ef6\uff0c\u5305\u542b\u6240\u6709\u521d\u59cb\u5316\u903b\u8f91  \r\n  Main entry point with all initialization logic\r\n\r\n- `libxr_config.yaml`\uff1a  \r\n  \u8fd0\u884c\u65f6\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u81ea\u5b9a\u4e49\u7f13\u51b2\u533a\u5927\u5c0f\u3001\u961f\u5217\u7b49\u53c2\u6570  \r\n  Runtime config YAML, can be customized with buffer size, queue, etc.\r\n\r\n- `flash_map.hpp`\uff1a  \r\n  \u81ea\u52a8\u751f\u6210\u7684 Flash \u6247\u533a\u8868\uff0c\u4f9b Flash \u62bd\u8c61\u5c42\u4f7f\u7528  \r\n  Auto-generated flash sector layout for use with Flash abstraction layer\r\n\r\n---\r\n\r\n### `xr_stm32_flash`\r\n\r\n\u89e3\u6790 STM32 \u578b\u53f7\uff0c\u751f\u6210 Flash \u6247\u533a\u4fe1\u606f\u8868\uff08YAML \u683c\u5f0f\u8f93\u51fa\uff09\u3002  \r\nParses STM32 model name and generates flash layout info (YAML output).\r\n\r\n```bash\r\nusage: xr_stm32_flash <STM32_MODEL>\r\n```\r\n\r\n### \ud83e\udde0 \u529f\u80fd\u8bf4\u660e (Functionality)\r\n\r\n- \u6839\u636e STM32 \u578b\u53f7\u540d\u79f0\u81ea\u52a8\u63a8\u5bfc Flash \u5927\u5c0f  \r\n  Automatically infers flash size from the STM32 model string\r\n\r\n- \u6839\u636e\u82af\u7247\u7cfb\u5217\uff08\u5982 F1/F4/H7/U5 \u7b49\uff09\u751f\u6210\u5bf9\u5e94\u7684\u6247\u533a\u5e03\u5c40  \r\n  Generates sector layout depending on the chip series (e.g., F1/F4/H7/U5)\r\n\r\n- \u8f93\u51fa\u5305\u62ec\u6bcf\u4e2a\u6247\u533a\u7684\u5730\u5740\u3001\u5927\u5c0f\u548c\u7d22\u5f15  \r\n  Output includes address, size, and index of each sector\r\n\r\n### \ud83d\udce6 \u8f93\u51fa\u5185\u5bb9 (Outputs)\r\n\r\n- YAML \u683c\u5f0f\u7684 Flash \u4fe1\u606f  \r\n  Flash info in YAML format:\r\n\r\n```yaml\r\nmodel: STM32F103C8\r\nflash_base: '0x08000000'\r\nflash_size_kb: 64\r\nsectors:\r\n- index: 0\r\n  address: '0x08000000'\r\n  size_kb: 1.0\r\n- index: 1\r\n  address: '0x08000400'\r\n  size_kb: 1.0\r\n  ...\r\n```\r\n\r\n---\r\n\r\n### `xr_stm32_it`\r\n\r\n\u6279\u91cf\u4fee\u6539 STM32 \u4e2d\u65ad\u5904\u7406\u6587\u4ef6\uff0c\u63d2\u5165 UART IDLE \u56de\u8c03\u548c USB F1 \u56de\u8c03\u652f\u6301\u3002\r\nModifies STM32 interrupt handlers to add UART IDLE callback and USB F1 callback support for LibXR.\r\n\r\n```bash\r\nusage: xr_stm32_it [-h] input_dir\r\n```\r\n\r\n#### \ud83d\udd27 \u5fc5\u9009\u53c2\u6570 (Required)\r\n\r\n- `input_dir`\uff1a\r\n\r\n  \u5305\u542b `*_it.c` \u6587\u4ef6\u7684\u6587\u4ef6\u5939\u8def\u5f84  \r\n  Directory containing the `*_it.c` source files.\r\n\r\n#### \u2699\ufe0f \u529f\u80fd\u8bf4\u660e (Functionality)\r\n\r\n- \u67e5\u627e\u6bcf\u4e2a `*_it.c` \u6587\u4ef6\u4e2d\u7684 `HAL_UART_IRQHandler(&huartX)` \u8c03\u7528  \r\n  Find `HAL_UART_IRQHandler(&huartX)` calls in each `*_it.c` file\r\n\r\n- \u67e5\u627e `USB_HP_CAN1_TX_IRQHandler` \u548c `USB_LP_CAN1_RX0_IRQHandler` \u4e2d\u65ad\u51fd\u6570  \r\n  Find `USB_HP_CAN1_TX_IRQHandler` and `USB_LP_CAN1_RX0_IRQHandler` handlers\r\n\r\n- \u5411\u5bf9\u5e94\u4e2d\u65ad\u51fd\u6570\u7684 `/* USER CODE BEGIN XXX_IRQn 0/1 */` \u533a\u57df\u63d2\u5165\uff1a  \r\n  Add to the `/* USER CODE BEGIN XXX_IRQn 0/1 */` section of the corresponding interrupt function\r\n  \r\n```c\r\n  /* LibXR UART IDLE callback (Auto-generated) */\r\n#ifdef HAL_UART_MODULE_ENABLED\r\n  STM32_UART_ISR_Handler_IDLE(&huartX);\r\n#endif\r\n```\r\n\r\n- \u5bf9\u4e8e USB \u4e2d\u65ad\uff08\u4ec5 STM32F1\uff0c\u4e14\u542f\u7528 HAL_PCD_MODULE\uff09\uff0c\u63d2\u5165\uff1a  \r\n  For USB interrupts (STM32F1 only, with HAL_PCD_MODULE enabled)\r\n\r\n```c\r\n/* LibXR USB Tx Cplt callback (Auto-generated, For STM32F1) */\r\n#if defined(STM32F1) && defined(HAL_PCD_MODULE_ENABLED)\r\n  STM32_USB_ISR_Handler_F1();\r\n#endif\r\n```\r\n\r\n- \u82e5\u672a\u5b9a\u4e49 `STM32_UART_ISR_Handler_IDLE`\u548c `STM32_USB_ISR_Handler_F1`\u7684 `extern` \u58f0\u660e\uff0c\u5c06\u63d2\u5165\u81f3 `/* USER CODE BEGIN 0 */` \u533a\u57df\u4e0b  \r\n  Insert at `/* USER CODE BEGIN 0 */` if `STM32_UART_ISR_Handler_IDLE` and `STM32_USB_ISR_Handler_F1` is not defined\r\n\r\n- \u652f\u6301\u591a\u4e2a UART \u548c USB \u63a5\u53e3  \r\n  Support for multiple UART and USB interfaces\r\n\r\n#### \ud83d\udce6 \u8f93\u51fa\u5185\u5bb9 (Outputs)\r\n\r\n- \u88ab\u4fee\u6539\u7684 `*_it.c` \u6587\u4ef6  \r\n  Modified `*_it.c` files\r\n\r\n- \u63a7\u5236\u53f0\u8f93\u51fa\u4fee\u6539\u6458\u8981\uff0c\u5305\u62ec\u4fee\u6539\u7684\u6587\u4ef6\u4e0e\u51fd\u6570\u540d\u79f0  \r\n  Console output summary, including modified files and function names\r\n\r\n---\r\n\r\n### `xr_stm32_clang`\r\n\r\n\u81ea\u52a8\u4fee\u6539 STM32 \u5de5\u7a0b\uff0c\u9002\u914d Clang \u7f16\u8bd1\u5de5\u5177\u94fe\u3002  \r\nCreates Clang-compatible toolchain file.\r\n\r\n```bash\r\nusage: xr_stm32_clang [-h] input_dir\r\n```\r\n\r\n#### \ud83d\udd27 \u5fc5\u9009\u53c2\u6570 (Required)\r\n\r\n- `input_dir`\uff1a\r\n\r\n  \u5305\u542b `gcc-arm-none-eabi.cmake` \u7684 STM32 \u5de5\u7a0b\u76ee\u5f55\u8def\u5f84  \r\n  Directory containing `gcc-arm-none-eabi.cmake` for the STM32 project\r\n\r\n#### \u2699\ufe0f \u529f\u80fd\u8bf4\u660e (Functionality)\r\n\r\n- \u5728 `{input_dir}/cmake/` \u4e2d\u67e5\u627e `gcc-arm-none-eabi.cmake` \u6587\u4ef6  \r\n  Locate `gcc-arm-none-eabi.cmake` inside `{input_dir}/cmake/`\r\n\r\n- \u89e3\u6790\u5176\u4e2d\u7684 `linker_script` \u8def\u5f84\u4e0e `-mcpu` \u7f16\u8bd1\u5668\u53c2\u6570  \r\n  Extract `linker_script` path and `-mcpu` target flag\r\n\r\n- \u81ea\u52a8\u751f\u6210 `gcc-arm-none-eabi.cmake` \u6587\u4ef6\uff0c\u9002\u914d Clang \u7f16\u8bd1\u5de5\u5177\u94fe  \r\n  Generate Clang-compatible `gcc-arm-none-eabi.cmake` toolchain file\r\n\r\n- \u81ea\u52a8\u4fee\u6539 `CMakeLists.txt` \u6587\u4ef6\uff0c\u63d2\u5165  \r\n  Automatically modify `CMakeLists.txt` to include:\r\n  \r\n  ```cmake\r\n  include(\"cmake/gcc-arm-none-eabi.cmake\")\r\n  ```\r\n\r\n#### \ud83d\udce6 \u8f93\u51fa\u5185\u5bb9 (Outputs)\r\n\r\n- \u8986\u76d6\u539f\u6709 `gcc-arm-none-eabi.cmake` \u6587\u4ef6  \r\n  Overwrites original `gcc-arm-none-eabi.cmake` file\r\n\r\n- \u81ea\u52a8\u6dfb\u52a0\u6216\u66f4\u65b0 `CMakeLists.txt` \u6587\u4ef6\u4e2d\u7684 include \u6307\u4ee4  \r\n  Auto-updates `CMakeLists.txt` to include the toolchain file\r\n\r\n---\r\n\r\n### `xr_libxr_cmake`\r\n\r\n\u4e3a STM32CubeMX \u5de5\u7a0b\u751f\u6210 `LibXR.CMake` \u914d\u7f6e\uff0c\u5e76\u81ea\u52a8\u96c6\u6210\u81f3 `CMakeLists.txt`\u3002  \r\nGenerates `LibXR.CMake` file and injects it into the STM32CubeMX CMake project.\r\n\r\n```bash\r\nusage: xr_libxr_cmake [-h] input_dir\r\n```\r\n\r\n#### \ud83d\udd27 \u5fc5\u9009\u53c2\u6570 (Required)\r\n\r\n- `input_dir`\uff1a\r\n\r\n  \u6307\u5b9a CubeMX \u751f\u6210\u7684 CMake \u5de5\u7a0b\u6839\u76ee\u5f55  \r\n  Path to the CubeMX-generated CMake project root\r\n\r\n#### \u2699\ufe0f \u529f\u80fd\u8bf4\u660e (Functionality)\r\n\r\n- \u81ea\u52a8\u751f\u6210 `cmake/LibXR.CMake` \u6587\u4ef6\uff0c\u5185\u5bb9\u5305\u62ec\uff1a  \r\n  Generate `cmake/LibXR.CMake` containing:\r\n  \r\n  - \u6dfb\u52a0 `LibXR` \u5b50\u76ee\u5f55  \r\n    Add `LibXR` as a subdirectory\r\n  \r\n  - \u94fe\u63a5 `xr` \u9759\u6001\u5e93  \r\n    Link the `xr` static library\r\n  \r\n  - \u6dfb\u52a0 `Core/Inc`\u3001`User` \u76ee\u5f55\u4e3a\u5305\u542b\u8def\u5f84  \r\n    Include `Core/Inc` and `User` directories\r\n  \r\n  - \u6dfb\u52a0 `User/*.cpp` \u4e3a\u6e90\u6587\u4ef6  \r\n    Add `User/*.cpp` to project sources\r\n\r\n- \u81ea\u52a8\u68c0\u6d4b\u662f\u5426\u542f\u7528 FreeRTOS\uff1a  \r\n  Auto-detect FreeRTOS configuration:\r\n  \r\n  - \u5b58\u5728 `Core/Inc/FreeRTOSConfig.h` \u2192 `LIBXR_SYSTEM=FreeRTOS`\r\n  - \u5426\u5219\u8bbe\u7f6e\u4e3a `None`\r\n\r\n- \u81ea\u52a8\u5220\u9664\u65e7\u7684 `build/` \u76ee\u5f55(\u5982\u5b58\u5728)  \r\n  Automatically deletes existing `build/` directory if found\r\n\r\n- \u81ea\u52a8\u5411\u4e3b `CMakeLists.txt` \u6dfb\u52a0\u4ee5\u4e0b\u6307\u4ee4(\u82e5\u5c1a\u672a\u5305\u542b)\uff1a  \r\n  Auto-appends the following line to `CMakeLists.txt` if missing:\r\n\r\n  ```cmake\r\n  include(${CMAKE_CURRENT_LIST_DIR}/cmake/LibXR.CMake)\r\n  ```\r\n\r\n#### \ud83d\udce6 \u8f93\u51fa\u5185\u5bb9 (Outputs)\r\n\r\n- \u751f\u6210 `cmake/LibXR.CMake` \u6587\u4ef6  \r\n  Generates `cmake/LibXR.CMake` file\r\n\r\n- \u4fee\u6539\u4e3b\u5de5\u7a0b\u7684 `CMakeLists.txt`\uff0c\u63d2\u5165 `include(...)`  \r\n  Updates `CMakeLists.txt` to include `LibXR.CMake`\r\n\r\n- \u5220\u9664\u539f\u6709\u6784\u5efa\u7f13\u5b58\u76ee\u5f55 `build/`(\u5982\u5b58\u5728)  \r\n  Deletes the old `build/` directory if present\r\n\r\n---\r\n\r\n### STM32 \u5de5\u7a0b\u8981\u6c42  (STM32 Project Requirements)\r\n\r\n#### \ud83d\udcc1 \u9879\u76ee\u7ed3\u6784\u8981\u6c42(Project Structure)\r\n\r\n- \u5fc5\u987b\u4e3a **STM32CubeMX \u5bfc\u51fa\u7684 CMake \u5de5\u7a0b**  \r\n  Must be a CMake project exported from STM32CubeMX\r\n\r\n- \u9879\u76ee\u5e94\u5305\u542b\u4ee5\u4e0b\u8def\u5f84\uff1a  \r\n  Project should contain the following directories:\r\n\r\n  - `xx.ioc`\r\n  - `CMakeLists.txt`\r\n  - `cmake/gcc-arm-none-eabi.cmake`\r\n  - `Core/Inc`, `Core/Src`\r\n\r\n#### \u2699\ufe0f \u914d\u7f6e\u8981\u6c42(Peripheral & Middleware)\r\n\r\n- \u6240\u6709 **UART / SPI / I2C** \u5916\u8bbe\u5fc5\u987b\u542f\u7528 **DMA**  \r\n  All **UART / SPI / I2C** peripherals must have **DMA** enabled\r\n\r\n- \u5982\u679cADC\u542f\u7528\u4e86DMA\uff0c\u8bf7\u5f00\u542f\u8fde\u7eed\u8f6c\u6362\u6a21\u5f0f  \r\n  If ADC has DMA enabled, enable continuous mode\r\n\r\n- \u63a8\u8350\u542f\u7528 **FreeRTOS**\uff0c\u81ea\u52a8\u751f\u6210 `FreeRTOSConfig.h`  \r\n  Recommended to enable **FreeRTOS** and generate `FreeRTOSConfig.h`\r\n\r\n- \u82e5\u4f7f\u7528 USB \u4f5c\u4e3a\u7ec8\u7aef\uff1a  \r\n  If using USB as a terminal:\r\n\r\n  - \u542f\u7528 `USB_DEVICE` \u4e2d\u95f4\u4ef6\uff0c\u5e76\u9009\u62e9 `Communication Device Class (CDC)`  \r\n    Enable `USB_DEVICE` middleware and select `Communication Device Class (CDC)`\r\n\r\n#### \u23f1\ufe0f Timebase \u914d\u7f6e\u5efa\u8bae(Timebase Configuration)\r\n\r\n> \u2705 \u5f3a\u70c8\u63a8\u8350\u4f7f\u7528 `TIM6`/`TIM7` \u7b49 Timer \u4f5c\u4e3a Timebase  \r\n    Strongly recommended to use `TIM6`/`TIM7` Timers as Timebase  \r\n> \u2705 \u5e76\u5c06\u8be5\u4e2d\u65ad\u4f18\u5148\u7ea7\u8bbe\u7f6e\u4e3a **\u6700\u9ad8(0)**  \r\n    And set the interrupt priority to **highest (0)**\r\n\r\n---\r\n\r\n## \ud83e\udde9 \u4ee3\u7801\u751f\u6210\u540e\u64cd\u4f5c (After Code Generation)\r\n\r\n\u751f\u6210\u4ee3\u7801\u540e\uff0c\u4f60\u9700\u8981**\u624b\u52a8\u6dfb\u52a0**\u4ee5\u4e0b\u5185\u5bb9\uff1a  \r\nAfter generating code, you must **manually add** the following:  \r\n\r\n```cpp\r\n#include \"app_main.h\"\r\n```\r\n\r\n\u5e76\u5728\u5408\u9002\u4f4d\u7f6e\u8c03\u7528 `app_main();`\uff1a  \r\nAnd call `app_main();` in the appropriate location:\r\n\r\n| \u573a\u666f (Scenario)       | \u6dfb\u52a0\u4f4d\u7f6e        |Where to add|\r\n|-----------------------|------------------------------------| -----------|\r\n| \ud83d\udfe2 Bare metal \u88f8\u673a\u5de5\u7a0b | `main()` \u51fd\u6570\u672b\u5c3e   | End of `main()` |\r\n| \ud83d\udd35 FreeRTOS \u5de5\u7a0b       | \u7ebf\u7a0b\u5165\u53e3       | Thread entry function |\r\n\r\n---\r\n\r\n## LibXR / LibXR_CppCodeGenerator / XRobot Relationship\r\n\r\nLibXR\u3001LibXR_CppCodeGenerator \u4e0e XRobot \u4e09\u8005\u5f62\u6210\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u5d4c\u5165\u5f0f\u4e0e\u673a\u5668\u4eba\u8f6f\u4ef6\u5f00\u53d1\u4f53\u7cfb\uff0c\u5206\u5de5\u660e\u786e\uff0c\u534f\u540c\u7d27\u5bc6\u3002  \r\nLibXR, LibXR_CppCodeGenerator and XRobot together form a complete software ecosystem for embedded and robotics development, with clear separation of concerns and tight integration.\r\n\r\n---\r\n\r\n### \ud83e\udde0 LibXR\r\n\r\n**LibXR \u662f\u8de8\u5e73\u53f0\u7684\u9a71\u52a8\u62bd\u8c61\u4e0e\u5de5\u5177\u5e93**\uff0c\u652f\u6301 STM32\u3001Linux \u7b49\u5e73\u53f0\uff0c\u5305\u542b\uff1a  \r\nLibXR is a cross-platform driver abstraction and utility library supporting STM32, Linux, and more. It provides:\r\n\r\n- \u901a\u7528\u5916\u8bbe\u63a5\u53e3\u5c01\u88c5  \r\n  Unified peripheral interface abstraction  \r\n- \u5d4c\u5165\u5f0f\u7ec4\u4ef6\uff08\u5982 Terminal\u3001PowerManager\u3001Database \u7b49\uff09  \r\n  Embedded modules like Terminal, PowerManager, Database, etc.  \r\n- FreeRTOS / bare-metal \u652f\u6301  \r\n  FreeRTOS and bare-metal support  \r\n- \u673a\u5668\u4eba\u8fd0\u52a8\u5b66\u4e0e\u5bfc\u822a  \r\n  Kinematics and navigation libraries for robotics  \r\n- \u81ea\u52a8\u4ee3\u7801\u751f\u6210\u652f\u6301  \r\n  Code generation support\r\n\r\n#### \ud83d\udd17 Links\r\n\r\n- **Repository**: [libxr](https://github.com/Jiu-xiao/libxr)  \r\n- **API Documentation**: [API](https://jiu-xiao.github.io/libxr/)  \r\n- **Issues**: [Issue Tracker](https://github.com/Jiu-xiao/libxr/issues)\r\n\r\n---\r\n\r\n### \ud83d\udd27 LibXR_CppCodeGenerator\r\n\r\n**LibXR_CppCodeGenerator \u662f\u7528\u4e8e LibXR \u7684\u4ee3\u7801\u751f\u6210\u5de5\u5177\u94fe**\uff0c\u5f53\u524d\u652f\u6301 STM32 + CubeMX\uff0c\u672a\u6765\u5c06\u6269\u5c55\u81f3 Zephyr\u3001ESP-IDF \u7b49\u5e73\u53f0\u3002  \r\nLibXR_CppCodeGenerator is a code generation toolchain for LibXR. It currently supports STM32 with CubeMX, and is planned to support Zephyr, ESP-IDF, and more.\r\n\r\n- \u4ece\u4e0d\u540c\u5e73\u53f0\u7684\u5de5\u7a0b\u6587\u4ef6\u751f\u6210 `.yaml` \u914d\u7f6e  \r\n  Parse project files from different platforms to generate `.yaml` configurations\r\n- \u57fa\u4e8e `.yaml` \u81ea\u52a8\u751f\u6210 `app_main.cpp`\u3001\u4e2d\u65ad\u3001CMake \u7b49  \r\n  Generate `app_main.cpp`, interrupt handlers, and CMake integration  \r\n- \u652f\u6301 `XRobot` glue \u5c42\u96c6\u6210  \r\n  Supports optional integration with XRobot framework  \r\n- \u652f\u6301\u7528\u6237\u4ee3\u7801\u4fdd\u7559\u4e0e\u591a\u6587\u4ef6\u7ed3\u6784  \r\n  Preserves user code blocks and supports modular output\r\n\r\n#### \ud83d\udd17 Links\r\n\r\n- **Repository**: [LibXR_CppCodeGenerator](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator)  \r\n- **Documentation and Releases**: [PyPI](https://pypi.org/project/libxr/)  \r\n- **Issues**: [Issue Tracker](https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/issues)\r\n\r\n---\r\n\r\n### \ud83e\udd16 XRobot\r\n\r\nXRobot \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u6a21\u5757\u5316\u5e94\u7528\u7ba1\u7406\u6846\u67b6\uff0c\u4e13\u4e3a\u5d4c\u5165\u5f0f\u8bbe\u5907\u800c\u8bbe\u8ba1\u3002\u5b83\u672c\u8eab\u4e0d\u5305\u542b\u4efb\u4f55\u9a71\u52a8\u6216\u4e1a\u52a1\u4ee3\u7801\uff0c\u4e13\u6ce8\u4e8e\u6a21\u5757\u7684\u6ce8\u518c\u3001\u8c03\u5ea6\u3001\u751f\u547d\u5468\u671f\u7ba1\u7406\u3001\u4e8b\u4ef6\u5904\u7406\u4e0e\u53c2\u6570\u914d\u7f6e\u3002  \r\n**XRobot is a lightweight modular application management framework designed for embedded systems.**  \r\nIt does not include any drivers or business logic by itself. Instead, it focuses on module registration, scheduling, lifecycle management, event handling, and parameter configuration.\r\n\r\n- \u6a21\u5757\u6ce8\u518c\u4e0e\u751f\u547d\u5468\u671f\u7ba1\u7406  \r\n  Module registration and lifecycle management  \r\n- \u53c2\u6570\u7ba1\u7406 / \u914d\u7f6e\u7cfb\u7edf / \u4e8b\u4ef6\u7cfb\u7edf  \r\n  Parameter management, configuration system, and event system  \r\n- ApplicationRunner / ThreadManager \u7b49\u5e94\u7528\u8c03\u5ea6\u5668  \r\n  ApplicationRunner and ThreadManager for runtime coordination  \r\n- \u4e0d\u76f4\u63a5\u8bbf\u95ee\u786c\u4ef6\uff0c\u4f9d\u8d56 LibXR \u7684 PeripheralManager  \r\n  Does not access hardware directly, relies on LibXR's PeripheralManager\r\n\r\n---\r\n\r\n#### \u2705 Recommended For \u63a8\u8350\u4f7f\u7528\u573a\u666f\r\n\r\n- \u62e5\u6709\u591a\u4e2a\u5b50\u6a21\u5757\uff08\u5982\u4f20\u611f\u5668\u3001\u901a\u4fe1\u3001\u63a7\u5236\u5668\uff09\u4e14\u5e0c\u671b\u7edf\u4e00\u7ba1\u7406\u521d\u59cb\u5316\u3001\u8c03\u5ea6\u4e0e\u8d44\u6e90\u4f9d\u8d56  \r\n  For projects with multiple submodules (e.g., sensors, communication, controllers) needing unified lifecycle and dependency management.\r\n\r\n- \u5e0c\u671b\u6784\u5efa\u5e73\u53f0\u65e0\u5173\u7684\u5e94\u7528\u5c42\u903b\u8f91\uff0c\u4e0e\u5e95\u5c42\u9a71\u52a8\u89e3\u8026  \r\n  For building platform-independent application logic decoupled from hardware drivers.\r\n\r\n- \u4e0e **LibXR** \u7ed3\u5408\u4f7f\u7528\uff0c\u5b9e\u73b0\u81ea\u52a8\u6ce8\u518c\u786c\u4ef6\u5bf9\u8c61\uff08\u901a\u8fc7 `HardwareContainer`\uff09  \r\n  When used with **LibXR**, supports automatic hardware registration via `HardwareContainer`.\r\n\r\n- \u652f\u6301\u751f\u6210\u6a21\u5757\u5165\u53e3\u4ee3\u7801\u3001\u914d\u7f6e\u903b\u8f91\u540d\u4e0e\u786c\u4ef6\u540d\u7684\u6620\u5c04\uff0c\u4fbf\u4e8e\u5feb\u901f\u9002\u914d\u4e0d\u540c\u786c\u4ef6\u914d\u7f6e  \r\n  Supports generating module entry code and logical-to-physical hardware name mapping for quick adaptation to different platforms.\r\n\r\n#### \ud83d\udd17 Links\r\n\r\n- **Repository**: [XRobot](https://github.com/xrobot-org/XRobot)  \r\n- **Documentation**: [GitHub Pages](https://xrobot-org.github.io)  \r\n- **Releases**: [PyPI](https://pypi.org/project/xrobot)  \r\n- **Issues**: [Issue Tracker](https://github.com/xrobot-org/XRobot/issues)\r\n\r\n---\r\n\r\n## \ud83d\udcc4 License\r\n\r\nLicensed under **Apache-2.0**. See [LICENSE](LICENSE).\r\n\r\n\r\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FJiu-xiao%2FLibXR_CppCodeGenerator?ref=badge_large)\r\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "C++ code generator for LibXR-based embedded systems, supporting STM32 and modular robotics applications.",
    "version": "0.4.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/Jiu-xiao/LibXR_CppCodeGenerator/issues",
        "Documentation": "https://xrobot-org.github.io/",
        "Homepage": "https://github.com/Jiu-xiao/libxr",
        "Repository": "https://github.com/Jiu-xiao/LibXR_CppCodeGenerator"
    },
    "split_keywords": [
        "code generation",
        " embedded systems",
        " automation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "006e57f1afb1aa120491d69cd31ab2667c0d5f5b1ee305b4c508eb1a3e455c52",
                "md5": "5b8964182075d70a396308ad101c1043",
                "sha256": "6b1d69525de67af54f4e3aecd647cd994c2f2d0e2ab107b3121b7210c415750e"
            },
            "downloads": -1,
            "filename": "libxr-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b8964182075d70a396308ad101c1043",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 49395,
            "upload_time": "2025-07-08T15:29:09",
            "upload_time_iso_8601": "2025-07-08T15:29:09.357385Z",
            "url": "https://files.pythonhosted.org/packages/00/6e/57f1afb1aa120491d69cd31ab2667c0d5f5b1ee305b4c508eb1a3e455c52/libxr-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dc857b04df7844cd50246692c4b2e3e191763e3a755394258820553090b86287",
                "md5": "9df23a4aea9e8e757b211e05a6b9b4e9",
                "sha256": "3722df0d4b68fb77a067dfd9c5651428d4a47a9e8e673939ba9b1da9518f1376"
            },
            "downloads": -1,
            "filename": "libxr-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9df23a4aea9e8e757b211e05a6b9b4e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 52862,
            "upload_time": "2025-07-08T15:29:10",
            "upload_time_iso_8601": "2025-07-08T15:29:10.721260Z",
            "url": "https://files.pythonhosted.org/packages/dc/85/7b04df7844cd50246692c4b2e3e191763e3a755394258820553090b86287/libxr-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-08 15:29:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Jiu-xiao",
    "github_project": "LibXR_CppCodeGenerator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "libxr"
}
        
Elapsed time: 0.41216s