Skip to content

Commit

Permalink
don't short circuit a 0 length write operation if stop=true
Browse files Browse the repository at this point in the history
  • Loading branch information
liebman committed Sep 5, 2024
1 parent 5acc300 commit 4e6dbab
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,9 @@ mod asynch {
where
I: Iterator<Item = &'a COMD>,
{
// Short circuit for zero length writes without start as that would be an
// Short circuit for zero length writes without start or end as that would be an
// invalid operation write lengths in the TRM (at least for ESP32-S3) are 1-255
if bytes.is_empty() && !start {
if bytes.is_empty() && !start && !stop {
return Ok(());
}

Expand Down Expand Up @@ -1516,10 +1516,6 @@ pub trait Instance: crate::private::Sealed {
where
I: Iterator<Item = &'a COMD>,
{
if bytes.is_empty() && !start {
return Err(Error::InvalidZeroLength);
}

// if start is true we can only send 254 additional bytes with the address as
// the first
let max_len = if start { 254usize } else { 255usize };
Expand All @@ -1528,16 +1524,19 @@ pub trait Instance: crate::private::Sealed {
return Err(Error::ExceedingFifo);
}

let extra_len = if start { 1 } else { 0 };
// WRITE command
add_cmd(
cmd_iterator,
Command::Write {
ack_exp: Ack::Ack,
ack_check_en: true,
length: extra_len + bytes.len() as u8,
},
)?;
let write_len = if start { bytes.len() + 1 } else { bytes.len() };
// don't issue write if there is no data to write
if write_len > 0 {
// WRITE command
add_cmd(
cmd_iterator,
Command::Write {
ack_exp: Ack::Ack,
ack_check_en: true,
length: write_len as u8,
},
)?;
}

self.update_config();

Expand Down Expand Up @@ -1986,9 +1985,9 @@ pub trait Instance: crate::private::Sealed {
where
I: Iterator<Item = &'a COMD>,
{
// Short circuit for zero length writes without start as that would be an
// Short circuit for zero length writes without start or end as that would be an
// invalid operation write lengths in the TRM (at least for ESP32-S3) are 1-255
if bytes.is_empty() && !start {
if bytes.is_empty() && !start && !stop {
return Ok(());
}

Expand Down

0 comments on commit 4e6dbab

Please sign in to comment.