@@ -294,21 +294,29 @@ where
294
294
}
295
295
}
296
296
297
- /// Return true if the line idle status is set
297
+ /// Returns true if the line idle status is set
298
298
pub fn is_idle ( & self ) -> bool {
299
299
self . usart . sr . read ( ) . idle ( ) . bit_is_set ( )
300
300
}
301
301
302
- /// Return true if the tx register is empty (and can accept data)
302
+ /// Returns true if the tx register is empty (and can accept data)
303
303
pub fn is_tx_empty ( & self ) -> bool {
304
304
self . usart . sr . read ( ) . txe ( ) . bit_is_set ( )
305
305
}
306
306
307
- /// Return true if the rx register is not empty (and can be read)
307
+ /// Returns true if the rx register is not empty (and can be read)
308
308
pub fn is_rx_not_empty ( & self ) -> bool {
309
309
self . usart . sr . read ( ) . rxne ( ) . bit_is_set ( )
310
310
}
311
311
312
+ /// Clear idle line interrupt flag
313
+ pub fn clear_idle_interrupt ( & self ) {
314
+ unsafe {
315
+ let _ = ( * USART :: ptr ( ) ) . sr . read ( ) ;
316
+ let _ = ( * USART :: ptr ( ) ) . dr . read ( ) ;
317
+ }
318
+ }
319
+
312
320
/// Returns ownership of the borrowed register handles
313
321
pub fn release ( self ) -> ( USART , PINS ) {
314
322
( self . usart , self . pins )
@@ -383,14 +391,17 @@ impl<USART> Tx<USART>
383
391
where
384
392
USART : Instance ,
385
393
{
394
+ /// Start listening for transmit interrupt event
386
395
pub fn listen ( & mut self ) {
387
396
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. txeie ( ) . set_bit ( ) ) } ;
388
397
}
389
398
399
+ /// Stop listening for transmit interrupt event
390
400
pub fn unlisten ( & mut self ) {
391
401
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. txeie ( ) . clear_bit ( ) ) } ;
392
402
}
393
403
404
+ /// Returns true if the tx register is empty (and can accept data)
394
405
pub fn is_tx_empty ( & self ) -> bool {
395
406
unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . txe ( ) . bit_is_set ( ) }
396
407
}
@@ -400,29 +411,43 @@ impl<USART> Rx<USART>
400
411
where
401
412
USART : Instance ,
402
413
{
414
+ /// Start listening for receive interrupt event
403
415
pub fn listen ( & mut self ) {
404
416
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. rxneie ( ) . set_bit ( ) ) } ;
405
417
}
406
418
419
+ /// Stop listening for receive interrupt event
407
420
pub fn unlisten ( & mut self ) {
408
421
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. rxneie ( ) . clear_bit ( ) ) } ;
409
422
}
410
423
424
+ /// Start listening for idle interrupt event
411
425
pub fn listen_idle ( & mut self ) {
412
426
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. idleie ( ) . set_bit ( ) ) } ;
413
427
}
414
428
429
+ /// Stop listening for idle interrupt event
415
430
pub fn unlisten_idle ( & mut self ) {
416
431
unsafe { ( * USART :: ptr ( ) ) . cr1 . modify ( |_, w| w. idleie ( ) . clear_bit ( ) ) } ;
417
432
}
418
433
434
+ /// Returns true if the line idle status is set
419
435
pub fn is_idle ( & self ) -> bool {
420
436
unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . idle ( ) . bit_is_set ( ) }
421
437
}
422
438
439
+ /// Returns true if the rx register is not empty (and can be read)
423
440
pub fn is_rx_not_empty ( & self ) -> bool {
424
441
unsafe { ( * USART :: ptr ( ) ) . sr . read ( ) . rxne ( ) . bit_is_set ( ) }
425
442
}
443
+
444
+ /// Clear idle line interrupt flag
445
+ pub fn clear_idle_interrupt ( & self ) {
446
+ unsafe {
447
+ let _ = ( * USART :: ptr ( ) ) . sr . read ( ) ;
448
+ let _ = ( * USART :: ptr ( ) ) . dr . read ( ) ;
449
+ }
450
+ }
426
451
}
427
452
428
453
impl < USART > crate :: hal:: serial:: Read < u8 > for Rx < USART >
0 commit comments