Struct Ws2812Esp32RmtDriver

Source
pub struct Ws2812Esp32RmtDriver<'d> {
    pub pixel_data: Option<Vec<u8>>,
    /* private fields */
}
Expand description

WS2812 ESP32 RMT driver wrapper.

§Examples

#[cfg(not(target_vendor = "espressif"))]
use ws2812_esp32_rmt_driver::mock::esp_idf_hal;

use esp_idf_hal::peripherals::Peripherals;
use ws2812_esp32_rmt_driver::driver::Ws2812Esp32RmtDriver;
use ws2812_esp32_rmt_driver::driver::color::{LedPixelColor, LedPixelColorGrb24};

let peripherals = Peripherals::take().unwrap();
let led_pin = peripherals.pins.gpio27;
let channel = peripherals.rmt.channel0;
let mut driver = Ws2812Esp32RmtDriver::new(channel, led_pin).unwrap();

// Single LED with RED color.
let red = LedPixelColorGrb24::new_with_rgb(30, 0, 0);
let pixel: [u8; 3] = red.as_ref().try_into().unwrap();
assert_eq!(pixel, [0, 30, 0]);

driver.write_blocking(pixel.clone().into_iter()).unwrap();

Fields§

§pixel_data: Option<Vec<u8>>
Available on non-target_vendor="espressif" only.

Pixel binary array to be written

If the target vendor does not equals to “espressif”, pixel data is written into this instead of genuine encoder.

Implementations§

Source§

impl<'d> Ws2812Esp32RmtDriver<'d>

Source

pub fn new<C: RmtChannel>( channel: impl Peripheral<P = C> + 'd, pin: impl Peripheral<P = impl OutputPin> + 'd, ) -> Result<Self, Ws2812Esp32RmtDriverError>

Creates a WS2812 ESP32 RMT driver wrapper.

RMT driver of channel shall be initialized and installed for pin. channel shall be different between different pin.

§Errors

Returns an error if the RMT driver initialization failed.

Source

pub fn new_with_rmt_driver( tx: TxRmtDriver<'d>, ) -> Result<Self, Ws2812Esp32RmtDriverError>

Source

pub fn write_blocking<'a, 'b, T>( &'a mut self, pixel_sequence: T, ) -> Result<(), Ws2812Esp32RmtDriverError>
where T: Iterator<Item = u8> + Send + 'b, 'b: 'a,

Writes pixel data from a pixel-byte sequence to the IO pin.

Byte count per LED pixel and channel order is not handled by this method. The pixel data sequence has to be correctly laid out depending on the LED strip model.

§Errors

Returns an error if an RMT driver error occurred.

§Warning

Iteration of pixel_sequence happens inside an interrupt handler so beware of side-effects that don’t work in interrupt handlers. See esp_idf_hal::rmt::TxRmtDriver for details.

Source

pub fn write<'b, T>( &'static mut self, pixel_sequence: T, ) -> Result<(), Ws2812Esp32RmtDriverError>
where T: Iterator<Item = u8> + Send + 'static,

Available on crate feature alloc only.

Writes pixel data from a pixel-byte sequence to the IO pin.

Byte count per LED pixel and channel order is not handled by this method. The pixel data sequence has to be correctly laid out depending on the LED strip model.

Note that this requires pixel_sequence to be Boxed for an allocation free version see Self::write_blocking.

§Errors

Returns an error if an RMT driver error occurred.

§Warning

Iteration of pixel_sequence happens inside an interrupt handler so beware of side-effects that don’t work in interrupt handlers. See esp_idf_hal::rmt::TxRmtDriver for details.

Auto Trait Implementations§

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

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.