Skip to content

Commit 31585c8

Browse files
committed
feat(led_strip): discontinue esp-idf v4 and bump major version 🚀
1 parent 9a664de commit 31585c8

20 files changed

+289
-490
lines changed

led_strip/CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## 2.6.0
1+
## 3.0.0
2+
3+
- Discontinued support for ESP-IDF v4.x
4+
- Added configuration for user-defined color component format
25

3-
- Add pixel order configuration to support user-defined pixel order.
4-
56
## 2.5.5
67

78
- Simplified the led_strip component dependency, the time of full build with ESP-IDF v5.3 can now be shorter.

led_strip/CMakeLists.txt

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
include($ENV{IDF_PATH}/tools/cmake/version.cmake)
22

3-
set(srcs "src/led_strip_api.c" "src/led_strip_common.c")
3+
set(srcs "src/led_strip_api.c")
44
set(public_requires)
55

6-
# Starting from esp-idf v5.x, the RMT driver is rewritten
7-
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
8-
if(CONFIG_SOC_RMT_SUPPORTED)
9-
list(APPEND srcs "src/led_strip_rmt_dev.c" "src/led_strip_rmt_encoder.c")
10-
endif()
11-
else()
12-
list(APPEND srcs "src/led_strip_rmt_dev_idf4.c")
6+
if(CONFIG_SOC_RMT_SUPPORTED)
7+
list(APPEND srcs "src/led_strip_rmt_dev.c" "src/led_strip_rmt_encoder.c")
138
endif()
149

1510
# the SPI backend driver relies on some feature that was available in IDF 5.1

led_strip/README.md

+34-29
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,29 @@ This is the most economical way to drive the LEDs because it only consumes one R
1515
```c
1616
#define BLINK_GPIO 0
1717

18-
led_strip_handle_t led_strip;
19-
20-
/* LED strip initialization with the GPIO and pixels number*/
18+
/// LED strip common configuration
2119
led_strip_config_t strip_config = {
22-
.strip_gpio_num = BLINK_GPIO, // The GPIO that connected to the LED strip's data line
23-
.max_leds = 1, // The number of LEDs in the strip,
24-
.bytes_per_pixel = 3, // 3 bytes per pixel of the LED strip
25-
.led_model = LED_MODEL_WS2812, // LED strip model
26-
.flags.invert_out = false, // whether to invert the output signal (useful when your hardware has a level inverter)
27-
.pixel_order = LED_STRIP_SET_RGB_ORDER(1, 0, 2), /* The order of the pixel color. Not set or set to 0 if the default order is used.
28-
Here set to the default GRB order to demonstrate usage */
20+
.strip_gpio_num = BLINK_GPIO, // The GPIO that connected to the LED strip's data line
21+
.max_leds = 1, // The number of LEDs in the strip,
22+
.led_model = LED_MODEL_WS2812, // LED strip model, it determines the bit timing
23+
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color component format is G-R-B
24+
.flags = {
25+
.invert_out = false, // don't invert the output signal
26+
}
2927
};
3028

29+
/// RMT backend specific configuration
3130
led_strip_rmt_config_t rmt_config = {
32-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
33-
.rmt_channel = 0,
34-
#else
35-
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
36-
.resolution_hz = 10 * 1000 * 1000, // 10MHz
37-
.flags.with_dma = false, // whether to enable the DMA feature
38-
#endif
31+
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
32+
.resolution_hz = 10 * 1000 * 1000, // RMT counter clock frequency: 10MHz
33+
.mem_block_symbols = 64, // the memory size of each RMT channel, in words (4 bytes)
34+
.flags = {
35+
.with_dma = false, // DMA feature is available on chips like ESP32-S3/P4
36+
}
3937
};
38+
39+
/// Create the LED strip object
40+
led_strip_handle_t led_strip;
4041
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
4142
```
4243
@@ -53,24 +54,28 @@ Please note, the SPI backend has a dependency of **ESP-IDF >= 5.1**
5354
```c
5455
#define BLINK_GPIO 0
5556
56-
led_strip_handle_t led_strip;
57-
58-
/* LED strip initialization with the GPIO and pixels number*/
57+
/// LED strip common configuration
5958
led_strip_config_t strip_config = {
60-
.strip_gpio_num = BLINK_GPIO, // The GPIO that connected to the LED strip's data line
61-
.max_leds = 1, // The number of LEDs in the strip,
62-
.bytes_per_pixel = 3, // 3 bytes per pixel of the LED strip
63-
.led_model = LED_MODEL_WS2812, // LED strip model
64-
.flags.invert_out = false, // whether to invert the output signal (useful when your hardware has a level inverter)
65-
.pixel_order = LED_STRIP_SET_RGB_ORDER(1, 0, 2), /* The order of the pixel color. Not set or set to 0 if the default order is used.
66-
Here set to the default GRB order to demonstrate usage */
59+
.strip_gpio_num = BLINK_GPIO, // The GPIO that connected to the LED strip's data line
60+
.max_leds = 1, // The number of LEDs in the strip,
61+
.led_model = LED_MODEL_WS2812, // LED strip model, it determines the bit timing
62+
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color component format is G-R-B
63+
.flags = {
64+
.invert_out = false, // don't invert the output signal
65+
}
6766
};
6867
68+
/// SPI backend specific configuration
6969
led_strip_spi_config_t spi_config = {
7070
.clk_src = SPI_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
71-
.flags.with_dma = true, // Using DMA can improve performance and help drive more LEDs
72-
.spi_bus = SPI2_HOST, // SPI bus ID
71+
.spi_bus = SPI2_HOST, // SPI bus ID
72+
.flags = {
73+
.with_dma = true, // Using DMA can improve performance and help drive more LEDs
74+
}
7375
};
76+
77+
/// Create the LED strip object
78+
led_strip_handle_t led_strip;
7479
ESP_ERROR_CHECK(led_strip_new_spi_device(&strip_config, &spi_config, &led_strip));
7580
```
7681

led_strip/api.md

+92-61
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121
| esp\_err\_t | [**led\_strip\_set\_pixel\_hsv**](#function-led_strip_set_pixel_hsv) ([**led\_strip\_handle\_t**](#typedef-led_strip_handle_t) strip, uint32\_t index, uint16\_t hue, uint8\_t saturation, uint8\_t value) <br>_Set HSV for a specific pixel._ |
2222
| esp\_err\_t | [**led\_strip\_set\_pixel\_rgbw**](#function-led_strip_set_pixel_rgbw) ([**led\_strip\_handle\_t**](#typedef-led_strip_handle_t) strip, uint32\_t index, uint32\_t red, uint32\_t green, uint32\_t blue, uint32\_t white) <br>_Set RGBW for a specific pixel._ |
2323

24-
## Macros
25-
26-
| Type | Name |
27-
| ---: | :--- |
28-
| define | [**LED\_STRIP\_SET\_RGBW\_ORDER**](#define-led_strip_set_rgbw_order) (R, G, B, W) (R &lt;&lt; 0 \| G &lt;&lt; 2 \| B &lt;&lt; 4 \| W &lt;&lt; 6)<br>_Help macro to set pixel RGBW color order The default order of the four-color LED strips is GRBW. If you have a different order, you can use the macro to set_ `pixel_order`_in_[_**led\_strip\_config\_t**_](#struct-led_strip_config_t)_. The positions are counted from the least significant bit (LSB)._ |
29-
| define | [**LED\_STRIP\_SET\_RGB\_ORDER**](#define-led_strip_set_rgb_order) (R, G, B) (R &lt;&lt; 0 \| G &lt;&lt; 2 \| B &lt;&lt; 4)<br>_Help macro to set pixel RGB color order The default order of the three-color LED strips is GRB. If you have a different order, you can use the macro to set_ `pixel_order`_in_[_**led\_strip\_config\_t**_](#struct-led_strip_config_t)_. The positions are counted from the least significant bit (LSB)._ |
30-
3124
## Functions Documentation
3225

3326
### function `led_strip_clear`
@@ -185,52 +178,14 @@ Also see `led_strip_set_pixel` if you only want to specify the RGB part of the c
185178
- ESP\_ERR\_INVALID\_ARG: Set RGBW color for a specific pixel failed because of an invalid argument
186179
- ESP\_FAIL: Set RGBW color for a specific pixel failed because other error occurred
187180

188-
## Macros Documentation
189-
190-
### define `LED_STRIP_SET_RGBW_ORDER`
191-
192-
_Help macro to set pixel RGBW color order The default order of the four-color LED strips is GRBW. If you have a different order, you can use the macro to set_ `pixel_order`_in_[_**led\_strip\_config\_t**_](#struct-led_strip_config_t)_. The positions are counted from the least significant bit (LSB)._
193-
194-
```c
195-
#define LED_STRIP_SET_RGBW_ORDER (R, G, B, W) (R << 0 | G << 2 | B << 4 | W << 6)
196-
```
197-
198-
**Parameters:**
199-
200-
- `R` The position of the red channel in the color order.
201-
- `G` The position of the green channel in the color order.
202-
- `B` The position of the blue channel in the color order.
203-
- `W` The position of the white channel in the color order.
204-
205-
**Note:**
206-
207-
The order starts from 0. And the user needs to make sure that all the numbers appear exactly once and are all less than the number of colors per pixel.
208-
209-
### define `LED_STRIP_SET_RGB_ORDER`
210-
211-
_Help macro to set pixel RGB color order The default order of the three-color LED strips is GRB. If you have a different order, you can use the macro to set_ `pixel_order`_in_[_**led\_strip\_config\_t**_](#struct-led_strip_config_t)_. The positions are counted from the least significant bit (LSB)._
212-
213-
```c
214-
#define LED_STRIP_SET_RGB_ORDER (R, G, B) (R << 0 | G << 2 | B << 4)
215-
```
216-
217-
**Parameters:**
218-
219-
- `R` The position of the red channel in the color order.
220-
- `G` The position of the green channel in the color order.
221-
- `B` The position of the blue channel in the color order.
222-
223-
**Note:**
224-
225-
The order starts from 0. And the user needs to make sure that all the numbers appear exactly once and are all less than the number of colors per pixel.
226-
227181
## File include/led_strip_rmt.h
228182

229183
## Structures and Types
230184

231185
| Type | Name |
232186
| ---: | :--- |
233187
| struct | [**led\_strip\_rmt\_config\_t**](#struct-led_strip_rmt_config_t) <br>_LED Strip RMT specific configuration._ |
188+
| struct | [**led\_strip\_rmt\_extra\_config**](#struct-led_strip_rmt_config_tled_strip_rmt_extra_config) <br> |
234189

235190
## Functions
236191

@@ -248,12 +203,16 @@ Variables:
248203

249204
- rmt\_clock\_source\_t clk_src <br>RMT clock source
250205

251-
- struct led\_strip\_rmt\_config\_t::@0 flags <br>Extra driver flags
206+
- struct [**led\_strip\_rmt\_config\_t::led\_strip\_rmt\_extra\_config**](#struct-led_strip_rmt_config_tled_strip_rmt_extra_config) flags <br>Extra driver flags
252207

253-
- size\_t mem_block_symbols <br>How many RMT symbols can one RMT channel hold at one time. Set to 0 will fallback to use the default size.
208+
- size\_t mem_block_symbols <br>How many RMT symbols can one RMT channel hold at one time. Set to 0 will fallback to use the default size. Extra RMT specific driver flags
254209

255210
- uint32\_t resolution_hz <br>RMT tick resolution, if set to zero, a default resolution (10MHz) will be applied
256211

212+
### struct `led_strip_rmt_config_t::led_strip_rmt_extra_config`
213+
214+
Variables:
215+
257216
- uint32\_t with_dma <br>Use DMA to transmit data
258217

259218
## Functions Documentation
@@ -307,7 +266,7 @@ Variables:
307266

308267
- spi\_clock\_source\_t clk_src <br>SPI clock source
309268

310-
- struct led\_strip\_spi\_config\_t::@1 flags <br>Extra driver flags
269+
- struct [**led\_strip\_spi\_config\_t**](#struct-led_strip_spi_config_t) flags <br>Extra driver flags
311270

312271
- spi\_host\_device\_t spi_bus <br>SPI bus ID. Which buses are available depends on the specific chip
313272

@@ -351,12 +310,54 @@ Although only the MOSI line is used for generating the signal, the whole SPI bus
351310

352311
| Type | Name |
353312
| ---: | :--- |
313+
| union | [**led\_color\_component\_format\_t**](#union-led_color_component_format_t) <br>_LED color component format._ |
314+
| struct | [**format\_layout**](#struct-led_color_component_format_tformat_layout) <br> |
354315
| enum | [**led\_model\_t**](#enum-led_model_t) <br>_LED strip model._ |
355-
| struct | [**led\_strip\_config\_t**](#struct-led_strip_config_t) <br>_LED Strip Configuration._ |
356-
| typedef struct [**led\_strip\_t**](#struct-led_strip_t) \* | [**led\_strip\_handle\_t**](#typedef-led_strip_handle_t) <br>_LED strip handle._ |
316+
| struct | [**led\_strip\_config\_t**](#struct-led_strip_config_t) <br>_LED Strip common configurations The common configurations are not specific to any backend peripheral._ |
317+
| struct | [**led\_strip\_extra\_flags**](#struct-led_strip_config_tled_strip_extra_flags) <br> |
318+
| typedef struct [**led\_strip\_t**](#struct-led_strip_t) \* | [**led\_strip\_handle\_t**](#typedef-led_strip_handle_t) <br>_Type of LED strip handle._ |
319+
320+
## Macros
321+
322+
| Type | Name |
323+
| ---: | :--- |
324+
| define | [**LED\_STRIP\_COLOR\_COMPONENT\_FMT\_GRB**](#define-led_strip_color_component_fmt_grb) ([**led\_color\_component\_format\_t**](#union-led_color_component_format_t)){.format = {.r\_pos = 1, .g\_pos = 0, .b\_pos = 2, .w\_pos = 3, .reserved = 0, .num\_components = 3}}<br>_Helper macros to set the color component format._ |
325+
| define | [**LED\_STRIP\_COLOR\_COMPONENT\_FMT\_GRBW**](#define-led_strip_color_component_fmt_grbw) ([**led\_color\_component\_format\_t**](#union-led_color_component_format_t)){.format = {.r\_pos = 1, .g\_pos = 0, .b\_pos = 2, .w\_pos = 3, .reserved = 0, .num\_components = 4}}<br> |
326+
| define | [**LED\_STRIP\_COLOR\_COMPONENT\_FMT\_RGB**](#define-led_strip_color_component_fmt_rgb) ([**led\_color\_component\_format\_t**](#union-led_color_component_format_t)){.format = {.r\_pos = 0, .g\_pos = 1, .b\_pos = 2, .w\_pos = 3, .reserved = 0, .num\_components = 3}}<br> |
327+
| define | [**LED\_STRIP\_COLOR\_COMPONENT\_FMT\_RGBW**](#define-led_strip_color_component_fmt_rgbw) ([**led\_color\_component\_format\_t**](#union-led_color_component_format_t)){.format = {.r\_pos = 0, .g\_pos = 1, .b\_pos = 2, .w\_pos = 3, .reserved = 0, .num\_components = 4}}<br> |
357328

358329
## Structures and Types Documentation
359330

331+
### union `led_color_component_format_t`
332+
333+
_LED color component format._
334+
335+
**Note:**
336+
337+
The format is used to specify the order of color components in each pixel, also the number of color components.
338+
339+
Variables:
340+
341+
- struct [**led\_color\_component\_format\_t::format\_layout**](#struct-led_color_component_format_tformat_layout) format <br>Format layout
342+
343+
- uint32\_t format_id <br>Format ID
344+
345+
### struct `led_color_component_format_t::format_layout`
346+
347+
Variables:
348+
349+
- uint32\_t b_pos <br>Position of the blue channel in the color order: 0~3
350+
351+
- uint32\_t g_pos <br>Position of the green channel in the color order: 0~3
352+
353+
- uint32\_t num_components <br>Number of color components per pixel: 3 or 4. If set to 0, it will fallback to 3
354+
355+
- uint32\_t r_pos <br>Position of the red channel in the color order: 0~3
356+
357+
- uint32\_t reserved <br>Reserved
358+
359+
- uint32\_t w_pos <br>Position of the white channel in the color order: 0~3
360+
360361
### enum `led_model_t`
361362

362363
_LED strip model._
@@ -375,40 +376,70 @@ Different led model may have different timing parameters, so we need to distingu
375376

376377
### struct `led_strip_config_t`
377378

378-
_LED Strip Configuration._
379+
_LED Strip common configurations The common configurations are not specific to any backend peripheral._
379380

380381
Variables:
381382

382-
- uint8\_t bytes_per_pixel <br>bytes per LED pixel. Should be 3 or 4
383+
- [**led\_color\_component\_format\_t**](#union-led_color_component_format_t) color_component_format <br>Specifies the order of color components in each pixel. Use helper macros like `LED_STRIP_COLOR_COMPONENT_FMT_GRB` to set the format LED strip extra driver flags
383384

384-
- struct led\_strip\_config\_t::@2 flags <br>The order of the pixel color. Use help macro LED\_STRIP\_SET\_RGB\_ORDER or LED\_STRIP\_SET\_RGBW\_ORDER to set. Not set or set to 0 if the default order is used. Extra driver flags
385+
- struct [**led\_strip\_config\_t::led\_strip\_extra\_flags**](#struct-led_strip_config_tled_strip_extra_flags) flags <br>Extra driver flags
385386

386-
- uint32\_t invert_out <br>Invert output signal
387+
- [**led\_model\_t**](#enum-led_model_t) led_model <br>Specifies the LED strip model (e.g., WS2812, SK6812)
387388

388-
- [**led\_model\_t**](#enum-led_model_t) led_model <br>LED model
389+
- uint32\_t max_leds <br>Maximum number of LEDs that can be controlled in a single strip
389390

390-
- uint32\_t max_leds <br>Maximum LEDs in a single strip
391+
- int strip_gpio_num <br>GPIO number that used by LED strip
391392

392-
- uint8\_t pixel_order
393+
### struct `led_strip_config_t::led_strip_extra_flags`
393394

394-
- int strip_gpio_num <br>GPIO number that used by LED strip
395+
Variables:
396+
397+
- uint32\_t invert_out <br>Invert output signal
395398

396399
### typedef `led_strip_handle_t`
397400

398-
_LED strip handle._
401+
_Type of LED strip handle._
399402

400403
```c
401404
typedef struct led_strip_t* led_strip_handle_t;
402405
```
403406

407+
## Macros Documentation
408+
409+
### define `LED_STRIP_COLOR_COMPONENT_FMT_GRB`
410+
411+
_Helper macros to set the color component format._
412+
413+
```c
414+
#define LED_STRIP_COLOR_COMPONENT_FMT_GRB ( led_color_component_format_t ){.format = {.r_pos = 1, .g_pos = 0, .b_pos = 2, .w_pos = 3, .reserved = 0, .num_components = 3}}
415+
```
416+
417+
### define `LED_STRIP_COLOR_COMPONENT_FMT_GRBW`
418+
419+
```c
420+
#define LED_STRIP_COLOR_COMPONENT_FMT_GRBW ( led_color_component_format_t ){.format = {.r_pos = 1, .g_pos = 0, .b_pos = 2, .w_pos = 3, .reserved = 0, .num_components = 4}}
421+
```
422+
423+
### define `LED_STRIP_COLOR_COMPONENT_FMT_RGB`
424+
425+
```c
426+
#define LED_STRIP_COLOR_COMPONENT_FMT_RGB ( led_color_component_format_t ){.format = {.r_pos = 0, .g_pos = 1, .b_pos = 2, .w_pos = 3, .reserved = 0, .num_components = 3}}
427+
```
428+
429+
### define `LED_STRIP_COLOR_COMPONENT_FMT_RGBW`
430+
431+
```c
432+
#define LED_STRIP_COLOR_COMPONENT_FMT_RGBW ( led_color_component_format_t ){.format = {.r_pos = 0, .g_pos = 1, .b_pos = 2, .w_pos = 3, .reserved = 0, .num_components = 4}}
433+
```
434+
404435
## File interface/led_strip_interface.h
405436

406437
## Structures and Types
407438

408439
| Type | Name |
409440
| ---: | :--- |
410441
| struct | [**led\_strip\_t**](#struct-led_strip_t) <br>_LED strip interface definition._ |
411-
| typedef struct [**led\_strip\_t**](#struct-led_strip_t) | [**led\_strip\_t**](#typedef-led_strip_t) <br> |
442+
| typedef struct led\_strip\_t | [**led\_strip\_t**](#typedef-led_strip_t) <br> |
412443

413444
## Structures and Types Documentation
414445

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# For more information about build system see
2-
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3-
# The following five lines of boilerplate have to be in your project's
4-
# CMakeLists in this exact order for cmake to work correctly
51
cmake_minimum_required(VERSION 3.16)
62

3+
set(COMPONENTS main)
4+
75
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
86
project(led_strip_rmt_ws2812)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## IDF Component Manager Manifest File
22
dependencies:
33
espressif/led_strip:
4-
version: '^2'
4+
version: '^3'
55
override_path: '../../../'

0 commit comments

Comments
 (0)