File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,34 @@ macro_rules! usart {
338
338
}
339
339
}
340
340
341
+ /// Returns a pending and enabled `Event`.
342
+ ///
343
+ /// Multiple `Event`s can be signaled at the same time. In that case, an arbitrary
344
+ /// pending event will be returned. Clearing the event condition will cause this
345
+ /// method to return the other pending event(s).
346
+ ///
347
+ /// For an event to be returned by this method, it must first be enabled by calling
348
+ /// `listen`.
349
+ ///
350
+ /// This method will never clear a pending event. If the event condition is not
351
+ /// resolved by the user, it will be returned again by the next call to
352
+ /// `pending_event`.
353
+ pub fn pending_event( & self ) -> Option <Event > {
354
+ let cr1 = self . usart. cr1. read( ) ;
355
+ let isr = self . usart. isr. read( ) ;
356
+
357
+ if cr1. rxneie( ) . bit_is_set( ) && isr. rxne( ) . bit_is_set( ) {
358
+ // Give highest priority to RXNE to help with avoiding overrun
359
+ Some ( Event :: Rxne )
360
+ } else if cr1. txeie( ) . bit_is_set( ) && isr. txe( ) . bit_is_set( ) {
361
+ Some ( Event :: Txe )
362
+ } else if cr1. idleie( ) . bit_is_set( ) && isr. idle( ) . bit_is_set( ) {
363
+ Some ( Event :: Idle )
364
+ } else {
365
+ None
366
+ }
367
+ }
368
+
341
369
/// Checks for reception errors that may have occurred.
342
370
///
343
371
/// Note that multiple errors can be signaled at the same time. In that case,
You can’t perform that action at this time.
0 commit comments