mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 21:11:31 +11:00
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:
parent
fb69308058
commit
6d917f498e
|
@ -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 :
|
/// 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
|
/// - 0 bytes were read, a WouldBlock Error is returned
|
||||||
/// - some bytes were read, it is deemed to be a success
|
/// - some bytes were read, it is deemed to be a success
|
||||||
/// Upon success, the remaining slice is returned.
|
/// Upon success, it will return how many bytes were read.
|
||||||
pub fn read_raw<'b>(&self, buffer: &'b mut [u8]) -> nb::Result<&'b mut [u8], ReadError<'b>> {
|
pub fn read_raw<'b>(&self, buffer: &'b mut [u8]) -> nb::Result<usize, ReadError<'b>> {
|
||||||
let mut bytes_read = 0;
|
let mut bytes_read = 0;
|
||||||
|
|
||||||
Ok(loop {
|
Ok(loop {
|
||||||
|
@ -320,7 +320,7 @@ impl<D: UartDevice> UartPeripheral<Enabled, D> {
|
||||||
if bytes_read == 0 {
|
if bytes_read == 0 {
|
||||||
return Err(WouldBlock);
|
return Err(WouldBlock);
|
||||||
} else {
|
} 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();
|
buffer[bytes_read] = read.data().bits();
|
||||||
bytes_read += 1;
|
bytes_read += 1;
|
||||||
} else {
|
} else {
|
||||||
break &mut buffer[bytes_read..];
|
break bytes_read;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ impl<D: UartDevice> UartPeripheral<Enabled, D> {
|
||||||
|
|
||||||
while offset != buffer.len() {
|
while offset != buffer.len() {
|
||||||
offset += match self.read_raw(&mut buffer[offset..]) {
|
offset += match self.read_raw(&mut buffer[offset..]) {
|
||||||
Ok(remaining) => remaining.len(),
|
Ok(bytes_read) => bytes_read,
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
Other(inner) => return Err(inner.err_type),
|
Other(inner) => return Err(inner.err_type),
|
||||||
WouldBlock => continue,
|
WouldBlock => continue,
|
||||||
|
|
Loading…
Reference in a new issue