Expand description
no_std driver for single-wire addressable LED strips (WS2812, SK6812, WS2811, WS2816).
§Architecture
LedStrip --> WireCodec (pixels => transport words) --> TransportBackend (transmit)
| |
+-- SpiCodec (SPI bit-banging) +-- SpiBackend (SPI)The WireCodec / TransportBackend traits are intentionally generic:
SpiCodec / SpiBackend are the current production implementation,
but the trait design accommodates future backends (RMT, PIO, etc.) without
API changes.
§Features
| Feature | Default | Description |
|---|---|---|
spi | Yes | SPI backend, requires embedded-hal |
§Quick start
use led_strip::{LedStrip, SpiCodec, SpiBackend, SpiEncodingPlan, Rgb, RgbOrder, Ws2812B};
let codec = SpiCodec::<Rgb, Ws2812B>::for_protocol(
SpiEncodingPlan::ws2812_3bit(), false
).unwrap();
let backend = SpiBackend::new(spi_peripheral);
// 60 pixels need 60 × 9 payload bytes + 15 reset bytes = 555 bytes.
let mut strip: LedStrip<Rgb, Ws2812B, _, _, 1024> =
LedStrip::new(RgbOrder::Grb, codec, backend);
let pixels = [Rgb::new(255, 0, 0); 60];
strip.write(&pixels).unwrap();Structs§
- LedStrip
- Stateless driver for a single-wire addressable LED strip.
- Pulse
Timing - High/low pulse widths for a single protocol bit.
- Rgb
- 8-bit RGB pixel (3 bytes on the wire).
- Rgb16
- 16-bit RGB pixel (6 bytes on the wire, big-endian per channel).
- Rgbw
- 8-bit RGBW pixel with dedicated white channel (4 bytes on the wire).
- Sk6812
- Protocol marker for SK6812 (4-channel 8-bit RGBW, GRBW order).
- SpiBackend
- SPI transport backend.
- SpiCodec
- SPI-based wire codec that encodes LED pixel data into a byte stream using configurable bit patterns (bit-banging over SPI MOSI).
- SpiEncoding
Plan - SPI clock frequency, bit patterns, and symbol width for encoding a single-wire LED protocol over an SPI bus.
- Ws2811
- Protocol marker for WS2811 (3-channel 8-bit RGB, RGB order, 400 kbps slow mode).
- Ws2816
- Protocol marker for the 48-bit WS2816B/WS2816C variants (3-channel 16-bit RGB, GRB order).
- Ws2812B
- Protocol marker for WS2812B (3-channel 8-bit RGB, GRB order, 800 kbps).
Enums§
- LedStrip
Error - The unified error type for all
led-stripoperations. - Refresh
Error - Unified error type returned by
LedStrip::write. - Rgb16
Order - Wire-level byte order for 16-bit RGB pixels.
- RgbOrder
- Wire-level byte order for 8-bit RGB pixels.
- Rgbw
Order - Wire-level byte order for 8-bit RGBW pixels.
- SpiCodec
Plan Error - Errors returned when constructing a
SpiCodecor validating anSpiEncodingPlanagainst a protocol’s timing limits and reset-duration arithmetic. - SpiEncode
Error - Rare encode-time failures.
- Timing
Edge - Identifies one of the four timing edges in a single-wire protocol bit: T0H (zero high), T0L (zero low), T1H (one high), T1L (one low).
Traits§
- LedPixel
- Logical pixel representation for a single LED.
- Single
Wire Protocol - Describes the wire-level electrical characteristics of a single-wire LED protocol (pulse timings, reset duration).
- Transport
Backend - Low-level transport for encoded LED data.
- Wire
Codec - Encodes LED pixel data into transport words for a specific protocol.
Type Aliases§
- LedStrip
Result - Convenience alias for
Result<T, LedStripError<E>>.