Skip to content

Commit

Permalink
Clippy + Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed Jan 7, 2025
1 parent e7278ac commit f9816b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
5 changes: 2 additions & 3 deletions esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2342,11 +2342,10 @@ fn estimate_ack_failed_reason(_register_block: &RegisterBlock) -> AcknowledgeChe
} else {
// this is based on observations rather than documented behavior
if _register_block.fifo_st().read().txfifo_raddr().bits() <= 1 {
return AcknowledgeCheckFailedReason::Address;
AcknowledgeCheckFailedReason::Address
} else {
return AcknowledgeCheckFailedReason::Data;
AcknowledgeCheckFailedReason::Data
}

}
}
}
Expand Down
27 changes: 20 additions & 7 deletions hil-test/tests/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ mod tests {

#[test]
fn empty_write_returns_ack_error_for_unknown_address(mut ctx: Context) {
// we don't specify the exact reason yet
assert_eq!(
ctx.i2c.write(NON_EXISTENT_ADDRESS, &[]),
Err(Error::AcknowledgeCheckFailed(
AcknowledgeCheckFailedReason::Unknown
))
);
// on some chips we can determine the ack-check-failed reason but not on all
// chips
cfg_if::cfg_if! {
if #[cfg(any(esp32,esp32s2,esp32c2,esp32c3))] {
assert_eq!(
ctx.i2c.write(NON_EXISTENT_ADDRESS, &[]),
Err(Error::AcknowledgeCheckFailed(
AcknowledgeCheckFailedReason::Unknown
))
);
} else {
assert_eq!(
ctx.i2c.write(NON_EXISTENT_ADDRESS, &[]),
Err(Error::AcknowledgeCheckFailed(
AcknowledgeCheckFailedReason::Address
))
);
}
}

assert_eq!(ctx.i2c.write(DUT_ADDRESS, &[]), Ok(()));
}

Expand Down

0 comments on commit f9816b4

Please sign in to comment.