1
1
//! Serial Peripheral Interface
2
2
3
- use core:: future:: Future ;
3
+ use core:: { future:: Future , mem :: MaybeUninit } ;
4
4
5
- /// Async transfer
6
- pub trait Transfer < Word : ' static > {
5
+ /// Async read + write
6
+ pub trait ReadWrite < Word : ' static > {
7
7
/// Error type
8
8
type Error ;
9
9
10
10
/// Associated future for the `transfer` method.
11
- type TransferFuture < ' a > : Future < Output = Result < & ' a [ Word ] , Self :: Error > > + ' a
11
+ type ReadWriteFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > + ' a
12
12
where
13
13
Self : ' a ;
14
14
15
- /// Writes `words` to the slave. Returns the `words` received from the slave
16
- fn transfer < ' a > ( & ' a mut self , words : & ' a mut [ Word ] ) -> Self :: TransferFuture < ' a > ;
15
+ /// Writes `words` to the slave from the `write` buffer. Puts the words returned in the `read` buffer.
16
+ /// This method uses separate `write` and `read` buffers.
17
+ fn readwrite < ' a > ( & ' a mut self , write : & ' a [ Word ] , read : & ' a mut [ MaybeUninit < Word > ] ) -> Self :: ReadWriteFuture < ' a > ;
18
+ }
19
+
20
+ /// Async read + write in place.
21
+ pub trait ReadWriteInPlace < Word : ' static > {
22
+ /// Error type
23
+ type Error ;
24
+
25
+ /// Associated future for the `transfer` method.
26
+ type ReadWriteInPlaceFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > + ' a
27
+ where
28
+ Self : ' a ;
29
+
30
+ /// Writes `words` to the slave from the `readwrite` buffer and reads words into the same buffer.
31
+ /// This method uses a single `readwrite` buffer.
32
+ fn readwrite_inplace < ' a > ( & ' a mut self , readwrite : & ' a mut [ MaybeUninit < Word > ] ) -> Self :: ReadWriteInPlaceFuture < ' a > ;
17
33
}
18
34
19
35
/// Async write
@@ -30,6 +46,22 @@ pub trait Write<W> {
30
46
fn write < ' a > ( & ' a mut self , words : & ' a [ W ] ) -> Self :: WriteFuture < ' a > ;
31
47
}
32
48
49
+ /// Async read
50
+ pub trait Read < W > {
51
+ /// Error type
52
+ type Error ;
53
+
54
+ /// Associated future for the `read` method.
55
+ type ReadFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > + ' a
56
+ where
57
+ Self : ' a ;
58
+
59
+ /// Reads words from the slave without specifying any data to write.
60
+ /// The SPI hardware will send data, though what data it sends is not defined
61
+ /// by this trait. Some hardware can configure what values (e.g. all zeroes, all ones), some cannot.
62
+ fn read < ' a > ( & ' a mut self , words : & ' a mut [ MaybeUninit < W > ] ) -> Self :: ReadFuture < ' a > ;
63
+ }
64
+
33
65
// /// Operation for transactional SPI trait
34
66
// ///
35
67
// /// This allows composition of SPI operations into a single bus transaction
0 commit comments