Skip to content

Commit 493dfd8

Browse files
committed
bus: use shared fn transaction for exclusive bus too.
1 parent 4ec58c8 commit 493dfd8

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

embedded-hal-bus/src/spi/exclusive.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,7 @@ where
7474
{
7575
#[inline]
7676
fn transaction(&mut self, operations: &mut [Operation<'_, Word>]) -> Result<(), Self::Error> {
77-
self.cs.set_low().map_err(DeviceError::Cs)?;
78-
79-
let op_res = operations.iter_mut().try_for_each(|op| match op {
80-
Operation::Read(buf) => self.bus.read(buf),
81-
Operation::Write(buf) => self.bus.write(buf),
82-
Operation::Transfer(read, write) => self.bus.transfer(read, write),
83-
Operation::TransferInPlace(buf) => self.bus.transfer_in_place(buf),
84-
Operation::DelayUs(us) => {
85-
self.bus.flush()?;
86-
self.delay.delay_us(*us);
87-
Ok(())
88-
}
89-
});
90-
91-
// On failure, it's important to still flush and deassert CS.
92-
let flush_res = self.bus.flush();
93-
let cs_res = self.cs.set_high();
94-
95-
op_res.map_err(DeviceError::Spi)?;
96-
flush_res.map_err(DeviceError::Spi)?;
97-
cs_res.map_err(DeviceError::Cs)?;
98-
99-
Ok(())
77+
transaction(operations, &mut self.bus, &mut self.delay, &mut self.cs)
10078
}
10179
}
10280

0 commit comments

Comments
 (0)