Skip to content

Commit 3307308

Browse files
committed
spi/blocking: add read_batch, write_batch.
1 parent 44e0da1 commit 3307308

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
@@ -9,19 +9,32 @@ pub trait Read<W = u8>: ErrorType {
99
/// The word value sent on MOSI during reading is implementation-defined,
1010
/// typically `0x00`, `0xFF`, or configurable.
1111
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
12+
13+
/// Reads all slices in `words` from the slave as part of a single SPI transaction.
14+
///
15+
/// The word value sent on MOSI during reading is implementation-defined,
16+
/// typically `0x00`, `0xFF`, or configurable.
17+
fn read_batch(&mut self, words: &mut [&mut [W]]) -> Result<(), Self::Error>;
1218
}
1319

1420
impl<T: Read<W>, W> Read<W> for &mut T {
1521
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
1622
T::read(self, words)
1723
}
24+
25+
fn read_batch(&mut self, words: &mut [&mut [W]]) -> Result<(), Self::Error> {
26+
T::read_batch(self, words)
27+
}
1828
}
1929

2030
/// Blocking write-only SPI
2131
pub trait Write<W = u8>: ErrorType {
2232
/// Writes `words` to the slave, ignoring all the incoming words
2333
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>;
2434

35+
/// Writes all slices in `words` to the slave as part of a single SPI transaction, ignoring all the incoming words
36+
fn write_batch(&mut self, words: &[&[W]]) -> Result<(), Self::Error>;
37+
2538
/// Writes `words` to the slave, ignoring all the incoming words
2639
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
2740
where
@@ -33,6 +46,10 @@ impl<T: Write<W>, W> Write<W> for &mut T {
3346
T::write(self, words)
3447
}
3548

49+
fn write_batch(&mut self, words: &[&[W]]) -> Result<(), Self::Error> {
50+
T::write_batch(self, words)
51+
}
52+
3653
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
3754
where
3855
WI: IntoIterator<Item = W>,

0 commit comments

Comments
 (0)