rp: Allow zero len reads for buffered uart

Prevents the read methods from getting stuck forever.
This commit is contained in:
Timo Kröger 2023-04-01 14:31:24 +02:00
parent e3efda2249
commit f78aa4f936

View file

@ -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() };