Skip to content

Commit

Permalink
fix setup_read() logic for 0 length reads.
Browse files Browse the repository at this point in the history
  • Loading branch information
liebman committed Aug 30, 2024
1 parent e6d8b32 commit 3742ed3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,12 @@ pub trait Instance: crate::private::Sealed {
let (max_len, initial_len) = if will_continue {
(255usize, buffer.len())
} else {
(254usize, buffer.len() - 1)
let len = if buffer.is_empty() {
0
} else {
buffer.len() - 1
};
(254usize, len)
};
if buffer.len() > max_len {
// we could support more by adding multiple read operations
Expand Down Expand Up @@ -1601,7 +1606,9 @@ pub trait Instance: crate::private::Sealed {
)?;
}

if !will_continue {
// If we are not continuing the read in the next operation we need to nack the
// last byte. But don't issue the read command if the buffer is empty!
if !will_continue && !buffer.is_empty() {
// this is the last read so we need to nack the last byte
// READ w/o ACK
add_cmd(
Expand Down

0 comments on commit 3742ed3

Please sign in to comment.