@@ -342,6 +342,21 @@ where
342
342
}
343
343
}
344
344
345
+ /// Return true if the line idle status is set
346
+ pub fn is_idle ( & self ) -> bool {
347
+ self . usart . sr . read ( ) . idle ( ) . bit_is_set ( ) ;
348
+ }
349
+
350
+ /// Return true if the tx register is empty (and can accept data)
351
+ pub fn is_txe ( & self ) -> bool {
352
+ self . usart . sr . read ( ) . txe ( ) . bit_is_set ( ) ;
353
+ }
354
+
355
+ /// Return true if the rx register is not empty (and can be read)
356
+ pub fn is_rxne ( & self ) -> bool {
357
+ self . usart . sr . read ( ) . rxne ( ) . bit_is_set ( ) ;
358
+ }
359
+
345
360
/// Returns ownership of the borrowed register handles
346
361
pub fn release ( self ) -> ( USART , PINS ) {
347
362
( self . usart , self . pins )
@@ -418,6 +433,10 @@ macro_rules! hal {
418
433
pub fn unlisten( & mut self ) {
419
434
unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. txeie( ) . clear_bit( ) ) } ;
420
435
}
436
+
437
+ pub fn is_txe( & self ) -> bool {
438
+ unsafe { ( * $USARTX:: ptr( ) ) . sr. read( ) . txe( ) . bit_is_set( ) }
439
+ }
421
440
}
422
441
423
442
impl Rx <$USARTX> {
@@ -428,6 +447,22 @@ macro_rules! hal {
428
447
pub fn unlisten( & mut self ) {
429
448
unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. rxneie( ) . clear_bit( ) ) } ;
430
449
}
450
+
451
+ pub fn listen_idle( & mut self ) {
452
+ unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. idleie( ) . set_bit( ) ) } ;
453
+ }
454
+
455
+ pub fn unlisten_idle( & mut self ) {
456
+ unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. idleie( ) . clear_bit( ) ) } ;
457
+ }
458
+
459
+ pub fn is_idle( & self ) -> bool {
460
+ unsafe { ( * $USARTX:: ptr( ) ) . sr. read( ) . idle( ) . bit_is_set( ) }
461
+ }
462
+
463
+ pub fn is_rxne( & self ) -> bool {
464
+ unsafe { ( * $USARTX:: ptr( ) ) . sr. read( ) . rxne( ) . bit_is_set( ) }
465
+ }
431
466
}
432
467
433
468
impl crate :: hal:: serial:: Read <u8 > for Rx <$USARTX> {
0 commit comments