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/blocking/spi.rs | |
| parent | 3fb83898bc2ed0c8c9eccdf17a4852457b0bcebb (diff) | |
embassy-embedded-hal: docs
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/blocking/spi.rs')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/blocking/spi.rs | 8 |
1 files changed, 8 insertions, 0 deletions
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; | |||
| 29 | use crate::shared_bus::SpiDeviceError; | 29 | use crate::shared_bus::SpiDeviceError; |
| 30 | use crate::SetConfig; | 30 | use crate::SetConfig; |
| 31 | 31 | ||
| 32 | /// SPI device on a shared bus. | ||
| 32 | pub struct SpiDevice<'a, M: RawMutex, BUS, CS> { | 33 | pub 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 | ||
| 37 | impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> { | 38 | impl<'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. | ||
| 120 | pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> { | 127 | pub 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 | ||
| 126 | impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { | 133 | impl<'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 | } |
