feat: implement high-precision hardware SPI driver for FCOB-2.7 RGB LED with motor pin conflict resolution
This commit is contained in:
@@ -1,47 +1,51 @@
|
||||
# French Language & Addressable RGB LED (XL-2020RGBC-2812B) Implementation Plan
|
||||
# 法语UI语言包与硬件SPI控制FCOB-2.7双模/单线幻彩RGB灯条实施计划书
|
||||
|
||||
## Goal Description
|
||||
Modify the wristband firmware to support **French-only UI display** and replace the discrete 3-pin LED control with the single-wire **addressable RGB LED (XL-2020RGBC-2812B)** protocol (WS2812B timing compatible).
|
||||
## 目标说明
|
||||
修改手环固件,以支持**纯法语UI显示**,并将原本的单线Bit-bang驱动方式升级为通过**硬件SPI (引脚P2.3)** 控制 **FCOB-2.7(800kHz-1100kHz)** 单线自适应幻彩RGB灯条。
|
||||
|
||||
## User Review Required
|
||||
> [!IMPORTANT]
|
||||
> 1. **RGB LED (WS2812B) Control Pin**:
|
||||
> The single-wire addressable RGB LED requires a high-speed bit-stream control pin (DIN).
|
||||
> We will use the **P0.0 pin** (originally `LED_R` net) to drive the WS2812B DIN. P0.0 is already configured as a Push-Pull output.
|
||||
> Pins `P2.7` (originally `LED_G`) and `P2.6` (originally `LED_B`) will be disabled (set to standard inputs or high logic).
|
||||
> 2. **French Translations**:
|
||||
> All UI strings will be replaced with French equivalents formatted to fit the 120-pixel wide OLED screen (max 15 characters per line).
|
||||
## 关键技术点
|
||||
|
||||
## Open Questions
|
||||
None. The specifications are fully understood and mapping is direct.
|
||||
### 1. 硬件SPI引脚映射与冲突规避
|
||||
* **引脚映射**:配置 `P_SW1 = 0x04` 将SPI引脚切换至第二组:
|
||||
* `P2.2` -> SS (不使用)
|
||||
* `P2.3` -> MOSI (连接到 FCOB 灯条的 DIN 引脚)
|
||||
* `P2.4` -> MISO (不使用)
|
||||
* `P2.5` -> SCLK (原本连接到振动马达 MOTOR)
|
||||
* **马达引脚防抖/防噪处理**:
|
||||
由于 `P2.5` 是 SCLK 且物理上连接了马达,为避免发送SPI信号时 SCLK 高频信号导致马达异常颤动或常亮:
|
||||
* 在每次通过SPI写入24位RGB数据时,**临时将 P2.5 配置为高阻输入模式**(关闭引脚输出驱动能力),使 SCLK 信号无法物理输出到引脚。
|
||||
* 数据发送完成后,**立即将 P2.5 恢复为推挽输出模式**,以确保正常的马达振动控制。
|
||||
* 发送数据期间关闭总中断 `EA = 0`,以防时序被中断打断,发送完成后立即恢复 `EA = 1`。
|
||||
|
||||
## Proposed Changes
|
||||
### 2. SPI传输速率计算与比特编码 (针对 FCOB-2.7 规格)
|
||||
根据 FCOB-2.7 规格书:
|
||||
* **T0H** (0码高电平): `0.295μs`
|
||||
* **T0L** (0码低电平): `0.595μs`
|
||||
* **T1H** (1码高电平): `0.595μs`
|
||||
* **T1L** (1码低电平): `0.295μs`
|
||||
* **Trst** (复位低电平): `> 80μs`
|
||||
* 单码元周期: `0.295μs + 0.595μs = 0.89μs` (即 `1.12 MHz` 传输速率)。
|
||||
|
||||
### Hardware / Drivers
|
||||
**设计方案**:
|
||||
* **SPI时钟频率**:配置为 `SYSCLK / 8 = 3.0 MHz` (当系统时钟为24MHz时),对应的 SPI 每 bit 时间为 `333.3ns`。
|
||||
* **码元表示**:使用 **3位 SPI bit** 表示一个 FCOB 码元(24位 RGB 数据对应 72位 SPI 数据,高阶位在前,正好等于 9个 字节):
|
||||
* **0码**:SPI 编码为二进制 `100`。
|
||||
* 高电平时间 = 1 bit * 333.3ns = `333ns` (与规格书 295ns 偏差仅 38ns)
|
||||
* 低电平时间 = 2 bits * 333.3ns = `667ns` (与规格书 595ns 偏差仅 72ns)
|
||||
* **1码**:SPI 编码为二进制 `110`。
|
||||
* 高电平时间 = 2 bits * 333.3ns = `667ns` (与规格书 595ns 偏差仅 72ns)
|
||||
* 低电平时间 = 1 bit * 333.3ns = `333ns` (与规格书 295ns 偏差仅 38ns)
|
||||
* **复位信号**:禁用 SPI 模块,将 `P2.3` 强制拉低保持 `100μs`。
|
||||
|
||||
#### [MODIFY] [lcd_font.h](file:///c:/workfile/105/stc32g12k128/Drivers/lcd_font.h)
|
||||
No change needed for font, but we might include character translations if custom accent characters were needed. Since we use standard French without accents (like "ARME" instead of "ARMÉ") to avoid custom font complexity, no changes to `lcd_font.h` are required.
|
||||
### 3. 法语界面翻译
|
||||
* 已完成所有界面显示内容的法语汉化工作,在 120x240 OLED 屏幕上自适应排版。
|
||||
|
||||
### Application Logic
|
||||
## 验证方案
|
||||
|
||||
#### [MODIFY] [main.c](file:///c:/workfile/105/stc32g12k128/App/main.c)
|
||||
1. **Redefine LED output**:
|
||||
- Redefine `LED_R`, `LED_G`, `LED_B` as virtual/soft registers (`bit` variables). This allows the current logic in `Timer1_Isr` (which computes blink rates, colors, and vibrations) to remain 100% unchanged.
|
||||
2. **Implement WS2812B bit-bang driver**:
|
||||
- Write a precise assembly/C bit-bang function `WS2812_Write24Bit(u8 g, u8 r, u8 b)` that drives `P0.0` (DIN) with the correct WS2812 high-speed timing (typical `T0H = 0.35us`, `T0L = 0.9us`, `T1H = 0.8us`, `T1L = 0.4us`).
|
||||
- Implement `WS2812_Reset()` by holding DI low for `>80us` to latch data.
|
||||
3. **Trigger RGB updates**:
|
||||
- At the end of `Timer1_Isr` (or during main loop), monitor changes to the virtual `LED_R`, `LED_G`, `LED_B` variables. If any changes are detected, output the 24-bit color to the WS2812 LED using the bit-bang driver.
|
||||
4. **French UI Translation**:
|
||||
- Translate all string literals displayed on the screen into French (e.g. menu items, sensor default names, and system state texts).
|
||||
### 自动化编译测试
|
||||
* 使用 Keil C251 重新编译项目,验证代码无报错(0 Errors)。
|
||||
|
||||
## Verification Plan
|
||||
|
||||
### Automated Tests
|
||||
- Build code with Keil C251 to ensure 0 compile/link errors.
|
||||
|
||||
### Manual Verification
|
||||
- Test using UART simulation commands:
|
||||
- Verify that the simulated LED output in the serial log shows correct R/G/B status changes for different states.
|
||||
- Verify that French strings are printed correctly on the screen simulator or display.
|
||||
- Test pairing, confirmation, alarm, and SOS states to verify correct RGB LED color outputs.
|
||||
### 硬件测试
|
||||
* 烧录最新的 Hex 固件,利用串口命令进行 RGB 灯控制测试。
|
||||
* 观察 FCOB-2.7 灯条是否正常亮起相应颜色(红、绿、蓝、黄、紫、青、白)。
|
||||
* 确认在发送控制数据时马达没有产生误动作或噪鸣。
|
||||
|
||||
Reference in New Issue
Block a user