# codegen **Repository Path**: xingzhenmin/codegen ## Basic Information - **Project Name**: codegen - **Description**: 代码自动生成 - **Primary Language**: C - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-22 - **Last Updated**: 2025-12-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # codegen #### 介绍 代码自动生成工具,特别适用于单片机开发中的多项目、多配置场景。 该工具可以帮助单片机开发者快速生成不同平台(如STM32、ESP32、Arduino等)的项目框架, 并根据不同需求定制配置,大幅提高开发效率。 #### 软件架构 软件架构说明 ``` codegen/ ├── config_manager.py # 配置管理模块 ├── template_engine.py # 模板引擎模块 ├── project_generator.py # 项目生成器模块 ├── main.py # 主程序入口 ├── example_usage.py # 使用示例 ├── complex_example_usage.py # 复杂配置使用示例 ├── configs/ # 项目配置文件目录 ├── templates/ # 代码模板目录 ├── project/ # 生成的项目输出目录 └── requirements.txt # 依赖声明文件 ``` #### 安装教程 1. 确保已安装Python 3.6+ 2. 克隆或下载本项目到本地 3. 进入项目根目录 4. 执行: `python main.py --help` 查看使用帮助 #### 使用说明 ##### 快速开始 1. 运行示例项目生成: ``` python main.py --example ``` 2. 查看已有的项目配置: ``` python main.py --list ``` 3. 查看特定项目的配置: ``` python main.py --show <项目名称> ``` 4. 从配置文件创建新项目: ``` python main.py --create <项目名称> <配置文件路径> ``` ##### 使用示例 运行简单示例: ```bash python example_usage.py ``` 这将生成三个不同平台的示例项目: - STM32基础项目 - ESP32 Wi-Fi项目 - Arduino Uno项目 运行复杂配置示例: ```bash python complex_example_usage.py ``` ##### 配置文件详解 ###### 基础配置 ```json { "mcu_type": "STM32F103C8T6", "frequency": "72", "pins": { "led": "GPIO_PIN_13", "button": "GPIO_PIN_0" }, "features": { "usart": true, "spi": false } } ``` ###### 复杂配置 ```json { "project_name": "complex_stm32_project", "mcu_type": "STM32F407VET6", "frequency": "168", "board": "STM32F4Discovery", "pins": { "led": "GPIO_PIN_12", "button": "GPIO_PIN_0", "uart_tx": "GPIO_PIN_10", "uart_rx": "GPIO_PIN_11" }, "features": { "usart": true, "spi": true, "i2c": true }, "clock_settings": { "hse_value": "8000000", "hclk": "168000000" }, "interrupts": { "nvic_priority_groups": 4, "usart1_irq_priority": 5 }, "memory_layout": { "flash_size": "512K", "sram_size": "128K" } } ``` ##### 自定义配置 创建一个JSON格式的配置文件,例如 my_project_config.json: ```json { "mcu_type": "STM32F407VET6", "frequency": "168", "pins": { "led": "GPIO_PIN_12", "button": "GPIO_PIN_1" }, "features": { "usart": true, "ethernet": true } } ``` 然后使用此配置创建项目: ```bash python main.py --create my_new_project my_project_config.json ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 技术特点 1. 支持多种单片机平台(STM32、ESP32、Arduino等) 2. 可扩展的模板系统,轻松适配新的MCU平台 3. 灵活的配置管理,支持多项目独立配置 4. 一键生成完整的项目框架,包括源代码、头文件和构建脚本 5. 易于集成到现有开发流程中 #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)