From 46849dad3dcb36330a34bf510004399f9e41dfd4 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Dec 2023 13:09:11 +0100 Subject: [PATCH 1/3] Fixing an issue when writing empty buffers --- Cargo.toml | 1 + src/io.rs | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 91e0b30..45fa162 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ embedded-hal = "0.2.4" nb = "1" usb-device = "0.3" embedded-io = "0.6" +log = "0.4" diff --git a/src/io.rs b/src/io.rs index a5c2765..a23bcb0 100644 --- a/src/io.rs +++ b/src/io.rs @@ -49,13 +49,28 @@ impl embedded_io::ReadReady for SerialPort<'_, Bus> { impl embedded_io::Write for SerialPort<'_, Bus> { fn write(&mut self, buf: &[u8]) -> Result { + if buf.is_empty() { + return Ok(0); + } + loop { match self.write(buf) { // We are required by `embedded-io` to continue writing until at least one byte is // written. - Ok(0) => {} - Err(usb_device::UsbError::WouldBlock) => {} - other => return Ok(other?), + Ok(0) => { + log::info!("write::0"); + } + Err(usb_device::UsbError::WouldBlock) => { + log::info!("write::WouldBlock"); + } + Ok(n) => { + log::info!("write::{n}"); + return Ok(n) + } + other => { + log::info!("write::other"); + return Ok(other?) + } } } } @@ -67,6 +82,7 @@ impl embedded_io::Write for SerialPort<'_, Bus> { impl embedded_io::WriteReady for SerialPort<'_, Bus> { fn write_ready(&mut self) -> Result { + log::info!("WriteAVail: {}", self.write_buf.available_write()); Ok(self.write_buf.available_write() != 0) } } From 091ca5038eb62cea80837c830a5b24d374a26a9c Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Dec 2023 13:12:08 +0100 Subject: [PATCH 2/3] Reverting unintentional changes --- Cargo.toml | 1 - src/io.rs | 17 +++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 45fa162..91e0b30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,3 @@ embedded-hal = "0.2.4" nb = "1" usb-device = "0.3" embedded-io = "0.6" -log = "0.4" diff --git a/src/io.rs b/src/io.rs index a23bcb0..9111d5f 100644 --- a/src/io.rs +++ b/src/io.rs @@ -57,20 +57,9 @@ impl embedded_io::Write for SerialPort<'_, Bus> { match self.write(buf) { // We are required by `embedded-io` to continue writing until at least one byte is // written. - Ok(0) => { - log::info!("write::0"); - } - Err(usb_device::UsbError::WouldBlock) => { - log::info!("write::WouldBlock"); - } - Ok(n) => { - log::info!("write::{n}"); - return Ok(n) - } - other => { - log::info!("write::other"); - return Ok(other?) - } + Ok(0) => {} + Err(usb_device::UsbError::WouldBlock) => {} + other => return Ok(other?), } } } From 096742c1c480f6f63c1a936a3c23ede7993c624d Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 4 Dec 2023 13:12:30 +0100 Subject: [PATCH 3/3] Removing log message --- src/io.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/io.rs b/src/io.rs index 9111d5f..b485b25 100644 --- a/src/io.rs +++ b/src/io.rs @@ -71,7 +71,6 @@ impl embedded_io::Write for SerialPort<'_, Bus> { impl embedded_io::WriteReady for SerialPort<'_, Bus> { fn write_ready(&mut self) -> Result { - log::info!("WriteAVail: {}", self.write_buf.available_write()); Ok(self.write_buf.available_write() != 0) } }