1313//! Bear in mind that you will have to take care of timing requirements
1414//! yourself then.
1515
16- use cortex_m;
1716use embedded_hal:: timer:: CountDown ;
18- use fugit:: { ExtU32 , HertzU32 } ;
17+ use fugit:: { ExtU32 , HertzU32 , MicrosDurationU32 } ;
1918use rp2040_hal:: {
20- gpio:: { Function , FunctionConfig , Pin , PinId , ValidPinMode } ,
19+ gpio:: AnyPin ,
2120 pio:: { PIOExt , StateMachineIndex , Tx , UninitStateMachine , PIO } ,
2221} ;
2322use smart_leds_trait:: SmartLedsWrite ;
@@ -56,25 +55,23 @@ use smart_leds_trait::SmartLedsWrite;
5655///```
5756pub struct Ws2812Direct < P , SM , I >
5857where
59- I : PinId ,
60- P : PIOExt + FunctionConfig ,
61- Function < P > : ValidPinMode < I > ,
58+ I : AnyPin < Function = P :: PinFunction > ,
59+ P : PIOExt ,
6260 SM : StateMachineIndex ,
6361{
6462 tx : Tx < ( P , SM ) > ,
65- _pin : Pin < I , Function < P > > ,
63+ _pin : I ,
6664}
6765
6866impl < P , SM , I > Ws2812Direct < P , SM , I >
6967where
70- I : PinId ,
71- P : PIOExt + FunctionConfig ,
72- Function < P > : ValidPinMode < I > ,
68+ I : AnyPin < Function = P :: PinFunction > ,
69+ P : PIOExt ,
7370 SM : StateMachineIndex ,
7471{
7572 /// Creates a new instance of this driver.
7673 pub fn new (
77- pin : Pin < I , Function < P > > ,
74+ pin : I ,
7875 pio : & mut PIO < P > ,
7976 sm : UninitStateMachine < ( P , SM ) > ,
8077 clock_freq : fugit:: HertzU32 ,
@@ -127,11 +124,12 @@ where
127124 let int: u16 = int as u16 ;
128125 let frac: u8 = frac as u8 ;
129126
127+ let pin = pin. into ( ) ;
130128 let ( mut sm, _, tx) = rp2040_hal:: pio:: PIOBuilder :: from_program ( installed)
131129 // only use TX FIFO
132130 . buffers ( rp2040_hal:: pio:: Buffers :: OnlyTx )
133131 // Pin configuration
134- . side_set_pin_base ( I :: DYN . num )
132+ . side_set_pin_base ( pin . id ( ) . num )
135133 // OSR config
136134 . out_shift_direction ( rp2040_hal:: pio:: ShiftDirection :: Left )
137135 . autopull ( true )
@@ -140,19 +138,21 @@ where
140138 . build ( sm) ;
141139
142140 // Prepare pin's direction.
143- sm. set_pindirs ( [ ( I :: DYN . num , rp2040_hal:: pio:: PinDir :: Output ) ] ) ;
141+ sm. set_pindirs ( [ ( pin . id ( ) . num , rp2040_hal:: pio:: PinDir :: Output ) ] ) ;
144142
145143 sm. start ( ) ;
146144
147- Self { tx, _pin : pin }
145+ Self {
146+ tx,
147+ _pin : I :: from ( pin) ,
148+ }
148149 }
149150}
150151
151152impl < P , SM , I > SmartLedsWrite for Ws2812Direct < P , SM , I >
152153where
153- I : PinId ,
154- P : PIOExt + FunctionConfig ,
155- Function < P > : ValidPinMode < I > ,
154+ I : AnyPin < Function = P :: PinFunction > ,
155+ P : PIOExt ,
156156 SM : StateMachineIndex ,
157157{
158158 type Color = smart_leds_trait:: RGB8 ;
@@ -214,10 +214,9 @@ where
214214///```
215215pub struct Ws2812 < P , SM , C , I >
216216where
217- I : PinId ,
218217 C : CountDown ,
219- P : PIOExt + FunctionConfig ,
220- Function < P > : ValidPinMode < I > ,
218+ I : AnyPin < Function = P :: PinFunction > ,
219+ P : PIOExt ,
221220 SM : StateMachineIndex ,
222221{
223222 driver : Ws2812Direct < P , SM , I > ,
@@ -226,15 +225,14 @@ where
226225
227226impl < P , SM , C , I > Ws2812 < P , SM , C , I >
228227where
229- I : PinId ,
230228 C : CountDown ,
231- P : PIOExt + FunctionConfig ,
232- Function < P > : ValidPinMode < I > ,
229+ I : AnyPin < Function = P :: PinFunction > ,
230+ P : PIOExt ,
233231 SM : StateMachineIndex ,
234232{
235233 /// Creates a new instance of this driver.
236234 pub fn new (
237- pin : Pin < I , Function < P > > ,
235+ pin : I ,
238236 pio : & mut PIO < P > ,
239237 sm : UninitStateMachine < ( P , SM ) > ,
240238 clock_freq : fugit:: HertzU32 ,
@@ -246,11 +244,12 @@ where
246244 }
247245}
248246
249- impl < ' timer , P , SM , I > SmartLedsWrite for Ws2812 < P , SM , rp2040_hal :: timer :: CountDown < ' timer > , I >
247+ impl < P , SM , I , C > SmartLedsWrite for Ws2812 < P , SM , C , I >
250248where
251- I : PinId ,
252- P : PIOExt + FunctionConfig ,
253- Function < P > : ValidPinMode < I > ,
249+ C : CountDown ,
250+ C :: Time : From < MicrosDurationU32 > ,
251+ I : AnyPin < Function = P :: PinFunction > ,
252+ P : PIOExt ,
254253 SM : StateMachineIndex ,
255254{
256255 type Color = smart_leds_trait:: RGB8 ;
0 commit comments