make I2C writes retry instead of unwrap-failing

This commit is contained in:
bunnie 2026-05-29 00:06:55 +08:00
parent 0b3b481322
commit 542bec7541

View file

@ -103,7 +103,18 @@ impl Gc2145 {
pub fn has_ifram(&self) -> bool { self.ifram.is_some() }
pub fn poke(&self, i2c: &mut dyn I2cApi, adr: u8, dat: u8) {
i2c.i2c_write(GC2145_DEV, adr, &[dat]).expect("write failed");
const MAX_RETRIES: usize = 3;
let mut retries = 0;
while retries < MAX_RETRIES {
match i2c.i2c_write(GC2145_DEV, adr, &[dat]) {
Ok(_) => break,
Err(_e) => {
#[cfg(feature = "std")]
log::warn!("I2C error in camera {}/{}: {:?}", retries + 1, MAX_RETRIES, _e);
retries += 1;
}
}
}
}
// chip does not support sequential reads