aboutsummaryrefslogtreecommitdiff
path: root/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-19 07:57:39 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-19 07:58:29 +0200
commitd2f4a9bf8df8de9f51b29659b464b4509af47dc6 (patch)
treef5eac13ddbed4e67aa1b1a6243b880f233658352 /embassy-embedded-hal/src/shared_bus/blocking/spi.rs
parent3fb83898bc2ed0c8c9eccdf17a4852457b0bcebb (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.rs8
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;
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 }