WS2812 RMT Driver
API reference
Loading...
Searching...
No Matches
Macros | Functions
ws2812_control.c File Reference
#include "ws2812_control.h"
#include "driver/rmt_tx.h"
#include "driver/rmt_types.h"
#include "esp_check.h"
#include "esp_err.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "led_strip_encoder.h"
Include dependency graph for ws2812_control.c:

Macros

#define BYTES_PER_LED   3
 
#define WS2812_RMT_RESOLUTION_HZ   (10 * 1000 * 1000)
 

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.
 

Macro Definition Documentation

◆ BYTES_PER_LED

#define BYTES_PER_LED   3

◆ WS2812_RMT_RESOLUTION_HZ

#define WS2812_RMT_RESOLUTION_HZ   (10 * 1000 * 1000)

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.