LED Controller Design Specification¶
This document specifies the design of the WS2812 LED controller component, using ESP32 RMT peripheral for precise timing and providing a simple pixel-level control API.
Document Version: 2.0 Last Updated: 2025-11-12
Overview¶
The LED controller abstracts WS2812 timing complexity using ESP32 RMT peripheral, providing a simple buffer-based API with batch operations and color utilities.
Hardware Abstraction¶
Design: ESP32 RMT (Remote Control) peripheral abstraction for WS2812 timing generation. Implementation:
Validation: RMT channel created successfully, timing parameters match WS2812 datasheet, transmission completes without errors. |
Design: In-memory LED state buffer for performance optimization and atomic updates. Implementation:
Validation: Buffer allocates correctly for configured LED count, updates modify only buffer until show, memory freed on cleanup. |
API Specifications¶
Design: Individual LED pixel manipulation with bounds checking and color utilities. Implementation:
Validation: Index validation prevents buffer overruns, color values stored accurately, predefined colors work correctly. |
Design: Efficient batch operations for common patterns and hardware updates. Implementation:
Validation: Clear all zeros entire buffer, show triggers RMT transmission, utilities produce correct colors. |
Design: Thread-safe LED state snapshot API for external monitoring and visualization components. Implementation:
Rationale: Web server and monitoring tasks need non-blocking access to LED state without interfering with display logic updates. Mutex ensures data consistency when display task is updating buffer. Validation: Concurrent access from web server and display task shows no corruption, returned colors match physical LED state, mutex prevents race conditions, partial reads work correctly with buffer size limits. |
Timing and Data Format¶
Design: Precise WS2812 protocol timing using RMT encoder configuration. Implementation:
Validation: Timing measurements match WS2812 datasheet specifications, LED strips respond correctly. |
Design: RGB color representation with GRB hardware conversion for WS2812 compatibility. Implementation:
Validation: Color values convert correctly RGB→GRB, brightness scaling maintains color ratios, no precision loss. |
Memory and Error Handling¶
Design: Controlled dynamic allocation with proper cleanup and error handling. Implementation:
Validation: Memory allocated correctly, no leaks after deinitialization, error paths clean up properly. |
Design: Comprehensive input validation and state checking with appropriate error codes. Implementation:
Validation: Invalid inputs return appropriate error codes, operations fail safely, system remains stable. |
Simulator Specification¶
Design: Provide a simulator implementation for the LED controller that exposes the full
public API ( Implementation:
Validation: Simulator build compiles with |