diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-19 07:57:39 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-19 07:58:29 +0200 |
| commit | d2f4a9bf8df8de9f51b29659b464b4509af47dc6 (patch) | |
| tree | f5eac13ddbed4e67aa1b1a6243b880f233658352 /embassy-embedded-hal/src/shared_bus/asynch | |
| parent | 3fb83898bc2ed0c8c9eccdf17a4852457b0bcebb (diff) | |
embassy-embedded-hal: docs
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/asynch')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | 8 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/spi.rs | 8 |
2 files changed, 16 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 | } |
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; | |||
| 36 | use crate::shared_bus::SpiDeviceError; | 36 | use crate::shared_bus::SpiDeviceError; |
| 37 | use crate::SetConfig; | 37 | use crate::SetConfig; |
| 38 | 38 | ||
| 39 | /// SPI device on a shared bus. | ||
| 39 | pub struct SpiDevice<'a, M: RawMutex, BUS, CS> { | 40 | pub 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 | ||
| 44 | impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> { | 45 | impl<'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. | ||
| 96 | pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> { | 103 | pub 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 | ||
| 102 | impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { | 109 | impl<'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 | } |
