aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src/shared_bus
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus')
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/i2c.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/spi.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/i2c.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/spi.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/mod.rs5
5 files changed, 37 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 }
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
index 343184d12..a08eaa82d 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
@@ -36,12 +36,14 @@ use embedded_hal_async::spi;
36use crate::shared_bus::SpiDeviceError; 36use crate::shared_bus::SpiDeviceError;
37use crate::SetConfig; 37use crate::SetConfig;
38 38
39/// SPI device on a shared bus.
39pub struct SpiDevice<'a, M: RawMutex, BUS, CS> { 40pub struct SpiDevice<'a, M: RawMutex, BUS, CS> {
40 bus: &'a Mutex<M, BUS>, 41 bus: &'a Mutex<M, BUS>,
41 cs: CS, 42 cs: CS,
42} 43}
43 44
44impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> { 45impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> {
46 /// Create a new `SpiDevice`.
45 pub fn new(bus: &'a Mutex<M, BUS>, cs: CS) -> Self { 47 pub fn new(bus: &'a Mutex<M, BUS>, cs: CS) -> Self {
46 Self { bus, cs } 48 Self { bus, cs }
47 } 49 }
@@ -93,6 +95,11 @@ where
93 } 95 }
94} 96}
95 97
98/// SPI device on a shared bus, with its own configuration.
99///
100/// This is like [`SpiDevice`], with an additional bus configuration that's applied
101/// to the bus before each use using [`SetConfig`]. This allows different
102/// devices on the same bus to use different communication settings.
96pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> { 103pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> {
97 bus: &'a Mutex<M, BUS>, 104 bus: &'a Mutex<M, BUS>,
98 cs: CS, 105 cs: CS,
@@ -100,6 +107,7 @@ pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> {
100} 107}
101 108
102impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { 109impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> {
110 /// Create a new `SpiDeviceWithConfig`.
103 pub fn new(bus: &'a Mutex<M, BUS>, cs: CS, config: BUS::Config) -> Self { 111 pub fn new(bus: &'a Mutex<M, BUS>, cs: CS, config: BUS::Config) -> Self {
104 Self { bus, cs, config } 112 Self { bus, cs, config }
105 } 113 }
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 }
diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs
index 3cd380f72..76ee413d9 100644
--- a/embassy-embedded-hal/src/shared_bus/mod.rs
+++ b/embassy-embedded-hal/src/shared_bus/mod.rs
@@ -8,8 +8,10 @@ pub mod asynch;
8 8
9pub mod blocking; 9pub mod blocking;
10 10
11/// Error returned by I2C device implementations in this crate.
11#[derive(Copy, Clone, Eq, PartialEq, Debug)] 12#[derive(Copy, Clone, Eq, PartialEq, Debug)]
12pub enum I2cDeviceError<BUS> { 13pub enum I2cDeviceError<BUS> {
14 /// An operation on the inner I2C bus failed.
13 I2c(BUS), 15 I2c(BUS),
14} 16}
15 17
@@ -24,9 +26,12 @@ where
24 } 26 }
25} 27}
26 28
29/// Error returned by SPI device implementations in this crate.
27#[derive(Copy, Clone, Eq, PartialEq, Debug)] 30#[derive(Copy, Clone, Eq, PartialEq, Debug)]
28pub enum SpiDeviceError<BUS, CS> { 31pub enum SpiDeviceError<BUS, CS> {
32 /// An operation on the inner SPI bus failed.
29 Spi(BUS), 33 Spi(BUS),
34 /// Setting the value of the Chip Select (CS) pin failed.
30 Cs(CS), 35 Cs(CS),
31} 36}
32 37