diff options
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/blocking/spi.rs | 12 |
1 files changed, 10 insertions, 2 deletions
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 | |||
| 55 | CS: OutputPin, | 55 | CS: OutputPin, |
| 56 | { | 56 | { |
| 57 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { | 57 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 58 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { | ||
| 59 | return Err(SpiDeviceError::DelayUsNotSupported); | ||
| 60 | } | ||
| 61 | |||
| 58 | self.bus.lock(|bus| { | 62 | self.bus.lock(|bus| { |
| 59 | let mut bus = bus.borrow_mut(); | 63 | let mut bus = bus.borrow_mut(); |
| 60 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 64 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| @@ -65,7 +69,7 @@ where | |||
| 65 | Operation::Transfer(read, write) => bus.transfer(read, write), | 69 | Operation::Transfer(read, write) => bus.transfer(read, write), |
| 66 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), | 70 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), |
| 67 | #[cfg(not(feature = "time"))] | 71 | #[cfg(not(feature = "time"))] |
| 68 | Operation::DelayUs(_) => Err(SpiDeviceError::DelayUsNotSupported), | 72 | Operation::DelayUs(_) => unreachable!(), |
| 69 | #[cfg(feature = "time")] | 73 | #[cfg(feature = "time")] |
| 70 | Operation::DelayUs(us) => { | 74 | Operation::DelayUs(us) => { |
| 71 | embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); | 75 | embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); |
| @@ -161,6 +165,10 @@ where | |||
| 161 | CS: OutputPin, | 165 | CS: OutputPin, |
| 162 | { | 166 | { |
| 163 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { | 167 | fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 168 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { | ||
| 169 | return Err(SpiDeviceError::DelayUsNotSupported); | ||
| 170 | } | ||
| 171 | |||
| 164 | self.bus.lock(|bus| { | 172 | self.bus.lock(|bus| { |
| 165 | let mut bus = bus.borrow_mut(); | 173 | let mut bus = bus.borrow_mut(); |
| 166 | bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; | 174 | bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; |
| @@ -172,7 +180,7 @@ where | |||
| 172 | Operation::Transfer(read, write) => bus.transfer(read, write), | 180 | Operation::Transfer(read, write) => bus.transfer(read, write), |
| 173 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), | 181 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), |
| 174 | #[cfg(not(feature = "time"))] | 182 | #[cfg(not(feature = "time"))] |
| 175 | Operation::DelayUs(_) => Err(SpiDeviceError::DelayUsNotSupported), | 183 | Operation::DelayUs(_) => unreachable!(), |
| 176 | #[cfg(feature = "time")] | 184 | #[cfg(feature = "time")] |
| 177 | Operation::DelayUs(us) => { | 185 | Operation::DelayUs(us) => { |
| 178 | embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); | 186 | embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); |
