1
1
//! Blocking SPI API
2
2
3
- /// Blocking transfer with separate buffers
4
- pub trait Transfer < W = u8 > {
5
- /// Error type
6
- type Error : crate :: spi:: Error ;
3
+ use super :: ErrorType ;
7
4
5
+ /// Blocking transfer with separate buffers
6
+ pub trait Transfer < W = u8 > : ErrorType {
8
7
/// Writes and reads simultaneously. `write` is written to the slave on MOSI and
9
8
/// words received on MISO are stored in `read`.
10
9
///
@@ -17,37 +16,27 @@ pub trait Transfer<W = u8> {
17
16
}
18
17
19
18
impl < T : Transfer < W > , W > Transfer < W > for & mut T {
20
- type Error = T :: Error ;
21
-
22
19
fn transfer ( & mut self , read : & mut [ W ] , write : & [ W ] ) -> Result < ( ) , Self :: Error > {
23
20
T :: transfer ( self , read, write)
24
21
}
25
22
}
26
23
27
24
/// Blocking transfer with single buffer (in-place)
28
- pub trait TransferInplace < W = u8 > {
29
- /// Error type
30
- type Error : crate :: spi:: Error ;
31
-
25
+ pub trait TransferInplace < W = u8 > : ErrorType {
32
26
/// Writes and reads simultaneously. The contents of `words` are
33
27
/// written to the slave, and the received words are stored into the same
34
28
/// `words` buffer, overwriting it.
35
29
fn transfer_inplace ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > ;
36
30
}
37
31
38
32
impl < T : TransferInplace < W > , W > TransferInplace < W > for & mut T {
39
- type Error = T :: Error ;
40
-
41
33
fn transfer_inplace ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > {
42
34
T :: transfer_inplace ( self , words)
43
35
}
44
36
}
45
37
46
38
/// Blocking read
47
- pub trait Read < W = u8 > {
48
- /// Error type
49
- type Error : crate :: spi:: Error ;
50
-
39
+ pub trait Read < W = u8 > : ErrorType {
51
40
/// Reads `words` from the slave.
52
41
///
53
42
/// The word value sent on MOSI during reading is implementation-defined,
@@ -56,44 +45,32 @@ pub trait Read<W = u8> {
56
45
}
57
46
58
47
impl < T : Read < W > , W > Read < W > for & mut T {
59
- type Error = T :: Error ;
60
-
61
48
fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > {
62
49
T :: read ( self , words)
63
50
}
64
51
}
65
52
66
53
/// Blocking write
67
- pub trait Write < W = u8 > {
68
- /// Error type
69
- type Error : crate :: spi:: Error ;
70
-
54
+ pub trait Write < W = u8 > : ErrorType {
71
55
/// Writes `words` to the slave, ignoring all the incoming words
72
56
fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > ;
73
57
}
74
58
75
59
impl < T : Write < W > , W > Write < W > for & mut T {
76
- type Error = T :: Error ;
77
-
78
60
fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > {
79
61
T :: write ( self , words)
80
62
}
81
63
}
82
64
83
65
/// Blocking write (iterator version)
84
- pub trait WriteIter < W = u8 > {
85
- /// Error type
86
- type Error : crate :: spi:: Error ;
87
-
66
+ pub trait WriteIter < W = u8 > : ErrorType {
88
67
/// Writes `words` to the slave, ignoring all the incoming words
89
68
fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
90
69
where
91
70
WI : IntoIterator < Item = W > ;
92
71
}
93
72
94
73
impl < T : WriteIter < W > , W > WriteIter < W > for & mut T {
95
- type Error = T :: Error ;
96
-
97
74
fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
98
75
where
99
76
WI : IntoIterator < Item = W > ,
@@ -119,17 +96,12 @@ pub enum Operation<'a, W: 'static = u8> {
119
96
120
97
/// Transactional trait allows multiple actions to be executed
121
98
/// as part of a single SPI transaction
122
- pub trait Transactional < W : ' static = u8 > {
123
- /// Associated error type
124
- type Error : crate :: spi:: Error ;
125
-
99
+ pub trait Transactional < W : ' static = u8 > : ErrorType {
126
100
/// Execute the provided transactions
127
101
fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , W > ] ) -> Result < ( ) , Self :: Error > ;
128
102
}
129
103
130
104
impl < T : Transactional < W > , W : ' static > Transactional < W > for & mut T {
131
- type Error = T :: Error ;
132
-
133
105
fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , W > ] ) -> Result < ( ) , Self :: Error > {
134
106
T :: exec ( self , operations)
135
107
}
0 commit comments