@@ -62,25 +62,25 @@ mod embedded_hal_impl {
6262 use i2cdev:: linux:: LinuxI2CMessage ;
6363
6464 impl Read for I2cdev {
65- type Error = i2cdev :: linux :: LinuxI2CError ;
65+ type Error = I2CError ;
6666
6767 fn read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
6868 self . set_address ( address) ?;
69- self . inner . read ( buffer)
69+ self . inner . read ( buffer) . map_err ( |err| I2CError { err } )
7070 }
7171 }
7272
7373 impl Write for I2cdev {
74- type Error = i2cdev :: linux :: LinuxI2CError ;
74+ type Error = I2CError ;
7575
7676 fn write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
7777 self . set_address ( address) ?;
78- self . inner . write ( bytes)
78+ self . inner . write ( bytes) . map_err ( |err| I2CError { err } )
7979 }
8080 }
8181
8282 impl WriteRead for I2cdev {
83- type Error = i2cdev :: linux :: LinuxI2CError ;
83+ type Error = I2CError ;
8484
8585 fn write_read (
8686 & mut self ,
@@ -90,12 +90,15 @@ mod embedded_hal_impl {
9090 ) -> Result < ( ) , Self :: Error > {
9191 self . set_address ( address) ?;
9292 let mut messages = [ LinuxI2CMessage :: write ( bytes) , LinuxI2CMessage :: read ( buffer) ] ;
93- self . inner . transfer ( & mut messages) . map ( drop)
93+ self . inner
94+ . transfer ( & mut messages)
95+ . map ( drop)
96+ . map_err ( |err| I2CError { err } )
9497 }
9598 }
9699
97100 impl Transactional for I2cdev {
98- type Error = i2cdev :: linux :: LinuxI2CError ;
101+ type Error = I2CError ;
99102
100103 fn exec (
101104 & mut self ,
@@ -113,7 +116,71 @@ mod embedded_hal_impl {
113116 . collect ( ) ;
114117
115118 self . set_address ( address) ?;
116- self . inner . transfer ( & mut messages) . map ( drop)
119+ self . inner
120+ . transfer ( & mut messages)
121+ . map ( drop)
122+ . map_err ( |err| I2CError { err } )
123+ }
124+ }
125+ }
126+
127+ #[ derive( Debug ) ]
128+ pub struct I2CError {
129+ err : i2cdev:: linux:: LinuxI2CError ,
130+ }
131+
132+ impl From < i2cdev:: linux:: LinuxI2CError > for I2CError {
133+ fn from ( err : i2cdev:: linux:: LinuxI2CError ) -> Self {
134+ Self { err }
135+ }
136+ }
137+
138+ impl embedded_hal:: i2c:: Error for I2CError {
139+ fn kind ( & self ) -> embedded_hal:: i2c:: ErrorKind {
140+ use embedded_hal:: i2c:: ErrorKind :: * ;
141+ match & self . err {
142+ // IoErrorKind::NotFound => todo!(),
143+ // IoErrorKind::PermissionDenied => todo!(),
144+ // IoErrorKind::ConnectionRefused => todo!(),
145+ // IoErrorKind::ConnectionReset => todo!(),
146+ // IoErrorKind::HostUnreachable => todo!(),
147+ // IoErrorKind::NetworkUnreachable => todo!(),
148+ // IoErrorKind::ConnectionAborted => todo!(),
149+ // IoErrorKind::NotConnected => todo!(),
150+ // IoErrorKind::AddrInUse => todo!(),
151+ // IoErrorKind::AddrNotAvailable => todo!(),
152+ // IoErrorKind::NetworkDown => todo!(),
153+ // IoErrorKind::BrokenPipe => todo!(),
154+ // IoErrorKind::AlreadyExists => todo!(),
155+ // IoErrorKind::WouldBlock => todo!(),
156+ // IoErrorKind::NotADirectory => todo!(),
157+ // IoErrorKind::IsADirectory => todo!(),
158+ // IoErrorKind::DirectoryNotEmpty => todo!(),
159+ // IoErrorKind::ReadOnlyFilesystem => todo!(),
160+ // IoErrorKind::FilesystemLoop => todo!(),
161+ // IoErrorKind::StaleNetworkFileHandle => todo!(),
162+ // IoErrorKind::InvalidInput => todo!(),
163+ // IoErrorKind::InvalidData => todo!(),
164+ // IoErrorKind::TimedOut => todo!(),
165+ // IoErrorKind::WriteZero => todo!(),
166+ // IoErrorKind::StorageFull => todo!(),
167+ // IoErrorKind::NotSeekable => todo!(),
168+ // IoErrorKind::FilesystemQuotaExceeded => todo!(),
169+ // IoErrorKind::FileTooLarge => todo!(),
170+ // IoErrorKind::ResourceBusy => todo!(),
171+ // IoErrorKind::ExecutableFileBusy => todo!(),
172+ // IoErrorKind::Deadlock => todo!(),
173+ // IoErrorKind::CrossesDevices => todo!(),
174+ // IoErrorKind::TooManyLinks => todo!(),
175+ // IoErrorKind::FilenameTooLong => todo!(),
176+ // IoErrorKind::ArgumentListTooLong => todo!(),
177+ // IoErrorKind::Interrupted => todo!(),
178+ // IoErrorKind::Unsupported => todo!(),
179+ // IoErrorKind::UnexpectedEof => todo!(),
180+ // IoErrorKind::OutOfMemory => todo!(),
181+ // IoErrorKind::Other => todo!(),
182+ // IoErrorKind::Uncategorized => todo!(),
183+ _ => Other ,
117184 }
118185 }
119186}
0 commit comments