aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src/shared_bus/blocking
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
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')
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/i2c.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/spi.rs8
2 files changed, 16 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 }
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
index ff92e1a7e..d0648f59a 100644
--- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
@@ -29,12 +29,14 @@ use embedded_hal_1::spi::blocking::SpiBusFlush;
29use crate::shared_bus::SpiDeviceError; 29use crate::shared_bus::SpiDeviceError;
30use crate::SetConfig; 30use crate::SetConfig;
31 31
32/// SPI device on a shared bus.
32pub struct SpiDevice<'a, M: RawMutex, BUS, CS> { 33pub struct SpiDevice<'a, M: RawMutex, BUS, CS> {
33 bus: &'a Mutex<M, RefCell<BUS>>, 34 bus: &'a Mutex<M, RefCell<BUS>>,
34 cs: CS, 35 cs: CS,
35} 36}
36 37
37impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> { 38impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> {
39 /// Create a new `SpiDevice`.
38 pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS) -> Self { 40 pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS) -> Self {
39 Self { bus, cs } 41 Self { bus, cs }
40 } 42 }
@@ -117,6 +119,11 @@ where
117 } 119 }
118} 120}
119 121
122/// SPI device on a shared bus, with its own configuration.
123///
124/// This is like [`SpiDevice`], with an additional bus configuration that's applied
125/// to the bus before each use using [`SetConfig`]. This allows different
126/// devices on the same bus to use different communication settings.
120pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> { 127pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> {
121 bus: &'a Mutex<M, RefCell<BUS>>, 128 bus: &'a Mutex<M, RefCell<BUS>>,
122 cs: CS, 129 cs: CS,
@@ -124,6 +131,7 @@ pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> {
124} 131}
125 132
126impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { 133impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> {
134 /// Create a new `SpiDeviceWithConfig`.
127 pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self { 135 pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self {
128 Self { bus, cs, config } 136 Self { bus, cs, config }
129 } 137 }