Skip to main content

SpiEncodingPlan

Struct SpiEncodingPlan 

Source
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

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub const fn with_extra_reset_ns(self, extra_reset_ns: u32) -> Self

Appends extra reset time for external signal conditioning.

Source

pub const fn spi_hz(&self) -> u32

Source

pub const fn zero_pattern(&self) -> u8

Source

pub const fn one_pattern(&self) -> u8

Source

pub const fn bits_per_symbol(&self) -> u8

Source

pub const fn extra_reset_ns(&self) -> u32

Trait Implementations§

Source§

impl Clone for SpiEncodingPlan

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SpiEncodingPlan

Source§

impl Debug for SpiEncodingPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SpiEncodingPlan

Source§

impl PartialEq for SpiEncodingPlan

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SpiEncodingPlan

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.