Struct ws2812_pio::Ws2812Direct
source · pub struct Ws2812Direct<P, SM, I>{ /* private fields */ }
Expand description
This is the WS2812 PIO Driver.
For blocking applications is recommended to use the Ws2812 struct instead of this raw driver.
If you use this driver directly, you will need to take care of the timing expectations of the Ws2812Direct::write method.
Typical usage example:
ⓘ
use rp2040_hal::clocks::init_clocks_and_plls;
let clocks = init_clocks_and_plls(...);
let pins = rp2040_hal::gpio::pin::bank0::Pins::new(...);
let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
let mut ws = Ws2812Direct::new(
pins.gpio4.into_mode(),
&mut pio,
sm0,
clocks.peripheral_clock.freq(),
);
// Then you will make sure yourself to not write too frequently:
loop {
use smart_leds::{SmartLedsWrite, RGB8};
let color : RGB8 = (255, 0, 255).into();
ws.write([color].iter().copied()).unwrap();
delay_for_at_least_60_microseconds();
};
Implementations§
source§impl<P, SM, I> Ws2812Direct<P, SM, I>
impl<P, SM, I> Ws2812Direct<P, SM, I>
Trait Implementations§
source§impl<P, SM, I> SmartLedsWrite for Ws2812Direct<P, SM, I>
impl<P, SM, I> SmartLedsWrite for Ws2812Direct<P, SM, I>
source§fn write<T, J>(&mut self, iterator: T) -> Result<(), ()>
fn write<T, J>(&mut self, iterator: T) -> Result<(), ()>
If you call this function, be advised that you will have to wait at least 60 microseconds between calls of this function! That means, either you get hold on a timer and the timing requirements right your self, or rather use Ws2812.
Please bear in mind, that it still blocks when writing into the PIO FIFO until all data has been transmitted to the LED chain.
type Color = RGB<u8>
type Error = ()
Auto Trait Implementations§
impl<P, SM, I> Freeze for Ws2812Direct<P, SM, I>where
I: Freeze,
impl<P, SM, I> !RefUnwindSafe for Ws2812Direct<P, SM, I>
impl<P, SM, I> Send for Ws2812Direct<P, SM, I>where
I: Send,
impl<P, SM, I> !Sync for Ws2812Direct<P, SM, I>
impl<P, SM, I> Unpin for Ws2812Direct<P, SM, I>
impl<P, SM, I> !UnwindSafe for Ws2812Direct<P, SM, I>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more