16
16
//! Since 7-bit addressing is the mode of the majority of I2C devices,
17
17
//! `SevenBitAddress` has been set as default mode and thus can be omitted if desired.
18
18
19
- use core:: future:: Future ;
20
- pub use crate :: blocking:: i2c:: { AddressMode , SevenBitAddress , TenBitAddress , Operation } ;
19
+ use core:: { future:: Future , mem :: MaybeUninit } ;
20
+ pub use crate :: blocking:: i2c:: { AddressMode , SevenBitAddress , TenBitAddress } ;
21
21
22
22
/// Async read
23
23
pub trait Read < A : AddressMode = SevenBitAddress > {
@@ -46,7 +46,7 @@ pub trait Read<A: AddressMode = SevenBitAddress> {
46
46
/// - `MAK` = master acknowledge
47
47
/// - `NMAK` = master no acknowledge
48
48
/// - `SP` = stop condition
49
- fn read < ' a > ( & ' a mut self , address : A , buffer : & ' a mut [ u8 ] ) -> Self :: ReadFuture < ' a > ;
49
+ fn read < ' a > ( & ' a mut self , address : A , read : & ' a mut [ MaybeUninit < u8 > ] ) -> Self :: ReadFuture < ' a > ;
50
50
}
51
51
52
52
/// Async write
@@ -74,7 +74,7 @@ pub trait Write<A: AddressMode = SevenBitAddress> {
74
74
/// - `SAK` = slave acknowledge
75
75
/// - `Bi` = ith byte of data
76
76
/// - `SP` = stop condition
77
- fn write < ' a > ( & ' a mut self , address : A , bytes : & ' a [ u8 ] ) -> Self :: WriteFuture < ' a > ;
77
+ fn write < ' a > ( & ' a mut self , address : A , write : & ' a [ u8 ] ) -> Self :: WriteFuture < ' a > ;
78
78
}
79
79
80
80
/// Async write + read
@@ -86,7 +86,7 @@ pub trait WriteRead<A: AddressMode = SevenBitAddress> {
86
86
where
87
87
Self : ' a ;
88
88
89
- /// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer ` *in a
89
+ /// Writes bytes to slave with address `address` and then reads enough bytes to fill `read ` *in a
90
90
/// single transaction*
91
91
///
92
92
/// # I2C Events (contract)
@@ -111,72 +111,7 @@ pub trait WriteRead<A: AddressMode = SevenBitAddress> {
111
111
fn write_read < ' a > (
112
112
& ' a mut self ,
113
113
address : A ,
114
- bytes : & ' a [ u8 ] ,
115
- buffer : & ' a mut [ u8 ] ,
114
+ write : & ' a [ u8 ] ,
115
+ read : & ' a mut [ MaybeUninit < u8 > ] ,
116
116
) -> Self :: WriteReadFuture < ' a > ;
117
117
}
118
-
119
- /// Transactional I2C interface.
120
- ///
121
- /// This allows combining operations within an I2C transaction.
122
- pub trait Transactional < A : AddressMode = SevenBitAddress > {
123
- /// Error type
124
- type Error ;
125
- /// The future associated with the `exec` method.
126
- type ExecFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > > + ' a
127
- where
128
- Self : ' a ;
129
-
130
- /// Execute the provided operations on the I2C bus.
131
- ///
132
- /// Transaction contract:
133
- /// - Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
134
- /// - Data from adjacent operations of the same type are sent after each other without an SP or SR.
135
- /// - Between adjacent operations of a different type an SR and SAD+R/W is sent.
136
- /// - After executing the last operation an SP is sent automatically.
137
- /// - If the last operation is a `Read` the master does not send an acknowledge for the last byte.
138
- ///
139
- /// - `ST` = start condition
140
- /// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
141
- /// - `SR` = repeated start condition
142
- /// - `SP` = stop condition
143
- fn exec < ' a > ( & ' a mut self , address : A , operations : & ' a mut [ Operation < ' a > ] )
144
- -> Self :: ExecFuture < ' a > ;
145
- }
146
-
147
- /// Default implementation of `futures::i2c::Transactional` for `futures::i2c::{Read, Write}` implementers.
148
- ///
149
- /// If you implement `futures::i2c::Read` and `futures::i2c::Write` for your I2C peripheral,
150
- /// you can use this default implementation so to automatically implement
151
- /// `futures::i2c::Transactional` as well.
152
- pub mod transactional {
153
- use super :: { Future , AddressMode , Operation , Read , Transactional , Write } ;
154
-
155
- /// Default implementation of `futures::i2c::Write`, `futures::i2c::Read` and
156
- /// `futures::i2c::WriteRead` traits for `futures::i2c::Transactional` implementers.
157
- pub trait Default < A : AddressMode > : Read < A > + Write < A > { }
158
-
159
- impl < A , E , S > Transactional < A > for S
160
- where
161
- A : AddressMode + Copy + ' static ,
162
- S : Default < A > + Read < A , Error = E > + Write < A , Error = E > ,
163
- E : ' static ,
164
- {
165
- type Error = E ;
166
-
167
- type ExecFuture < ' a > where Self : ' a = impl Future < Output = Result < ( ) , Self :: Error > > + ' a ;
168
-
169
- fn exec < ' a > ( & ' a mut self , address : A , operations : & ' a mut [ Operation < ' a > ] ) -> Self :: ExecFuture < ' a > {
170
- async move {
171
- for op in operations {
172
- match op {
173
- Operation :: Read ( buffer) => self . read ( address, buffer) . await ?,
174
- Operation :: Write ( buffer) => self . write ( address, buffer) . await ?,
175
- }
176
- }
177
-
178
- Ok ( ( ) )
179
- }
180
- }
181
- }
182
- }
0 commit comments