@@ -45,10 +45,7 @@ use esp_hal::{
4545 Async , Blocking ,
4646 clock:: Clocks ,
4747 gpio:: { Level , interconnect:: PeripheralOutput } ,
48- rmt:: {
49- Channel , Error as RmtError , PulseCode , RawChannelAccess , TxChannel , TxChannelAsync ,
50- TxChannelConfig , TxChannelCreator , TxChannelInternal ,
51- } ,
48+ rmt:: { Channel , Error as RmtError , PulseCode , Tx , TxChannelConfig , TxChannelCreator } ,
5249} ;
5350use rgb:: Grb ;
5451use smart_leds_trait:: { SmartLedsWrite , SmartLedsWriteAsync } ;
@@ -81,7 +78,7 @@ impl From<RmtError> for LedAdapterError {
8178 }
8279}
8380
84- fn led_pulses_for_clock ( src_clock : u32 ) -> ( u32 , u32 ) {
81+ fn led_pulses_for_clock ( src_clock : u32 ) -> ( PulseCode , PulseCode ) {
8582 (
8683 PulseCode :: new (
8784 Level :: High ,
@@ -108,8 +105,8 @@ fn led_config() -> TxChannelConfig {
108105
109106fn convert_to_pulses (
110107 value : & [ u8 ] ,
111- mut_iter : & mut IterMut < u32 > ,
112- pulses : ( u32 , u32 ) ,
108+ mut_iter : & mut IterMut < PulseCode > ,
109+ pulses : ( PulseCode , PulseCode ) ,
113110) -> Result < ( ) , LedAdapterError > {
114111 for v in value {
115112 convert_rgb_channel_to_pulses ( * v, mut_iter, pulses) ?;
@@ -119,8 +116,8 @@ fn convert_to_pulses(
119116
120117fn convert_rgb_channel_to_pulses (
121118 channel_value : u8 ,
122- mut_iter : & mut IterMut < u32 > ,
123- pulses : ( u32 , u32 ) ,
119+ mut_iter : & mut IterMut < PulseCode > ,
120+ pulses : ( PulseCode , PulseCode ) ,
124121) -> Result < ( ) , LedAdapterError > {
125122 for position in [ 128 , 64 , 32 , 16 , 8 , 4 , 2 , 1 ] {
126123 * mut_iter. next ( ) . ok_or ( LedAdapterError :: BufferSizeExceeded ) ? =
@@ -148,7 +145,7 @@ pub const fn buffer_size(num_leds: usize) -> usize {
148145/// Function to calculate the required RMT buffer size for a given number of RGBW LEDs when using
149146/// the blocking API.
150147///
151- /// For RGB leds use [buffer_size_rgb ].
148+ /// For RGB leds use [buffer_size ].
152149///
153150/// This buffer size is calculated for the synchronous API provided by the [SmartLedsAdapter].
154151/// [buffer_size_async] should be used for the asynchronous API.
@@ -167,10 +164,10 @@ pub const fn buffer_size_rgbw(num_leds: usize) -> usize {
167164#[ macro_export]
168165macro_rules! smart_led_buffer {
169166 ( $num_leds: expr ) => {
170- [ 0u32 ; $crate:: buffer_size( $num_leds) ]
167+ [ :: esp_hal :: rmt :: PulseCode :: default ( ) ; $crate:: buffer_size( $num_leds) ]
171168 } ;
172169 ( $num_leds: expr; RGBW ) => {
173- [ 0u32 ; $crate:: buffer_size_rgbw( $num_leds) ]
170+ [ :: esp_hal :: rmt :: PulseCode :: default ( ) ; $crate:: buffer_size_rgbw( $num_leds) ]
174171 } ;
175172}
176173
@@ -185,44 +182,37 @@ macro_rules! smartLedBuffer {
185182
186183/// Adapter taking an RMT channel and a specific pin and providing RGB LED
187184/// interaction functionality using the `smart-leds` crate
188- pub struct SmartLedsAdapter < TX , const BUFFER_SIZE : usize , Color = Grb < u8 > >
189- where
190- TX : RawChannelAccess + TxChannelInternal + ' static ,
191- {
192- channel : Option < Channel < Blocking , TX > > ,
193- rmt_buffer : [ u32 ; BUFFER_SIZE ] ,
194- pulses : ( u32 , u32 ) ,
185+ pub struct SmartLedsAdapter < ' ch , const BUFFER_SIZE : usize , Color = Grb < u8 > > {
186+ channel : Option < Channel < ' ch , Blocking , Tx > > ,
187+ rmt_buffer : [ PulseCode ; BUFFER_SIZE ] ,
188+ pulses : ( PulseCode , PulseCode ) ,
195189 color : PhantomData < Color > ,
196190}
197191
198- impl < ' d , TX , const BUFFER_SIZE : usize > SmartLedsAdapter < TX , BUFFER_SIZE , Grb < u8 > >
199- where
200- TX : RawChannelAccess + TxChannelInternal + ' static ,
201- {
192+ impl < ' ch , const BUFFER_SIZE : usize > SmartLedsAdapter < ' ch , BUFFER_SIZE , Grb < u8 > > {
202193 /// Create a new adapter object that drives the pin using the RMT channel.
203- pub fn new < C , O > ( channel : C , pin : O , rmt_buffer : [ u32 ; BUFFER_SIZE ] ) -> Self
194+ pub fn new < C , O > ( channel : C , pin : O , rmt_buffer : [ PulseCode ; BUFFER_SIZE ] ) -> Self
204195 where
205- O : PeripheralOutput < ' d > ,
206- C : TxChannelCreator < ' d , Blocking , Raw = TX > ,
196+ O : PeripheralOutput < ' ch > ,
197+ C : TxChannelCreator < ' ch , Blocking > ,
207198 {
208199 Self :: new_with_color ( channel, pin, rmt_buffer)
209200 }
210201}
211202
212- impl < ' d , TX , const BUFFER_SIZE : usize , Color > SmartLedsAdapter < TX , BUFFER_SIZE , Color >
203+ impl < ' ch , const BUFFER_SIZE : usize , Color > SmartLedsAdapter < ' ch , BUFFER_SIZE , Color >
213204where
214- TX : RawChannelAccess + TxChannelInternal + ' static ,
215205 Color : rgb:: ComponentSlice < u8 > ,
216206{
217207 /// Create a new adapter object that drives the pin using the RMT channel.
218208 pub fn new_with_color < C , O > (
219209 channel : C ,
220210 pin : O ,
221- rmt_buffer : [ u32 ; BUFFER_SIZE ] ,
222- ) -> SmartLedsAdapter < TX , BUFFER_SIZE , Color >
211+ rmt_buffer : [ PulseCode ; BUFFER_SIZE ] ,
212+ ) -> SmartLedsAdapter < ' ch , BUFFER_SIZE , Color >
223213 where
224- O : PeripheralOutput < ' d > ,
225- C : TxChannelCreator < ' d , Blocking , Raw = TX > ,
214+ O : PeripheralOutput < ' ch > ,
215+ C : TxChannelCreator < ' ch , Blocking > ,
226216 {
227217 let channel = channel. configure_tx ( pin, led_config ( ) ) . unwrap ( ) ;
228218
@@ -238,10 +228,9 @@ where
238228 }
239229}
240230
241- impl < TX , const BUFFER_SIZE : usize , Color > SmartLedsWrite
242- for SmartLedsAdapter < TX , BUFFER_SIZE , Color >
231+ impl < ' ch , const BUFFER_SIZE : usize , Color > SmartLedsWrite
232+ for SmartLedsAdapter < ' ch , BUFFER_SIZE , Color >
243233where
244- TX : RawChannelAccess + TxChannelInternal + ' static ,
245234 Color : rgb:: ComponentSlice < u8 > ,
246235{
247236 type Error = LedAdapterError ;
@@ -266,9 +255,9 @@ where
266255 }
267256
268257 // Finally, add an end element.
269- * seq_iter. next ( ) . ok_or ( LedAdapterError :: BufferSizeExceeded ) ? = 0 ;
258+ * seq_iter. next ( ) . ok_or ( LedAdapterError :: BufferSizeExceeded ) ? = PulseCode :: end_marker ( ) ;
270259
271- // Perform the actual RMT operation. We use the u32 values here right away.
260+ // Perform the actual RMT operation.
272261 let channel = self . channel . take ( ) . unwrap ( ) ;
273262 match channel. transmit ( & self . rmt_buffer ) ?. wait ( ) {
274263 Ok ( chan) => {
@@ -311,44 +300,37 @@ pub const fn buffer_size_async_rgbw(num_leds: usize) -> usize {
311300
312301/// Adapter taking an RMT channel and a specific pin and providing RGB LED
313302/// interaction functionality.
314- pub struct SmartLedsAdapterAsync < Tx , const BUFFER_SIZE : usize , Color = Grb < u8 > >
315- where
316- Tx : RawChannelAccess + TxChannelInternal + ' static ,
317- {
318- channel : Channel < Async , Tx > ,
319- rmt_buffer : [ u32 ; BUFFER_SIZE ] ,
320- pulses : ( u32 , u32 ) ,
303+ pub struct SmartLedsAdapterAsync < ' ch , const BUFFER_SIZE : usize , Color = Grb < u8 > > {
304+ channel : Channel < ' ch , Async , Tx > ,
305+ rmt_buffer : [ PulseCode ; BUFFER_SIZE ] ,
306+ pulses : ( PulseCode , PulseCode ) ,
321307 color : PhantomData < Color > ,
322308}
323309
324- impl < ' d , Tx , const BUFFER_SIZE : usize > SmartLedsAdapterAsync < Tx , BUFFER_SIZE , Grb < u8 > >
325- where
326- Tx : RawChannelAccess + TxChannelInternal + ' static ,
327- {
310+ impl < ' ch , const BUFFER_SIZE : usize > SmartLedsAdapterAsync < ' ch , BUFFER_SIZE , Grb < u8 > > {
328311 /// Create a new adapter object that drives the pin using the RMT channel.
329- pub fn new < C , O > ( channel : C , pin : O , rmt_buffer : [ u32 ; BUFFER_SIZE ] ) -> Self
312+ pub fn new < C , O > ( channel : C , pin : O , rmt_buffer : [ PulseCode ; BUFFER_SIZE ] ) -> Self
330313 where
331- O : PeripheralOutput < ' d > ,
332- C : TxChannelCreator < ' d , Async , Raw = Tx > ,
314+ O : PeripheralOutput < ' ch > ,
315+ C : TxChannelCreator < ' ch , Async > ,
333316 {
334317 Self :: new_with_color ( channel, pin, rmt_buffer)
335318 }
336319}
337320
338- impl < ' d , Tx , const BUFFER_SIZE : usize , Color > SmartLedsAdapterAsync < Tx , BUFFER_SIZE , Color >
321+ impl < ' ch , const BUFFER_SIZE : usize , Color > SmartLedsAdapterAsync < ' ch , BUFFER_SIZE , Color >
339322where
340- Tx : RawChannelAccess + TxChannelInternal + ' static ,
341323 Color : rgb:: ComponentSlice < u8 > ,
342324{
343325 /// Create a new adapter object that drives the pin using the RMT channel.
344326 pub fn new_with_color < C , O > (
345327 channel : C ,
346328 pin : O ,
347- rmt_buffer : [ u32 ; BUFFER_SIZE ] ,
348- ) -> SmartLedsAdapterAsync < Tx , BUFFER_SIZE , Color >
329+ rmt_buffer : [ PulseCode ; BUFFER_SIZE ] ,
330+ ) -> SmartLedsAdapterAsync < ' ch , BUFFER_SIZE , Color >
349331 where
350- O : PeripheralOutput < ' d > ,
351- C : TxChannelCreator < ' d , Async , Raw = Tx > ,
332+ O : PeripheralOutput < ' ch > ,
333+ C : TxChannelCreator < ' ch , Async > ,
352334 {
353335 let channel = channel. configure_tx ( pin, led_config ( ) ) . unwrap ( ) ;
354336
@@ -382,21 +364,20 @@ where
382364 /// Async sends one pixel at a time so needs a delimiter after each pixel
383365 fn convert_to_pulses (
384366 value : & [ u8 ] ,
385- mut_iter : & mut IterMut < u32 > ,
386- pulses : ( u32 , u32 ) ,
367+ mut_iter : & mut IterMut < PulseCode > ,
368+ pulses : ( PulseCode , PulseCode ) ,
387369 ) -> Result < ( ) , LedAdapterError > {
388370 for v in value {
389371 convert_rgb_channel_to_pulses ( * v, mut_iter, pulses) ?;
390372 }
391- * mut_iter. next ( ) . ok_or ( LedAdapterError :: BufferSizeExceeded ) ? = 0 ;
373+ * mut_iter. next ( ) . ok_or ( LedAdapterError :: BufferSizeExceeded ) ? = PulseCode :: end_marker ( ) ;
392374 Ok ( ( ) )
393375 }
394376}
395377
396- impl < Tx , const BUFFER_SIZE : usize , Color > SmartLedsWriteAsync
397- for SmartLedsAdapterAsync < Tx , BUFFER_SIZE , Color >
378+ impl < ' ch , const BUFFER_SIZE : usize , Color > SmartLedsWriteAsync
379+ for SmartLedsAdapterAsync < ' ch , BUFFER_SIZE , Color >
398380where
399- Tx : RawChannelAccess + TxChannelInternal + ' static ,
400381 Color : rgb:: ComponentSlice < u8 > ,
401382{
402383 type Error = LedAdapterError ;
0 commit comments