aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemicstry <[email protected]>2022-10-24 12:39:47 +0300
committerchemicstry <[email protected]>2022-10-24 12:39:47 +0300
commit9b209ffe1c9048f296213c7050919ccbcd7ded1b (patch)
tree3be740d04315c30d4441d9758624c171674787f5
parent5f02bee388c1754a95e5cab95338aef9c5605c9a (diff)
Add docs
-rw-r--r--embassy-stm32/src/i2c/timeout.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/embassy-stm32/src/i2c/timeout.rs b/embassy-stm32/src/i2c/timeout.rs
index 12319af8a..c4c035b42 100644
--- a/embassy-stm32/src/i2c/timeout.rs
+++ b/embassy-stm32/src/i2c/timeout.rs
@@ -2,6 +2,7 @@ use embassy_time::{Duration, Instant};
2 2
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.
5pub struct TimeoutI2c<'d, T: Instance> { 6pub struct TimeoutI2c<'d, T: Instance> {
6 i2c: &'d mut I2c<'d, T>, 7 i2c: &'d mut I2c<'d, T>,
7 timeout: Duration, 8 timeout: Duration,
@@ -23,22 +24,27 @@ impl<'d, T: Instance> TimeoutI2c<'d, T> {
23 Self { i2c, timeout } 24 Self { i2c, timeout }
24 } 25 }
25 26
27 /// Blocking read with a custom timeout
26 pub fn blocking_read_timeout(&mut self, addr: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> { 28 pub fn blocking_read_timeout(&mut self, addr: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> {
27 self.i2c.blocking_read_timeout(addr, buffer, timeout_fn(timeout)) 29 self.i2c.blocking_read_timeout(addr, buffer, timeout_fn(timeout))
28 } 30 }
29 31
32 /// Blocking read with default timeout, provided in [`TimeoutI2c::new()`]
30 pub fn blocking_read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> { 33 pub fn blocking_read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> {
31 self.blocking_read_timeout(addr, buffer, self.timeout) 34 self.blocking_read_timeout(addr, buffer, self.timeout)
32 } 35 }
33 36
37 /// Blocking write with a custom timeout
34 pub fn blocking_write_timeout(&mut self, addr: u8, bytes: &[u8], timeout: Duration) -> Result<(), Error> { 38 pub fn blocking_write_timeout(&mut self, addr: u8, bytes: &[u8], timeout: Duration) -> Result<(), Error> {
35 self.i2c.blocking_write_timeout(addr, bytes, timeout_fn(timeout)) 39 self.i2c.blocking_write_timeout(addr, bytes, timeout_fn(timeout))
36 } 40 }
37 41
42 /// Blocking write with default timeout, provided in [`TimeoutI2c::new()`]
38 pub fn blocking_write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> { 43 pub fn blocking_write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> {
39 self.blocking_write_timeout(addr, bytes, self.timeout) 44 self.blocking_write_timeout(addr, bytes, self.timeout)
40 } 45 }
41 46
47 /// Blocking write-read with a custom timeout
42 pub fn blocking_write_read_timeout( 48 pub fn blocking_write_read_timeout(
43 &mut self, 49 &mut self,
44 addr: u8, 50 addr: u8,
@@ -50,6 +56,7 @@ impl<'d, T: Instance> TimeoutI2c<'d, T> {
50 .blocking_write_read_timeout(addr, bytes, buffer, timeout_fn(timeout)) 56 .blocking_write_read_timeout(addr, bytes, buffer, timeout_fn(timeout))
51 } 57 }
52 58
59 /// Blocking write-read with default timeout, provided in [`TimeoutI2c::new()`]
53 pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { 60 pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> {
54 self.blocking_write_read_timeout(addr, bytes, buffer, self.timeout) 61 self.blocking_write_read_timeout(addr, bytes, buffer, self.timeout)
55 } 62 }