@@ -56,14 +56,14 @@ use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02;
5656/// };
5757///```
5858///
59- /// Typical RGBW usage example :
59+ /// Usage for RGBW devices is similar :
6060///```ignore
6161/// use rp2040_hal::clocks::init_clocks_and_plls;
6262/// let clocks = init_clocks_and_plls(...);
6363/// let pins = rp2040_hal::gpio::pin::bank0::Pins::new(...);
6464///
6565/// let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
66- /// let mut ws = Ws2812Direct::<_, _, _, smart_leds::RGBA8>::new (
66+ /// let mut ws = Ws2812Direct::new_sk6812 (
6767/// pins.gpio4.into_mode(),
6868/// &mut pio,
6969/// sm0,
@@ -72,10 +72,10 @@ use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02;
7272///
7373/// // Then you will make sure yourself to not write too frequently:
7474/// loop {
75- /// use smart_leds::{SmartLedsWrite, RGBA8 };
76- /// let color : RGBA8 = ( 255, 0, 255, 127).into() ;
75+ /// use smart_leds::{SmartLedsWrite, RGBW, White };
76+ /// let color = RGBW { r: 255, g: 0, b: 255, w: White( 127) } ;
7777///
78- /// ws.write([color].iter().copied() ).unwrap();
78+ /// ws.write([color]).unwrap();
7979/// delay_for_at_least_60_microseconds();
8080/// };
8181///```
@@ -97,12 +97,11 @@ where
9797 SM : StateMachineIndex ,
9898 CF : ColorFormat ,
9999{
100- /// Creates a new instance of this driver.
101- pub fn new (
100+ fn new_generic (
102101 pin : I ,
103102 pio : & mut PIO < P > ,
104103 sm : UninitStateMachine < ( P , SM ) > ,
105- clock_freq : fugit :: HertzU32 ,
104+ clock_freq : HertzU32 ,
106105 ) -> Self {
107106 // prepare the PIO program
108107 let side_set = pio:: SideSet :: new ( false , 1 , false ) ;
@@ -178,6 +177,40 @@ where
178177 }
179178}
180179
180+ impl < P , SM , I > Ws2812Direct < P , SM , I , smart_leds_trait:: RGB8 >
181+ where
182+ I : AnyPin < Function = P :: PinFunction > ,
183+ P : PIOExt ,
184+ SM : StateMachineIndex ,
185+ {
186+ /// Creates a new instance of this driver.
187+ pub fn new (
188+ pin : I ,
189+ pio : & mut PIO < P > ,
190+ sm : UninitStateMachine < ( P , SM ) > ,
191+ clock_freq : HertzU32 ,
192+ ) -> Self {
193+ Self :: new_generic ( pin, pio, sm, clock_freq)
194+ }
195+ }
196+
197+ impl < P , SM , I > Ws2812Direct < P , SM , I , smart_leds_trait:: RGBW < u8 , u8 > >
198+ where
199+ I : AnyPin < Function = P :: PinFunction > ,
200+ P : PIOExt ,
201+ SM : StateMachineIndex ,
202+ {
203+ /// Creates a new instance of this driver.
204+ pub fn new_sk6218 (
205+ pin : I ,
206+ pio : & mut PIO < P > ,
207+ sm : UninitStateMachine < ( P , SM ) > ,
208+ clock_freq : HertzU32 ,
209+ ) -> Self {
210+ Self :: new_generic ( pin, pio, sm, clock_freq)
211+ }
212+ }
213+
181214/// Specify whether to use 3 or 4 bytes per led color.
182215pub enum ColorBytes {
183216 ThreeBytes ,
@@ -212,13 +245,13 @@ impl ColorFormat for smart_leds_trait::RGB8 {
212245 }
213246}
214247
215- impl ColorFormat for smart_leds_trait:: RGBA < u8 > {
248+ impl ColorFormat for smart_leds_trait:: RGBW < u8 , u8 > {
216249 const COLOR_BYTES : ColorBytes = ColorBytes :: FourBytes ;
217250 fn to_word ( self ) -> u32 {
218251 ( u32:: from ( self . g ) << 24 )
219252 | ( u32:: from ( self . r ) << 16 )
220253 | ( u32:: from ( self . b ) << 8 )
221- | ( u32:: from ( self . a ) )
254+ | ( u32:: from ( self . a . 0 ) )
222255 }
223256}
224257
@@ -310,7 +343,7 @@ where
310343/// };
311344///```
312345///
313- /// Typical RGBW usage example :
346+ /// Usage for RGBW devices is similar :
314347///```ignore
315348/// use rp2040_hal::clocks::init_clocks_and_plls;
316349/// let clocks = init_clocks_and_plls(...);
@@ -319,7 +352,7 @@ where
319352/// let timer = Timer::new(pac.TIMER, &mut pac.RESETS);
320353///
321354/// let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
322- /// let mut ws = Ws2812::<_, _, _, _, smart_leds::RGBA8>::new (
355+ /// let mut ws = Ws2812::new_sk6812 (
323356/// pins.gpio4.into_mode(),
324357/// &mut pio,
325358/// sm0,
@@ -328,10 +361,10 @@ where
328361/// );
329362///
330363/// loop {
331- /// use smart_leds::{SmartLedsWrite, RGBA8 };
332- /// let color : RGBA8 = ( 255, 0, 255, 127).into() ;
364+ /// use smart_leds::{SmartLedsWrite, RGBW, White };
365+ /// let color = RGBW { r: 255, g: 0, b: 255, w: White( 127) } ;
333366///
334- /// ws.write([color].iter().copied() ).unwrap();
367+ /// ws.write([color]).unwrap();
335368///
336369/// // Do other stuff here...
337370/// };
@@ -347,28 +380,48 @@ where
347380 cd : C ,
348381}
349382
350- impl < P , SM , C , I , CF > Ws2812 < P , SM , C , I , CF >
383+ impl < P , SM , C , I > Ws2812 < P , SM , C , I , smart_leds_trait :: RGB8 >
351384where
352385 C : CountDown ,
353386 I : AnyPin < Function = P :: PinFunction > ,
354387 P : PIOExt ,
355388 SM : StateMachineIndex ,
356- CF : ColorFormat ,
357389{
358390 /// Creates a new instance of this driver.
359391 pub fn new (
360392 pin : I ,
361393 pio : & mut PIO < P > ,
362394 sm : UninitStateMachine < ( P , SM ) > ,
363- clock_freq : fugit :: HertzU32 ,
395+ clock_freq : HertzU32 ,
364396 cd : C ,
365- ) -> Ws2812 < P , SM , C , I , CF > {
397+ ) -> Ws2812 < P , SM , C , I , smart_leds_trait :: RGB8 > {
366398 let driver = Ws2812Direct :: new ( pin, pio, sm, clock_freq) ;
367399
368400 Self { driver, cd }
369401 }
370402}
371403
404+ impl < P , SM , C , I > Ws2812 < P , SM , C , I , smart_leds_trait:: RGBW < u8 , u8 > >
405+ where
406+ C : CountDown ,
407+ I : AnyPin < Function = P :: PinFunction > ,
408+ P : PIOExt ,
409+ SM : StateMachineIndex ,
410+ {
411+ /// Creates a new instance of this driver for SK6812 devices.
412+ pub fn new_sk6812 (
413+ pin : I ,
414+ pio : & mut PIO < P > ,
415+ sm : UninitStateMachine < ( P , SM ) > ,
416+ clock_freq : HertzU32 ,
417+ cd : C ,
418+ ) -> Ws2812 < P , SM , C , I , smart_leds_trait:: RGBW < u8 , u8 > > {
419+ let driver = Ws2812Direct :: new_sk6218 ( pin, pio, sm, clock_freq) ;
420+
421+ Self { driver, cd }
422+ }
423+ }
424+
372425impl < P , SM , I , C , CF > SmartLedsWrite for Ws2812 < P , SM , C , I , CF >
373426where
374427 C : CountDown ,
0 commit comments