diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-30 07:52:49 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-30 07:52:49 +0000 |
| commit | 94c6727b3fccd39093eb6eb61d8505f63b082d2c (patch) | |
| tree | 754e5e3689d5c3e3cb3321e693a6385315662fa9 | |
| parent | 3e730aa8b06401003202bf9e21a9c83ec6b21b0e (diff) | |
| parent | ba886b45b8a78d4fd3f2442607d515fc024eff1b (diff) | |
Merge #1410
1410: Add `Transactional` trait to rp's i2c impl r=Dirbaio a=DasLixou
Fixes #1409
Co-authored-by: Lixou <[email protected]>
Co-authored-by: xoviat <[email protected]>
| -rw-r--r-- | embassy-rp/src/i2c.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 40e85c66f..cd5364393 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -617,6 +617,28 @@ mod eh02 { | |||
| 617 | self.blocking_write_read(address, bytes, buffer) | 617 | self.blocking_write_read(address, bytes, buffer) |
| 618 | } | 618 | } |
| 619 | } | 619 | } |
| 620 | |||
| 621 | impl<'d, T: Instance, M: Mode> embedded_hal_02::blocking::i2c::Transactional for I2c<'d, T, M> { | ||
| 622 | type Error = Error; | ||
| 623 | |||
| 624 | fn exec( | ||
| 625 | &mut self, | ||
| 626 | address: u8, | ||
| 627 | operations: &mut [embedded_hal_02::blocking::i2c::Operation<'_>], | ||
| 628 | ) -> Result<(), Self::Error> { | ||
| 629 | Self::setup(address.into())?; | ||
| 630 | for i in 0..operations.len() { | ||
| 631 | let last = i == operations.len() - 1; | ||
| 632 | match &mut operations[i] { | ||
| 633 | embedded_hal_02::blocking::i2c::Operation::Read(buf) => { | ||
| 634 | self.read_blocking_internal(buf, false, last)? | ||
| 635 | } | ||
| 636 | embedded_hal_02::blocking::i2c::Operation::Write(buf) => self.write_blocking_internal(buf, last)?, | ||
| 637 | } | ||
| 638 | } | ||
| 639 | Ok(()) | ||
| 640 | } | ||
| 641 | } | ||
| 620 | } | 642 | } |
| 621 | 643 | ||
| 622 | #[cfg(feature = "unstable-traits")] | 644 | #[cfg(feature = "unstable-traits")] |
