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>,
impl<P, Proto> SpiCodec<P, Proto>where
P: LedPixel,
Proto: SingleWireProtocol<P>,
Sourcepub fn new(
plan: SpiEncodingPlan,
invert_output: bool,
) -> Result<Self, SpiCodecPlanError>
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.
Sourcepub fn for_protocol(
plan: SpiEncodingPlan,
invert_output: bool,
) -> Result<Self, SpiCodecPlanError>
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.