mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 22:55:26 +00:00
Add i2c blocking timeout test, unwrap results (#3567)
* Add blocking timeout test * Don't ignore return values
This commit is contained in:
parent
13b46968f3
commit
f5305a6686
@ -112,12 +112,12 @@ mod tests {
|
|||||||
// state
|
// state
|
||||||
ctx.i2c
|
ctx.i2c
|
||||||
.write_read(NON_EXISTENT_ADDRESS, &[0xaa], &mut read_data)
|
.write_read(NON_EXISTENT_ADDRESS, &[0xaa], &mut read_data)
|
||||||
.ok();
|
.expect_err("Expected error for non-existent address");
|
||||||
|
|
||||||
// do the real read which should succeed
|
// do the real read which should succeed
|
||||||
ctx.i2c
|
ctx.i2c
|
||||||
.write_read(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
.write_read(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
||||||
.ok();
|
.unwrap();
|
||||||
|
|
||||||
assert_ne!(read_data, [0u8; 22])
|
assert_ne!(read_data, [0u8; 22])
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ mod tests {
|
|||||||
Operation::Read(&mut read_data),
|
Operation::Read(&mut read_data),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.ok();
|
.unwrap();
|
||||||
|
|
||||||
assert_ne!(read_data, [0u8; 22])
|
assert_ne!(read_data, [0u8; 22])
|
||||||
}
|
}
|
||||||
@ -167,12 +167,12 @@ mod tests {
|
|||||||
// state
|
// state
|
||||||
i2c.write_read_async(NON_EXISTENT_ADDRESS, &[0xaa], &mut read_data)
|
i2c.write_read_async(NON_EXISTENT_ADDRESS, &[0xaa], &mut read_data)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.expect_err("Expected error for non-existent address");
|
||||||
|
|
||||||
// do the real read which should succeed
|
// do the real read which should succeed
|
||||||
i2c.write_read_async(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
i2c.write_read_async(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.unwrap();
|
||||||
|
|
||||||
assert_ne!(read_data, [0u8; 22])
|
assert_ne!(read_data, [0u8; 22])
|
||||||
}
|
}
|
||||||
@ -191,11 +191,25 @@ mod tests {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.unwrap();
|
||||||
|
|
||||||
assert_ne!(read_data, [0u8; 22])
|
assert_ne!(read_data, [0u8; 22])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is still an issue on ESP32-S2
|
||||||
|
#[cfg(not(esp32s2))]
|
||||||
|
#[test]
|
||||||
|
async fn test_timeout_when_scl_kept_low(ctx: Context) {
|
||||||
|
let mut i2c = ctx.i2c.into_async();
|
||||||
|
|
||||||
|
esp_hal::gpio::InputSignal::I2CEXT0_SCL.connect_to(&esp_hal::gpio::Level::Low);
|
||||||
|
|
||||||
|
let mut read_data = [0u8; 22];
|
||||||
|
// will run into an error but it should return at least
|
||||||
|
i2c.write_read(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
||||||
|
.expect_err("Expected timeout error");
|
||||||
|
}
|
||||||
|
|
||||||
// This is still an issue on ESP32-S2
|
// This is still an issue on ESP32-S2
|
||||||
#[cfg(not(esp32s2))]
|
#[cfg(not(esp32s2))]
|
||||||
#[test]
|
#[test]
|
||||||
@ -208,7 +222,7 @@ mod tests {
|
|||||||
// will run into an error but it should return at least
|
// will run into an error but it should return at least
|
||||||
i2c.write_read_async(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
i2c.write_read_async(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.expect_err("Expected timeout error");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user