diff options
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/blocking/i2c.rs')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 1ec480c0c..c8b5e30f6 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | |||
| @@ -26,11 +26,13 @@ use embedded_hal_1::i2c::ErrorType; | |||
| 26 | use crate::shared_bus::I2cDeviceError; | 26 | use crate::shared_bus::I2cDeviceError; |
| 27 | use crate::SetConfig; | 27 | use crate::SetConfig; |
| 28 | 28 | ||
| 29 | /// I2C device on a shared bus. | ||
| 29 | pub struct I2cDevice<'a, M: RawMutex, BUS> { | 30 | pub struct I2cDevice<'a, M: RawMutex, BUS> { |
| 30 | bus: &'a Mutex<M, RefCell<BUS>>, | 31 | bus: &'a Mutex<M, RefCell<BUS>>, |
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> { | 34 | impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> { |
| 35 | /// Create a new `I2cDevice`. | ||
| 34 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>) -> Self { | 36 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>) -> Self { |
| 35 | Self { bus } | 37 | Self { bus } |
| 36 | } | 38 | } |
| @@ -143,12 +145,18 @@ where | |||
| 143 | } | 145 | } |
| 144 | } | 146 | } |
| 145 | 147 | ||
| 148 | /// I2C device on a shared bus, with its own configuration. | ||
| 149 | /// | ||
| 150 | /// This is like [`I2cDevice`], with an additional bus configuration that's applied | ||
| 151 | /// to the bus before each use using [`SetConfig`]. This allows different | ||
| 152 | /// devices on the same bus to use different communication settings. | ||
| 146 | pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { | 153 | pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { |
| 147 | bus: &'a Mutex<M, RefCell<BUS>>, | 154 | bus: &'a Mutex<M, RefCell<BUS>>, |
| 148 | config: BUS::Config, | 155 | config: BUS::Config, |
| 149 | } | 156 | } |
| 150 | 157 | ||
| 151 | impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { | 158 | impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { |
| 159 | /// Create a new `I2cDeviceWithConfig`. | ||
| 152 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, config: BUS::Config) -> Self { | 160 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, config: BUS::Config) -> Self { |
| 153 | Self { bus, config } | 161 | Self { bus, config } |
| 154 | } | 162 | } |
