Skip to content

Commit db702a5

Browse files
Merge branch 'feature/add_sm16825e_driver' into 'master'
feat(lightbulb_driver): add sm16825e chip driver See merge request ae_group/esp-iot-solution!1357
2 parents a59d9f8 + 4921508 commit db702a5

File tree

16 files changed

+1349
-66
lines changed

16 files changed

+1349
-66
lines changed

components/led/lightbulb_driver/CHANGELOG.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## v1.10.0 - 2025-08-19
4+
5+
### Improve:
6+
7+
* Added new dimming driver SM16825E
8+
39
## v1.9.0 - 2025-08-11
410

511
### Improve:
@@ -61,7 +67,7 @@
6167

6268
### Enhancements:
6369

64-
* Remove linear dimming, default to enabling curve dimming for all.
70+
* Remove linear dimming, default to enabling curve dimming for all.
6571

6672
## v1.4.0 - 2024-11-15
6773

@@ -151,7 +157,7 @@
151157
* The driver now supports setting white balance parameters for all channels. This means that you can adjust the white balance individually for each channel, allowing for precise control and customization of the lighting output.
152158
* Increased the power limit range from 100-300 to 100-500, facilitating power setting for RGBWW beads.
153159
* Introduced CCT output modes: standard mode (consistent with original scheme, mapping percentage to Kelvin values proportionally) and precise mode (setting individual percentages for each Kelvin value and predetermining current coefficients for each channel, scaling these coefficients proportionally during writing).
154-
* Some configuration changes:
160+
* Some configuration changes:
155161
* Removed mode_mask from capability, now using led_beads to set the LED panel bead combination
156162
* Renamed enable_mix_cct to enable_hardware_cct, fades_ms to fade_time_ms, and enable_fades to enable_fade
157163
* Removed hardware_monitor_cb
@@ -194,6 +200,7 @@
194200
* Add a phase delay function to the PWM drive, and after enabling this function, all channel outputs will be in a complementary state.
195201

196202
## v0.4.1 - 2023-8-30
203+
197204
### Bug Fixes:
198205

199206
* Fixed a thread safety issue.
@@ -347,8 +354,8 @@
347354
### Enhancements:
348355

349356
* Initial version
350-
351357
* The following dimming solutions are supported
358+
352359
* PWM
353360
* RGB + CW
354361
* RGB + CCT/Brightness
@@ -360,13 +367,14 @@
360367
* BP5758/BP5758D/BP5768D
361368
* Single Line
362369
* WS2812
363-
364370
* Support for power limit
365371
* Support for color calibration
366372
* Support for effect
373+
367374
* Blink
368375
* Breathe
369376
* Support for application layer capability configuration
377+
370378
* Status memory
371379
* Fade
372380
* Mix CCT

components/led/lightbulb_driver/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ if(CONFIG_ENABLE_WS2812_DRIVER)
6363
list(APPEND incs "drivers/ws2812")
6464
endif()
6565

66+
if(CONFIG_ENABLE_SM16825E_DRIVER)
67+
list(APPEND srcs "drivers/sm16825e/sm16825e.c")
68+
list(APPEND incs "drivers/sm16825e")
69+
endif()
70+
6671
idf_component_register(SRCS ${srcs}
6772
INCLUDE_DIRS ${incs}
6873
PRIV_INCLUDE_DIRS "src/priv_include"

components/led/lightbulb_driver/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ menu "LightBulb Driver Config"
5757
help
5858
Enable ws2812 output.
5959

60+
config ENABLE_SM16825E_DRIVER
61+
bool "Enable sm16825e interface"
62+
default "y"
63+
help
64+
Enable SM16825E output.
65+
6066
menu "IIC Config"
6167
depends on ENABLE_KP18058_DRIVER || ENABLE_BP1658CJ_DRIVER || ENABLE_BP57X8D_DRIVER || ENABLE_SM2X35EGH_DRIVER || ENABLE_SM2135EH_DRIVER || ENABLE_SM2135E_DRIVER
6268

components/led/lightbulb_driver/README.md

Lines changed: 144 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ The lightbulb component encapsulates several commonly used dimming schemes for l
88

99
- RGB + C/W
1010
- RGB + CCT/Brightness
11-
1211
- IIC Dimming Scheme
1312

1413
- ~~SM2135E~~
@@ -18,10 +17,10 @@ The lightbulb component encapsulates several commonly used dimming schemes for l
1817
- BP57x8D (BP5758/BP5758D/BP5768)
1918
- BP1658CJ
2019
- KP18058
21-
2220
- Single Bus Scheme:
2321

2422
- WS2812
23+
- SM16825E
2524

2625
## Supported common functionalities
2726

@@ -130,6 +129,8 @@ lightbulb_init(&config);
130129

131130
## Example of Single-bus Scheme
132131

132+
### WS2812 Usage example
133+
133134
Single-bus scheme utilizes the SPI driver to output data for WS2812 LEDs, with data packaging sequence set as GRB.
134135

135136
```c
@@ -164,6 +165,139 @@ lightbulb_config_t config = {
164165
lightbulb_init(&config);
165166
```
166167
168+
### SM16825E usage example
169+
170+
The SM16825E is an RGBWY five-channel LED driver that uses an SPI interface and RZ coding protocol, supporting 16-bit grey scale control and current regulation.
171+
172+
```cpp
173+
lightbulb_config_t config = {
174+
//1. Select SM16825E output and configure parameters
175+
.type = DRIVER_SM16825E,
176+
.driver_conf.sm16825e.led_num = 1, // Number of LED chips
177+
.driver_conf.sm16825e.ctrl_io = 9, // Control GPIO pin
178+
.driver_conf.sm16825e.freq_hz = 3333000, // SPI frequency (default: 3.33MHz, auto-calculated based on RZ protocol timing)
179+
180+
//2. Driver capability selection, enable/disable according to your needs
181+
.capability.enable_fade = true,
182+
.capability.fade_time_ms = 800,
183+
.capability.enable_lowpower = false,
184+
.capability.enable_status_storage = true,
185+
.capability.led_beads = LED_BEADS_5CH_RGBCW, // Supports 5-channel RGBWY
186+
.capability.storage_cb = NULL,
187+
.capability.sync_change_brightness_value = true,
188+
189+
//3. Limit parameters, see details in later sections
190+
.external_limit = NULL,
191+
192+
//4. Color calibration parameters
193+
.gamma_conf = NULL,
194+
195+
//5. Initialize lighting parameters; if "on" is set, the light will turn on during driver initialization
196+
.init_status.mode = WORK_COLOR,
197+
.init_status.on = true,
198+
.init_status.hue = 0,
199+
.init_status.saturation = 100,
200+
.init_status.value = 100,
201+
};
202+
lightbulb_init(&config);
203+
204+
// Optional: Configure channel mapping (if custom pin mapping is needed)
205+
sm16825e_regist_channel(SM16825E_CHANNEL_R, SM16825E_PIN_OUTR);
206+
sm16825e_regist_channel(SM16825E_CHANNEL_G, SM16825E_PIN_OUTG);
207+
sm16825e_regist_channel(SM16825E_CHANNEL_B, SM16825E_PIN_OUTB);
208+
sm16825e_regist_channel(SM16825E_CHANNEL_W, SM16825E_PIN_OUTW);
209+
sm16825e_regist_channel(SM16825E_CHANNEL_Y, SM16825E_PIN_OUTY);
210+
211+
// Optional: Set channel current (10-300mA)
212+
sm16825e_set_channel_current(SM16825E_CHANNEL_R, 100); // 100mA
213+
sm16825e_set_channel_current(SM16825E_CHANNEL_G, 100); // 100mA
214+
sm16825e_set_channel_current(SM16825E_CHANNEL_B, 100); // 100mA
215+
sm16825e_set_channel_current(SM16825E_CHANNEL_W, 100); // 100mA
216+
sm16825e_set_channel_current(SM16825E_CHANNEL_Y, 100); // 100mA
217+
218+
// Optional: Enable/disable standby mode
219+
sm16825e_set_standby(false); // Disable standby mode, enable normal operation
220+
221+
// Optional: Shutdown all channels
222+
// sm16825e_set_shutdown();
223+
```
224+
225+
**Features of SM16825E**
226+
227+
* Supports RGBWY five-channel independent control
228+
* 16-bit grayscale resolution (65,536 levels)
229+
* Adjustable current control (10-300mA per channel)
230+
* Supports standby mode (power consumption <2mW)
231+
* RZ encoding protocol, 800Kbps data transmission rate, 1200ns code period
232+
* Support multi-chip cascading
233+
* Auto-timing calculation: dynamically calculates SPI frequency and bit patterns based on datasheet parameters
234+
* Flexible channel mapping: supports arbitrary mapping from logical channels to physical pins
235+
* Optimized SPI transmission: uses 3.33MHz SPI frequency, each SM16825E bit encoded with 4 SPI bits
236+
237+
#### SM16825E Advanced Features
238+
239+
##### Channel Mapping Configuration
240+
241+
SM16825E supports flexible channel mapping, allowing logical channels (R, G, B, W, Y) to be mapped to arbitrary physical pins:
242+
243+
```c
244+
// Custom channel mapping example
245+
sm16825e_regist_channel(SM16825E_CHANNEL_R, SM16825E_PIN_OUT1); // Red mapped to OUT1
246+
sm16825e_regist_channel(SM16825E_CHANNEL_G, SM16825E_PIN_OUT2); // Green mapped to OUT2
247+
sm16825e_regist_channel(SM16825E_CHANNEL_B, SM16825E_PIN_OUT3); // Blue mapped to OUT3
248+
sm16825e_regist_channel(SM16825E_CHANNEL_W, SM16825E_PIN_OUT4); // White mapped to OUT4
249+
sm16825e_regist_channel(SM16825E_CHANNEL_Y, SM16825E_PIN_OUT5); // Yellow mapped to OUT5
250+
```
251+
252+
##### Current Control
253+
254+
Each channel can independently set current value, range 10-300mA:
255+
256+
```c
257+
// Set current for different channels
258+
sm16825e_set_channel_current(SM16825E_CHANNEL_R, config->current[SM16825E_CHANNEL_R]); // Red Channel
259+
sm16825e_set_channel_current(SM16825E_CHANNEL_G, config->current[SM16825E_CHANNEL_G]); // Green Channel
260+
sm16825e_set_channel_current(SM16825E_CHANNEL_B, config->current[SM16825E_CHANNEL_B]); // Blue Channel
261+
sm16825e_set_channel_current(SM16825E_CHANNEL_W, config->current[SM16825E_CHANNEL_W]); // White Channel
262+
sm16825e_set_channel_current(SM16825E_CHANNEL_Y, config->current[SM16825E_CHANNEL_Y]); // Yellow Channel
263+
```
264+
265+
##### Standby Mode Control
266+
267+
Supports standby mode to reduce power consumption:
268+
269+
```c
270+
// Enable standby mode (power consumption <2mW)
271+
sm16825e_set_standby(true);
272+
273+
// Disable standby mode, resume normal operation
274+
sm16825e_set_standby(false);
275+
```
276+
277+
##### Direct Channel Control
278+
279+
Can directly set RGBWY channel values (0-255):
280+
281+
```c
282+
// Set channel values
283+
sm16825e_set_rgbwy_channel(255, 128, 64, 192, 96);
284+
// Parameter order: red, green, blue, white, yellow
285+
286+
// Shutdown all channels
287+
sm16825e_set_shutdown();
288+
```
289+
290+
##### Timing Optimization Details
291+
292+
The driver automatically calculates optimal timing based on datasheet parameters:
293+
294+
- **RZ Encoding**: 800Kbps effective transmission rate, 1200ns code period
295+
- **SPI Frequency**: 3.33MHz, each SM16825E bit encoded with 4 SPI bits
296+
- **Timing Parameters**:
297+
- T0 bit: 300ns high level + 900ns low level
298+
- T1 bit: 900ns high level + 300ns low level
299+
- Reset signal: minimum 200μs low level
300+
167301
## Example of Limit Parameters
168302

169303
The primary purpose of limit parameters is to restrict the maximum output power and constrain the brightness parameters within a specific range. This component allows independent control of colored light and white light, which results in two sets of maximum/minimum brightness parameters and power parameters. Colored light uses the HSV model, with the value representing colored light brightness, while white light uses the brightness parameter. The input range for both value and brightness is 0 <= x <= 100.
@@ -195,16 +329,14 @@ input output
195329

196330
Power limit is applied after the brightness parameter limitations, and for the RGB channel adjustment, the range is 100 <= x <= 300. The relationship between input and output is as follows:
197331

198-
```c
199-
input output(color_max_power = 100) output(color_max_power = 200) output(color_max_power = 300)
200-
255,255,0 127,127,0 255,255,0 255,255,0
201-
127,127,0 63,63,0 127,127,0 127,127,0
202-
63,63,0 31,31,0 63,63,0 63,63,0
203-
255,255,255 85,85,85 170,170,170 255,255,255
204-
127,127,127 42,42,42 84,84,84 127,127,127
205-
63,63,63 21,21,21 42,42,42 63,63,63
206-
207-
```
332+
| input | output(color_max_power = 100) | output(color_max_power = 200) | output(color_max_power = 300) |
333+
| :---------: | :---------------------------: | :---------------------------: | :---------------------------: |
334+
| 255,255,0 | 127,127,0 | 255,255,0 | 255,255,0 |
335+
| 127,127,0 | 63,63,0 | 127,127,0 | 127,127,0 |
336+
| 63,63,0 | 31,31,0 | 63,63,0 | 63,63,0 |
337+
| 255,255,255 | 85,85,85 | 170,170,170 | 255,255,255 |
338+
| 127,127,127 | 42,42,42 | 84,84,84 | 127,127,127 |
339+
| 63,63,63 | 21,21,21 | 42,42,42 | 63,63,63 |
208340

209341
## Example of Calibration Parameters
210342

0 commit comments

Comments
 (0)