docs: 补齐 README、LICENSE 与开发文档
- README.md:项目简介、环境版本、时钟架构、目录结构、文档索引与日常工作流 - LICENSE:内部使用声明 - docs/ac6-migration.md:AC6 端口替换与 CubeMX 固件包补丁说明 - docs/ioc-workflow.md:.ioc 管理约定与生成后检查清单 - docs/code-style.md:代码风格与格式化工具 - docs/commit-convention.md:提交信息规范与改写历史的规则 - docs/troubleshooting.md:已知坑与排查
This commit is contained in:
1 parent
850fc67138
commit
b8f480a28f
7 files changed
+419
No files matched your search
@@ -0,0 +1,66 @@
|
||||
# 代码风格与格式化
|
||||
|
||||
## 1. 基准
|
||||
|
||||
- 母本:**Google C++ Style Guide** 的 C 子集(Google 没有独立的 C 指南)
|
||||
- 团队覆写两项:**4 空格缩进 / 100 列**
|
||||
- 与 `Simba-OmniInfantry` 保持一致,便于在两个仓库间切换
|
||||
|
||||
## 2. 生效范围
|
||||
|
||||
```
|
||||
Simba-Titan/
|
||||
├─ .clang-format ← 4 空格 / 100 列(根目录及子目录)
|
||||
├─ Core/.clang-format ← DisableFormat: true
|
||||
├─ Drivers/.clang-format ← DisableFormat: true
|
||||
└─ Middlewares/.clang-format← DisableFormat: true
|
||||
```
|
||||
|
||||
`Core/`、`Drivers/`、`Middlewares/` **冻结不格式化**:
|
||||
|
||||
- `Core/` 每次 GENERATE 会被 CubeMX 按自己的风格(Allman 花括号)重写,格式化只是制造无意义 diff
|
||||
- `Drivers/`、`Middlewares/` 是第三方代码,改了就无法与官方版本对比
|
||||
|
||||
**只有 `Application/`、`Bsp/`、`Modules/` 与 USER CODE 区适用本规范。**
|
||||
|
||||
## 3. 工具链
|
||||
|
||||
| 项 | 说明 |
|
||||
|---|---|
|
||||
| 编辑器 | VS Code + `ms-vscode.cpptools` |
|
||||
| 格式化核心 | cpptools **自带**的 clang-format(无需另装 LLVM) |
|
||||
| 关键设置 | `C_Cpp.formatting=clangFormat`、`C_Cpp.clang_format_style=file` |
|
||||
| 保存行为 | 自动格式化,且**只格式化改动行**(`formatOnSaveMode: modificationsIfAvailable`) |
|
||||
|
||||
为什么要设 `C_Cpp.formatting=clangFormat`:cpptools 默认值是 `default`,在 Windows 上会解析成
|
||||
`vcFormat`(Visual Studio 风格),**根本不读 `.clang-format`**。这是最常见的一个坑。
|
||||
|
||||
批量格式化(首次接入或整理时):
|
||||
|
||||
```powershell
|
||||
# 只对自写代码,且单独一次提交;目录按实际结构调整
|
||||
clang-format -i Application\Src\*.c Bsp\Src\*.c Modules\Src\*.c
|
||||
```
|
||||
|
||||
## 4. 命名
|
||||
|
||||
| 对象 | 规则 | 示例 |
|
||||
|---|---|---|
|
||||
| 函数 | `CamelCase` | `ChassisUpdate()` |
|
||||
| 变量 / 参数 | `snake_case` | `wheel_speed` |
|
||||
| 宏 | `UPPER_CASE` | `MAX_WHEEL_SPEED` |
|
||||
| 类型 | `CamelCase` | `MotorState` |
|
||||
| 文件 | 小写 + 下划线 | `chassis_task.c` |
|
||||
|
||||
HAL / FreeRTOS 的既有命名(`HAL_GPIO_Init`、`osThreadNew`、`vTaskDelay`)**不强制改**。
|
||||
|
||||
## 5. 工具做不到的部分
|
||||
|
||||
格式化工具只改空白、换行与 `#include` 顺序,**从不改标识符**。以下必须由人保证:
|
||||
|
||||
- 命名是否表达意图(工具只查大小写模式)
|
||||
- 注释是否解释"为什么",而不是复述代码
|
||||
- 函数是否过长、是否需要拆分
|
||||
- 错误处理策略(HAL 返回值忽略 / 断言 / 复位)
|
||||
- `volatile` 与内存屏障(中断、DMA 共享变量)
|
||||
- 魔数是否具名(`1000` → `kPwmPeriodUs`)
|
||||
Reference in new issue
Block a user