Skip to content

Commit 588adde

Browse files
committed
Provide getters for serial status flags: idle/txe/rxne/tc
So that an ISR can differ between these events.
1 parent cb5a439 commit 588adde

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Updated the `cast` dependency from 0.2 to 0.3
1313

14+
### Added
15+
16+
- Provide getters to serial status flags idle/txe/rxne/tc.
17+
1418
### Fixed
1519

1620
- Wrong mode when using PWM channel 2 of a two-channel timer

src/serial.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,26 @@ macro_rules! usart {
378378
},
379379
}
380380
}
381+
382+
/// Returns true if the line idle status is set
383+
pub fn is_idle(&self) -> bool {
384+
self.usart.isr.read().idle().bit_is_set()
385+
}
386+
387+
/// Returns true if the tx register is empty
388+
pub fn is_txe(&self) -> bool {
389+
self.usart.isr.read().txe().bit_is_set()
390+
}
391+
392+
/// Returns true if the rx register is not empty (and can be read)
393+
pub fn is_rx_not_empty(&self) -> bool {
394+
self.usart.isr.read().rxne().bit_is_set()
395+
}
396+
397+
/// Returns true if transmission is complete
398+
pub fn is_tx_complete(&self) -> bool {
399+
self.usart.isr.read().tc().bit_is_set()
400+
}
381401
}
382402
)+
383403
}

0 commit comments

Comments
 (0)