Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

LED Strip Programming Guide

Allocate LED Strip Object with RMT Backend

#define BLINK_GPIO 0

/// LED strip common configuration
led_strip_config_t strip_config = {
    .strip_gpio_num = BLINK_GPIO,  // The GPIO that connected to the LED strip's data line
    .max_leds = 1,                 // The number of LEDs in the strip,
    .led_model = LED_MODEL_WS2812, // LED strip model, it determines the bit timing
    .color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color component format is G-R-B
    .flags = {
        .invert_out = false, // don't invert the output signal
    }
};

/// RMT backend specific configuration
led_strip_rmt_config_t rmt_config = {
    .clk_src = RMT_CLK_SRC_DEFAULT,    // different clock source can lead to different power consumption
    .resolution_hz = 10 * 1000 * 1000, // RMT counter clock frequency: 10MHz
    .mem_block_symbols = 64,           // the memory size of each RMT channel, in words (4 bytes)
    .flags = {
        .with_dma = false, // DMA feature is available on chips like ESP32-S3/P4
    }
};

/// Create the LED strip object
led_strip_handle_t led_strip = NULL;
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));

You can create multiple LED strip objects with different GPIOs and pixel numbers. The backend driver will automatically allocate sufficient RMT channels for you wherever possible. If the RMT channels are not enough, the led_strip_new_rmt_device will return an error.

Allocate LED Strip Object with SPI Backend

#define BLINK_GPIO 0

/// LED strip common configuration
led_strip_config_t strip_config = {
    .strip_gpio_num = BLINK_GPIO,  // The GPIO that connected to the LED strip's data line
    .max_leds = 1,                 // The number of LEDs in the strip,
    .led_model = LED_MODEL_WS2812, // LED strip model, it determines the bit timing
    .color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color component format is G-R-B
    .flags = {
        .invert_out = false, // don't invert the output signal
    }
};

/// SPI backend specific configuration
led_strip_spi_config_t spi_config = {
    .clk_src = SPI_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
    .spi_bus = SPI2_HOST,           // SPI bus ID
    .flags = {
        .with_dma = true, // Using DMA can improve performance and help drive more LEDs
    }
};

/// Create the LED strip object
led_strip_handle_t led_strip = NULL;
ESP_ERROR_CHECK(led_strip_new_spi_device(&strip_config, &spi_config, &led_strip));

The number of LED strip objects can be created depends on how many free SPI controllers are free to use in your project.

Asynchronous Refresh

led_strip_refresh_async() starts a transmission and returns immediately, so the caller does not have to block for the whole frame. led_strip_refresh_async_done() waits for the in-flight transmission to finish.

ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, 0, 0, 0, 255));
ESP_ERROR_CHECK(led_strip_refresh_async(led_strip));
// ... do some CPU work that does not touch the strip ...
ESP_ERROR_CHECK(led_strip_refresh_async_done(led_strip));
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, 0, 0, 255, 0));

There is no double buffer yet: the pixel buffer is shared with the transmission being sent, so led_strip_set_pixel*() must not be called between led_strip_refresh_async() and led_strip_refresh_async_done(). The benefit of the async API therefore is limited to deferring/overlapping the wait, and does not yet allow computing the next frame while the current one is on the wire.

Thread Safety

The set_pixel / refresh family is not a complete thread-safe solution. Internally the driver keeps a small state machine that only prevents two tasks from starting a transmission at the same time: the second task gets ESP_ERR_INVALID_STATE.

What is not provided:

  • No ordering guarantee between tasks. If several tasks call refresh in a loop, the arrival order of frames is undefined.
  • No protection of a multi-call sequence. set_pixel + refresh is not atomic, another task may interleave in between and modify the pixel buffer that is about to be sent.

If more than one task accesses the same strip, the caller has to add its own synchronization (e.g. a mutex or a dedicated LED task).

FAQ

  • How to set the brightness of the LED strip?
    • You can tune the brightness by scaling the value of each R-G-B element with a same factor. But pay attention to the overflow of the value.

API Reference

Header files

File include/led_strip.h

Functions

TypeName
esp_err_tled_strip_clear (led_strip_handle_t strip)
Clear LED strip (turn off all LEDs)
esp_err_tled_strip_del (led_strip_handle_t strip)
Free LED strip resources.
esp_err_tled_strip_refresh (led_strip_handle_t strip)
Refresh memory colors to LEDs.
esp_err_tled_strip_refresh_async (led_strip_handle_t strip)
Refresh memory colors to LEDs asynchronously.
esp_err_tled_strip_refresh_async_done (led_strip_handle_t strip)
Wait for the async refresh to complete.
esp_err_tled_strip_set_pixel (led_strip_handle_t strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
Set RGB for a specific pixel.
esp_err_tled_strip_set_pixel_hsv (led_strip_handle_t strip, uint32_t index, uint16_t hue, uint8_t saturation, uint8_t value)
Set HSV for a specific pixel.
esp_err_tled_strip_set_pixel_hsv_16 (led_strip_handle_t strip, uint32_t index, uint16_t hue, uint16_t saturation, uint16_t value)
Set HSV for a specific pixel in 16-bit resolution.
esp_err_tled_strip_set_pixel_rgbw (led_strip_handle_t strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white)
Set RGBW for a specific pixel.
esp_err_tled_strip_switch_gpio (led_strip_handle_t strip, gpio_num_t new_gpio_num, bool invert_output)
Switch GPIO of LED strip.

Functions Documentation

function led_strip_clear

Clear LED strip (turn off all LEDs)

esp_err_t led_strip_clear (
    led_strip_handle_t strip
) 

Parameters:

  • strip LED strip

Returns:

  • ESP_OK: Clear LEDs successfully
  • ESP_FAIL: Clear LEDs failed because some other error occurred

function led_strip_del

Free LED strip resources.

esp_err_t led_strip_del (
    led_strip_handle_t strip
) 

Parameters:

  • strip LED strip

Returns:

  • ESP_OK: Free resources successfully
  • ESP_FAIL: Free resources failed because error occurred

function led_strip_refresh

Refresh memory colors to LEDs.

esp_err_t led_strip_refresh (
    led_strip_handle_t strip
) 

Parameters:

  • strip LED strip

Returns:

  • ESP_OK: Refresh successfully
  • ESP_FAIL: Refresh failed because some other error occurred

Note:

After updating the LED colors in the memory, a following invocation of this API is needed to flush colors to strip.

function led_strip_refresh_async

Refresh memory colors to LEDs asynchronously.

esp_err_t led_strip_refresh_async (
    led_strip_handle_t strip
) 

Parameters:

  • strip LED strip

Returns:

  • ESP_OK: Refresh successfully
  • ESP_ERR_INVALID_ARG: Refresh failed because of an invalid argument
  • ESP_ERR_INVALID_STATE: Refresh failed because another transaction is in progress
  • ESP_ERR_NOT_SUPPORTED: Async refresh is not supported by this backend
  • ESP_FAIL: Refresh failed because some other error occurred

Note:

This function is non-blocking, but the driver does not have a double buffer yet. The pixel buffer is shared with the in-flight transaction, so you must still call led_strip_refresh_async_done before modifying the LED colors again. In other words, the only gain for now is that the waiting can be deferred and overlapped with CPU work that does not touch the strip.

function led_strip_refresh_async_done

Wait for the async refresh to complete.

esp_err_t led_strip_refresh_async_done (
    led_strip_handle_t strip
) 

Parameters:

  • strip LED strip

Returns:

  • ESP_OK: Wait for the async refresh to complete successfully
  • ESP_ERR_INVALID_ARG: Wait failed because of an invalid argument
  • ESP_ERR_INVALID_STATE: Wait failed because there is no in-flight async refresh
  • ESP_ERR_NOT_SUPPORTED: Async refresh is not supported by this backend

Note:

Pair this with led_strip_refresh_async. Until the double buffer is added, the pixel buffer must not be modified before this call returns.

function led_strip_set_pixel

Set RGB for a specific pixel.

esp_err_t led_strip_set_pixel (
    led_strip_handle_t strip,
    uint32_t index,
    uint32_t red,
    uint32_t green,
    uint32_t blue
) 

Parameters:

  • strip LED strip
  • index index of pixel to set
  • red red part of color
  • green green part of color
  • blue blue part of color

Returns:

  • ESP_OK: Set RGB for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set RGB for a specific pixel failed because of invalid parameters
  • ESP_FAIL: Set RGB for a specific pixel failed because other error occurred

function led_strip_set_pixel_hsv

Set HSV for a specific pixel.

esp_err_t led_strip_set_pixel_hsv (
    led_strip_handle_t strip,
    uint32_t index,
    uint16_t hue,
    uint8_t saturation,
    uint8_t value
) 

Parameters:

  • strip LED strip
  • index index of pixel to set
  • hue hue part of color (0 - 360)
  • saturation saturation part of color (0 - 255, rescaled from 0 - 1. e.g. saturation = 0.5, rescaled to 127)
  • value value part of color (0 - 255, rescaled from 0 - 1. e.g. value = 0.5, rescaled to 127)

Returns:

  • ESP_OK: Set HSV color for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set HSV color for a specific pixel failed because of an invalid argument
  • ESP_FAIL: Set HSV color for a specific pixel failed because other error occurred

function led_strip_set_pixel_hsv_16

Set HSV for a specific pixel in 16-bit resolution.

esp_err_t led_strip_set_pixel_hsv_16 (
    led_strip_handle_t strip,
    uint32_t index,
    uint16_t hue,
    uint16_t saturation,
    uint16_t value
) 

Parameters:

  • strip LED strip
  • index index of pixel to set
  • hue hue part of color (0 - 360)
  • saturation saturation part of color (0 - 65535, rescaled from 0 - 1. e.g. saturation = 0.5, rescaled to 32767)
  • value value part of color (0 - 65535, rescaled from 0 - 1. e.g. value = 0.5, rescaled to 32767)

Returns:

  • ESP_OK: Set HSV color for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set HSV color for a specific pixel failed because of an invalid argument
  • ESP_FAIL: Set HSV color for a specific pixel failed because other error occurred

function led_strip_set_pixel_rgbw

Set RGBW for a specific pixel.

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
) 

Note:

Only call this function if your led strip does have the white component (e.g. SK6812-RGBW)

Note:

Also see led_strip_set_pixel if you only want to specify the RGB part of the color and bypass the white component

Parameters:

  • strip LED strip
  • index index of pixel to set
  • red red part of color
  • green green part of color
  • blue blue part of color
  • white separate white component

Returns:

  • ESP_OK: Set RGBW color for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set RGBW color for a specific pixel failed because of an invalid argument
  • ESP_FAIL: Set RGBW color for a specific pixel failed because other error occurred

function led_strip_switch_gpio

Switch GPIO of LED strip.

esp_err_t led_strip_switch_gpio (
    led_strip_handle_t strip,
    gpio_num_t new_gpio_num,
    bool invert_output
) 

Parameters:

  • strip LED strip
  • new_gpio_num new GPIO number
  • invert_output invert output

Note:

Only the RMT backend supports this operation

Returns:

  • ESP_OK: Switch GPIO successfully
  • ESP_ERR_INVALID_ARG: Switch GPIO failed because of an invalid argument
  • ESP_ERR_INVALID_STATE: Switch GPIO failed because a transaction is in progress
  • ESP_ERR_NOT_SUPPORTED: Switch GPIO is not supported by this backend
  • ESP_FAIL: Switch GPIO failed because some other error occurred

File include/led_strip_rmt.h

Structures and Types

TypeName
structled_strip_rmt_config_t
LED Strip RMT specific configuration.
structled_strip_rmt_extra_config

Functions

TypeName
esp_err_tled_strip_new_rmt_device (const led_strip_config_t *led_config, const led_strip_rmt_config_t *rmt_config, led_strip_handle_t *ret_strip)
Create LED strip based on RMT TX channel.

Structures and Types Documentation

struct led_strip_rmt_config_t

LED Strip RMT specific configuration.

Variables:

  • rmt_clock_source_t clk_src
    RMT clock source

  • struct led_strip_rmt_config_t::led_strip_rmt_extra_config flags
    Extra driver flags

  • size_t mem_block_symbols
    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

  • uint32_t resolution_hz
    RMT tick resolution, if set to zero, a default resolution (10MHz) will be applied

struct led_strip_rmt_config_t::led_strip_rmt_extra_config

Variables:

  • uint32_t with_dma
    Use DMA to transmit data

Functions Documentation

function led_strip_new_rmt_device

Create LED strip based on RMT TX channel.

esp_err_t led_strip_new_rmt_device (
    const led_strip_config_t *led_config,
    const led_strip_rmt_config_t *rmt_config,
    led_strip_handle_t *ret_strip
) 

Parameters:

  • led_config LED strip configuration
  • rmt_config RMT specific configuration
  • ret_strip Returned LED strip handle

Returns:

  • ESP_OK: create LED strip handle successfully
  • ESP_ERR_INVALID_ARG: create LED strip handle failed because of invalid argument
  • ESP_ERR_NO_MEM: create LED strip handle failed because of out of memory
  • ESP_FAIL: create LED strip handle failed because some other error

File include/led_strip_spi.h

Structures and Types

TypeName
structled_strip_spi_config_t
LED Strip SPI specific configuration.
structled_strip_spi_extra_config

Functions

TypeName
esp_err_tled_strip_new_spi_device (const led_strip_config_t *led_config, const led_strip_spi_config_t *spi_config, led_strip_handle_t *ret_strip)
Create LED strip based on SPI MOSI channel.

Structures and Types Documentation

struct led_strip_spi_config_t

LED Strip SPI specific configuration.

Variables:

struct led_strip_spi_config_t::led_strip_spi_extra_config

Variables:

  • uint32_t with_dma
    Use DMA to transmit data

Functions Documentation

function led_strip_new_spi_device

Create LED strip based on SPI MOSI channel.

esp_err_t led_strip_new_spi_device (
    const led_strip_config_t *led_config,
    const led_strip_spi_config_t *spi_config,
    led_strip_handle_t *ret_strip
) 

Note:

Although only the MOSI line is used for generating the signal, the whole SPI bus can’t be used for other purposes.

Parameters:

  • led_config LED strip configuration
  • spi_config SPI specific configuration
  • ret_strip Returned LED strip handle

Returns:

  • ESP_OK: create LED strip handle successfully
  • ESP_ERR_INVALID_ARG: create LED strip handle failed because of invalid argument
  • ESP_ERR_NOT_SUPPORTED: create LED strip handle failed because of unsupported configuration
  • ESP_ERR_NO_MEM: create LED strip handle failed because of out of memory
  • ESP_FAIL: create LED strip handle failed because some other error

File include/led_strip_types.h

Structures and Types

TypeName
unionled_color_component_format_t
LED color component format.
structformat_layout
enumled_model_t
LED strip model.
structled_strip_config_t
LED Strip common configurations The common configurations are not specific to any backend peripheral.
structled_strip_extra_flags
typedef struct led_strip_t *led_strip_handle_t
Type of LED strip handle.
structled_strip_timings_t
LED strip timings.

Macros

TypeName
defineLED_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, .bytes_per_color = 1, .num_components = 3}}
Helper macros to set the color component format.
defineLED_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, .bytes_per_color = 1, .num_components = 4}}
defineLED_STRIP_COLOR_COMPONENT_FMT_GRBW_16 (led_color_component_format_t){.format = {.r_pos = 1, .g_pos = 0, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 4}}
defineLED_STRIP_COLOR_COMPONENT_FMT_GRB_16 (led_color_component_format_t){.format = {.r_pos = 1, .g_pos = 0, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 3}}
defineLED_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, .bytes_per_color = 1, .num_components = 3}}
defineLED_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, .bytes_per_color = 1, .num_components = 4}}
defineLED_STRIP_COLOR_COMPONENT_FMT_RGBW_16 (led_color_component_format_t){.format = {.r_pos = 0, .g_pos = 1, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 4}}
defineLED_STRIP_COLOR_COMPONENT_FMT_RGB_16 (led_color_component_format_t){.format = {.r_pos = 0, .g_pos = 1, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 3}}

Structures and Types Documentation

union led_color_component_format_t

LED color component format.

Note:

The format is used to specify the order of color components in each pixel, also the number of color components.

Variables:

struct led_color_component_format_t::format_layout

Variables:

  • uint32_t b_pos
    Position of the blue channel in the color order: 0~3

  • uint32_t bytes_per_color
    Bytes per color component: 1 or 2. If set to 0, it will fallback to 1

  • uint32_t g_pos
    Position of the green channel in the color order: 0~3

  • uint32_t num_components
    Number of color components per pixel: 3 or 4. If set to 0, it will fallback to 3

  • uint32_t r_pos
    Position of the red channel in the color order: 0~3

  • uint32_t reserved
    Reserved

  • uint32_t w_pos
    Position of the white channel in the color order: 0~3

enum led_model_t

LED strip model.

enum led_model_t {
    LED_MODEL_WS2812,
    LED_MODEL_SK6812,
    LED_MODEL_WS2811,
    LED_MODEL_WS2816,
    LED_MODEL_CUSTOM,
    LED_MODEL_INVALID
};

Note:

Different led model may have different timing parameters, so we need to distinguish them.

struct led_strip_config_t

LED Strip common configurations The common configurations are not specific to any backend peripheral.

Variables:

  • led_color_component_format_t color_component_format
    Specifies the order of color components in each pixel. Use helper macros like LED_STRIP_COLOR_COMPONENT_FMT_GRB to set the format

  • struct led_strip_config_t::led_strip_extra_flags flags
    Extra driver flags

  • led_model_t led_model
    Specifies the LED strip model (e.g., WS2812, SK6812)

  • uint32_t max_leds
    Maximum number of LEDs that can be controlled in a single strip

  • int strip_gpio_num
    GPIO number that used by LED strip

  • led_strip_timings_t timings
    When led_model isLED_MODEL_CUSTOM, this field is required and must be initialized with appropriate timing values. For other LED models, it may be left uninitialized, as model-specific defaults are used instead. LED strip extra driver flags

struct led_strip_config_t::led_strip_extra_flags

Variables:

  • uint32_t invert_out
    Invert output signal

typedef led_strip_handle_t

Type of LED strip handle.

typedef struct led_strip_t* led_strip_handle_t;

struct led_strip_timings_t

LED strip timings.

Note:

The bit timings are in nanoseconds and the reset timing is in microseconds.

Variables:

  • uint32_t reset_us
    Reset time, microseconds

  • uint32_t t0h_ns
    High time for 0 bit, nanoseconds

  • uint32_t t0l_ns
    Low time for 0 bit, nanoseconds

  • uint32_t t1h_ns
    High time for 1 bit, nanoseconds

  • uint32_t t1l_ns
    Low time for 1 bit, nanoseconds

Macros Documentation

define LED_STRIP_COLOR_COMPONENT_FMT_GRB

Helper macros to set the color component format.

#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, .bytes_per_color = 1, .num_components = 3}}

define LED_STRIP_COLOR_COMPONENT_FMT_GRBW

#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, .bytes_per_color = 1, .num_components = 4}}

define LED_STRIP_COLOR_COMPONENT_FMT_GRBW_16

#define LED_STRIP_COLOR_COMPONENT_FMT_GRBW_16 ( led_color_component_format_t ){.format = {.r_pos = 1, .g_pos = 0, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 4}}

define LED_STRIP_COLOR_COMPONENT_FMT_GRB_16

#define LED_STRIP_COLOR_COMPONENT_FMT_GRB_16 ( led_color_component_format_t ){.format = {.r_pos = 1, .g_pos = 0, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 3}}

define LED_STRIP_COLOR_COMPONENT_FMT_RGB

#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, .bytes_per_color = 1, .num_components = 3}}

define LED_STRIP_COLOR_COMPONENT_FMT_RGBW

#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, .bytes_per_color = 1, .num_components = 4}}

define LED_STRIP_COLOR_COMPONENT_FMT_RGBW_16

#define LED_STRIP_COLOR_COMPONENT_FMT_RGBW_16 ( led_color_component_format_t ){.format = {.r_pos = 0, .g_pos = 1, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 4}}

define LED_STRIP_COLOR_COMPONENT_FMT_RGB_16

#define LED_STRIP_COLOR_COMPONENT_FMT_RGB_16 ( led_color_component_format_t ){.format = {.r_pos = 0, .g_pos = 1, .b_pos = 2, .w_pos = 3, .reserved = 0, .bytes_per_color = 2, .num_components = 3}}

File interface/led_strip_interface.h

Structures and Types

TypeName
structled_strip_t
LED strip interface definition.
typedef struct led_strip_tled_strip_t

Structures and Types Documentation

struct led_strip_t

LED strip interface definition.

Variables:

  • esp_err_t(* clear
    Clear LED strip (turn off all LEDs)
    Parameters:
  • strip LED strip

Returns:

  • ESP_OK: Clear LEDs successfully
  • ESP_FAIL: Clear LEDs failed because some other error occurred
  • esp_err_t(* del
    Free LED strip resources.
    Parameters:
  • strip LED strip

Returns:

  • ESP_OK: Free resources successfully
  • ESP_FAIL: Free resources failed because error occurred
  • esp_err_t(* refresh
    Refresh memory colors to LEDs.
    Parameters:
  • strip LED strip

Returns:

  • ESP_OK: Refresh successfully
  • ESP_FAIL: Refresh failed because some other error occurred

Note:

After updating the LED colors in the memory, a following invocation of this API is needed to flush colors to strip.

  • esp_err_t(* refresh_async
    Refresh memory colors to LEDs asynchronously.
    Parameters:
  • strip LED strip

Returns:

  • ESP_OK: Refresh successfully
  • ESP_FAIL: Refresh failed because some other error occurred

Note:

This function is non-blocking, but the driver does not have a double buffer yet, so the pixel buffer is shared with the in-flight transaction. You still have to call led_strip_refresh_async_done() before modifying the LED colors again.

  • esp_err_t(* refresh_async_done
    Wait for the async refresh to complete.
    Parameters:
  • strip LED strip

Returns:

  • ESP_OK: Wait for the async refresh to complete successfully
  • ESP_ERR_INVALID_STATE: Wait failed because there is no in-flight async refresh
  • esp_err_t(* set_pixel
    Set RGB for a specific pixel.
    Parameters:
  • strip LED strip
  • index index of pixel to set
  • red red part of color
  • green green part of color
  • blue blue part of color

Returns:

  • ESP_OK: Set RGB for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set RGB for a specific pixel failed because of invalid parameters
  • ESP_FAIL: Set RGB for a specific pixel failed because other error occurred
  • esp_err_t(* set_pixel_rgbw
    Set RGBW for a specific pixel. Similar to set_pixel_ but also set the white component._
    Parameters:
  • strip LED strip
  • index index of pixel to set
  • red red part of color
  • green green part of color
  • blue blue part of color
  • white separate white component

Returns:

  • ESP_OK: Set RGBW color for a specific pixel successfully
  • ESP_ERR_INVALID_ARG: Set RGBW color for a specific pixel failed because of an invalid argument
  • ESP_FAIL: Set RGBW color for a specific pixel failed because other error occurred
  • esp_err_t(* switch_gpio
    Switch GPIO of LED strip.
    Parameters:
  • strip LED strip
  • new_gpio_num new GPIO number
  • invert_output invert output

Note:

Only support RMT backend now

Returns:

  • ESP_OK: Switch GPIO successfully
  • ESP_FAIL: Switch GPIO failed because some other error occurred

typedef led_strip_t

typedef struct led_strip_t led_strip_t;

Type of LED strip