RmtSmartLeds

Struct RmtSmartLeds 

Source
pub struct RmtSmartLeds<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing>
where Mode: DriverMode, C: Color, Order: ColorOrder<C>, Timing: Timing,
{ /* private fields */ }
Expand description

SmartLedsWrite driver implementation using the ESP32’s “remote control” (RMT) peripheral for hardware-offloaded, fast control of smart LEDs.

For usage examples and a general overview see the crate documentation.

This type supports many configurations of color order, LED timings, and LED count. For this reason, there are three main type parameters you have to choose:

  • The buffer size. This determines how many RMT pulses can be sent by this driver, and allows it to function entirely without heap allocation. It is strongly recommended to use the buffer_size function with the desired number of LEDs to choose a correct buffer size, otherwise SmartLedsWrite::write will return AdapterError::BufferSizeExceeded.
  • The Color. This determines the color model and number of channels to be sent.
  • The ColorOrder. This determines what order the LED expects the color values in.
  • The Timing. This determines the smart LED type in use; what kind of signal it expects. Several implementations for common LED types like WS2812 are provided. Note that many WS2812-like LEDs are at least almost compatible in their timing, even though the datasheets specify different amounts, the other LEDs’ values are within the tolerance range, and even exceeding these, many LEDs continue to work beyond their specified timing range. It is however recommended to use the corresponding LED type, or implement your own when needed.

When the driver mode is Blocking, this type implements the blocking SmartLedsWrite interface. When the driver mode is Async, this type implements the SmartLedsWriteAsync interface instead. (You usually don’t need to choose this manually, Rust can deduce it from the passed-in RMT channel.)

Some common configurations have predefined aliases: Ws2812SmartLeds, Sk68xxRgbwSmartLeds, WhiteSmartLeds, Rgb8RmtSmartLeds.

Implementations§

Source§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>
where Mode: DriverMode, C: Color, Order: ColorOrder<C>, Timing: Timing,

Source

pub fn new<Ch, P>(channel: Ch, pin: P) -> Result<Self, RmtError>
where Ch: TxChannelCreator<'d, Mode>, P: PeripheralOutput<'d>,

Creates a new RmtSmartLeds that drives the provided output using the given RMT channel.

Note that calling this function usually requires you to specify the desired buffer size, ColorOrder and Timing. See the struct documentation for details.

If you want to reuse the channel afterwards, you can use esp_hal::rmt::ChannelCreator::reborrow to create a shorter-lived derived channel.

§Errors

If any configuration issue with the RMT Channel occurs, the error will be returned.

Source

pub fn new_with_memsize<Ch, P>( channel: Ch, pin: P, memsize: u8, ) -> Result<Self, RmtError>
where Ch: TxChannelCreator<'d, Mode>, P: PeripheralOutput<'d>,

Creates a new RmtSmartLeds that drives the provided output using the given RMT channel.

Note that calling this function usually requires you to specify the desired buffer size, ColorOrder and Timing. See the struct documentation for details.

If you want to reuse the channel afterwards, you can use esp_hal::rmt::ChannelCreator::reborrow to create a shorter-lived derived channel.

The memsize parameter determines how many RMT blocks this adapter will use. If you use any value other than 1, other RMT channels will not be available, as their memory blocks will be used up by this driver. However, this can allow you to control many more LEDs without issues.

§Errors

If any configuration issue with the RMT Channel occurs, the error will be returned.

Source§

impl<'d, const BUFFER_SIZE: usize, C, Order, Timing> RmtSmartLeds<'d, BUFFER_SIZE, Blocking, C, Order, Timing>
where C: Color, Order: ColorOrder<C>, Timing: Timing,

Source

pub fn flush(&mut self) -> Result<(), AdapterError>

Transmit existing LED data via the RMT peripheral.

Trait Implementations§

Source§

impl<'d, const BUFFER_SIZE: usize, C, Order, Timing> SmartLedsWrite for RmtSmartLeds<'d, BUFFER_SIZE, Blocking, C, Order, Timing>
where C: Color, Order: ColorOrder<C>, Timing: Timing,

Source§

fn write<T, I>(&mut self, iterator: T) -> Result<(), Self::Error>
where T: IntoIterator<Item = I>, I: Into<Self::Color>,

Convert all Color items of the iterator to the RMT format and add them to internal buffer, then start a singular RMT operation based on that buffer.

Source§

type Error = AdapterError

Source§

type Color = C

Source§

impl<'d, const BUFFER_SIZE: usize, C, Order, Timing> SmartLedsWriteAsync for RmtSmartLeds<'d, BUFFER_SIZE, Async, C, Order, Timing>
where C: Color, Order: ColorOrder<C>, Timing: Timing,

Source§

fn write<T, I>( &mut self, iterator: T, ) -> impl Future<Output = Result<(), Self::Error>>
where T: IntoIterator<Item = I>, I: Into<Self::Color>,

Convert all Color items of the iterator to the RMT format and add them to internal buffer, then start a singular RMT operation based on that buffer.

Source§

type Error = AdapterError

Source§

type Color = C

Auto Trait Implementations§

§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> Freeze for RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>

§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> RefUnwindSafe for RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>
where Order: RefUnwindSafe, Timing: RefUnwindSafe, C: RefUnwindSafe, Mode: RefUnwindSafe,

§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> Send for RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>
where Order: Send, Timing: Send, C: Send, Mode: Send,

§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> Sync for RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>
where Order: Sync, Timing: Sync, C: Sync, Mode: Sync,

§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> Unpin for RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>
where Order: Unpin, Timing: Unpin, C: Unpin, Mode: Unpin,

§

impl<'d, const BUFFER_SIZE: usize, Mode, C, Order, Timing> !UnwindSafe for RmtSmartLeds<'d, BUFFER_SIZE, Mode, C, Order, Timing>

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.