File tree 2 files changed +78
-0
lines changed
2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,22 @@ pub trait Write {
55
55
fn write ( & mut self , addr : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
56
56
}
57
57
58
+ /// Blocking write (iterator version)
59
+ #[ cfg( feature = "unproven" ) ]
60
+ pub trait WriteIter {
61
+ /// Error type
62
+ type Error ;
63
+
64
+ /// Sends bytes to slave with address `addr`
65
+ ///
66
+ /// # I2C Events (contract)
67
+ ///
68
+ /// Same as `Write`
69
+ fn write < B > ( & mut self , addr : u8 , bytes : B ) -> Result < ( ) , Self :: Error >
70
+ where
71
+ B : IntoIterator < Item = u8 > ;
72
+ }
73
+
58
74
/// Blocking write + read
59
75
pub trait WriteRead {
60
76
/// Error type
@@ -89,3 +105,25 @@ pub trait WriteRead {
89
105
buffer : & mut [ u8 ] ,
90
106
) -> Result < ( ) , Self :: Error > ;
91
107
}
108
+
109
+ /// Blocking write (iterator version) + read
110
+ #[ cfg( feature = "unproven" ) ]
111
+ pub trait WriteIterRead {
112
+ /// Error type
113
+ type Error ;
114
+
115
+ /// Sends bytes to slave with address `addr` and then reads enough bytes to fill `buffer` *in a
116
+ /// single transaction*
117
+ ///
118
+ /// # I2C Events (contract)
119
+ ///
120
+ /// Same as the `WriteRead` trait
121
+ fn write_iter_read < B > (
122
+ & mut self ,
123
+ address : u8 ,
124
+ bytes : B ,
125
+ buffer : & mut [ u8 ] ,
126
+ ) -> Result < ( ) , Self :: Error >
127
+ where
128
+ B : IntoIterator < Item = u8 > ;
129
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,18 @@ pub trait Write<W> {
18
18
fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Self :: Error > ;
19
19
}
20
20
21
+ /// Blocking write (iterator version)
22
+ #[ cfg( feature = "unproven" ) ]
23
+ pub trait WriteIter < W > {
24
+ /// Error type
25
+ type Error ;
26
+
27
+ /// Sends `words` to the slave, ignoring all the incoming words
28
+ fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , Self :: Error >
29
+ where
30
+ WI : IntoIterator < Item = W > ;
31
+ }
32
+
21
33
/// Blocking transfer
22
34
pub mod transfer {
23
35
/// Default implementation of `blocking::spi::Transfer<W>` for implementers of
@@ -64,3 +76,31 @@ pub mod write {
64
76
}
65
77
}
66
78
}
79
+
80
+ /// Blocking write (iterator version)
81
+ #[ cfg( feature = "unproven" ) ]
82
+ pub mod write_iter {
83
+ /// Default implementation of `blocking::spi::WriteIter<W>` for implementers of
84
+ /// `spi::FullDuplex<W>`
85
+ pub trait Default < W > : :: spi:: FullDuplex < W > { }
86
+
87
+ impl < W , S > :: blocking:: spi:: WriteIter < W > for S
88
+ where
89
+ S : Default < W > ,
90
+ W : Clone ,
91
+ {
92
+ type Error = S :: Error ;
93
+
94
+ fn write_iter < WI > ( & mut self , words : WI ) -> Result < ( ) , S :: Error >
95
+ where
96
+ WI : IntoIterator < Item = W > ,
97
+ {
98
+ for word in words. into_iter ( ) {
99
+ block ! ( self . send( word. clone( ) ) ) ?;
100
+ block ! ( self . read( ) ) ?;
101
+ }
102
+
103
+ Ok ( ( ) )
104
+ }
105
+ }
106
+ }
You can’t perform that action at this time.
0 commit comments