@@ -270,3 +270,54 @@ pub trait Transactional {
270
270
operations : & mut [ Operation < ' a > ] ,
271
271
) -> Result < ( ) , Self :: Error > ;
272
272
}
273
+
274
+ /// Default implementation of `blocking::i2c::Write`, `blocking::i2c::Read` and
275
+ /// `blocking::i2c::WriteRead` traits for `blocking::i2c::Transactional` implementers.
276
+ pub mod transactional {
277
+ use super :: { Operation , Read , Transactional , Write , WriteRead } ;
278
+
279
+ /// Default implementation of `blocking::i2c::Write`, `blocking::i2c::Read` and
280
+ /// `blocking::i2c::WriteRead` traits for `blocking::i2c::Transactional` implementers.
281
+ pub trait Default < E > { }
282
+
283
+ impl < E , S > Write for S
284
+ where
285
+ S : self :: Default < E > + Transactional < Error = E > ,
286
+ {
287
+ type Error = E ;
288
+
289
+ fn try_write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
290
+ self . try_exec ( address, & mut [ Operation :: Write ( bytes) ] )
291
+ }
292
+ }
293
+
294
+ impl < E , S > Read for S
295
+ where
296
+ S : self :: Default < E > + Transactional < Error = E > ,
297
+ {
298
+ type Error = E ;
299
+
300
+ fn try_read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
301
+ self . try_exec ( address, & mut [ Operation :: Read ( buffer) ] )
302
+ }
303
+ }
304
+
305
+ impl < E , S > WriteRead for S
306
+ where
307
+ S : self :: Default < E > + Transactional < Error = E > ,
308
+ {
309
+ type Error = E ;
310
+
311
+ fn try_write_read (
312
+ & mut self ,
313
+ address : u8 ,
314
+ bytes : & [ u8 ] ,
315
+ buffer : & mut [ u8 ] ,
316
+ ) -> Result < ( ) , Self :: Error > {
317
+ self . try_exec (
318
+ address,
319
+ & mut [ Operation :: Write ( bytes) , Operation :: Read ( buffer) ] ,
320
+ )
321
+ }
322
+ }
323
+ }
0 commit comments