aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/asynch/spi.rs')
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/spi.rs52
1 files changed, 36 insertions, 16 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
index 5d3cf658a..17d5f3676 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
@@ -66,19 +66,29 @@ where
66 let mut bus = self.bus.lock().await; 66 let mut bus = self.bus.lock().await;
67 self.cs.set_low().map_err(SpiDeviceError::Cs)?; 67 self.cs.set_low().map_err(SpiDeviceError::Cs)?;
68 68
69 let op_res: Result<(), BUS::Error> = try { 69 let op_res = 'ops: {
70 for op in operations { 70 for op in operations {
71 match op { 71 let res = match op {
72 Operation::Read(buf) => bus.read(buf).await?, 72 Operation::Read(buf) => bus.read(buf).await,
73 Operation::Write(buf) => bus.write(buf).await?, 73 Operation::Write(buf) => bus.write(buf).await,
74 Operation::Transfer(read, write) => bus.transfer(read, write).await?, 74 Operation::Transfer(read, write) => bus.transfer(read, write).await,
75 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await?, 75 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await,
76 #[cfg(not(feature = "time"))] 76 #[cfg(not(feature = "time"))]
77 Operation::DelayUs(_) => return Err(SpiDeviceError::DelayUsNotSupported), 77 Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported),
78 #[cfg(feature = "time")] 78 #[cfg(feature = "time")]
79 Operation::DelayUs(us) => embassy_time::Timer::after_micros(*us as _).await, 79 Operation::DelayUs(us) => match bus.flush().await {
80 Err(e) => Err(e),
81 Ok(()) => {
82 embassy_time::Timer::after_micros(*us as _).await;
83 Ok(())
84 }
85 },
86 };
87 if let Err(e) = res {
88 break 'ops Err(e);
80 } 89 }
81 } 90 }
91 Ok(())
82 }; 92 };
83 93
84 // On failure, it's important to still flush and deassert CS. 94 // On failure, it's important to still flush and deassert CS.
@@ -131,19 +141,29 @@ where
131 bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; 141 bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?;
132 self.cs.set_low().map_err(SpiDeviceError::Cs)?; 142 self.cs.set_low().map_err(SpiDeviceError::Cs)?;
133 143
134 let op_res: Result<(), BUS::Error> = try { 144 let op_res = 'ops: {
135 for op in operations { 145 for op in operations {
136 match op { 146 let res = match op {
137 Operation::Read(buf) => bus.read(buf).await?, 147 Operation::Read(buf) => bus.read(buf).await,
138 Operation::Write(buf) => bus.write(buf).await?, 148 Operation::Write(buf) => bus.write(buf).await,
139 Operation::Transfer(read, write) => bus.transfer(read, write).await?, 149 Operation::Transfer(read, write) => bus.transfer(read, write).await,
140 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await?, 150 Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await,
141 #[cfg(not(feature = "time"))] 151 #[cfg(not(feature = "time"))]
142 Operation::DelayUs(_) => return Err(SpiDeviceError::DelayUsNotSupported), 152 Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported),
143 #[cfg(feature = "time")] 153 #[cfg(feature = "time")]
144 Operation::DelayUs(us) => embassy_time::Timer::after_micros(*us as _).await, 154 Operation::DelayUs(us) => match bus.flush().await {
155 Err(e) => Err(e),
156 Ok(()) => {
157 embassy_time::Timer::after_micros(*us as _).await;
158 Ok(())
159 }
160 },
161 };
162 if let Err(e) = res {
163 break 'ops Err(e);
145 } 164 }
146 } 165 }
166 Ok(())
147 }; 167 };
148 168
149 // On failure, it's important to still flush and deassert CS. 169 // On failure, it's important to still flush and deassert CS.