1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! NeoPixel (WS2812B) transport using SPI bit-encoding.
//!
//! Drives cascaded WS2812B-compatible addressable LEDs over a single data line
//! using a timing-encoded NZR protocol. The transport is write-only: pixels
//! accept data but never respond.
//!
//! All platforms use the same SPI bit-encoding approach: each NeoPixel bit is
//! encoded as 3 SPI bits at 2.4 MHz and shifted out on the MOSI line. The
//! encoding algorithm, configuration parameters, and reset handling are
//! identical across all platforms.
//!
//! # Hardware constraint
//! The NeoPixel DIN pin must be connected to the SPI MOSI pin. SCK, MISO,
//! and CS are unused by the strip.
//!
//! # Protocol
//! Each NeoPixel bit is encoded as 3 SPI bits at 2.4 MHz (one SPI bit = 416.7 ns):
//! - `0` → `100` (417 ns high, 833 ns low)
//! - `1` → `110` (833 ns high, 417 ns low)
//!
//! Each NeoPixel byte (8 bits) → 24 SPI bits → 3 SPI bytes, packed MSB-first.
//! For a buffer of `n` NeoPixel bytes: output `3n` encoded SPI bytes, then
//! 16 zero bytes (≈53 µs) for the reset.
/// Encode pixel data into WS2812B-compatible SPI bitstream.
///
/// Each NeoPixel byte becomes 3 SPI bytes (24 bits), followed by 16 trailing
/// zero bytes for the reset pulse. The encoding is MSB-first.
/// NeoPixel SPI transport.
///
/// Wraps any `embedded_hal::spi::SpiBus` configured at 2.4 MHz, mode 0.
/// The caller is responsible for configuring the SPI bus before passing it.