pub struct Sk6812Driver<const CODES: usize = MAX_CODES> { /* private fields */ }Expand description
CODES sizes the pulse buffer: pass codes_for with the strip length.
It is a parameter because that buffer lives across the transmit await, so
it sits in the caller’s future — 24 codes per LED at 4 bytes each is 1.5 KiB
for the default 16 LEDs, and a fire27’s main-task stack region has about
that much slack in total (its link assert is what found this). A board with
ten LEDs should pay for ten: Sk6812Driver::<{ codes_for(10) }>.
It is the code count rather than the LED count because
generic_const_exprs is unstable, so the buffer length cannot be computed
from a generic.
Implementations§
Source§impl<const CODES: usize> Sk6812Driver<CODES>
impl<const CODES: usize> Sk6812Driver<CODES>
Sourcepub fn new(rmt: RMT<'static>, pin: AnyPin<'static>) -> Result<Self, Sk6812Error>
pub fn new(rmt: RMT<'static>, pin: AnyPin<'static>) -> Result<Self, Sk6812Error>
Claim the WHOLE RMT peripheral (TX channel 0) and drive pin as the LED
data line.
Convenience for an app that uses RMT for nothing else. If it also reads
DS18B20 sensors, use Self::with_channel and
crate::driver::ds18b20::Ds18b20Driver::with_channels with channels
from crate::board::rmt::RmtChannels.
Sourcepub fn with_channel(
tx: impl TxChannelCreator<'static, Async>,
pin: AnyPin<'static>,
blocks: u8,
) -> Result<Self, Sk6812Error>
pub fn with_channel( tx: impl TxChannelCreator<'static, Async>, pin: AnyPin<'static>, blocks: u8, ) -> Result<Self, Sk6812Error>
Drive pin as the LED data line using the given RMT TX channel, which
claims blocks of channel RAM from that channel upwards.
Leaves the rest of the peripheral free — which is the whole point: the 1-Wire driver needs a TX and an RX channel of its own, and both drivers used to take the peripheral by value, so a board could have temperature sensing or light bars but not both.
blocks decides whether a frame transmits straight out of channel RAM
or is refilled by the CPU mid-stream, which is a visible correctness
matter rather than a tuning knob — crate::board::rmt::LED_BLOCKS is
the board’s answer, and its module docs carry the reasoning. The claim
must not reach another channel in use, or configure_tx rejects it.
Sourcepub async fn write(&mut self, colors: &[Rgb]) -> Result<(), Sk6812Error>
pub async fn write(&mut self, colors: &[Rgb]) -> Result<(), Sk6812Error>
Push a frame of colours to the strip (LED 0 first). Holds the line low
afterwards to latch. Errors if the frame needs more than CODES pulse
codes, i.e. more LEDs than this instance was sized for.
Sourcepub async fn write_frame(
&mut self,
frame: &[PulseCode],
) -> Result<(), Sk6812Error>
pub async fn write_frame( &mut self, frame: &[PulseCode], ) -> Result<(), Sk6812Error>
Transmit a frame built elsewhere — typically a const one from
uniform_frame, living in flash.
The only path that needs no frame storage in RAM.
Sourcepub async fn fill(&mut self, color: Rgb, len: usize) -> Result<(), Sk6812Error>
pub async fn fill(&mut self, color: Rgb, len: usize) -> Result<(), Sk6812Error>
Convenience: set every LED in a strip of len to the same colour.