pub struct Ws2812Esp32RmtDriver<'d> {
pub pixel_data: Option<Vec<u8>>,
/* private fields */
}Expand description
WS2812 ESP32 RMT driver wrapper.
§Examples
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>>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>
impl<'d> Ws2812Esp32RmtDriver<'d>
Sourcepub fn new<C: RmtChannel>(
channel: impl Peripheral<P = C> + 'd,
pin: impl Peripheral<P = impl OutputPin> + 'd,
) -> Result<Self, Ws2812Esp32RmtDriverError>
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.
Sourcepub fn new_with_rmt_driver(
tx: TxRmtDriver<'d>,
) -> Result<Self, Ws2812Esp32RmtDriverError>
pub fn new_with_rmt_driver( tx: TxRmtDriver<'d>, ) -> Result<Self, Ws2812Esp32RmtDriverError>
Creates a WS2812 ESP32 RMT driver wrapper with TxRmtDriver.
The clock divider must be set to 1 for the driver configuration.
let driver_config = TransmitConfig::new()
.clock_divider(1); // Required parameter.
let driver = TxRmtDriver::new(channel, led_pin, &driver_config).unwrap();§Errors
Returns an error if the RMT driver initialization failed.
Sourcepub fn write_blocking<'a, 'b, T>(
&'a mut self,
pixel_sequence: T,
) -> Result<(), Ws2812Esp32RmtDriverError>
pub fn write_blocking<'a, 'b, T>( &'a mut self, pixel_sequence: T, ) -> Result<(), Ws2812Esp32RmtDriverError>
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.
Sourcepub fn write<'b, T>(
&'static mut self,
pixel_sequence: T,
) -> Result<(), Ws2812Esp32RmtDriverError>
Available on crate feature alloc only.
pub fn write<'b, T>( &'static mut self, pixel_sequence: T, ) -> Result<(), Ws2812Esp32RmtDriverError>
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.