Skip to content

Commit 4ffa5da

Browse files
committed
spi/blocking: add read_batch, write_batch.
1 parent c9b9326 commit 4ffa5da

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/spi/blocking.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ pub trait Read<W>: Spi {
2323
/// The word value sent on MOSI during reading is implementation-defined,
2424
/// typically `0x00`, `0xFF`, or configurable.
2525
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
26+
27+
/// Reads all slices in `words` from the slave as part of a single SPI transaction.
28+
///
29+
/// The word value sent on MOSI during reading is implementation-defined,
30+
/// typically `0x00`, `0xFF`, or configurable.
31+
fn read_batch(&mut self, words: &mut [&mut [W]]) -> Result<(), Self::Error> {
32+
for buf in words {
33+
self.read(buf)?;
34+
}
35+
Ok(())
36+
}
2637
}
2738

2839
impl<T: Read<W>, W> Read<W> for &mut T {
@@ -36,6 +47,14 @@ pub trait Write<W>: Spi {
3647
/// Writes `words` to the slave, ignoring all the incoming words
3748
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>;
3849

50+
/// Writes all slices in `words` to the slave as part of a single SPI transaction, ignoring all the incoming words
51+
fn write_batch(&mut self, words: &[&[W]]) -> Result<(), Self::Error> {
52+
for buf in words {
53+
self.write(buf)?;
54+
}
55+
Ok(())
56+
}
57+
3958
/// Writes `words` to the slave, ignoring all the incoming words
4059
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
4160
where
@@ -53,6 +72,10 @@ impl<T: Write<W>, W> Write<W> for &mut T {
5372
T::write(self, words)
5473
}
5574

75+
fn write_batch(&mut self, words: &[&[W]]) -> Result<(), Self::Error> {
76+
T::write_batch(self, words)
77+
}
78+
5679
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
5780
where
5881
WI: IntoIterator<Item = W>,

0 commit comments

Comments
 (0)