diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-29 17:12:30 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-29 17:12:30 +0100 |
| commit | 384bad7bfaa1f2415baf2cd3b69ebf36dc0a02d7 (patch) | |
| tree | 1992bf003d6afcdeae926db2308f369bccfc42ea /embassy-embedded-hal/src/shared_bus/asynch | |
| parent | b4bc9ac028568dfb3896dfb00cbd1e181863fd64 (diff) | |
| parent | 4634316749c41dd5d8cc2f316033c9098369ed2f (diff) | |
Merge pull request #2231 from embassy-rs/stable3
Update embedded-(hal,io,nal).
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/asynch')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/spi.rs | 20 |
1 files changed, 14 insertions, 6 deletions
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 | |||
| 63 | CS: OutputPin, | 63 | CS: OutputPin, |
| 64 | { | 64 | { |
| 65 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { | 65 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 66 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { | ||
| 67 | return Err(SpiDeviceError::DelayNotSupported); | ||
| 68 | } | ||
| 69 | |||
| 66 | let mut bus = self.bus.lock().await; | 70 | let mut bus = self.bus.lock().await; |
| 67 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 71 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 68 | 72 | ||
| @@ -74,12 +78,12 @@ where | |||
| 74 | Operation::Transfer(read, write) => bus.transfer(read, write).await, | 78 | Operation::Transfer(read, write) => bus.transfer(read, write).await, |
| 75 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, | 79 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, |
| 76 | #[cfg(not(feature = "time"))] | 80 | #[cfg(not(feature = "time"))] |
| 77 | Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), | 81 | Operation::DelayNs(_) => unreachable!(), |
| 78 | #[cfg(feature = "time")] | 82 | #[cfg(feature = "time")] |
| 79 | Operation::DelayUs(us) => match bus.flush().await { | 83 | Operation::DelayNs(ns) => match bus.flush().await { |
| 80 | Err(e) => Err(e), | 84 | Err(e) => Err(e), |
| 81 | Ok(()) => { | 85 | Ok(()) => { |
| 82 | embassy_time::Timer::after_micros(*us as _).await; | 86 | embassy_time::Timer::after_nanos(*ns as _).await; |
| 83 | Ok(()) | 87 | Ok(()) |
| 84 | } | 88 | } |
| 85 | }, | 89 | }, |
| @@ -137,6 +141,10 @@ where | |||
| 137 | CS: OutputPin, | 141 | CS: OutputPin, |
| 138 | { | 142 | { |
| 139 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { | 143 | async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { |
| 144 | if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { | ||
| 145 | return Err(SpiDeviceError::DelayNotSupported); | ||
| 146 | } | ||
| 147 | |||
| 140 | let mut bus = self.bus.lock().await; | 148 | let mut bus = self.bus.lock().await; |
| 141 | bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; | 149 | bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; |
| 142 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; | 150 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| @@ -149,12 +157,12 @@ where | |||
| 149 | Operation::Transfer(read, write) => bus.transfer(read, write).await, | 157 | Operation::Transfer(read, write) => bus.transfer(read, write).await, |
| 150 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, | 158 | Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, |
| 151 | #[cfg(not(feature = "time"))] | 159 | #[cfg(not(feature = "time"))] |
| 152 | Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), | 160 | Operation::DelayNs(_) => unreachable!(), |
| 153 | #[cfg(feature = "time")] | 161 | #[cfg(feature = "time")] |
| 154 | Operation::DelayUs(us) => match bus.flush().await { | 162 | Operation::DelayNs(ns) => match bus.flush().await { |
| 155 | Err(e) => Err(e), | 163 | Err(e) => Err(e), |
| 156 | Ok(()) => { | 164 | Ok(()) => { |
| 157 | embassy_time::Timer::after_micros(*us as _).await; | 165 | embassy_time::Timer::after_nanos(*ns as _).await; |
| 158 | Ok(()) | 166 | Ok(()) |
| 159 | } | 167 | } |
| 160 | }, | 168 | }, |
