Skip to content

Commit 4cb75c4

Browse files
authored
doc: update led_strip doc for pixel format and led model (#127)
1 parent ccd598e commit 4cb75c4

8 files changed

+44
-22
lines changed

led_strip/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ led_strip_handle_t led_strip;
2020
/* LED strip initialization with the GPIO and pixels number*/
2121
led_strip_config_t strip_config = {
2222
.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
23+
.max_leds = 1, // The number of LEDs in the strip,
24+
.led_pixel_format = LED_PIXEL_FORMAT_GRB, // Pixel format of your 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)
2427
};
2528

2629
led_strip_rmt_config_t rmt_config = {
2730
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
2831
.resolution_hz = 10 * 1000 * 1000, // 10MHz
29-
.flags.with_dma = false, // wether to enable the DMA feature
32+
.flags.with_dma = false, // whether to enable the DMA feature
3033
};
3134
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
3235
```

led_strip/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "2.2.0"
1+
version: "2.2.1"
22
description: Driver for Addressable LED Strip (WS2812, etc)
33
url: https://github.com/espressif/idf-extra-components/tree/master/led_strip
44
dependencies:

led_strip/include/led_strip.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ esp_err_t led_strip_set_pixel(led_strip_handle_t strip, uint32_t index, uint32_t
3232
/**
3333
* @brief Set RGBW for a specific pixel
3434
*
35+
* @note Only call this function if your led strip does have the white component (e.g. SK6812-RGBW)
36+
* @note Also see `led_strip_set_pixel` if you only want to specify the RGB part of the color and bypass the white component
37+
*
3538
* @param strip: LED strip
3639
* @param index: index of pixel to set
3740
* @param red: red part of color
3841
* @param green: green part of color
3942
* @param blue: blue part of color
40-
* @param white: separate white component (sk6812rgbw leds)
43+
* @param white: separate white component
4144
*
4245
* @return
43-
* - ESP_OK: RGBW color succesfully set for the pixel
44-
* - ESP_ERR_INVALID_ARG: Set RGB for a specific pixel failed because of an invalid argument
46+
* - ESP_OK: Set RGBW color for a specific pixel successfully
47+
* - ESP_ERR_INVALID_ARG: Set RGBW color for a specific pixel failed because of an invalid argument
48+
* - ESP_FAIL: Set RGBW color for a specific pixel failed because other error occurred
4549
*/
4650
esp_err_t led_strip_set_pixel_rgbw(led_strip_handle_t strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white);
4751

led_strip/include/led_strip_types.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@
1111
extern "C" {
1212
#endif
1313

14+
/**
15+
* @brief LED strip pixel format
16+
*/
1417
typedef enum {
15-
LED_PIXEL_FORMAT_GRB,
16-
LED_PIXEL_FORMAT_GRBW
18+
LED_PIXEL_FORMAT_GRB, /*!< Pixel format: GRB */
19+
LED_PIXEL_FORMAT_GRBW, /*!< Pixel format: GRBW */
20+
LED_PIXEL_FORMAT_INVALID /*!< Invalid pixel format */
1721
} led_pixel_format_t;
1822

23+
/**
24+
* @brief LED strip model
25+
* @note Different led model may have different timing parameters, so we need to distinguish them.
26+
*/
1927
typedef enum {
20-
LED_MODEL_WS2812,
21-
LED_MODEL_SK6812
28+
LED_MODEL_WS2812, /*!< LED strip model: WS2812 */
29+
LED_MODEL_SK6812, /*!< LED strip model: SK6812 */
30+
LED_MODEL_INVALID /*!< Invalid LED strip model */
2231
} led_model_t;
2332

2433
/**
@@ -32,8 +41,8 @@ typedef struct led_strip_t *led_strip_handle_t;
3241
typedef struct {
3342
uint32_t strip_gpio_num; /*!< GPIO number that used by LED strip */
3443
uint32_t max_leds; /*!< Maximum LEDs in a single strip */
35-
led_pixel_format_t led_pixel_format;
36-
led_model_t led_model;
44+
led_pixel_format_t led_pixel_format; /*!< LED pixel format */
45+
led_model_t led_model; /*!< LED model */
3746
struct {
3847
uint32_t invert_out: 1; /*!< Invert output signal */
3948
} flags;

led_strip/interface/led_strip_interface.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ struct led_strip_t {
3535
esp_err_t (*set_pixel)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue);
3636

3737
/**
38-
* @brief Set RGBW for a specific pixel
38+
* @brief Set RGBW for a specific pixel. Similar to `set_pixel` but also set the white component
3939
*
4040
* @param strip: LED strip
4141
* @param index: index of pixel to set
4242
* @param red: red part of color
4343
* @param green: green part of color
4444
* @param blue: blue part of color
45-
* @param white: separate white component (sk6812rgbw leds)
45+
* @param white: separate white component
4646
*
4747
* @return
48-
* - ESP_OK: RGBW color succesfully set for the pixel
49-
* - ESP_ERR_INVALID_ARG: Set RGB for a specific pixel failed because of an invalid argument
48+
* - ESP_OK: Set RGBW color for a specific pixel successfully
49+
* - ESP_ERR_INVALID_ARG: Set RGBW color for a specific pixel failed because of an invalid argument
50+
* - ESP_FAIL: Set RGBW color for a specific pixel failed because other error occurred
5051
*/
5152
esp_err_t (*set_pixel_rgbw)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white);
5253

led_strip/src/led_strip_rmt_dev.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ esp_err_t led_strip_new_rmt_device(const led_strip_config_t *led_config, const l
9292
led_strip_rmt_obj *rmt_strip = NULL;
9393
esp_err_t ret = ESP_OK;
9494
ESP_GOTO_ON_FALSE(led_config && rmt_config && ret_strip, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
95-
ESP_GOTO_ON_FALSE(led_config->led_pixel_format <= LED_PIXEL_FORMAT_GRBW, ESP_ERR_INVALID_ARG, err, TAG, "invalid led_pixel_format");
95+
ESP_GOTO_ON_FALSE(led_config->led_pixel_format < LED_PIXEL_FORMAT_INVALID, ESP_ERR_INVALID_ARG, err, TAG, "invalid led_pixel_format");
9696
uint8_t bytes_per_pixel;
9797
if (led_config->led_pixel_format == LED_PIXEL_FORMAT_GRBW) {
9898
bytes_per_pixel = 4;
99-
} else {
99+
} else if (led_config->led_pixel_format == LED_PIXEL_FORMAT_GRB) {
100100
bytes_per_pixel = 3;
101+
} else {
102+
assert(false);
101103
}
102104
rmt_strip = calloc(1, sizeof(led_strip_rmt_obj) + led_config->max_leds * bytes_per_pixel);
103105
ESP_GOTO_ON_FALSE(rmt_strip, ESP_ERR_NO_MEM, err, TAG, "no mem for rmt strip");

led_strip/src/led_strip_rmt_encoder.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rm
7676
esp_err_t ret = ESP_OK;
7777
rmt_led_strip_encoder_t *led_encoder = NULL;
7878
ESP_GOTO_ON_FALSE(config && ret_encoder, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
79+
ESP_GOTO_ON_FALSE(config->led_model < LED_MODEL_INVALID, ESP_ERR_INVALID_ARG, err, TAG, "invalid led model");
7980
led_encoder = calloc(1, sizeof(rmt_led_strip_encoder_t));
8081
ESP_GOTO_ON_FALSE(led_encoder, ESP_ERR_NO_MEM, err, TAG, "no mem for led strip encoder");
8182
led_encoder->base.encode = rmt_encode_led_strip;
@@ -96,9 +97,9 @@ esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rm
9697
.level1 = 0,
9798
.duration1 = 0.6 * config->resolution / 1000000, // T1L=0.6us
9899
},
99-
.flags.msb_first = 1 // SK6812 transfer bit order: G7...G0R7...R0B7...B0W7...W0
100+
.flags.msb_first = 1 // SK6812 transfer bit order: G7...G0R7...R0B7...B0(W7...W0)
100101
};
101-
} else {
102+
} else if (config->led_model == LED_MODEL_WS2812) {
102103
// different led strip might have its own timing requirements, following parameter is for WS2812
103104
bytes_encoder_config = (rmt_bytes_encoder_config_t) {
104105
.bit0 = {
@@ -115,6 +116,8 @@ esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rm
115116
},
116117
.flags.msb_first = 1 // WS2812 transfer bit order: G7...G0R7...R0B7...B0
117118
};
119+
} else {
120+
assert(false);
118121
}
119122
ESP_GOTO_ON_ERROR(rmt_new_bytes_encoder(&bytes_encoder_config, &led_encoder->bytes_encoder), err, TAG, "create bytes encoder failed");
120123
rmt_copy_encoder_config_t copy_encoder_config = {};

led_strip/src/led_strip_rmt_encoder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ extern "C" {
1717
* @brief Type of led strip encoder configuration
1818
*/
1919
typedef struct {
20-
uint32_t resolution; /*!< Encoder resolution, in Hz */
21-
led_model_t led_model;
20+
uint32_t resolution; /*!< Encoder resolution, in Hz */
21+
led_model_t led_model; /*!< LED model */
2222
} led_strip_encoder_config_t;
2323

2424
/**

0 commit comments

Comments
 (0)