Skip to content

Commit c9b9326

Browse files
committed
spi/blocking: add default impls for write_iter and exec.
1 parent 57ff41d commit c9b9326

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
@@ -39,7 +39,13 @@ pub trait Write<W>: Spi {
3939
/// Writes `words` to the slave, ignoring all the incoming words
4040
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
4141
where
42-
WI: IntoIterator<Item = W>;
42+
WI: IntoIterator<Item = W>,
43+
{
44+
for word in words {
45+
self.write(&[word])?;
46+
}
47+
Ok(())
48+
}
4349
}
4450

4551
impl<T: Write<W>, W> Write<W> for &mut T {
@@ -88,7 +94,17 @@ pub trait ReadWrite<W>: Read<W> + Write<W> {
8894
fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
8995

9096
/// Execute multiple actions as part of a single SPI transaction
91-
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
97+
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error> {
98+
for op in operations {
99+
match op {
100+
Operation::Read(words) => self.read(words)?,
101+
Operation::Write(words) => self.write(words)?,
102+
Operation::Transfer(read, write) => self.transfer(read, write)?,
103+
Operation::TransferInplace(words) => self.transfer_inplace(words)?,
104+
}
105+
}
106+
Ok(())
107+
}
92108
}
93109

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

0 commit comments

Comments
 (0)