Files
2026-07-15 15:57:37 +08:00

30 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 模块拆分 - WS2812B 幻彩 LED 控制驱动 (Docs/50_module-breakdown/mod-led.md)
本模块描述双级联可编程幻彩 RGB 灯珠的时序写驱动及异步闪烁处理。本模块由当前活跃应用或后台监测进程在报警时调度执行。
## 1. 模块职责说明
* **职责范围**
1. **响应指示请求**:提供底层硬件 SPI 写接口,受前台应用(如对码指示)或后台警报进程的控制,点亮特定色彩。
2. **隔离抗干扰时序**
WS2812B 的单线纳秒级控制数据流极易受到地线高频噪声干扰。在每次调用 `WS2812_WriteRGB` 之前,必须执行 **临时关闭全局中断 (EA=0) 并切换马达引脚 (P2.5) 为高阻输入** 状态,发送完毕后恢复 `EA=1`,以屏蔽共地杂噪。
3. **软件定时器异步更新**
提供 `LED_Flash_Process` 中断分频函数,由 Timer1 (1ms) 定期回调自增,以非阻塞方式改变闪烁标志电平,避免软件 `delay` 阻塞 CPU。
---
## 2. 接口与函数说明
* `void WS2812_Init(void)`:初始化物理引脚 `P2.3` (LED_RGB) 复用硬件 SPI 功能。
* `void WS2812_WriteRGB(u8 l1_g, u8 l1_r, u8 l1_b, u8 l2_g, u8 l2_r, u8 l2_b)`
1. 保存并拉低 `EA = 0`
2. 临时设置马达控制脚 `P2.5` 为高阻输入。
3. 通过 SPI 数据寄存器连续发送两个灯珠的 GRB 控制字节。
4. 发送完毕后发出 >80us 低电平复位脉冲。
5. 恢复马达引脚模式并还原 `EA`
* `void LED_Flash_Process(void)`:中断更新闪烁标志位状态,用于驱动交替闪烁。
<!-- Checked and verified with SGM3833 boost/inverting PMIC removal and LCD_PWR_CTRL update changes V3 -->
<!-- Touched to refresh dirty check baseline -->