29
29
//! # impl ErrorType for I2c0 { type Error = ErrorKind; }
30
30
//! impl I2c<SevenBitAddress> for I2c0
31
31
//! {
32
- //! fn read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Self::Error> {
33
- //! // ...
34
- //! # Ok(())
35
- //! }
36
- //! fn write(&mut self, addr: u8, write: &[u8]) -> Result<(), Self::Error> {
37
- //! // ...
38
- //! # Ok(())
39
- //! }
40
- //! fn write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
41
- //! // ...
42
- //! # Ok(())
43
- //! }
44
32
//! fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> {
45
33
//! // ...
46
34
//! # Ok(())
49
37
//!
50
38
//! impl I2c<TenBitAddress> for I2c0
51
39
//! {
52
- //! fn read(&mut self, addr: u16, write: &mut [u8]) -> Result<(), Self::Error> {
53
- //! // ...
54
- //! # Ok(())
55
- //! }
56
- //! fn write(&mut self, addr: u16, read: &[u8]) -> Result<(), Self::Error> {
57
- //! // ...
58
- //! # Ok(())
59
- //! }
60
- //! fn write_read(&mut self, addr: u16, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
61
- //! // ...
62
- //! # Ok(())
63
- //! }
64
40
//! fn transaction(&mut self, address: u16, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> {
65
41
//! // ...
66
42
//! # Ok(())
@@ -232,7 +208,7 @@ impl AddressMode for SevenBitAddress {}
232
208
233
209
impl AddressMode for TenBitAddress { }
234
210
235
- /// Transactional I2C operation.
211
+ /// I2C operation.
236
212
///
237
213
/// Several operations can be combined as part of a transaction.
238
214
#[ derive( Debug , PartialEq , Eq ) ]
@@ -263,7 +239,9 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
263
239
/// - `MAK` = master acknowledge
264
240
/// - `NMAK` = master no acknowledge
265
241
/// - `SP` = stop condition
266
- fn read ( & mut self , address : A , read : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
242
+ fn read ( & mut self , address : A , read : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
243
+ self . transaction ( address, & mut [ Operation :: Read ( read) ] )
244
+ }
267
245
268
246
/// Writes bytes to slave with address `address`
269
247
///
@@ -281,7 +259,9 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
281
259
/// - `SAK` = slave acknowledge
282
260
/// - `Bi` = ith byte of data
283
261
/// - `SP` = stop condition
284
- fn write ( & mut self , address : A , write : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
262
+ fn write ( & mut self , address : A , write : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
263
+ self . transaction ( address, & mut [ Operation :: Write ( write) ] )
264
+ }
285
265
286
266
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `read` *in a
287
267
/// single transaction*
@@ -305,7 +285,12 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
305
285
/// - `MAK` = master acknowledge
306
286
/// - `NMAK` = master no acknowledge
307
287
/// - `SP` = stop condition
308
- fn write_read ( & mut self , address : A , write : & [ u8 ] , read : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
288
+ fn write_read ( & mut self , address : A , write : & [ u8 ] , read : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
289
+ self . transaction (
290
+ address,
291
+ & mut [ Operation :: Write ( write) , Operation :: Read ( read) ] ,
292
+ )
293
+ }
309
294
310
295
/// Execute the provided operations on the I2C bus.
311
296
///
0 commit comments