rp: Allow zero len reads for buffered uart
Prevents the read methods from getting stuck forever.
This commit is contained in:
parent
e3efda2249
commit
f78aa4f936
@ -175,6 +175,10 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> {
|
||||
|
||||
fn read<'a>(buf: &'a mut [u8]) -> impl Future<Output = Result<usize, Error>> + 'a {
|
||||
poll_fn(move |cx| {
|
||||
if buf.is_empty() {
|
||||
return Poll::Ready(Ok(0));
|
||||
}
|
||||
|
||||
let state = T::state();
|
||||
let mut rx_reader = unsafe { state.rx_buf.reader() };
|
||||
let n = rx_reader.pop(|data| {
|
||||
@ -202,6 +206,10 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> {
|
||||
}
|
||||
|
||||
pub fn blocking_read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
|
||||
if buf.is_empty() {
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
loop {
|
||||
let state = T::state();
|
||||
let mut rx_reader = unsafe { state.rx_buf.reader() };
|
||||
|
Loading…
Reference in New Issue
Block a user