Skip to content

Commit 4ff05ac

Browse files
committed
Update docs and changelog
1 parent 03e9784 commit 4ff05ac

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

embedded-hal-bus/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
No unreleased changes
10+
- Require infallible chipselects for all spi utilities
11+
- Add `UnwrappingAdapter`
1112

1213
## [v0.1.0] - 2023-12-28
1314

embedded-hal-bus/src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,24 @@ pub mod spi;
2323
///
2424
/// It currently supports [embedded_hal::digital::OutputPin], but other traits may be added in the future.
2525
///
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+
/// ```
2744
#[repr(transparent)]
2845
pub struct UnwrappingAdapter<T>(pub T);
2946

embedded-hal-bus/src/spi/critical_section.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::spi::shared::transaction;
1212
/// This allows for sharing an [`SpiBus`], obtaining multiple [`SpiDevice`] instances,
1313
/// each with its own `CS` pin.
1414
///
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+
///
1518
/// Sharing is implemented with a `critical-section` [`Mutex`]. A critical section is taken for
1619
/// the entire duration of a transaction. This allows sharing a single bus across multiple threads (interrupt priority levels).
1720
/// The downside is critical sections typically require globally disabling interrupts, so `CriticalSectionDevice` will likely

embedded-hal-bus/src/spi/exclusive.rs

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use super::shared::transaction;
1717
///
1818
/// This is the most straightforward way of obtaining an [`SpiDevice`] from an [`SpiBus`],
1919
/// 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).
2023
pub struct ExclusiveDevice<BUS, CS, D> {
2124
bus: BUS,
2225
cs: CS,

embedded-hal-bus/src/spi/mutex.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::spi::shared::transaction;
1212
/// This allows for sharing an [`SpiBus`], obtaining multiple [`SpiDevice`] instances,
1313
/// each with its own `CS` pin.
1414
///
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+
///
1518
/// Sharing is implemented with a `std` [`Mutex`]. It allows a single bus across multiple threads,
1619
/// with finer-grained locking than [`CriticalSectionDevice`](super::CriticalSectionDevice). The downside is
1720
/// it is only available in `std` targets.

embedded-hal-bus/src/spi/refcell.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use crate::spi::shared::transaction;
1111
/// This allows for sharing an [`SpiBus`], obtaining multiple [`SpiDevice`] instances,
1212
/// each with its own `CS` pin.
1313
///
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+
///
1417
/// Sharing is implemented with a `RefCell`. This means it has low overhead, but `RefCellDevice` instances are not `Send`,
1518
/// so it only allows sharing within a single thread (interrupt priority level). If you need to share a bus across several
1619
/// threads, use [`CriticalSectionDevice`](super::CriticalSectionDevice) instead.

0 commit comments

Comments
 (0)