mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 08:12:30 +00:00
spi shared bus: assert/deassert CS inside the lock.
This commit is contained in:
parent
ba2412ff7e
commit
455374b7f9
@ -37,22 +37,21 @@ where
|
||||
type Bus = BUS;
|
||||
|
||||
fn transaction<R>(&mut self, f: impl FnOnce(&mut Self::Bus) -> Result<R, BUS::Error>) -> Result<R, Self::Error> {
|
||||
self.cs.set_low().map_err(SpiBusDeviceError::Cs)?;
|
||||
|
||||
let (f_res, flush_res) = self.bus.lock(|bus| {
|
||||
self.bus.lock(|bus| {
|
||||
let mut bus = bus.borrow_mut();
|
||||
self.cs.set_low().map_err(SpiBusDeviceError::Cs)?;
|
||||
|
||||
let f_res = f(&mut bus);
|
||||
|
||||
// On failure, it's important to still flush and deassert CS.
|
||||
let flush_res = bus.flush();
|
||||
(f_res, flush_res)
|
||||
});
|
||||
let cs_res = self.cs.set_high();
|
||||
|
||||
let cs_res = self.cs.set_high();
|
||||
let f_res = f_res.map_err(SpiBusDeviceError::Spi)?;
|
||||
flush_res.map_err(SpiBusDeviceError::Spi)?;
|
||||
cs_res.map_err(SpiBusDeviceError::Cs)?;
|
||||
|
||||
let f_res = f_res.map_err(SpiBusDeviceError::Spi)?;
|
||||
flush_res.map_err(SpiBusDeviceError::Spi)?;
|
||||
cs_res.map_err(SpiBusDeviceError::Cs)?;
|
||||
|
||||
Ok(f_res)
|
||||
Ok(f_res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user