@@ -213,14 +213,17 @@ pub enum Error {
213213 Arbitration ,
214214 /// NACK received
215215 NotAcknowledge ,
216- /// Target operation only:
216+ /// Target error occurred. Can be ignored during controller operation.
217+ TargetError ( TargetError ) ,
218+ }
219+
220+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
221+ pub enum TargetError {
217222 /// Indicates that a stop or repeat start was received while reading, or
218223 /// while explicitly waiting for a controller read or write event.
219224 TransferStopped ,
220- /// Target operation only:
221225 /// While waiting for a controller read event, a write event was received.
222226 ControllerExpectedWrite ,
223- /// Target operation only:
224227 /// While waiting for a controller write event, a read event was received.
225228 ControllerExpectedRead ,
226229}
@@ -817,7 +820,7 @@ impl<I2C: Instance> Inner<I2C> {
817820 } else if isr. stopf ( ) . is_stop ( ) || isr. addr ( ) . is_match ( ) {
818821 // This is only relevant to Target operation, when the controller stops the read
819822 // operation with a Stop or Restart condition.
820- Err ( Error :: TransferStopped )
823+ Err ( Error :: TargetError ( TargetError :: TransferStopped ) )
821824 } else {
822825 Ok ( false )
823826 }
@@ -1127,7 +1130,7 @@ impl<I2C: Instance, A, R> I2cTarget<I2C, A, R> {
11271130 Ok ( data) => {
11281131 * byte = data;
11291132 }
1130- Err ( Error :: TransferStopped ) => return Ok ( i) ,
1133+ Err ( Error :: TargetError ( TargetError :: TransferStopped ) ) => return Ok ( i) ,
11311134 Err ( error) => return Err ( error) ,
11321135 } ;
11331136 }
@@ -1460,10 +1463,10 @@ where
14601463 ) -> Result < usize , Error > {
14611464 match self . wait_for_event ( ) ? {
14621465 TargetEvent :: Read { address : _ } => {
1463- Err ( Error :: ControllerExpectedWrite )
1466+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedWrite ) )
14641467 }
14651468 TargetEvent :: Write { address : _ } => self . read ( buffer) ,
1466- TargetEvent :: Stop => Err ( Error :: TransferStopped ) ,
1469+ TargetEvent :: Stop => Err ( Error :: TargetError ( TargetError :: TransferStopped ) ) ,
14671470 }
14681471 }
14691472
@@ -1483,9 +1486,9 @@ where
14831486 match self . wait_for_event ( ) ? {
14841487 TargetEvent :: Read { address : _ } => self . write ( bytes) ,
14851488 TargetEvent :: Write { address : _ } => {
1486- Err ( Error :: ControllerExpectedRead )
1489+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedRead ) )
14871490 }
1488- TargetEvent :: Stop => Err ( Error :: TransferStopped ) ,
1491+ TargetEvent :: Stop => Err ( Error :: TargetError ( TargetError :: TransferStopped ) ) ,
14891492 }
14901493 }
14911494
@@ -1496,10 +1499,10 @@ where
14961499 pub fn wait_for_stop ( & mut self ) -> Result < ( ) , Error > {
14971500 match self . wait_for_event ( ) ? {
14981501 TargetEvent :: Read { address : _ } => {
1499- Err ( Error :: ControllerExpectedWrite )
1502+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedWrite ) )
15001503 }
15011504 TargetEvent :: Write { address : _ } => {
1502- Err ( Error :: ControllerExpectedRead )
1505+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedRead ) )
15031506 }
15041507 TargetEvent :: Stop => Ok ( ( ) ) ,
15051508 }
0 commit comments