mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
make I2C writes retry instead of unwrap-failing
This commit is contained in:
parent
0b3b481322
commit
542bec7541
1 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue