aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-11-24 22:55:02 +0000
committerGitHub <[email protected]>2023-11-24 22:55:02 +0000
commit78f8e6112a506633a0b2dcaba9434f376256b77c (patch)
tree8dbcb224a564fcad3646b73fb5ba5c93d6b7e9ce
parente8ff5a2baf217ac7e52f119c0d17a9826ad60067 (diff)
parent5528c336495ffc5868d91af2867f6f8e22be8283 (diff)
Merge pull request #2217 from embassy-rs/no-try
embassy-embedded-hal: don't use feature(try_blocks).
-rw-r--r--embassy-embedded-hal/src/lib.rs2
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/spi.rs52
2 files changed, 37 insertions, 17 deletions
diff --git a/embassy-embedded-hal/src/lib.rs b/embassy-embedded-hal/src/lib.rs
index f836d9f76..ce5fac3f0 100644
--- a/embassy-embedded-hal/src/lib.rs
+++ b/embassy-embedded-hal/src/lib.rs
@@ -1,5 +1,5 @@
1#![cfg_attr(not(feature = "std"), no_std)] 1#![cfg_attr(not(feature = "std"), no_std)]
2#![cfg_attr(feature = "nightly", feature(async_fn_in_trait, impl_trait_projections, try_blocks))] 2#![cfg_attr(feature = "nightly", feature(async_fn_in_trait, impl_trait_projections))]
3#![cfg_attr(feature = "nightly", allow(stable_features, unknown_lints, async_fn_in_trait))] 3#![cfg_attr(feature = "nightly", allow(stable_features, unknown_lints, async_fn_in_trait))]
4#![warn(missing_docs)] 4#![warn(missing_docs)]
5 5
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.