diff --git a/va108xx-hal/CHANGELOG.md b/va108xx-hal/CHANGELOG.md index fd7e926..5085cd5 100644 --- a/va108xx-hal/CHANGELOG.md +++ b/va108xx-hal/CHANGELOG.md @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] +## [v0.11.1] 2025-03-10 + +## Fixed + +- Fix `embedded_io` UART implementation to implement the documented contract properly. + The implementation will now block until at least one byte is available or can be written, unless + the send or receive buffer is empty. + ## [v0.11.0] 2025-03-07 ## Changed @@ -253,6 +261,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - README with basic instructions how to set up own binary crate [unreleased]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.11.0...HEAD +[v0.11.1]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.11.0...va108xx-hal-v0.11.1 [v0.11.0]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.10.0...va108xx-hal-v0.11.0 [v0.10.0]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.9.0...va108xx-hal-v0.10.0 [v0.9.0]: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/compare/va108xx-hal-v0.8.0...va108xx-hal-v0.9.0 diff --git a/va108xx-hal/Cargo.toml b/va108xx-hal/Cargo.toml index e5b5adb..82449b9 100644 --- a/va108xx-hal/Cargo.toml +++ b/va108xx-hal/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "va108xx-hal" -version = "0.11.0" +version = "0.11.1" authors = ["Robin Mueller "] edition = "2021" description = "HAL for the Vorago VA108xx family of microcontrollers" diff --git a/va108xx-hal/src/uart/mod.rs b/va108xx-hal/src/uart/mod.rs index 24fe195..67f3fd8 100644 --- a/va108xx-hal/src/uart/mod.rs +++ b/va108xx-hal/src/uart/mod.rs @@ -892,7 +892,15 @@ impl embedded_hal_nb::serial::Read for Rx { impl embedded_io::Read for Rx { fn read(&mut self, buf: &mut [u8]) -> Result { + if buf.is_empty() { + return Ok(0); + } let mut read = 0; + loop { + if self.0.rxstatus().read().rdavl().bit_is_set() { + break; + } + } for byte in buf.iter_mut() { match >::read(self) { Ok(w) => { @@ -1058,6 +1066,14 @@ impl embedded_hal_nb::serial::Write for Tx { impl embedded_io::Write for Tx { fn write(&mut self, buf: &[u8]) -> Result { + if buf.is_empty() { + return Ok(0); + } + loop { + if self.0.txstatus().read().wrrdy().bit_is_set() { + break; + } + } let mut written = 0; for byte in buf.iter() { match >::write(self, *byte) { @@ -1066,7 +1082,7 @@ impl embedded_io::Write for Tx { } } - Ok(buf.len()) + Ok(written) } fn flush(&mut self) -> Result<(), Self::Error> {