Skip to content

Commit b7029c9

Browse files
committed
spi/blocking: add read_batch, write_batch.
1 parent 9d2f99b commit b7029c9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/spi/blocking.rs

+17
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,32 @@ pub trait Read<W = u8>: Spi {
1919
/// The word value sent on MOSI during reading is implementation-defined,
2020
/// typically `0x00`, `0xFF`, or configurable.
2121
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
22+
23+
/// Reads all slices in `words` from the slave as part of a single SPI transaction.
24+
///
25+
/// The word value sent on MOSI during reading is implementation-defined,
26+
/// typically `0x00`, `0xFF`, or configurable.
27+
fn read_batch(&mut self, words: &mut [&mut [W]]) -> Result<(), Self::Error>;
2228
}
2329

2430
impl<T: Read<W>, W> Read<W> for &mut T {
2531
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
2632
T::read(self, words)
2733
}
34+
35+
fn read_batch(&mut self, words: &mut [&mut [W]]) -> Result<(), Self::Error> {
36+
T::read_batch(self, words)
37+
}
2838
}
2939

3040
/// Blocking write-only SPI
3141
pub trait Write<W = u8>: Spi {
3242
/// Writes `words` to the slave, ignoring all the incoming words
3343
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>;
3444

45+
/// Writes all slices in `words` to the slave as part of a single SPI transaction, ignoring all the incoming words
46+
fn write_batch(&mut self, words: &[&[W]]) -> Result<(), Self::Error>;
47+
3548
/// Writes `words` to the slave, ignoring all the incoming words
3649
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
3750
where
@@ -43,6 +56,10 @@ impl<T: Write<W>, W> Write<W> for &mut T {
4356
T::write(self, words)
4457
}
4558

59+
fn write_batch(&mut self, words: &[&[W]]) -> Result<(), Self::Error> {
60+
T::write_batch(self, words)
61+
}
62+
4663
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
4764
where
4865
WI: IntoIterator<Item = W>,

0 commit comments

Comments
 (0)