WS2812 RMT Driver
API reference
Loading...
Searching...
No Matches
Classes | Functions
ws2812_control.h File 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>
Include dependency graph for ws2812_control.h:
This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

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.

Macro Definition Documentation

◆ NUM_LEDS

#define NUM_LEDS   CONFIG_WS2812_NUM_LEDS

Number of LEDs that will be driven by the component.

◆ WS2812_BITS_PER_LED

#define WS2812_BITS_PER_LED   24

◆ WS2812_DEFAULT_BRIGHTNESS

#define WS2812_DEFAULT_BRIGHTNESS   CONFIG_WS2812_DEFAULT_BRIGHTNESS

Default global brightness scaling

◆ WS2812_LED_BUFFER_ITEMS

#define WS2812_LED_BUFFER_ITEMS   (NUM_LEDS * WS2812_BITS_PER_LED)

Number of RMT items required to represent the LED chain.

◆ WS2812_T0H

#define WS2812_T0H   CONFIG_WS2812_T0H

Timing for a '0' bit high pulse in RMT ticks

◆ WS2812_T0L

#define WS2812_T0L   CONFIG_WS2812_T0L

Low time for any bit in RMT ticks

◆ WS2812_T1H

#define WS2812_T1H   CONFIG_WS2812_T1H

Timing for a '1' bit high pulse in RMT ticks

◆ WS2812_T1L

#define WS2812_T1L   CONFIG_WS2812_T1L

Function Documentation

◆ ws2812_control_init()

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.

Parameters
gpio_numGPIO connected to the LED strip.
channelUnused: ESP-IDF v5's RMT driver picks a free channel itself.
Returns
ESP_OK on success, ESP_ERR_INVALID_STATE if already initialised, or an error code from the ESP-IDF drivers.

◆ ws2812_set_brightness()

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.

Parameters
brightnessBrightness level 0-255.

◆ ws2812_write_leds()

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.

Parameters
new_stateDesired LED colours.
Returns
ESP_OK on success, ESP_ERR_INVALID_STATE before ws2812_control_init(), or an ESP-IDF error code.