@@ -262,19 +262,33 @@ impl<USART: Instance, WORD> Rx<USART, WORD> {
262
262
pub fn unlisten_idle ( & mut self ) {
263
263
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. idleie ( ) . clear_bit ( ) ) }
264
264
}
265
+ }
266
+
267
+ /// Trait for [`Rx`] interrupt handling.
268
+ pub trait RxISR {
269
+ /// Return true if the line idle status is set
270
+ fn is_idle ( & self ) -> bool ;
271
+
272
+ /// Return true if the rx register is not empty (and can be read)
273
+ fn is_rx_not_empty ( & self ) -> bool ;
274
+
275
+ /// Clear idle line interrupt flag
276
+ fn clear_idle_interrupt ( & self ) ;
277
+ }
265
278
279
+ impl < USART : Instance , WORD > RxISR for Rx < USART , WORD > {
266
280
/// Return true if the line idle status is set
267
- pub fn is_idle ( & self ) -> bool {
281
+ fn is_idle ( & self ) -> bool {
268
282
unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . idle ( ) . bit_is_set ( ) }
269
283
}
270
284
271
285
/// Return true if the rx register is not empty (and can be read)
272
- pub fn is_rx_not_empty ( & self ) -> bool {
286
+ fn is_rx_not_empty ( & self ) -> bool {
273
287
unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . rxne ( ) . bit_is_set ( ) }
274
288
}
275
289
276
290
/// Clear idle line interrupt flag
277
- pub fn clear_idle_interrupt ( & self ) {
291
+ fn clear_idle_interrupt ( & self ) {
278
292
unsafe {
279
293
let _ = ( * USART :: ptr ( ) ) . sr . read ( ) ;
280
294
let _ = ( * USART :: ptr ( ) ) . dr . read ( ) ;
@@ -302,9 +316,17 @@ impl<USART: Instance, WORD> Tx<USART, WORD> {
302
316
pub fn unlisten ( & mut self ) {
303
317
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. txeie ( ) . clear_bit ( ) ) }
304
318
}
319
+ }
320
+
321
+ /// Trait for [`Tx`] interrupt handling.
322
+ pub trait TxISR {
323
+ /// Return true if the tx register is empty (and can accept data)
324
+ fn is_tx_empty ( & self ) -> bool ;
325
+ }
305
326
327
+ impl < USART : Instance , WORD > TxISR for Tx < USART , WORD > {
306
328
/// Return true if the tx register is empty (and can accept data)
307
- pub fn is_tx_empty ( & self ) -> bool {
329
+ fn is_tx_empty ( & self ) -> bool {
308
330
unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . txe ( ) . bit_is_set ( ) }
309
331
}
310
332
}
@@ -713,31 +735,32 @@ impl<USART: Instance, PINS, WORD> Serial<USART, PINS, WORD> {
713
735
}
714
736
}
715
737
716
- /// Return true if the line idle status is set
717
- pub fn is_idle ( & self ) -> bool {
718
- unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . idle ( ) . bit_is_set ( ) }
738
+ pub fn split ( self ) -> ( Tx < USART , WORD > , Rx < USART , WORD > ) {
739
+ ( self . tx , self . rx )
719
740
}
741
+ }
720
742
721
- /// Return true if the tx register is empty (and can accept data)
722
- pub fn is_tx_empty ( & self ) -> bool {
723
- unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . txe ( ) . bit_is_set ( ) }
743
+ impl < USART : Instance , PINS , WORD > RxISR for Serial < USART , PINS , WORD > {
744
+ /// Return true if the line idle status is set
745
+ fn is_idle ( & self ) -> bool {
746
+ self . rx . is_idle ( )
724
747
}
725
748
726
749
/// Return true if the rx register is not empty (and can be read)
727
- pub fn is_rx_not_empty ( & self ) -> bool {
728
- unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . rxne ( ) . bit_is_set ( ) }
750
+ fn is_rx_not_empty ( & self ) -> bool {
751
+ self . rx . is_rx_not_empty ( )
729
752
}
730
753
731
754
/// Clear idle line interrupt flag
732
- pub fn clear_idle_interrupt ( & self ) {
733
- unsafe {
734
- let _ = ( * USART :: ptr ( ) ) . sr . read ( ) ;
735
- let _ = ( * USART :: ptr ( ) ) . dr . read ( ) ;
736
- }
755
+ fn clear_idle_interrupt ( & self ) {
756
+ self . rx . clear_idle_interrupt ( ) ;
737
757
}
758
+ }
738
759
739
- pub fn split ( self ) -> ( Tx < USART , WORD > , Rx < USART , WORD > ) {
740
- ( self . tx , self . rx )
760
+ impl < USART : Instance , PINS , WORD > TxISR for Serial < USART , PINS , WORD > {
761
+ /// Return true if the tx register is empty (and can accept data)
762
+ fn is_tx_empty ( & self ) -> bool {
763
+ self . tx . is_tx_empty ( )
741
764
}
742
765
}
743
766
0 commit comments