aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/asynch/i2c.rs')
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/i2c.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
index 5bd3d9bc5..fa77a06d3 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
@@ -31,11 +31,13 @@ use embedded_hal_async::i2c;
31use crate::shared_bus::I2cDeviceError; 31use crate::shared_bus::I2cDeviceError;
32use crate::SetConfig; 32use crate::SetConfig;
33 33
34/// I2C device on a shared bus.
34pub struct I2cDevice<'a, M: RawMutex, BUS> { 35pub struct I2cDevice<'a, M: RawMutex, BUS> {
35 bus: &'a Mutex<M, BUS>, 36 bus: &'a Mutex<M, BUS>,
36} 37}
37 38
38impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> { 39impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> {
40 /// Create a new `I2cDevice`.
39 pub fn new(bus: &'a Mutex<M, BUS>) -> Self { 41 pub fn new(bus: &'a Mutex<M, BUS>) -> Self {
40 Self { bus } 42 Self { bus }
41 } 43 }
@@ -103,12 +105,18 @@ where
103 } 105 }
104} 106}
105 107
108/// I2C device on a shared bus, with its own configuration.
109///
110/// This is like [`I2cDevice`], with an additional bus configuration that's applied
111/// to the bus before each use using [`SetConfig`]. This allows different
112/// devices on the same bus to use different communication settings.
106pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { 113pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> {
107 bus: &'a Mutex<M, BUS>, 114 bus: &'a Mutex<M, BUS>,
108 config: BUS::Config, 115 config: BUS::Config,
109} 116}
110 117
111impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { 118impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> {
119 /// Create a new `I2cDeviceWithConfig`.
112 pub fn new(bus: &'a Mutex<M, BUS>, config: BUS::Config) -> Self { 120 pub fn new(bus: &'a Mutex<M, BUS>, config: BUS::Config) -> Self {
113 Self { bus, config } 121 Self { bus, config }
114 } 122 }