Skip to content

Commit a191534

Browse files
authored
Merge pull request #60 from ijager/uart_int
USART: Add methods to check rxne and txe bits
2 parents a30cadc + 942bad6 commit a191534

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/serial/usart.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ macro_rules! uart_shared {
168168
let usart = unsafe { &(*$USARTX::ptr()) };
169169
usart.cr1.modify(|_, w| w.rxneie().clear_bit());
170170
}
171+
172+
/// Return true if the rx register is not empty (and can be read)
173+
pub fn is_rxne(&self) -> bool {
174+
let usart = unsafe { &(*$USARTX::ptr()) };
175+
usart.isr.read().rxne().bit_is_set()
176+
}
177+
171178
}
172179

173180
impl<Config> hal::serial::Read<u8> for Rx<$USARTX, Config> {
@@ -219,6 +226,13 @@ macro_rules! uart_shared {
219226
let usart = unsafe { &(*$USARTX::ptr()) };
220227
usart.cr1.modify(|_, w| w.txeie().clear_bit());
221228
}
229+
230+
/// Return true if the tx register is empty (and can accept data)
231+
pub fn is_txe(&self) -> bool {
232+
let usart = unsafe { &(*$USARTX::ptr()) };
233+
usart.isr.read().txe().bit_is_set()
234+
}
235+
222236
}
223237

224238
impl<Config> hal::serial::Write<u8> for Tx<$USARTX, Config> {

0 commit comments

Comments
 (0)