3
3
use super :: ErrorType ;
4
4
5
5
/// Blocking transfer with separate buffers
6
- pub trait Transfer < W = u8 > : ErrorType {
6
+ pub trait Transfer < Word = u8 > : ErrorType {
7
7
/// Writes and reads simultaneously. `write` is written to the slave on MOSI and
8
8
/// words received on MISO are stored in `read`.
9
9
///
@@ -12,68 +12,68 @@ pub trait Transfer<W = u8>: ErrorType {
12
12
/// incoming words after `read` has been filled will be discarded. If `write` is shorter,
13
13
/// the value of words sent in MOSI after all `write` has been sent is implementation-defined,
14
14
/// typically `0x00`, `0xFF`, or configurable.
15
- fn transfer ( & mut self , read : & mut [ W ] , write : & [ W ] ) -> Result < ( ) , Self :: Error > ;
15
+ fn transfer ( & mut self , read : & mut [ Word ] , write : & [ Word ] ) -> Result < ( ) , Self :: Error > ;
16
16
}
17
17
18
- impl < T : Transfer < W > , W : Copy > Transfer < W > for & mut T {
19
- fn transfer ( & mut self , read : & mut [ W ] , write : & [ W ] ) -> Result < ( ) , Self :: Error > {
18
+ impl < T : Transfer < Word > , Word : Copy > Transfer < Word > for & mut T {
19
+ fn transfer ( & mut self , read : & mut [ Word ] , write : & [ Word ] ) -> Result < ( ) , Self :: Error > {
20
20
T :: transfer ( self , read, write)
21
21
}
22
22
}
23
23
24
24
/// Blocking transfer with single buffer (in-place)
25
- pub trait TransferInplace < W : Copy = u8 > : ErrorType {
25
+ pub trait TransferInplace < Word : Copy = u8 > : ErrorType {
26
26
/// Writes and reads simultaneously. The contents of `words` are
27
27
/// written to the slave, and the received words are stored into the same
28
28
/// `words` buffer, overwriting it.
29
- fn transfer_inplace ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > ;
29
+ fn transfer_inplace ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > ;
30
30
}
31
31
32
- impl < T : TransferInplace < W > , W : Copy > TransferInplace < W > for & mut T {
33
- fn transfer_inplace ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > {
32
+ impl < T : TransferInplace < Word > , Word : Copy > TransferInplace < Word > for & mut T {
33
+ fn transfer_inplace ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
34
34
T :: transfer_inplace ( self , words)
35
35
}
36
36
}
37
37
38
38
/// Blocking read
39
- pub trait Read < W : Copy = u8 > : ErrorType {
39
+ pub trait Read < Word : Copy = u8 > : ErrorType {
40
40
/// Reads `words` from the slave.
41
41
///
42
42
/// The word value sent on MOSI during reading is implementation-defined,
43
43
/// typically `0x00`, `0xFF`, or configurable.
44
- fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > ;
44
+ fn read ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > ;
45
45
}
46
46
47
- impl < T : Read < W > , W : Copy > Read < W > for & mut T {
48
- fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > {
47
+ impl < T : Read < Word > , Word : Copy > Read < Word > for & mut T {
48
+ fn read ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
49
49
T :: read ( self , words)
50
50
}
51
51
}
52
52
53
53
/// Blocking write
54
- pub trait Write < W : Copy = u8 > : ErrorType {
54
+ pub trait Write < Word : Copy = u8 > : ErrorType {
55
55
/// Writes `words` to the slave, ignoring all the incoming words
56
- fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > ;
56
+ fn write ( & mut self , words : & [ Word ] ) -> Result < ( ) , Self :: Error > ;
57
57
}
58
58
59
- impl < T : Write < W > , W : Copy > Write < W > for & mut T {
60
- fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > {
59
+ impl < T : Write < Word > , Word : Copy > Write < Word > for & mut T {
60
+ fn write ( & mut self , words : & [ Word ] ) -> Result < ( ) , Self :: Error > {
61
61
T :: write ( self , words)
62
62
}
63
63
}
64
64
65
65
/// Blocking write (iterator version)
66
- pub trait WriteIter < W : Copy = u8 > : ErrorType {
66
+ pub trait WriteIter < Word : Copy = u8 > : ErrorType {
67
67
/// Writes `words` to the slave, ignoring all the incoming words
68
68
fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
69
69
where
70
- WI : IntoIterator < Item = W > ;
70
+ WI : IntoIterator < Item = Word > ;
71
71
}
72
72
73
- impl < T : WriteIter < W > , W : Copy > WriteIter < W > for & mut T {
73
+ impl < T : WriteIter < Word > , Word : Copy > WriteIter < Word > for & mut T {
74
74
fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
75
75
where
76
- WI : IntoIterator < Item = W > ,
76
+ WI : IntoIterator < Item = Word > ,
77
77
{
78
78
T :: write_iter ( self , words)
79
79
}
@@ -83,26 +83,26 @@ impl<T: WriteIter<W>, W: Copy> WriteIter<W> for &mut T {
83
83
///
84
84
/// This allows composition of SPI operations into a single bus transaction
85
85
#[ derive( Debug , PartialEq ) ]
86
- pub enum Operation < ' a , W : ' static + Copy = u8 > {
86
+ pub enum Operation < ' a , Word : ' static + Copy = u8 > {
87
87
/// Read data into the provided buffer.
88
- Read ( & ' a mut [ W ] ) ,
88
+ Read ( & ' a mut [ Word ] ) ,
89
89
/// Write data from the provided buffer, discarding read data
90
- Write ( & ' a [ W ] ) ,
90
+ Write ( & ' a [ Word ] ) ,
91
91
/// Write data out while reading data into the provided buffer
92
- Transfer ( & ' a mut [ W ] , & ' a [ W ] ) ,
92
+ Transfer ( & ' a mut [ Word ] , & ' a [ Word ] ) ,
93
93
/// Write data out while reading data into the provided buffer
94
- TransferInplace ( & ' a mut [ W ] ) ,
94
+ TransferInplace ( & ' a mut [ Word ] ) ,
95
95
}
96
96
97
97
/// Transactional trait allows multiple actions to be executed
98
98
/// as part of a single SPI transaction
99
- pub trait Transactional < W : ' static + Copy = u8 > : ErrorType {
99
+ pub trait Transactional < Word : ' static + Copy = u8 > : ErrorType {
100
100
/// Execute the provided transactions
101
- fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , W > ] ) -> Result < ( ) , Self :: Error > ;
101
+ fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , Word > ] ) -> Result < ( ) , Self :: Error > ;
102
102
}
103
103
104
- impl < T : Transactional < W > , W : ' static + Copy > Transactional < W > for & mut T {
105
- fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , W > ] ) -> Result < ( ) , Self :: Error > {
104
+ impl < T : Transactional < Word > , Word : ' static + Copy > Transactional < Word > for & mut T {
105
+ fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , Word > ] ) -> Result < ( ) , Self :: Error > {
106
106
T :: exec ( self , operations)
107
107
}
108
108
}
0 commit comments