Skip to content

Commit ca09776

Browse files
committed
Changed CircBuffer new signiture to not consume UsartRx, added idle line detection to Rx
1 parent 21b6ad3 commit ca09776

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/serial.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ macro_rules! hal {
232232

233233
impl Rx<$USARTX> {
234234
pub fn circ_read<B>(
235-
self,
235+
&self,
236236
mut chan: $rx_chan,
237237
buffer: &'static mut [B; 2],
238238
) -> CircBuffer<B, $rx_chan>
@@ -289,6 +289,24 @@ macro_rules! hal {
289289

290290
CircBuffer::new(buffer, chan)
291291
}
292+
293+
/// Checks to see if the usart peripheral has detected an idle line and clears the flag
294+
pub fn is_idle(&mut self, clear: bool) -> bool {
295+
let isr = unsafe { &(*$USARTX::ptr()).isr.read() };
296+
let icr = unsafe { &(*$USARTX::ptr()).icr };
297+
298+
if isr.idle().bit_is_set() {
299+
if clear {
300+
icr.write(|w| {
301+
w.idlecf()
302+
.set_bit()
303+
});
304+
}
305+
true
306+
} else {
307+
false
308+
}
309+
}
292310
}
293311
)+
294312
}

0 commit comments

Comments
 (0)