@@ -313,15 +313,8 @@ where
313313 let value = self . i2c . rxdr . read ( ) . bits ( ) as u8 ;
314314 Ok ( value)
315315 }
316- }
317-
318- impl < I2C , SCLPIN , SDAPIN > WriteRead for I2c < I2C , SCLPIN , SDAPIN >
319- where
320- I2C : Deref < Target = I2cRegisterBlock > ,
321- {
322- type Error = Error ;
323316
324- fn write_read ( & mut self , addr : u8 , bytes : & [ u8 ] , buffer : & mut [ u8 ] ) -> Result < ( ) , Error > {
317+ fn write_read_impl ( & mut self , addr : u8 , bytes : & [ u8 ] , buffer : & mut [ u8 ] ) -> Result < ( ) , Error > {
325318 // Set up current slave address for writing and disable autoending
326319 self . i2c . cr2 . modify ( |_, w| {
327320 w. sadd ( )
@@ -386,15 +379,8 @@ where
386379
387380 Ok ( ( ) )
388381 }
389- }
390382
391- impl < I2C , SCLPIN , SDAPIN > Read for I2c < I2C , SCLPIN , SDAPIN >
392- where
393- I2C : Deref < Target = I2cRegisterBlock > ,
394- {
395- type Error = Error ;
396-
397- fn read ( & mut self , addr : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Error > {
383+ fn read_impl ( & mut self , addr : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Error > {
398384 // Set up current address for reading
399385 self . i2c . cr2 . modify ( |_, w| {
400386 w. sadd ( )
@@ -421,15 +407,8 @@ where
421407
422408 Ok ( ( ) )
423409 }
424- }
425-
426- impl < I2C , SCLPIN , SDAPIN > Write for I2c < I2C , SCLPIN , SDAPIN >
427- where
428- I2C : Deref < Target = I2cRegisterBlock > ,
429- {
430- type Error = Error ;
431410
432- fn write ( & mut self , addr : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Error > {
411+ fn write_impl ( & mut self , addr : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Error > {
433412 // Set up current slave address for writing and enable autoending
434413 self . i2c . cr2 . modify ( |_, w| {
435414 w. sadd ( )
@@ -456,3 +435,93 @@ where
456435 Ok ( ( ) )
457436 }
458437}
438+
439+ impl < I2C , SCLPIN , SDAPIN > WriteRead for I2c < I2C , SCLPIN , SDAPIN >
440+ where
441+ I2C : Deref < Target = I2cRegisterBlock > ,
442+ {
443+ type Error = Error ;
444+
445+ fn write_read ( & mut self , addr : u8 , bytes : & [ u8 ] , buffer : & mut [ u8 ] ) -> Result < ( ) , Error > {
446+ self . write_read_impl ( addr, bytes, buffer)
447+ }
448+ }
449+
450+ impl < I2C , SCLPIN , SDAPIN > Read for I2c < I2C , SCLPIN , SDAPIN >
451+ where
452+ I2C : Deref < Target = I2cRegisterBlock > ,
453+ {
454+ type Error = Error ;
455+
456+ fn read ( & mut self , addr : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Error > {
457+ self . read_impl ( addr, buffer)
458+ }
459+ }
460+
461+ impl < I2C , SCLPIN , SDAPIN > Write for I2c < I2C , SCLPIN , SDAPIN >
462+ where
463+ I2C : Deref < Target = I2cRegisterBlock > ,
464+ {
465+ type Error = Error ;
466+
467+ fn write ( & mut self , addr : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Error > {
468+ self . write_impl ( addr, bytes)
469+ }
470+ }
471+
472+ impl < I2C , SCLPIN , SDAPIN > embedded_hal_1:: i2c:: I2c for I2c < I2C , SCLPIN , SDAPIN >
473+ where
474+ I2C : Deref < Target = I2cRegisterBlock > ,
475+ {
476+ fn read (
477+ & mut self ,
478+ address : embedded_hal_1:: i2c:: SevenBitAddress ,
479+ read : & mut [ u8 ] ,
480+ ) -> Result < ( ) , Self :: Error > {
481+ self . read_impl ( address, read)
482+ }
483+
484+ fn write (
485+ & mut self ,
486+ address : embedded_hal_1:: i2c:: SevenBitAddress ,
487+ write : & [ u8 ] ,
488+ ) -> Result < ( ) , Self :: Error > {
489+ self . write_impl ( address, write)
490+ }
491+
492+ fn write_read (
493+ & mut self ,
494+ address : embedded_hal_1:: i2c:: SevenBitAddress ,
495+ write : & [ u8 ] ,
496+ read : & mut [ u8 ] ,
497+ ) -> Result < ( ) , Self :: Error > {
498+ self . write_read_impl ( address, write, read)
499+ }
500+
501+ fn transaction (
502+ & mut self ,
503+ _address : embedded_hal_1:: i2c:: SevenBitAddress ,
504+ _operations : & mut [ embedded_hal_1:: i2c:: Operation < ' _ > ] ,
505+ ) -> Result < ( ) , Self :: Error > {
506+ todo ! ( )
507+ }
508+ }
509+
510+ impl < I2C , SCLPIN , SDAPIN > embedded_hal_1:: i2c:: ErrorType for I2c < I2C , SCLPIN , SDAPIN >
511+ where
512+ I2C : Deref < Target = I2cRegisterBlock > ,
513+ {
514+ type Error = Error ;
515+ }
516+
517+ impl embedded_hal_1:: i2c:: Error for Error {
518+ fn kind ( & self ) -> embedded_hal_1:: i2c:: ErrorKind {
519+ match self {
520+ Error :: OVERRUN => embedded_hal_1:: i2c:: ErrorKind :: Overrun ,
521+ Error :: NACK => embedded_hal_1:: i2c:: ErrorKind :: NoAcknowledge (
522+ embedded_hal_1:: i2c:: NoAcknowledgeSource :: Unknown ,
523+ ) ,
524+ Error :: BUS => embedded_hal_1:: i2c:: ErrorKind :: Bus ,
525+ }
526+ }
527+ }
0 commit comments