Skip to content

Commit 2c4ae95

Browse files
committed
spi/blocking: add default impls for write_iter and exec.
1 parent 9d2f99b commit 2c4ae95

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/spi/blocking.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ pub trait Write<W = u8>: Spi {
3535
/// Writes `words` to the slave, ignoring all the incoming words
3636
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
3737
where
38-
WI: IntoIterator<Item = W>;
38+
WI: IntoIterator<Item = W>,
39+
{
40+
for word in words {
41+
self.write(&[word])?;
42+
}
43+
Ok(())
44+
}
3945
}
4046

4147
impl<T: Write<W>, W> Write<W> for &mut T {
@@ -84,7 +90,17 @@ pub trait ReadWrite<W = u8>: Read<W> + Write<W> {
8490
fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
8591

8692
/// Execute multiple actions as part of a single SPI transaction
87-
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
93+
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error> {
94+
for op in operations {
95+
match op {
96+
Operation::Read(words) => self.read(words)?,
97+
Operation::Write(words) => self.write(words)?,
98+
Operation::Transfer(read, write) => self.transfer(read, write)?,
99+
Operation::TransferInplace(words) => self.transfer_inplace(words)?,
100+
}
101+
}
102+
Ok(())
103+
}
88104
}
89105

90106
impl<T: ReadWrite<W>, W> ReadWrite<W> for &mut T {

0 commit comments

Comments
 (0)