From fff4f6ca3ba5ab29def96c005d8bd174e48c512e Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 4 Feb 2025 17:09:38 +0000 Subject: [PATCH] Fix implementations of embedded_io::Write for UartPeripheral Fixes #840 --- rp2040-hal/src/uart/peripheral.rs | 4 ++-- rp235x-hal/src/uart/peripheral.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 6435229db..f4d3a7252 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -504,8 +504,8 @@ impl> embedded_io::ReadReady impl> embedded_io::Write for UartPeripheral { fn write(&mut self, buf: &[u8]) -> Result { - self.write_full_blocking(buf); - Ok(buf.len()) + 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 diff --git a/rp235x-hal/src/uart/peripheral.rs b/rp235x-hal/src/uart/peripheral.rs index 95421d3b8..9a15e0950 100644 --- a/rp235x-hal/src/uart/peripheral.rs +++ b/rp235x-hal/src/uart/peripheral.rs @@ -504,8 +504,8 @@ impl> embedded_io::ReadReady impl> embedded_io::Write for UartPeripheral { fn write(&mut self, buf: &[u8]) -> Result { - self.write_full_blocking(buf); - Ok(buf.len()) + 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