|
WS2812 RMT Driver
API reference
|
ESP-IDF RMT backend for WS2812 / NeoPixel LED chains. More...
#include "driver/gpio.h"#include "driver/rmt_tx.h"#include "driver/rmt_types.h"#include "esp_err.h"#include "led_strip_encoder.h"#include "sdkconfig.h"#include "ws2812_rmt_caps.h"#include <stdint.h>Go to the source code of this file.
Classes | |
| struct | led_state |
| Desired colors for a chain of LEDs. More... | |
Macros | |
Driver constants | |
| #define | NUM_LEDS CONFIG_WS2812_NUM_LEDS |
| #define | WS2812_BITS_PER_LED 24 |
| #define | WS2812_LED_BUFFER_ITEMS (NUM_LEDS * WS2812_BITS_PER_LED) |
| #define | WS2812_T0H CONFIG_WS2812_T0H |
| #define | WS2812_T1H CONFIG_WS2812_T1H |
| #define | WS2812_T0L CONFIG_WS2812_T0L |
| #define | WS2812_T1L CONFIG_WS2812_T1L |
| #define | WS2812_DEFAULT_BRIGHTNESS CONFIG_WS2812_DEFAULT_BRIGHTNESS |
Functions | |
| esp_err_t | ws2812_control_init (gpio_num_t gpio_num, int channel) |
| Initialise the RMT peripheral for WS2812 output. | |
| esp_err_t | ws2812_write_leds (struct led_state new_state) |
| Send LED colour data. | |
| void | ws2812_set_brightness (uint8_t brightness) |
| Set global brightness for subsequent transmissions. | |
ESP-IDF RMT backend for WS2812 / NeoPixel LED chains.
This is not a portable CRTP chip driver. Public headers include ESP-IDF (driver/rmt_*.h, sdkconfig.h). Hosts that are not ESP32 do not compile this tree.
| #define NUM_LEDS CONFIG_WS2812_NUM_LEDS |
Number of LEDs that will be driven by the component.
| #define WS2812_BITS_PER_LED 24 |
| #define WS2812_DEFAULT_BRIGHTNESS CONFIG_WS2812_DEFAULT_BRIGHTNESS |
Default global brightness scaling
| #define WS2812_LED_BUFFER_ITEMS (NUM_LEDS * WS2812_BITS_PER_LED) |
Number of RMT items required to represent the LED chain.
| #define WS2812_T0H CONFIG_WS2812_T0H |
Timing for a '0' bit high pulse in RMT ticks
| #define WS2812_T0L CONFIG_WS2812_T0L |
Low time for any bit in RMT ticks
| #define WS2812_T1H CONFIG_WS2812_T1H |
Timing for a '1' bit high pulse in RMT ticks
| #define WS2812_T1L CONFIG_WS2812_T1L |
| esp_err_t ws2812_control_init | ( | gpio_num_t | gpio_num, |
| int | channel | ||
| ) |
Initialise the RMT peripheral for WS2812 output.
This function must be called once before any LED data is transmitted. On failure everything it allocated is released, so it can be called again.
| gpio_num | GPIO connected to the LED strip. |
| channel | Unused: ESP-IDF v5's RMT driver picks a free channel itself. |
| void ws2812_set_brightness | ( | uint8_t | brightness | ) |
Set global brightness for subsequent transmissions.
All LED values are scaled by this factor before being sent. 255 means full brightness.
| brightness | Brightness level 0-255. |
| esp_err_t ws2812_write_leds | ( | struct led_state | new_state | ) |
Send LED colour data.
Sends every LED's colour (green, red, blue[, white], scaled by the brightness) with the Kconfig bit timing, then the reset code that latches the frame. Blocks the calling task until the frame has been transmitted.
| new_state | Desired LED colours. |