diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index feb0f5b7d..2b67862ea 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs @@ -55,6 +55,10 @@ 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); + } + self.bus.lock(|bus| { let mut bus = bus.borrow_mut(); self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -65,7 +69,7 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayUs(_) => unreachable!(), #[cfg(feature = "time")] Operation::DelayUs(us) => { embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); @@ -161,6 +165,10 @@ 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); + } + self.bus.lock(|bus| { let mut bus = bus.borrow_mut(); bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; @@ -172,7 +180,7 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayUs(_) => unreachable!(), #[cfg(feature = "time")] Operation::DelayUs(us) => { embassy_time::block_for(embassy_time::Duration::from_micros(*us as _));