41
41
//! // ...
42
42
//! # Ok(())
43
43
//! }
44
- //! fn transaction<'a> (&mut self, address: u8, operations: &mut [Operation<'a >]) -> Result<(), Self::Error> {
44
+ //! fn transaction(&mut self, address: u8, operations: &mut [Operation<'_ >]) -> Result<(), Self::Error> {
45
45
//! // ...
46
46
//! # Ok(())
47
47
//! }
61
61
//! // ...
62
62
//! # Ok(())
63
63
//! }
64
- //! fn transaction<'a> (&mut self, address: u16, operations: &mut [Operation<'a >]) -> Result<(), Self::Error> {
64
+ //! fn transaction(&mut self, address: u16, operations: &mut [Operation<'_ >]) -> Result<(), Self::Error> {
65
65
//! // ...
66
66
//! # Ok(())
67
67
//! }
@@ -232,7 +232,7 @@ impl AddressMode for SevenBitAddress {}
232
232
233
233
impl AddressMode for TenBitAddress { }
234
234
235
- /// Transactional I2C operation.
235
+ /// I2C operation.
236
236
///
237
237
/// Several operations can be combined as part of a transaction.
238
238
#[ derive( Debug , PartialEq , Eq ) ]
@@ -245,7 +245,7 @@ pub enum Operation<'a> {
245
245
246
246
/// Blocking I2C
247
247
pub trait I2c < A : AddressMode = SevenBitAddress > : ErrorType {
248
- /// Reads enough bytes from slave with `address` to fill `buffer `
248
+ /// Reads enough bytes from slave with `address` to fill `read `
249
249
///
250
250
/// # I2C Events (contract)
251
251
///
@@ -263,7 +263,9 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
263
263
/// - `MAK` = master acknowledge
264
264
/// - `NMAK` = master no acknowledge
265
265
/// - `SP` = stop condition
266
- fn read ( & mut self , address : A , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
266
+ fn read ( & mut self , address : A , read : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
267
+ self . transaction ( address, & mut [ Operation :: Read ( read) ] )
268
+ }
267
269
268
270
/// Writes bytes to slave with address `address`
269
271
///
@@ -281,9 +283,11 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
281
283
/// - `SAK` = slave acknowledge
282
284
/// - `Bi` = ith byte of data
283
285
/// - `SP` = stop condition
284
- fn write ( & mut self , address : A , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
286
+ fn write ( & mut self , address : A , write : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
287
+ self . transaction ( address, & mut [ Operation :: Write ( write) ] )
288
+ }
285
289
286
- /// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer ` *in a
290
+ /// Writes bytes to slave with address `address` and then reads enough bytes to fill `read ` *in a
287
291
/// single transaction*
288
292
///
289
293
/// # I2C Events (contract)
@@ -305,12 +309,12 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
305
309
/// - `MAK` = master acknowledge
306
310
/// - `NMAK` = master no acknowledge
307
311
/// - `SP` = stop condition
308
- fn write_read (
309
- & mut self ,
310
- address : A ,
311
- bytes : & [ u8 ] ,
312
- buffer : & mut [ u8 ] ,
313
- ) -> Result < ( ) , Self :: Error > ;
312
+ fn write_read ( & mut self , address : A , write : & [ u8 ] , read : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
313
+ self . transaction (
314
+ address ,
315
+ & mut [ Operation :: Write ( write ) , Operation :: Read ( read ) ] ,
316
+ )
317
+ }
314
318
315
319
/// Execute the provided operations on the I2C bus.
316
320
///
@@ -325,10 +329,10 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
325
329
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
326
330
/// - `SR` = repeated start condition
327
331
/// - `SP` = stop condition
328
- fn transaction < ' a > (
332
+ fn transaction (
329
333
& mut self ,
330
334
address : A ,
331
- operations : & mut [ Operation < ' a > ] ,
335
+ operations : & mut [ Operation < ' _ > ] ,
332
336
) -> Result < ( ) , Self :: Error > ;
333
337
}
334
338
@@ -350,10 +354,10 @@ impl<A: AddressMode, T: I2c<A>> I2c<A> for &mut T {
350
354
T :: write_read ( self , address, bytes, buffer)
351
355
}
352
356
353
- fn transaction < ' a > (
357
+ fn transaction (
354
358
& mut self ,
355
359
address : A ,
356
- operations : & mut [ Operation < ' a > ] ,
360
+ operations : & mut [ Operation < ' _ > ] ,
357
361
) -> Result < ( ) , Self :: Error > {
358
362
T :: transaction ( self , address, operations)
359
363
}
0 commit comments