led_strip - RMT-based driver for WS2812B/SK6812/APA106 LED strips

Warning

This component does not support ESP8266 RTOS SDK!

Warning

If you try to use this driver simultaneously with Wi-Fi, you may encounter RMT transmission bugs. To avoid them, simply initialize device from the task bound to the second processor core.

Interrupt handlers assigned during the initialization of the RMT driver are bound to the core on which the initialization took place.

group led_strip

RMT-based ESP-IDF driver for WS2812B/SK6812/APA106/SM16703 LED strips.

Copyright (c) 2020 Ruslan V. Uss unclerus@gmail.com

MIT Licensed as described in the file LICENSE

Defines

LED_STRIP_BRIGHTNESS

Enums

enum led_strip_type_t

LED type.

Values:

enumerator LED_STRIP_WS2812
enumerator LED_STRIP_SK6812
enumerator LED_STRIP_APA106
enumerator LED_STRIP_SM16703
enumerator LED_STRIP_TYPE_MAX

Functions

void led_strip_install()

Setup library.

This method must be called before any other led_strip methods

esp_err_t led_strip_init(led_strip_t *strip)

Initialize LED strip and allocate buffer memory.

Parameters:

strip – Descriptor of LED strip

Returns:

ESP_OK on success

esp_err_t led_strip_free(led_strip_t *strip)

Deallocate buffer memory and release RMT channel.

Parameters:

strip – Descriptor of LED strip

Returns:

ESP_OK on success

esp_err_t led_strip_flush(led_strip_t *strip)

Send strip buffer to LEDs.

Parameters:

strip – Descriptor of LED strip

Returns:

ESP_OK on success

bool led_strip_busy(led_strip_t *strip)

Check if associated RMT channel is busy.

Parameters:

strip – Descriptor of LED strip

Returns:

true if RMT peripherals is busy

esp_err_t led_strip_wait(led_strip_t *strip, TickType_t timeout)

Wait until RMT peripherals is free to send buffer to LEDs.

Parameters:
  • strip – Descriptor of LED strip

  • timeout – Timeout in RTOS ticks

Returns:

ESP_OK on success

esp_err_t led_strip_set_pixel(led_strip_t *strip, size_t num, rgb_t color)

Set color of single LED in strip.

This function does not actually change colors of the LEDs. Call led_strip_flush() to send buffer to the LEDs.

Parameters:
  • strip – Descriptor of LED strip

  • num – LED number, 0..strip length - 1

  • color – RGB color

Returns:

ESP_OK on success

esp_err_t led_strip_set_pixels(led_strip_t *strip, size_t start, size_t len, rgb_t *data)

Set colors of multiple LEDs.

This function does not actually change colors of the LEDs. Call led_strip_flush() to send buffer to the LEDs.

Parameters:
  • strip – Descriptor of LED strip

  • start – First LED index, 0-based

  • len – Number of LEDs

  • data – Pointer to RGB data

Returns:

ESP_OK on success

esp_err_t led_strip_fill(led_strip_t *strip, size_t start, size_t len, rgb_t color)

Set multiple LEDs to the one color.

This function does not actually change colors of the LEDs. Call led_strip_flush() to send buffer to the LEDs.

Parameters:
  • strip – Descriptor of LED strip

  • start – First LED index, 0-based

  • len – Number of LEDs

  • color – RGB color

Returns:

ESP_OK on success

struct led_strip_t
#include <led_strip.h>

LED strip descriptor.

Public Members

led_strip_type_t type

LED type.

bool is_rgbw

true for RGBW strips

uint8_t brightness

Brightness 0..255, call led_strip_flush() after change.

Supported only for ESP-IDF version >= 4.3

size_t length

Number of LEDs in strip.

gpio_num_t gpio

Data GPIO pin.

rmt_channel_t channel

RMT channel.