aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-19 05:59:36 +0000
committerGitHub <[email protected]>2022-07-19 05:59:36 +0000
commit26fdfdb00a1819f4a21c8d0fe1220c079983eecc (patch)
treef5eac13ddbed4e67aa1b1a6243b880f233658352 /embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
parente5d3f01bc444c257dbdfc75e504767e8e13d2a02 (diff)
parentd2f4a9bf8df8de9f51b29659b464b4509af47dc6 (diff)
Merge #869
869: Add some docs. r=Dirbaio a=Dirbaio bors r+ Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/blocking/i2c.rs')
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/i2c.rs8
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;
26use crate::shared_bus::I2cDeviceError; 26use crate::shared_bus::I2cDeviceError;
27use crate::SetConfig; 27use crate::SetConfig;
28 28
29/// I2C device on a shared bus.
29pub struct I2cDevice<'a, M: RawMutex, BUS> { 30pub struct I2cDevice<'a, M: RawMutex, BUS> {
30 bus: &'a Mutex<M, RefCell<BUS>>, 31 bus: &'a Mutex<M, RefCell<BUS>>,
31} 32}
32 33
33impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> { 34impl<'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.
146pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { 153pub 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
151impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { 158impl<'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 }