Skip to content

Commit

Permalink
Fix implementations of embedded_io::Write for UartPeripheral (#895)
Browse files Browse the repository at this point in the history
Fixes #840
  • Loading branch information
jannic authored Feb 4, 2025
1 parent d927dce commit eea9ecf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions rp2040-hal/src/uart/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ReadReady

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for UartPeripheral<Enabled, D, P> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.write_full_blocking(buf);
Ok(buf.len())
// Blocks if and only if no bytes can be written.
let remaining = nb::block!(super::writer::write_raw(&self.device, buf)).unwrap(); // Infallible
Ok(buf.len() - remaining.len())
}
fn flush(&mut self) -> Result<(), Self::Error> {
nb::block!(super::writer::transmit_flushed(&self.device)).unwrap(); // Infallible
Expand Down
1 change: 1 addition & 0 deletions rp2040-hal/src/uart/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ErrorType for Writer<D,

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for Writer<D, P> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
// Blocks if and only if no bytes can be written.
let remaining = nb::block!(write_raw(&self.device, buf)).unwrap(); // Infallible
Ok(buf.len() - remaining.len())
}
Expand Down
5 changes: 3 additions & 2 deletions rp235x-hal/src/uart/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ReadReady

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for UartPeripheral<Enabled, D, P> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.write_full_blocking(buf);
Ok(buf.len())
// Blocks if and only if no bytes can be written.
let remaining = nb::block!(super::writer::write_raw(&self.device, buf)).unwrap(); // Infallible
Ok(buf.len() - remaining.len())
}
fn flush(&mut self) -> Result<(), Self::Error> {
nb::block!(super::writer::transmit_flushed(&self.device)).unwrap(); // Infallible
Expand Down
1 change: 1 addition & 0 deletions rp235x-hal/src/uart/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ErrorType for Writer<D,

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for Writer<D, P> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
// Blocks if and only if no bytes can be written.
let remaining = nb::block!(write_raw(&self.device, buf)).unwrap(); // Infallible
Ok(buf.len() - remaining.len())
}
Expand Down

0 comments on commit eea9ecf

Please sign in to comment.