SmartLedsAdapter

Struct SmartLedsAdapter 

Source
pub struct SmartLedsAdapter<'d, const BUFFER_SIZE: usize, Mode, Order, Timing>
where Mode: DriverMode, Order: ColorOrder, 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 ColorOrder. This determines what order the LED expects the color values in. Almost all LEDs use color_order::Rgb or color_order::Grb.
  • 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 move is Blocking, this type implements the blocking SmartLedsWrite interface. An async interface for esp_hal::Async may be added in the future. (You usually don’t need to choose this manually, Rust can deduce it from the passed-in RMT channel.)

Implementations§

Source§

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

Source

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

Creates a new SmartLedsAdapter 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<C, P>( channel: C, pin: P, memsize: u8, ) -> Result<Self, RmtError>
where C: TxChannelCreator<'d, Mode>, P: PeripheralOutput<'d>,

Creates a new SmartLedsAdapter 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.

Trait Implementations§

Source§

impl<'d, const BUFFER_SIZE: usize, Order, Timing> SmartLedsWrite for SmartLedsAdapter<'d, BUFFER_SIZE, Blocking, Order, Timing>
where Order: ColorOrder, 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 RGB8 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 = Rgb<u8>

Source§

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

Source§

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

Convert all RGB8 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 = Rgb<u8>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'d, const BUFFER_SIZE: usize, Mode, Order, Timing> !UnwindSafe for SmartLedsAdapter<'d, BUFFER_SIZE, Mode, 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.