@@ -27,14 +27,11 @@ pub use gpio_cdev;
27
27
28
28
use core:: convert:: Infallible ;
29
29
use std:: io:: { self , Write } ;
30
- use std:: path:: { Path , PathBuf } ;
30
+ use std:: path:: Path ;
31
31
use std:: time:: Duration ;
32
32
use std:: { ops, thread} ;
33
33
34
34
use cast:: { u32, u64} ;
35
- use embedded_hal:: blocking:: i2c:: Operation as I2cOperation ;
36
- use i2cdev:: core:: { I2CDevice , I2CMessage , I2CTransfer } ;
37
- use i2cdev:: linux:: LinuxI2CMessage ;
38
35
use spidev:: SpidevTransfer ;
39
36
40
37
mod serial;
@@ -139,109 +136,8 @@ impl embedded_hal::blocking::delay::DelayMs<u64> for Delay {
139
136
}
140
137
}
141
138
142
- /// Newtype around [`i2cdev::linux::LinuxI2CDevice`] that implements the `embedded-hal` traits
143
- ///
144
- /// [`i2cdev::linux::LinuxI2CDevice`]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html
145
- pub struct I2cdev {
146
- inner : i2cdev:: linux:: LinuxI2CDevice ,
147
- path : PathBuf ,
148
- address : Option < u8 > ,
149
- }
150
-
151
- impl I2cdev {
152
- /// See [`i2cdev::linux::LinuxI2CDevice::new`][0] for details.
153
- ///
154
- /// [0]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html#method.new
155
- pub fn new < P > ( path : P ) -> Result < Self , i2cdev:: linux:: LinuxI2CError >
156
- where
157
- P : AsRef < Path > ,
158
- {
159
- let dev = I2cdev {
160
- path : path. as_ref ( ) . to_path_buf ( ) ,
161
- inner : i2cdev:: linux:: LinuxI2CDevice :: new ( path, 0 ) ?,
162
- address : None ,
163
- } ;
164
- Ok ( dev)
165
- }
166
-
167
- fn set_address ( & mut self , address : u8 ) -> Result < ( ) , i2cdev:: linux:: LinuxI2CError > {
168
- if self . address != Some ( address) {
169
- self . inner = i2cdev:: linux:: LinuxI2CDevice :: new ( & self . path , u16:: from ( address) ) ?;
170
- self . address = Some ( address) ;
171
- }
172
- Ok ( ( ) )
173
- }
174
- }
175
-
176
- impl embedded_hal:: blocking:: i2c:: Read for I2cdev {
177
- type Error = i2cdev:: linux:: LinuxI2CError ;
178
-
179
- fn try_read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
180
- self . set_address ( address) ?;
181
- self . inner . read ( buffer)
182
- }
183
- }
184
-
185
- impl embedded_hal:: blocking:: i2c:: Write for I2cdev {
186
- type Error = i2cdev:: linux:: LinuxI2CError ;
187
-
188
- fn try_write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
189
- self . set_address ( address) ?;
190
- self . inner . write ( bytes)
191
- }
192
- }
193
-
194
- impl embedded_hal:: blocking:: i2c:: WriteRead for I2cdev {
195
- type Error = i2cdev:: linux:: LinuxI2CError ;
196
-
197
- fn try_write_read (
198
- & mut self ,
199
- address : u8 ,
200
- bytes : & [ u8 ] ,
201
- buffer : & mut [ u8 ] ,
202
- ) -> Result < ( ) , Self :: Error > {
203
- self . set_address ( address) ?;
204
- let mut messages = [ LinuxI2CMessage :: write ( bytes) , LinuxI2CMessage :: read ( buffer) ] ;
205
- self . inner . transfer ( & mut messages) . map ( drop)
206
- }
207
- }
208
-
209
- impl embedded_hal:: blocking:: i2c:: Transactional for I2cdev {
210
- type Error = i2cdev:: linux:: LinuxI2CError ;
211
-
212
- fn try_exec (
213
- & mut self ,
214
- address : u8 ,
215
- operations : & mut [ I2cOperation ] ,
216
- ) -> Result < ( ) , Self :: Error > {
217
- // Map operations from generic to linux objects
218
- let mut messages: Vec < _ > = operations
219
- . as_mut ( )
220
- . iter_mut ( )
221
- . map ( |a| match a {
222
- I2cOperation :: Write ( w) => LinuxI2CMessage :: write ( w) ,
223
- I2cOperation :: Read ( r) => LinuxI2CMessage :: read ( r) ,
224
- } )
225
- . collect ( ) ;
226
-
227
- self . set_address ( address) ?;
228
- self . inner . transfer ( & mut messages) . map ( drop)
229
- }
230
- }
231
-
232
- impl ops:: Deref for I2cdev {
233
- type Target = i2cdev:: linux:: LinuxI2CDevice ;
234
-
235
- fn deref ( & self ) -> & Self :: Target {
236
- & self . inner
237
- }
238
- }
239
-
240
- impl ops:: DerefMut for I2cdev {
241
- fn deref_mut ( & mut self ) -> & mut Self :: Target {
242
- & mut self . inner
243
- }
244
- }
139
+ mod i2c;
140
+ pub use crate :: i2c:: I2cdev ;
245
141
246
142
/// Newtype around [`spidev::Spidev`] that implements the `embedded-hal` traits
247
143
///
0 commit comments