@@ -49,9 +49,13 @@ impl EcI2cPassthruResponse {
4949 if self . i2c_status & ( 1 << 1 ) > 0 {
5050 return Err ( EcError :: DeviceError ( "I2C Transfer timeout" . to_string ( ) ) ) ;
5151 }
52- // I'm not aware of any other errors, but there might be.
53- // But I don't think multiple errors can be indicated at the same time
54- assert_eq ! ( self . i2c_status, 0 ) ;
52+ // Check for any other unknown error bits
53+ if self . i2c_status != 0 {
54+ return Err ( EcError :: DeviceError ( format ! (
55+ "I2C Transfer failed with unknown status: 0x{:02X}" ,
56+ self . i2c_status
57+ ) ) ) ;
58+ }
5559 Ok ( ( ) )
5660 }
5761}
@@ -221,7 +225,13 @@ pub fn i2c_write_block(
221225 let data = ec. send_command ( EcCommands :: I2cPassthrough as u16 , 0 , & buffer) ?;
222226 let res: _EcI2cPassthruResponse = unsafe { std:: ptr:: read ( data. as_ptr ( ) as * const _ ) } ;
223227 util:: assert_win_len ( data. len ( ) , size_of :: < _EcI2cPassthruResponse > ( ) ) ; // No extra data other than the header
224- debug_assert_eq ! ( res. messages as usize , messages. len( ) ) ;
228+
229+ // Only assert message count if the transfer was successful
230+ // On error (NAK/timeout), the EC may return 0 messages processed
231+ if res. i2c_status == 0 {
232+ debug_assert_eq ! ( res. messages as usize , messages. len( ) ) ;
233+ }
234+
225235 Ok ( EcI2cPassthruResponse {
226236 i2c_status : res. i2c_status ,
227237 data : vec ! [ ] , // Writing doesn't return any data
@@ -267,7 +277,13 @@ pub fn i2c_write(
267277 let data = ec. send_command ( EcCommands :: I2cPassthrough as u16 , 0 , & buffer) ?;
268278 let res: _EcI2cPassthruResponse = unsafe { std:: ptr:: read ( data. as_ptr ( ) as * const _ ) } ;
269279 util:: assert_win_len ( data. len ( ) , size_of :: < _EcI2cPassthruResponse > ( ) ) ; // No extra data other than the header
270- debug_assert_eq ! ( res. messages as usize , messages. len( ) ) ;
280+
281+ // Only assert message count if the transfer was successful
282+ // On error (NAK/timeout), the EC may return 0 messages processed
283+ if res. i2c_status == 0 {
284+ debug_assert_eq ! ( res. messages as usize , messages. len( ) ) ;
285+ }
286+
271287 Ok ( EcI2cPassthruResponse {
272288 i2c_status : res. i2c_status ,
273289 data : vec ! [ ] , // Writing doesn't return any data
0 commit comments