Skip to main content

SpiCodec

Struct SpiCodec 

Source
pub struct SpiCodec<P, Proto>
where P: LedPixel, Proto: SingleWireProtocol<P>,
{ /* private fields */ }
Expand description

SPI-based wire codec that encodes LED pixel data into a byte stream using configurable bit patterns (bit-banging over SPI MOSI).

Pre-computes inverted/normal patterns and reset fill bytes at construction time so the hot encoding path is branch-free.

The type parameters P and Proto tie the codec to a specific <pixel, protocol> pair at compile time —a codec built via SpiCodec::<Rgb, Ws2812B>::for_protocol cannot be used with a LedStrip parameterized on a different protocol, even if both happen to implement the same WireCodec trait.

Implementations§

Source§

impl<P, Proto> SpiCodec<P, Proto>
where P: LedPixel, Proto: SingleWireProtocol<P>,

Source

pub fn new( plan: SpiEncodingPlan, invert_output: bool, ) -> Result<Self, SpiCodecPlanError>

Constructs a codec from a plan. Validates the plan’s structural parameters (clock, symbol width, pattern range) and rejects reset durations whose fixed-point arithmetic would overflow, but does not check protocol timing. Use for_protocol if timing validation is desired. Each symbol must be a distinct, contiguous high-then-low waveform.

Source

pub fn for_protocol( plan: SpiEncodingPlan, invert_output: bool, ) -> Result<Self, SpiCodecPlanError>

Constructs a codec with structural, protocol timing limits, and reset-duration overflow validation.

Preferred over Self::new when the target protocol is known at construction time. Checks all four phases against Proto::ZERO_MIN/ZERO_MAX and Proto::ONE_MIN/ONE_MAX, plus Proto::MIN_BIT_PERIOD_NS, without rounding the durations. Error durations are rounded only for diagnostics.

Source

pub const fn plan(&self) -> SpiEncodingPlan

Trait Implementations§

Source§

impl<P, Proto> Clone for SpiCodec<P, Proto>
where P: LedPixel + Clone, Proto: SingleWireProtocol<P> + Clone,

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<P, Proto> Copy for SpiCodec<P, Proto>
where P: LedPixel + Copy, Proto: SingleWireProtocol<P> + Copy,

Source§

impl<P, Proto> Debug for SpiCodec<P, Proto>
where P: LedPixel + Debug, Proto: SingleWireProtocol<P> + Debug,

Source§

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

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

impl<P, Proto> Eq for SpiCodec<P, Proto>
where P: LedPixel + Eq, Proto: SingleWireProtocol<P> + Eq,

Source§

impl<P, Proto> PartialEq for SpiCodec<P, Proto>

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<P, Proto> StructuralPartialEq for SpiCodec<P, Proto>

Source§

impl<P, Proto> WireCodec<P, Proto, u8> for SpiCodec<P, Proto>
where P: LedPixel, Proto: SingleWireProtocol<P>,

Source§

type EncodeError = SpiEncodeError

Error type produced by encode. Read more
Source§

fn encoded_len(&self, pixel_count: usize) -> usize

Returns the exact number of Words that encode will produce for pixel_count pixels. Includes payload + reset/trailer overhead.
Source§

fn encode<const TX_CAPACITY: usize>( &self, color_order: P::Order, pixels: &[P], out: &mut Vec<u8, TX_CAPACITY>, ) -> LedStripResult<(), Self::EncodeError>

Encodes pixels into transport words, appending to out. Read more

Auto Trait Implementations§

§

impl<P, Proto> Freeze for SpiCodec<P, Proto>

§

impl<P, Proto> RefUnwindSafe for SpiCodec<P, Proto>

§

impl<P, Proto> Send for SpiCodec<P, Proto>

§

impl<P, Proto> Sync for SpiCodec<P, Proto>

§

impl<P, Proto> Unpin for SpiCodec<P, Proto>

§

impl<P, Proto> UnsafeUnpin for SpiCodec<P, Proto>

§

impl<P, Proto> UnwindSafe for SpiCodec<P, Proto>

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.