File tree 6 files changed +32
-2
lines changed
6 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
8
8
## [ Unreleased]
9
9
10
- No unreleased changes
10
+ - Require infallible chipselects for all spi utilities
11
+ - Add ` UnwrappingAdapter `
11
12
12
13
## [ v0.1.0] - 2023-12-28
13
14
Original file line number Diff line number Diff line change @@ -23,7 +23,24 @@ pub mod spi;
23
23
///
24
24
/// It currently supports [embedded_hal::digital::OutputPin], but other traits may be added in the future.
25
25
///
26
- /// TODO: add usage example
26
+ /// # Example
27
+ ///
28
+ /// ```
29
+ /// use core::convert::Infallible;
30
+ /// use embedded_hal::digital::OutputPin;
31
+ /// use embedded_hal_bus::UnwrappingAdapter;
32
+ ///
33
+ /// /// This could be any function or struct that requires an infallible output pin
34
+ /// fn requires_infallible(output: impl OutputPin<Error = Infallible>) { /* ... */ }
35
+ ///
36
+ /// fn accepts_fallible(output: impl OutputPin) {
37
+ /// // this wouldn't work:
38
+ /// // requires_infallible(output);
39
+ ///
40
+ /// let unwrapping_output = UnwrappingAdapter(output);
41
+ /// requires_infallible(unwrapping_output);
42
+ /// }
43
+ /// ```
27
44
#[ repr( transparent) ]
28
45
pub struct UnwrappingAdapter < T > ( pub T ) ;
29
46
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ use crate::spi::shared::transaction;
12
12
/// This allows for sharing an [`SpiBus`], obtaining multiple [`SpiDevice`] instances,
13
13
/// each with its own `CS` pin.
14
14
///
15
+ /// The `CS` pin must be infallible (`CS: OutputPin<Error = Infallible>`) because proper error handling would be complicated
16
+ /// and it's usually not needed. If you are using a fallible `CS` pin, you can use [UnwrappingAdapter](crate::UnwrappingAdapter).
17
+ ///
15
18
/// Sharing is implemented with a `critical-section` [`Mutex`]. A critical section is taken for
16
19
/// the entire duration of a transaction. This allows sharing a single bus across multiple threads (interrupt priority levels).
17
20
/// The downside is critical sections typically require globally disabling interrupts, so `CriticalSectionDevice` will likely
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ use super::shared::transaction;
17
17
///
18
18
/// This is the most straightforward way of obtaining an [`SpiDevice`] from an [`SpiBus`],
19
19
/// ideal for when no sharing is required (only one SPI device is present on the bus).
20
+ ///
21
+ /// The `CS` pin must be infallible (`CS: OutputPin<Error = Infallible>`) because proper error handling would be complicated
22
+ /// and it's usually not needed. If you are using a fallible `CS` pin, you can use [UnwrappingAdapter](crate::UnwrappingAdapter).
20
23
pub struct ExclusiveDevice < BUS , CS , D > {
21
24
bus : BUS ,
22
25
cs : CS ,
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ use crate::spi::shared::transaction;
12
12
/// This allows for sharing an [`SpiBus`], obtaining multiple [`SpiDevice`] instances,
13
13
/// each with its own `CS` pin.
14
14
///
15
+ /// The `CS` pin must be infallible (`CS: OutputPin<Error = Infallible>`) because proper error handling would be complicated
16
+ /// and it's usually not needed. If you are using a fallible `CS` pin, you can use [UnwrappingAdapter](crate::UnwrappingAdapter).
17
+ ///
15
18
/// Sharing is implemented with a `std` [`Mutex`]. It allows a single bus across multiple threads,
16
19
/// with finer-grained locking than [`CriticalSectionDevice`](super::CriticalSectionDevice). The downside is
17
20
/// it is only available in `std` targets.
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ use crate::spi::shared::transaction;
11
11
/// This allows for sharing an [`SpiBus`], obtaining multiple [`SpiDevice`] instances,
12
12
/// each with its own `CS` pin.
13
13
///
14
+ /// The `CS` pin must be infallible (`CS: OutputPin<Error = Infallible>`) because proper error handling would be complicated
15
+ /// and it's usually not needed. If you are using a fallible `CS` pin, you can use [UnwrappingAdapter](crate::UnwrappingAdapter).
16
+ ///
14
17
/// Sharing is implemented with a `RefCell`. This means it has low overhead, but `RefCellDevice` instances are not `Send`,
15
18
/// so it only allows sharing within a single thread (interrupt priority level). If you need to share a bus across several
16
19
/// threads, use [`CriticalSectionDevice`](super::CriticalSectionDevice) instead.
You can’t perform that action at this time.
0 commit comments