aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-cortex-m/src/interrupt.rs9
-rw-r--r--embassy-cortex-m/src/lib.rs1
-rw-r--r--embassy-embedded-hal/src/adapter.rs7
-rw-r--r--embassy-embedded-hal/src/lib.rs17
-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
9 files changed, 69 insertions, 2 deletions
diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs
index 8a63b18b1..715f00381 100644
--- a/embassy-cortex-m/src/interrupt.rs
+++ b/embassy-cortex-m/src/interrupt.rs
@@ -211,6 +211,7 @@ const PRIO_MASK: u8 = 0xff;
211#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 211#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
212#[cfg_attr(feature = "defmt", derive(defmt::Format))] 212#[cfg_attr(feature = "defmt", derive(defmt::Format))]
213#[repr(u8)] 213#[repr(u8)]
214#[allow(missing_docs)]
214pub enum Priority { 215pub enum Priority {
215 P0 = 0x0, 216 P0 = 0x0,
216} 217}
@@ -222,6 +223,7 @@ pub enum Priority {
222#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 223#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
223#[cfg_attr(feature = "defmt", derive(defmt::Format))] 224#[cfg_attr(feature = "defmt", derive(defmt::Format))]
224#[repr(u8)] 225#[repr(u8)]
226#[allow(missing_docs)]
225pub enum Priority { 227pub enum Priority {
226 P0 = 0x0, 228 P0 = 0x0,
227 P1 = 0x80, 229 P1 = 0x80,
@@ -234,6 +236,7 @@ pub enum Priority {
234#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 236#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
235#[cfg_attr(feature = "defmt", derive(defmt::Format))] 237#[cfg_attr(feature = "defmt", derive(defmt::Format))]
236#[repr(u8)] 238#[repr(u8)]
239#[allow(missing_docs)]
237pub enum Priority { 240pub enum Priority {
238 P0 = 0x0, 241 P0 = 0x0,
239 P1 = 0x40, 242 P1 = 0x40,
@@ -248,6 +251,7 @@ pub enum Priority {
248#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 251#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
249#[cfg_attr(feature = "defmt", derive(defmt::Format))] 252#[cfg_attr(feature = "defmt", derive(defmt::Format))]
250#[repr(u8)] 253#[repr(u8)]
254#[allow(missing_docs)]
251pub enum Priority { 255pub enum Priority {
252 P0 = 0x0, 256 P0 = 0x0,
253 P1 = 0x20, 257 P1 = 0x20,
@@ -266,6 +270,7 @@ pub enum Priority {
266#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 270#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
267#[cfg_attr(feature = "defmt", derive(defmt::Format))] 271#[cfg_attr(feature = "defmt", derive(defmt::Format))]
268#[repr(u8)] 272#[repr(u8)]
273#[allow(missing_docs)]
269pub enum Priority { 274pub enum Priority {
270 P0 = 0x0, 275 P0 = 0x0,
271 P1 = 0x10, 276 P1 = 0x10,
@@ -292,6 +297,7 @@ pub enum Priority {
292#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 297#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
293#[cfg_attr(feature = "defmt", derive(defmt::Format))] 298#[cfg_attr(feature = "defmt", derive(defmt::Format))]
294#[repr(u8)] 299#[repr(u8)]
300#[allow(missing_docs)]
295pub enum Priority { 301pub enum Priority {
296 P0 = 0x0, 302 P0 = 0x0,
297 P1 = 0x8, 303 P1 = 0x8,
@@ -334,6 +340,7 @@ pub enum Priority {
334#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 340#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
335#[cfg_attr(feature = "defmt", derive(defmt::Format))] 341#[cfg_attr(feature = "defmt", derive(defmt::Format))]
336#[repr(u8)] 342#[repr(u8)]
343#[allow(missing_docs)]
337pub enum Priority { 344pub enum Priority {
338 P0 = 0x0, 345 P0 = 0x0,
339 P1 = 0x4, 346 P1 = 0x4,
@@ -408,6 +415,7 @@ pub enum Priority {
408#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 415#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
409#[cfg_attr(feature = "defmt", derive(defmt::Format))] 416#[cfg_attr(feature = "defmt", derive(defmt::Format))]
410#[repr(u8)] 417#[repr(u8)]
418#[allow(missing_docs)]
411pub enum Priority { 419pub enum Priority {
412 P0 = 0x0, 420 P0 = 0x0,
413 P1 = 0x2, 421 P1 = 0x2,
@@ -546,6 +554,7 @@ pub enum Priority {
546#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 554#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
547#[cfg_attr(feature = "defmt", derive(defmt::Format))] 555#[cfg_attr(feature = "defmt", derive(defmt::Format))]
548#[repr(u8)] 556#[repr(u8)]
557#[allow(missing_docs)]
549pub enum Priority { 558pub enum Priority {
550 P0 = 0x0, 559 P0 = 0x0,
551 P1 = 0x1, 560 P1 = 0x1,
diff --git a/embassy-cortex-m/src/lib.rs b/embassy-cortex-m/src/lib.rs
index 680c2c8db..fba23367b 100644
--- a/embassy-cortex-m/src/lib.rs
+++ b/embassy-cortex-m/src/lib.rs
@@ -1,5 +1,6 @@
1//! Embassy executor and interrupt handling specific to cortex-m devices. 1//! Embassy executor and interrupt handling specific to cortex-m devices.
2#![no_std] 2#![no_std]
3#![warn(missing_docs)]
3 4
4// This mod MUST go first, so that the others see its macros. 5// This mod MUST go first, so that the others see its macros.
5pub(crate) mod fmt; 6pub(crate) mod fmt;
diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs
index 7d25d89fc..1c43f015f 100644
--- a/embassy-embedded-hal/src/adapter.rs
+++ b/embassy-embedded-hal/src/adapter.rs
@@ -1,9 +1,12 @@
1//! Adapters between embedded-hal traits.
2
1use core::future::Future; 3use core::future::Future;
2 4
3use embedded_hal_02::{blocking, serial}; 5use embedded_hal_02::{blocking, serial};
4 6
5/// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows 7/// Wrapper that implements async traits using blocking implementations.
6/// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. 8///
9/// This allows driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations.
7/// 10///
8/// BlockingAsync will implement any async trait that maps to embedded-hal traits implemented for the wrapped driver. 11/// BlockingAsync will implement any async trait that maps to embedded-hal traits implemented for the wrapped driver.
9/// 12///
diff --git a/embassy-embedded-hal/src/lib.rs b/embassy-embedded-hal/src/lib.rs
index d77c2d635..0c6f2786a 100644
--- a/embassy-embedded-hal/src/lib.rs
+++ b/embassy-embedded-hal/src/lib.rs
@@ -1,12 +1,29 @@
1#![cfg_attr(not(feature = "std"), no_std)] 1#![cfg_attr(not(feature = "std"), no_std)]
2#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] 2#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
3#![warn(missing_docs)]
4
5//! Utilities to use `embedded-hal` traits with Embassy.
3 6
4#[cfg(feature = "nightly")] 7#[cfg(feature = "nightly")]
5pub mod adapter; 8pub mod adapter;
6 9
7pub mod shared_bus; 10pub mod shared_bus;
8 11
12/// Set the configuration of a peripheral driver.
13///
14/// This trait is intended to be implemented by peripheral drivers such as SPI
15/// and I2C. It allows changing the configuration at runtime.
16///
17/// The exact type of the "configuration" is defined by each individual driver, since different
18/// drivers support different options. Therefore it is defined as an associated type.
19///
20/// For example, it is used by [`SpiDeviceWithConfig`](crate::shared_bus::asynch::spi::SpiDeviceWithConfig) and
21/// [`I2cDeviceWithConfig`](crate::shared_bus::asynch::i2c::I2cDeviceWithConfig) to allow different
22/// devices on the same bus to use different communication settings.
9pub trait SetConfig { 23pub trait SetConfig {
24 /// The configuration type used by this driver.
10 type Config; 25 type Config;
26
27 /// Set the configuration of the driver.
11 fn set_config(&mut self, config: &Self::Config); 28 fn set_config(&mut self, config: &Self::Config);
12} 29}
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