11//! Blocking SPI API
22
3- /// Blocking transfer with separate buffers
4- pub trait Transfer < W : Copy = u8 > {
5- /// Error type
6- type Error : crate :: spi:: Error ;
3+ use super :: ErrorType ;
74
5+ /// Blocking transfer with separate buffers
6+ pub trait Transfer < W = u8 > : ErrorType {
87 /// Writes and reads simultaneously. `write` is written to the slave on MOSI and
98 /// words received on MISO are stored in `read`.
109 ///
@@ -17,37 +16,27 @@ pub trait Transfer<W: Copy = u8> {
1716}
1817
1918impl < T : Transfer < W > , W : Copy > Transfer < W > for & mut T {
20- type Error = T :: Error ;
21-
2219 fn transfer ( & mut self , read : & mut [ W ] , write : & [ W ] ) -> Result < ( ) , Self :: Error > {
2320 T :: transfer ( self , read, write)
2421 }
2522}
2623
2724/// Blocking transfer with single buffer (in-place)
28- pub trait TransferInplace < W : Copy = u8 > {
29- /// Error type
30- type Error : crate :: spi:: Error ;
31-
25+ pub trait TransferInplace < W : Copy = u8 > : ErrorType {
3226 /// Writes and reads simultaneously. The contents of `words` are
3327 /// written to the slave, and the received words are stored into the same
3428 /// `words` buffer, overwriting it.
3529 fn transfer_inplace ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > ;
3630}
3731
3832impl < T : TransferInplace < W > , W : Copy > TransferInplace < W > for & mut T {
39- type Error = T :: Error ;
40-
4133 fn transfer_inplace ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > {
4234 T :: transfer_inplace ( self , words)
4335 }
4436}
4537
4638/// Blocking read
47- pub trait Read < W : Copy = u8 > {
48- /// Error type
49- type Error : crate :: spi:: Error ;
50-
39+ pub trait Read < W : Copy = u8 > : ErrorType {
5140 /// Reads `words` from the slave.
5241 ///
5342 /// The word value sent on MOSI during reading is implementation-defined,
@@ -56,44 +45,32 @@ pub trait Read<W: Copy = u8> {
5645}
5746
5847impl < T : Read < W > , W : Copy > Read < W > for & mut T {
59- type Error = T :: Error ;
60-
6148 fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Self :: Error > {
6249 T :: read ( self , words)
6350 }
6451}
6552
6653/// Blocking write
67- pub trait Write < W : Copy = u8 > {
68- /// Error type
69- type Error : crate :: spi:: Error ;
70-
54+ pub trait Write < W : Copy = u8 > : ErrorType {
7155 /// Writes `words` to the slave, ignoring all the incoming words
7256 fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > ;
7357}
7458
7559impl < T : Write < W > , W : Copy > Write < W > for & mut T {
76- type Error = T :: Error ;
77-
7860 fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > {
7961 T :: write ( self , words)
8062 }
8163}
8264
8365/// Blocking write (iterator version)
84- pub trait WriteIter < W : Copy = u8 > {
85- /// Error type
86- type Error : crate :: spi:: Error ;
87-
66+ pub trait WriteIter < W : Copy = u8 > : ErrorType {
8867 /// Writes `words` to the slave, ignoring all the incoming words
8968 fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
9069 where
9170 WI : IntoIterator < Item = W > ;
9271}
9372
9473impl < T : WriteIter < W > , W : Copy > WriteIter < W > for & mut T {
95- type Error = T :: Error ;
96-
9774 fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
9875 where
9976 WI : IntoIterator < Item = W > ,
@@ -119,17 +96,12 @@ pub enum Operation<'a, W: 'static + Copy = u8> {
11996
12097/// Transactional trait allows multiple actions to be executed
12198/// as part of a single SPI transaction
122- pub trait Transactional < W : ' static + Copy = u8 > {
123- /// Associated error type
124- type Error : crate :: spi:: Error ;
125-
99+ pub trait Transactional < W : ' static + Copy = u8 > : ErrorType {
126100 /// Execute the provided transactions
127101 fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , W > ] ) -> Result < ( ) , Self :: Error > ;
128102}
129103
130104impl < T : Transactional < W > , W : ' static + Copy > Transactional < W > for & mut T {
131- type Error = T :: Error ;
132-
133105 fn exec < ' a > ( & mut self , operations : & mut [ Operation < ' a , W > ] ) -> Result < ( ) , Self :: Error > {
134106 T :: exec ( self , operations)
135107 }
0 commit comments