diff options
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/asynch/i2c.rs')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | 8 |
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; | |||
| 31 | use crate::shared_bus::I2cDeviceError; | 31 | use crate::shared_bus::I2cDeviceError; |
| 32 | use crate::SetConfig; | 32 | use crate::SetConfig; |
| 33 | 33 | ||
| 34 | /// I2C device on a shared bus. | ||
| 34 | pub struct I2cDevice<'a, M: RawMutex, BUS> { | 35 | pub struct I2cDevice<'a, M: RawMutex, BUS> { |
| 35 | bus: &'a Mutex<M, BUS>, | 36 | bus: &'a Mutex<M, BUS>, |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> { | 39 | impl<'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. | ||
| 106 | pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { | 113 | pub 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 | ||
| 111 | impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { | 118 | impl<'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 | } |
