@@ -57,32 +57,32 @@ impl ops::DerefMut for I2cdev {
5757
5858mod embedded_hal_impl {
5959 use super :: * ;
60- use embedded_hal:: i2c:: blocking:: {
61- Operation as I2cOperation , Read , Transactional , Write , WriteRead ,
62- } ;
60+ use embedded_hal:: i2c:: blocking:: { I2c , Operation as I2cOperation } ;
61+ use embedded_hal:: i2c:: ErrorType ;
6362 use i2cdev:: core:: { I2CDevice , I2CMessage , I2CTransfer } ;
6463 use i2cdev:: linux:: LinuxI2CMessage ;
65-
66- impl Read for I2cdev {
64+ impl ErrorType for I2cdev {
6765 type Error = I2CError ;
66+ }
6867
68+ impl I2c for I2cdev {
6969 fn read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
7070 self . set_address ( address) ?;
7171 self . inner . read ( buffer) . map_err ( |err| I2CError { err } )
7272 }
73- }
74-
75- impl Write for I2cdev {
76- type Error = I2CError ;
7773
7874 fn write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
7975 self . set_address ( address) ?;
8076 self . inner . write ( bytes) . map_err ( |err| I2CError { err } )
8177 }
82- }
8378
84- impl WriteRead for I2cdev {
85- type Error = I2CError ;
79+ fn write_iter < B > ( & mut self , address : u8 , bytes : B ) -> Result < ( ) , Self :: Error >
80+ where
81+ B : IntoIterator < Item = u8 > ,
82+ {
83+ let bytes: Vec < _ > = bytes. into_iter ( ) . collect ( ) ;
84+ self . write ( address, & bytes)
85+ }
8686
8787 fn write_read (
8888 & mut self ,
@@ -97,12 +97,24 @@ mod embedded_hal_impl {
9797 . map ( drop)
9898 . map_err ( |err| I2CError { err } )
9999 }
100- }
101100
102- impl Transactional for I2cdev {
103- type Error = I2CError ;
101+ fn write_iter_read < B > (
102+ & mut self ,
103+ address : u8 ,
104+ bytes : B ,
105+ buffer : & mut [ u8 ] ,
106+ ) -> Result < ( ) , Self :: Error >
107+ where
108+ B : IntoIterator < Item = u8 > ,
109+ {
110+ let bytes: Vec < _ > = bytes. into_iter ( ) . collect ( ) ;
111+ self . transaction (
112+ address,
113+ & mut [ I2cOperation :: Write ( & bytes) , I2cOperation :: Read ( buffer) ] ,
114+ )
115+ }
104116
105- fn exec (
117+ fn transaction (
106118 & mut self ,
107119 address : u8 ,
108120 operations : & mut [ I2cOperation ] ,
@@ -123,6 +135,14 @@ mod embedded_hal_impl {
123135 . map ( drop)
124136 . map_err ( |err| I2CError { err } )
125137 }
138+
139+ fn transaction_iter < ' a , O > ( & mut self , address : u8 , operations : O ) -> Result < ( ) , Self :: Error >
140+ where
141+ O : IntoIterator < Item = I2cOperation < ' a > > ,
142+ {
143+ let mut ops: Vec < _ > = operations. into_iter ( ) . collect ( ) ;
144+ self . transaction ( address, & mut ops)
145+ }
126146 }
127147}
128148
0 commit comments