@@ -9,8 +9,8 @@ use embedded_hal::{digital::blocking::OutputPin, spi::blocking};
9
9
10
10
/// SPI device trait
11
11
///
12
- /// SpiDevice represents ownership over a single SPI device on a (possibly shared) bus, selected
13
- /// with a CS pin.
12
+ /// ` SpiDevice` represents ownership over a single SPI device on a (possibly shared) bus, selected
13
+ /// with a CS (Chip Select) pin.
14
14
///
15
15
/// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for important information on SPI Bus vs Device traits.
16
16
pub trait SpiDevice : ErrorType {
@@ -30,17 +30,18 @@ pub trait SpiDevice: ErrorType {
30
30
) ,
31
31
> + ' a ;
32
32
33
- /// Start a transaction against the device.
33
+ /// Perform a transaction against the device.
34
34
///
35
35
/// - Locks the bus
36
36
/// - Asserts the CS (Chip Select) pin.
37
37
/// - Calls `f` with an exclusive reference to the bus, which can then be used to do transfers against the device.
38
+ /// - [Flushes](SpiBusFlush::flush) the bus.
38
39
/// - Deasserts the CS pin.
39
- /// - Unlocks the bus,
40
+ /// - Unlocks the bus.
40
41
///
41
- /// The lock mechanism is implementation-defined. The only requirement is it must prevent two
42
+ /// The locking mechanism is implementation-defined. The only requirement is it must prevent two
42
43
/// transactions from executing concurrently against the same bus. Examples of implementations are:
43
- /// critical sections, blocking mutexes, async mutexes, or returning an error or panicking if the bus is already busy.
44
+ /// critical sections, blocking mutexes, async mutexes, returning an error or panicking if the bus is already busy.
44
45
fn transaction < ' a , R , F , Fut > ( & ' a mut self , f : F ) -> Self :: TransactionFuture < ' a , R , F , Fut >
45
46
where
46
47
F : FnOnce ( & ' a mut Self :: Bus ) -> Fut + ' a ,
@@ -74,14 +75,16 @@ impl<T: SpiDevice> SpiDevice for &mut T {
74
75
}
75
76
}
76
77
77
- /// Flush for SPI bus
78
+ /// Flush support for SPI bus
78
79
pub trait SpiBusFlush : ErrorType {
79
80
/// Future returned by the `flush` method.
80
81
type FlushFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > + ' a
81
82
where
82
83
Self : ' a ;
83
84
84
- /// Flush
85
+ /// Wait until all operations have completed and the bus is idle.
86
+ ///
87
+ /// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for information on flushing.
85
88
fn flush < ' a > ( & ' a mut self ) -> Self :: FlushFuture < ' a > ;
86
89
}
87
90
@@ -104,6 +107,9 @@ pub trait SpiBusRead<Word: 'static + Copy = u8>: SpiBusFlush {
104
107
///
105
108
/// The word value sent on MOSI during reading is implementation-defined,
106
109
/// typically `0x00`, `0xFF`, or configurable.
110
+ ///
111
+ /// Implementations are allowed to return before the operation is
112
+ /// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
107
113
fn read < ' a > ( & ' a mut self , words : & ' a mut [ Word ] ) -> Self :: ReadFuture < ' a > ;
108
114
}
109
115
@@ -123,6 +129,9 @@ pub trait SpiBusWrite<Word: 'static + Copy = u8>: SpiBusFlush {
123
129
Self : ' a ;
124
130
125
131
/// Write `words` to the slave, ignoring all the incoming words
132
+ ///
133
+ /// Implementations are allowed to return before the operation is
134
+ /// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
126
135
fn write < ' a > ( & ' a mut self , words : & ' a [ Word ] ) -> Self :: WriteFuture < ' a > ;
127
136
}
128
137
@@ -136,7 +145,7 @@ impl<T: SpiBusWrite<Word>, Word: 'static + Copy> SpiBusWrite<Word> for &mut T {
136
145
137
146
/// Read-write SPI bus
138
147
///
139
- /// SpiBus represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
148
+ /// ` SpiBus` represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
140
149
///
141
150
/// See (the docs on embedded-hal)[embedded_hal::spi::blocking] for important information on SPI Bus vs Device traits.
142
151
pub trait SpiBus < Word : ' static + Copy = u8 > : SpiBusRead < Word > + SpiBusWrite < Word > {
@@ -153,6 +162,9 @@ pub trait SpiBus<Word: 'static + Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word
153
162
/// incoming words after `read` has been filled will be discarded. If `write` is shorter,
154
163
/// the value of words sent in MOSI after all `write` has been sent is implementation-defined,
155
164
/// typically `0x00`, `0xFF`, or configurable.
165
+ ///
166
+ /// Implementations are allowed to return before the operation is
167
+ /// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
156
168
fn transfer < ' a > (
157
169
& ' a mut self ,
158
170
read : & ' a mut [ Word ] ,
@@ -167,6 +179,9 @@ pub trait SpiBus<Word: 'static + Copy = u8>: SpiBusRead<Word> + SpiBusWrite<Word
167
179
/// Write and read simultaneously. The contents of `words` are
168
180
/// written to the slave, and the received words are stored into the same
169
181
/// `words` buffer, overwriting it.
182
+ ///
183
+ /// Implementations are allowed to return before the operation is
184
+ /// complete. See (the docs on embedded-hal)[embedded_hal::spi::blocking] for details on flushing.
170
185
fn transfer_in_place < ' a > (
171
186
& ' a mut self ,
172
187
words : & ' a mut [ Word ] ,
0 commit comments