Change UART raw read return type and fix full read (#189)

* UART read_raw returns bytes read

This also fixed broken read_full_blocking code.

* chang documentation to reflect return value change
This commit is contained in:
Benno 2021-11-01 00:24:24 +01:00 committed by GitHub
parent fb69308058
commit 6d917f498e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -311,8 +311,8 @@ impl<D: UartDevice> UartPeripheral<Enabled, D> {
/// This function reads as long as it can. As soon that the FIFO is empty, if :
/// - 0 bytes were read, a WouldBlock Error is returned
/// - some bytes were read, it is deemed to be a success
/// Upon success, the remaining slice is returned.
pub fn read_raw<'b>(&self, buffer: &'b mut [u8]) -> nb::Result<&'b mut [u8], ReadError<'b>> {
/// Upon success, it will return how many bytes were read.
pub fn read_raw<'b>(&self, buffer: &'b mut [u8]) -> nb::Result<usize, ReadError<'b>> {
let mut bytes_read = 0;
Ok(loop {
@ -320,7 +320,7 @@ impl<D: UartDevice> UartPeripheral<Enabled, D> {
if bytes_read == 0 {
return Err(WouldBlock);
} else {
break &mut buffer[bytes_read..];
break bytes_read;
}
}
@ -355,7 +355,7 @@ impl<D: UartDevice> UartPeripheral<Enabled, D> {
buffer[bytes_read] = read.data().bits();
bytes_read += 1;
} else {
break &mut buffer[bytes_read..];
break bytes_read;
}
})
}
@ -381,7 +381,7 @@ impl<D: UartDevice> UartPeripheral<Enabled, D> {
while offset != buffer.len() {
offset += match self.read_raw(&mut buffer[offset..]) {
Ok(remaining) => remaining.len(),
Ok(bytes_read) => bytes_read,
Err(e) => match e {
Other(inner) => return Err(inner.err_type),
WouldBlock => continue,