@@ -213,14 +213,17 @@ pub enum Error {
213
213
Arbitration ,
214
214
/// NACK received
215
215
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 {
217
222
/// Indicates that a stop or repeat start was received while reading, or
218
223
/// while explicitly waiting for a controller read or write event.
219
224
TransferStopped ,
220
- /// Target operation only:
221
225
/// While waiting for a controller read event, a write event was received.
222
226
ControllerExpectedWrite ,
223
- /// Target operation only:
224
227
/// While waiting for a controller write event, a read event was received.
225
228
ControllerExpectedRead ,
226
229
}
@@ -817,7 +820,7 @@ impl<I2C: Instance> Inner<I2C> {
817
820
} else if isr. stopf ( ) . is_stop ( ) || isr. addr ( ) . is_match ( ) {
818
821
// This is only relevant to Target operation, when the controller stops the read
819
822
// operation with a Stop or Restart condition.
820
- Err ( Error :: TransferStopped )
823
+ Err ( Error :: TargetError ( TargetError :: TransferStopped ) )
821
824
} else {
822
825
Ok ( false )
823
826
}
@@ -1127,7 +1130,7 @@ impl<I2C: Instance, A, R> I2cTarget<I2C, A, R> {
1127
1130
Ok ( data) => {
1128
1131
* byte = data;
1129
1132
}
1130
- Err ( Error :: TransferStopped ) => return Ok ( i) ,
1133
+ Err ( Error :: TargetError ( TargetError :: TransferStopped ) ) => return Ok ( i) ,
1131
1134
Err ( error) => return Err ( error) ,
1132
1135
} ;
1133
1136
}
@@ -1460,10 +1463,10 @@ where
1460
1463
) -> Result < usize , Error > {
1461
1464
match self . wait_for_event ( ) ? {
1462
1465
TargetEvent :: Read { address : _ } => {
1463
- Err ( Error :: ControllerExpectedWrite )
1466
+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedWrite ) )
1464
1467
}
1465
1468
TargetEvent :: Write { address : _ } => self . read ( buffer) ,
1466
- TargetEvent :: Stop => Err ( Error :: TransferStopped ) ,
1469
+ TargetEvent :: Stop => Err ( Error :: TargetError ( TargetError :: TransferStopped ) ) ,
1467
1470
}
1468
1471
}
1469
1472
@@ -1483,9 +1486,9 @@ where
1483
1486
match self . wait_for_event ( ) ? {
1484
1487
TargetEvent :: Read { address : _ } => self . write ( bytes) ,
1485
1488
TargetEvent :: Write { address : _ } => {
1486
- Err ( Error :: ControllerExpectedRead )
1489
+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedRead ) )
1487
1490
}
1488
- TargetEvent :: Stop => Err ( Error :: TransferStopped ) ,
1491
+ TargetEvent :: Stop => Err ( Error :: TargetError ( TargetError :: TransferStopped ) ) ,
1489
1492
}
1490
1493
}
1491
1494
@@ -1496,10 +1499,10 @@ where
1496
1499
pub fn wait_for_stop ( & mut self ) -> Result < ( ) , Error > {
1497
1500
match self . wait_for_event ( ) ? {
1498
1501
TargetEvent :: Read { address : _ } => {
1499
- Err ( Error :: ControllerExpectedWrite )
1502
+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedWrite ) )
1500
1503
}
1501
1504
TargetEvent :: Write { address : _ } => {
1502
- Err ( Error :: ControllerExpectedRead )
1505
+ Err ( Error :: TargetError ( TargetError :: ControllerExpectedRead ) )
1503
1506
}
1504
1507
TargetEvent :: Stop => Ok ( ( ) ) ,
1505
1508
}
0 commit comments