aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemicstry <[email protected]>2022-10-24 22:11:15 +0300
committerchemicstry <[email protected]>2022-10-24 22:11:15 +0300
commitca8afacfd07b24c27441f5a4ea1d66719fd50038 (patch)
tree745da01e15f5f3a9b4b27ae96f0f353b537744d7
parent9ad7e8528831cb88e77c0efcf98944fecfe88848 (diff)
Implement TimeoutI2c for i2cv2
-rw-r--r--embassy-stm32/src/i2c/mod.rs4
-rw-r--r--embassy-stm32/src/i2c/timeout.rs18
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;
7mod _version; 7mod _version;
8pub use _version::*; 8pub use _version::*;
9 9
10#[cfg(all(i2c_v1, feature = "time"))] 10#[cfg(feature = "time")]
11mod timeout; 11mod timeout;
12#[cfg(all(i2c_v1, feature = "time"))] 12#[cfg(feature = "time")]
13pub use timeout::*; 13pub use timeout::*;
14 14
15use crate::peripherals; 15use 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};
3use super::{Error, I2c, Instance}; 3use super::{Error, I2c, Instance};
4 4
5/// An I2C wrapper, which provides `embassy-time` based timeouts for all `embedded-hal` trait methods. 5/// An I2C wrapper, which provides `embassy-time` based timeouts for all `embedded-hal` trait methods.
6pub struct TimeoutI2c<'d, T: Instance> { 6pub struct TimeoutI2c<'d, T: Instance, TXDMA, RXDMA> {
7 i2c: &'d mut I2c<'d, T>, 7 i2c: &'d mut I2c<'d, T, TXDMA, RXDMA>,
8 timeout: Duration, 8 timeout: Duration,
9} 9}
10 10
@@ -19,8 +19,8 @@ fn timeout_fn(timeout: Duration) -> impl Fn() -> Result<(), Error> {
19 } 19 }
20} 20}
21 21
22impl<'d, T: Instance> TimeoutI2c<'d, T> { 22impl<'d, T: Instance, TXDMA, RXDMA> TimeoutI2c<'d, T, TXDMA, RXDMA> {
23 pub fn new(i2c: &'d mut I2c<'d, T>, timeout: Duration) -> Self { 23 pub fn new(i2c: &'d mut I2c<'d, T, TXDMA, RXDMA>, timeout: Duration) -> Self {
24 Self { i2c, timeout } 24 Self { i2c, timeout }
25 } 25 }
26 26
@@ -62,7 +62,7 @@ impl<'d, T: Instance> TimeoutI2c<'d, T> {
62 } 62 }
63} 63}
64 64
65impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T> { 65impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Read for TimeoutI2c<'d, T, TXDMA, RXDMA> {
66 type Error = Error; 66 type Error = Error;
67 67
68 fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { 68 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>
70 } 70 }
71} 71}
72 72
73impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T> { 73impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Write for TimeoutI2c<'d, T, TXDMA, RXDMA> {
74 type Error = Error; 74 type Error = Error;
75 75
76 fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { 76 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
78 } 78 }
79} 79}
80 80
81impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<'d, T> { 81impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::WriteRead for TimeoutI2c<'d, T, TXDMA, RXDMA> {
82 type Error = Error; 82 type Error = Error;
83 83
84 fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { 84 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<'
90mod eh1 { 90mod eh1 {
91 use super::*; 91 use super::*;
92 92
93 impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for TimeoutI2c<'d, T> { 93 impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for TimeoutI2c<'d, T, TXDMA, RXDMA> {
94 type Error = Error; 94 type Error = Error;
95 } 95 }
96 96
97 impl<'d, T: Instance> embedded_hal_1::i2c::I2c for TimeoutI2c<'d, T> { 97 impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::I2c for TimeoutI2c<'d, T, TXDMA, RXDMA> {
98 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { 98 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
99 self.blocking_read(address, buffer) 99 self.blocking_read(address, buffer)
100 } 100 }