pub struct SpiEncodingPlan { /* private fields */ }Expand description
SPI clock frequency, bit patterns, and symbol width for encoding a single-wire LED protocol over an SPI bus.
Each protocol bit is encoded as bits_per_symbol SPI bits (typically 3 or 4).
For example, WS2812B uses 3-bit symbols: 0b100 for logical 0, 0b110 for logical 1.
Use the predefined constructors (ws2812_3bit,
sk6812_4bit, ws2811_8bit,
ws2816_5bit) or build a custom plan with
new.
Implementations§
Source§impl SpiEncodingPlan
impl SpiEncodingPlan
Sourcepub const fn new(
spi_hz: u32,
zero_pattern: u8,
one_pattern: u8,
bits_per_symbol: u8,
) -> Self
pub const fn new( spi_hz: u32, zero_pattern: u8, one_pattern: u8, bits_per_symbol: u8, ) -> Self
Creates a new encoding plan. Use SpiCodec::for_protocol to validate
that the plan fits a target protocol’s timing tolerances.
Sourcepub const fn ws2812_3bit() -> Self
pub const fn ws2812_3bit() -> Self
3-bit SPI plan at 2.4 MHz for WS2812 / WS2812B.
Derived timing (spi_bit ~ 416.667 ns, tolerance +/-150 ns per WS2812B datasheet V1):
- T0H ~ 416.667 ns (expected 400 ns, delta ~ 16.667 ns OK)
- T0L ~ 833.333 ns (expected 850 ns, delta ~ 16.667 ns OK)
- T1H ~ 833.333 ns (expected 800 ns, delta ~ 33.333 ns OK)
- T1L ~ 416.667 ns (expected 450 ns, delta ~ 33.333 ns OK)
TX bytes per pixel: 3 ch × 8 bits × 3 SPI bits / 8 = 9 bytes.
Sourcepub const fn sk6812_4bit() -> Self
pub const fn sk6812_4bit() -> Self
4-bit SPI plan at 3.2 MHz for SK6812.
Derived timing (spi_bit = 312.5 ns, tolerance +/-150 ns per SK6812 datasheet):
- T0H = 312.5 ns (expected 300 ns, delta = 12.5 ns OK)
- T0L = 937.5 ns (expected 900 ns, delta = 37.5 ns OK)
- T1H ~ 625 ns (expected 600 ns, delta = 25 ns OK)
- T1L ~ 625 ns (expected 600 ns, delta = 25 ns OK)
TX bytes per pixel: 4 ch × 8 bits × 4 SPI bits / 8 = 16 bytes. Note: bits_per_symbol = 4; size TX_CAPACITY accordingly (larger than ws2812_3bit).
Sourcepub const fn ws2811_8bit() -> Self
pub const fn ws2811_8bit() -> Self
8-bit SPI plan at 3.2 MHz for WS2811 (400 kbps slow mode).
Derived timing (spi_bit = 312.5 ns, tolerance +/-150 ns):
- T0H = 625 ns (expected 500 ns, delta = 125 ns OK)
- T0L = 1875 ns (expected 2000 ns, delta = 125 ns OK)
- T1H = 1250 ns (expected 1200 ns, delta = 50 ns OK)
- T1L = 1250 ns (expected 1300 ns, delta = 50 ns OK)
TX bytes per pixel: 3 ch × 8 bits × 8 SPI bits / 8 = 24 bytes.
Sourcepub const fn ws2816_5bit() -> Self
pub const fn ws2816_5bit() -> Self
5-bit SPI plan at 4 MHz for the 48-bit WS2816B/WS2816C variants.
T0H/T0L are 250/1000 ns and T1H/T1L are 750/500 ns. Each bit lasts 1250 ns, satisfying both the per-phase limits and the minimum bit period. TX bytes per pixel: 6 wire bytes × 5 = 30 bytes, plus reset.
Sourcepub const fn with_extra_reset_ns(self, extra_reset_ns: u32) -> Self
pub const fn with_extra_reset_ns(self, extra_reset_ns: u32) -> Self
Appends extra reset time for external signal conditioning.