pub struct Ws2812Direct<P, SM, I>
where I: AnyPin<Function = P::PinFunction>, P: PIOExt, SM: StateMachineIndex,
{ /* 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>
where I: AnyPin<Function = P::PinFunction>, P: PIOExt, SM: StateMachineIndex,

source

pub fn new( pin: I, pio: &mut PIO<P>, sm: UninitStateMachine<(P, SM)>, clock_freq: HertzU32 ) -> Self

Creates a new instance of this driver.

Trait Implementations§

source§

impl<P, SM, I> SmartLedsWrite for Ws2812Direct<P, SM, I>
where I: AnyPin<Function = P::PinFunction>, P: PIOExt, SM: StateMachineIndex,

source§

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

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>
where I: Unpin, P: Unpin, SM: Unpin,

§

impl<P, SM, I> !UnwindSafe for Ws2812Direct<P, SM, I>

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<Choices> CoproductSubsetter<CNil, HNil> for Choices

§

type Remainder = Choices

source§

fn subset( self ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) 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, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

source§

fn lift_into(self) -> U

Performs the indexed conversion.
source§

impl<Source> Sculptor<HNil, HNil> for Source

§

type Remainder = Source

source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
source§

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

§

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>,

§

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.