mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 21:11:31 +11:00
Propagate read errors.
This commit is contained in:
parent
992bcdf47b
commit
8d29464ee3
|
@ -337,16 +337,20 @@ impl<D: UARTDevice> UARTPeripheral<Enabled, D> {
|
||||||
|
|
||||||
/// Reads bytes from the UART.
|
/// Reads bytes from the UART.
|
||||||
/// This function blocks until the full buffer has been received.
|
/// This function blocks until the full buffer has been received.
|
||||||
pub fn read_full_blocking(&self, buffer: &mut [u8]) {
|
pub fn read_full_blocking(&self, buffer: &mut [u8]) -> Result<(), ReadErrorType> {
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
|
|
||||||
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(remaining) => remaining.len(),
|
||||||
Err(WouldBlock) => continue,
|
Err(e) => match e {
|
||||||
Err(_) => unreachable!(),
|
Other(inner) => return Err(inner.err_type),
|
||||||
|
WouldBlock => continue,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,15 +441,17 @@ fn set_format<'w>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: UARTDevice> Read<u8> for UARTPeripheral<Enabled, D> {
|
impl<D: UARTDevice> Read<u8> for UARTPeripheral<Enabled, D> {
|
||||||
type Error = Infallible;
|
type Error = ReadErrorType;
|
||||||
|
|
||||||
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
fn read(&mut self) -> nb::Result<u8, Self::Error> {
|
||||||
let byte: &mut [u8] = &mut [0; 1];
|
let byte: &mut [u8] = &mut [0; 1];
|
||||||
|
|
||||||
if let Err(_) = self.read_raw(byte) {
|
match self.read_raw(byte) {
|
||||||
Err(WouldBlock)
|
Ok(_) => Ok(byte[0]),
|
||||||
} else {
|
Err(e) => match e {
|
||||||
Ok(byte[0])
|
Other(inner) => return Err(Other(inner.err_type)),
|
||||||
|
WouldBlock => return Err(WouldBlock),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue