1318: rp: Allow zero len reads for buffered uart r=Dirbaio a=timokroeger

Prevents the read methods from getting stuck forever.

cc `@MathiasKoch` can you test if this fixes the problem you described in the chat?

Co-authored-by: Timo Kröger <timokroeger93@gmail.com>
This commit is contained in:
bors[bot] 2023-04-02 18:33:36 +00:00 committed by GitHub
commit 08f911d25e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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() };
@ -293,6 +301,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
fn write<'a>(buf: &'a [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 tx_writer = unsafe { state.tx_buf.writer() };
let n = tx_writer.push(|data| {
@ -327,6 +339,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
}
pub fn blocking_write(&mut self, buf: &[u8]) -> Result<usize, Error> {
if buf.is_empty() {
return Ok(0);
}
loop {
let state = T::state();
let mut tx_writer = unsafe { state.tx_buf.writer() };