LED Controller API¶
Brief Description Hardware abstraction layer for WS2812 addressable LED strips using ESP32 RMT peripheral. Provides low-level control with RAM buffer management for efficient updates. Key features:
Architecture: Uses ESP32 RMT peripheral for precise WS2812 timing. Maintains a RAM buffer for current LED state. Only one controller instance supported. Configuration is loaded from NVS via config_manager. |
Data Types¶
RGB color structure for LED pixel color. Definition: typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
} led_color_t;
Fields:
|
Lifecycle Functions¶
Initialize the LED controller. Loads configuration from config_manager and allocates RAM buffer. Only one instance supported. Uses RMT channel 0. Signature: esp_err_t led_controller_init(gpio_num_t data_pin);
Parameters:
Returns:
Note Allocates memory for LED buffer (3 bytes per LED). Only one instance supported. RMT channel 0 is used. |
Deinitialize the LED controller. Frees memory, deinitializes RMT, and resets GPIO. Signature: esp_err_t led_controller_deinit(void);
Parameters:
Returns:
Note Frees all allocated resources and resets hardware state. |
Pixel Control Functions¶
Set color of a specific LED pixel in RAM buffer. Call led_show() to update physical LEDs. Signature: esp_err_t led_set_pixel(uint16_t index, led_color_t color);
Parameters:
Returns:
Note Does not update physical LEDs until led_show() is called. |
Clear a specific LED pixel (turn off). Equivalent to led_set_pixel(index, LED_COLOR_OFF). Signature: esp_err_t led_clear_pixel(uint16_t index);
Parameters:
Returns:
Note Does not update physical LEDs until led_show() is called. |
Get current color of a specific LED pixel from RAM buffer. Signature: led_color_t led_get_pixel(uint16_t index);
Parameters:
Returns:
Note Reads from RAM buffer, not physical LED. |
Clear all LED pixels (turn off all LEDs) in RAM buffer. Call led_show() to update physical LEDs. Signature: esp_err_t led_clear_all(void);
Parameters:
Returns:
Note Does not update physical LEDs until led_show() is called. |
Update physical LED strip with current RAM buffer using RMT peripheral. Blocks until transmission is complete. Signature: esp_err_t led_show(void);
Parameters:
Returns:
Note Blocks for ~1-2ms for 40 LEDs. Only function that updates visible LEDs. |
Utility Functions¶
Create RGB color from individual components. Signature: led_color_t led_color_rgb(uint8_t r, uint8_t g, uint8_t b);
Parameters:
Returns:
Note Utility for constructing custom colors. |
Apply brightness scaling to a color. Scales all RGB components by brightness factor. Signature: led_color_t led_color_brightness(led_color_t color, uint8_t brightness);
Parameters:
Returns:
Note Uses integer math for efficiency. |
Query and State Functions¶
Get configured LED count. Signature: uint16_t led_get_count(void);
Parameters:
Returns:
|
Check if LED controller is initialized. Signature: bool led_is_initialized(void);
Parameters:
Returns:
|
Get snapshot of all LED colors (thread-safe). Returns stable snapshot matching last physical LED update. Signature: uint16_t led_get_all_colors(led_color_t* output_buffer, uint16_t max_count);
Parameters:
Returns:
Note Caller must allocate output_buffer with size >= led_count * sizeof(led_color_t). Thread-safe, may block briefly. Returns snapshot matching physical LED state. |