From ca8afacfd07b24c27441f5a4ea1d66719fd50038 Mon Sep 17 00:00:00 2001 From: chemicstry Date: Mon, 24 Oct 2022 22:11:15 +0300 Subject: [PATCH] Implement TimeoutI2c for i2cv2 --- embassy-stm32/src/i2c/mod.rs | 4 ++-- embassy-stm32/src/i2c/timeout.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 1dffbd10a..f898fcc8b 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -7,9 +7,9 @@ use crate::interrupt::Interrupt; mod _version; pub use _version::*; -#[cfg(all(i2c_v1, feature = "time"))] +#[cfg(feature = "time")] mod timeout; -#[cfg(all(i2c_v1, feature = "time"))] +#[cfg(feature = "time")] pub use timeout::*; use crate::peripherals; diff --git a/embassy-stm32/src/i2c/timeout.rs b/embassy-stm32/src/i2c/timeout.rs index c4c035b42..fd9a753a5 100644 --- a/embassy-stm32/src/i2c/timeout.rs +++ b/embassy-stm32/src/i2c/timeout.rs @@ -3,8 +3,8 @@ use embassy_time::{Duration, Instant}; use super::{Error, I2c, Instance}; /// An I2C wrapper, which provides `embassy-time` based timeouts for all `embedded-hal` trait methods. -pub struct TimeoutI2c<'d, T: Instance> { - i2c: &'d mut I2c<'d, T>, +pub struct TimeoutI2c<'d, T: Instance, TXDMA, RXDMA> { + i2c: &'d mut I2c<'d, T, TXDMA, RXDMA>, timeout: Duration, } @@ -19,8 +19,8 @@ fn timeout_fn(timeout: Duration) -> impl Fn() -> Result<(), Error> { } } -impl<'d, T: Instance> TimeoutI2c<'d, T> { - pub fn new(i2c: &'d mut I2c<'d, T>, timeout: Duration) -> Self { +impl<'d, T: Instance, TXDMA, RXDMA> TimeoutI2c<'d, T, TXDMA, RXDMA> { + pub fn new(i2c: &'d mut I2c<'d, T, TXDMA, RXDMA>, timeout: Duration) -> Self { Self { i2c, timeout } } @@ -62,7 +62,7 @@ impl<'d, T: Instance> TimeoutI2c<'d, T> { } } -impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T> { +impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T, TXDMA, RXDMA> { type Error = Error; fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { @@ -70,7 +70,7 @@ impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T> } } -impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T> { +impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T, TXDMA, RXDMA> { type Error = Error; fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { @@ -78,7 +78,7 @@ impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T } } -impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<'d, T> { +impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<'d, T, TXDMA, RXDMA> { type Error = Error; fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { @@ -90,11 +90,11 @@ impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<' mod eh1 { use super::*; - impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for TimeoutI2c<'d, T> { + impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for TimeoutI2c<'d, T, TXDMA, RXDMA> { type Error = Error; } - impl<'d, T: Instance> embedded_hal_1::i2c::I2c for TimeoutI2c<'d, T> { + impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::I2c for TimeoutI2c<'d, T, TXDMA, RXDMA> { fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { self.blocking_read(address, buffer) }