diff options
| author | Alex Ferro <[email protected]> | 2023-07-16 19:59:35 -0600 |
|---|---|---|
| committer | Alex Ferro <[email protected]> | 2023-07-16 19:59:35 -0600 |
| commit | e4ad1aa542ad28bed23532b3a0bee0d062454516 (patch) | |
| tree | 7b5bbcc3bb2b5f02d3d14b7782e0578f8a131518 | |
| parent | 6b5df4523aa1c4902f02e803450ae4b418e0e3ca (diff) | |
Embassy-rp I2C: Fix 1664
Change embassy-rp i2c.rs impl of embedded_hal_async::i2c::I2c::transaction
to only do the call to setup() for address once per call to transactions.
Calling setup multiple times results in I2C transactions being skipped
on the bus, even across calls to transaction() or devices.
| -rw-r--r-- | embassy-rp/src/i2c.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 791c64554..9b85b2345 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -716,6 +716,9 @@ mod nightly { | |||
| 716 | async fn transaction(&mut self, address: A, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> { | 716 | async fn transaction(&mut self, address: A, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> { |
| 717 | let addr: u16 = address.into(); | 717 | let addr: u16 = address.into(); |
| 718 | 718 | ||
| 719 | if operations.len() > 0 { | ||
| 720 | Self::setup(addr)?; | ||
| 721 | } | ||
| 719 | let mut iterator = operations.iter_mut(); | 722 | let mut iterator = operations.iter_mut(); |
| 720 | 723 | ||
| 721 | while let Some(op) = iterator.next() { | 724 | while let Some(op) = iterator.next() { |
| @@ -723,11 +726,9 @@ mod nightly { | |||
| 723 | 726 | ||
| 724 | match op { | 727 | match op { |
| 725 | Operation::Read(buffer) => { | 728 | Operation::Read(buffer) => { |
| 726 | Self::setup(addr)?; | ||
| 727 | self.read_async_internal(buffer, false, last).await?; | 729 | self.read_async_internal(buffer, false, last).await?; |
| 728 | } | 730 | } |
| 729 | Operation::Write(buffer) => { | 731 | Operation::Write(buffer) => { |
| 730 | Self::setup(addr)?; | ||
| 731 | self.write_async_internal(buffer.into_iter().cloned(), last).await?; | 732 | self.write_async_internal(buffer.into_iter().cloned(), last).await?; |
| 732 | } | 733 | } |
| 733 | } | 734 | } |
