From 4634316749c41dd5d8cc2f316033c9098369ed2f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 29 Nov 2023 16:37:07 +0100 Subject: Update embedded-(hal,io,nal). --- embassy-embedded-hal/Cargo.toml | 4 ++-- embassy-embedded-hal/src/shared_bus/asynch/spi.rs | 20 ++++++++++++++------ embassy-embedded-hal/src/shared_bus/blocking/spi.rs | 20 ++++++++++---------- embassy-embedded-hal/src/shared_bus/mod.rs | 6 +++--- 4 files changed, 29 insertions(+), 21 deletions(-) (limited to 'embassy-embedded-hal') diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 11e47acb8..52ecd5c71 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -25,8 +25,8 @@ embassy-time = { version = "0.1.5", path = "../embassy-time", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [ "unproven", ] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true } embedded-storage = "0.3.0" embedded-storage-async = { version = "0.4.0", optional = true } nb = "1.0.0" diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 17d5f3676..b4f53c623 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs @@ -63,6 +63,10 @@ where CS: OutputPin, { async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); + } + let mut bus = self.bus.lock().await; self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -74,12 +78,12 @@ where Operation::Transfer(read, write) => bus.transfer(read, write).await, Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, #[cfg(not(feature = "time"))] - Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => match bus.flush().await { + Operation::DelayNs(ns) => match bus.flush().await { Err(e) => Err(e), Ok(()) => { - embassy_time::Timer::after_micros(*us as _).await; + embassy_time::Timer::after_nanos(*ns as _).await; Ok(()) } }, @@ -137,6 +141,10 @@ where CS: OutputPin, { async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); + } + let mut bus = self.bus.lock().await; bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -149,12 +157,12 @@ where Operation::Transfer(read, write) => bus.transfer(read, write).await, Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, #[cfg(not(feature = "time"))] - Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => match bus.flush().await { + Operation::DelayNs(ns) => match bus.flush().await { Err(e) => Err(e), Ok(()) => { - embassy_time::Timer::after_micros(*us as _).await; + embassy_time::Timer::after_nanos(*ns as _).await; Ok(()) } }, diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 2b67862ea..59b65bfbd 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs @@ -55,8 +55,8 @@ where CS: OutputPin, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { - return Err(SpiDeviceError::DelayUsNotSupported); + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); } self.bus.lock(|bus| { @@ -69,10 +69,10 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => unreachable!(), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => { - embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); + Operation::DelayNs(ns) => { + embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); Ok(()) } }); @@ -165,8 +165,8 @@ where CS: OutputPin, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { - return Err(SpiDeviceError::DelayUsNotSupported); + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); } self.bus.lock(|bus| { @@ -180,10 +180,10 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => unreachable!(), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => { - embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); + Operation::DelayNs(ns) => { + embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); Ok(()) } }); diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs index b0159ac09..ab96df134 100644 --- a/embassy-embedded-hal/src/shared_bus/mod.rs +++ b/embassy-embedded-hal/src/shared_bus/mod.rs @@ -39,8 +39,8 @@ pub enum SpiDeviceError { Spi(BUS), /// Setting the value of the Chip Select (CS) pin failed. Cs(CS), - /// DelayUs operations are not supported when the `time` Cargo feature is not enabled. - DelayUsNotSupported, + /// Delay operations are not supported when the `time` Cargo feature is not enabled. + DelayNotSupported, /// The SPI bus could not be configured. Config, } @@ -54,7 +54,7 @@ where match self { Self::Spi(e) => e.kind(), Self::Cs(_) => spi::ErrorKind::Other, - Self::DelayUsNotSupported => spi::ErrorKind::Other, + Self::DelayNotSupported => spi::ErrorKind::Other, Self::Config => spi::ErrorKind::Other, } } -- cgit