|
4 | 4 | //! traits. To save boilerplate when that's the case a `Default` marker trait may be provided.
|
5 | 5 | //! Implementing that marker trait will opt in your type into a blanket implementation.
|
6 | 6 |
|
7 |
| -/// Blocking transfer |
| 7 | +/// Blocking transfer with separate buffers |
8 | 8 | pub trait Transfer<W> {
|
9 | 9 | /// Error type
|
10 | 10 | type Error: core::fmt::Debug;
|
11 | 11 |
|
| 12 | + /// Writes and reads simultaneously. `write` is written to the slave on MOSI and |
| 13 | + /// words received on MISO are stored in `read`. |
| 14 | + /// |
| 15 | + /// It is allowed for `read` and `write` to have different lengths, even zero length. |
| 16 | + /// The transfer runs for `max(read.len(), write.len())` words. If `read` is shorter, |
| 17 | + /// incoming words after `read` has been filled will be discarded. If `write` is shorter, |
| 18 | + /// the value of words sent in MOSI after all `write` has been sent is implementation defined, |
| 19 | + /// typically `0x00`, `0xFF`, or configurable. |
| 20 | + fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error>; |
| 21 | +} |
| 22 | + |
| 23 | +/// Blocking transfer with single buffer (in-place) |
| 24 | +pub trait TransferInplace<W> { |
| 25 | + /// Error type |
| 26 | + type Error: core::fmt::Debug; |
| 27 | + |
12 | 28 | /// Writes and reads simultaneously. The contents of `words` are
|
13 | 29 | /// written to the slave, and the received words are stored into the same
|
14 | 30 | /// `words` buffer, overwriting it.
|
15 |
| - fn transfer(&mut self, words: &mut [W]) -> Result<(), Self::Error>; |
| 31 | + fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error>; |
| 32 | +} |
| 33 | + |
| 34 | +/// Blocking read |
| 35 | +pub trait Read<W> { |
| 36 | + /// Error type |
| 37 | + type Error; |
| 38 | + |
| 39 | + /// Reads `words` to the slave. The word value sent on MOSI during |
| 40 | + /// reading is implementation defined, typically `0x00`, `0xFF`, or configurable. |
| 41 | + fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>; |
16 | 42 | }
|
17 | 43 |
|
18 | 44 | /// Blocking write
|
@@ -40,10 +66,14 @@ pub trait WriteIter<W> {
|
40 | 66 | /// This allows composition of SPI operations into a single bus transaction
|
41 | 67 | #[derive(Debug, PartialEq)]
|
42 | 68 | pub enum Operation<'a, W: 'static> {
|
| 69 | + /// Read data into the provided buffer. |
| 70 | + Read(&'a mut [W]), |
43 | 71 | /// Write data from the provided buffer, discarding read data
|
44 | 72 | Write(&'a [W]),
|
45 | 73 | /// Write data out while reading data into the provided buffer
|
46 |
| - Transfer(&'a mut [W]), |
| 74 | + Transfer(&'a mut [W], &'a [W]), |
| 75 | + /// Write data out while reading data into the provided buffer |
| 76 | + TransferInplace(&'a mut [W]), |
47 | 77 | }
|
48 | 78 |
|
49 | 79 | /// Transactional trait allows multiple actions to be executed
|
|
0 commit comments