Skip to content

Commit e229494

Browse files
committed
Feature gate embedded-hal-bus atomic impls
1 parent 1c585d4 commit e229494

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

embedded-hal-bus/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ version = "0.2.0"
1616

1717
[features]
1818
std = []
19+
atomic-device = []
1920
async = ["dep:embedded-hal-async"]
2021
defmt-03 = ["dep:defmt-03", "embedded-hal/defmt-03", "embedded-hal-async?/defmt-03"]
2122

@@ -27,5 +28,5 @@ defmt-03 = { package = "defmt", version = "0.3", optional = true }
2728
portable-atomic = {version = "1", default-features = false}
2829

2930
[package.metadata.docs.rs]
30-
features = ["std", "async"]
31+
features = ["std", "async", "atomic-device"]
3132
rustdoc-args = ["--cfg", "docsrs"]

embedded-hal-bus/src/i2c/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ mod mutex;
88
pub use mutex::*;
99
mod critical_section;
1010
pub use self::critical_section::*;
11+
#[cfg(feature = "atomic-device")]
1112
mod atomic;
13+
#[cfg(feature = "atomic-device")]
1214
pub use atomic::*;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ pub use refcell::*;
1111
mod mutex;
1212
#[cfg(feature = "std")]
1313
pub use mutex::*;
14+
#[cfg(feature = "atomic-device")]
1415
mod atomic;
1516
mod critical_section;
1617
mod shared;
18+
#[cfg(feature = "atomic-device")]
1719
pub use atomic::*;
1820

1921
pub use self::critical_section::*;

embedded-hal-bus/src/util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Utilities shared by all bus types.
22
3+
#[allow(unused_imports)]
34
use core::cell::UnsafeCell;
45

6+
#[cfg(feature = "atomic-device")]
57
/// Cell type used by [`spi::AtomicDevice`](crate::spi::AtomicDevice) and [`i2c::AtomicDevice`](crate::i2c::AtomicDevice).
68
///
79
/// To use `AtomicDevice`, you must wrap the bus with this struct, and then
@@ -10,10 +12,12 @@ pub struct AtomicCell<BUS> {
1012
pub(crate) bus: UnsafeCell<BUS>,
1113
pub(crate) busy: portable_atomic::AtomicBool,
1214
}
13-
15+
#[cfg(feature = "atomic-device")]
1416
unsafe impl<BUS: Send> Send for AtomicCell<BUS> {}
17+
#[cfg(feature = "atomic-device")]
1518
unsafe impl<BUS: Send> Sync for AtomicCell<BUS> {}
1619

20+
#[cfg(feature = "atomic-device")]
1721
impl<BUS> AtomicCell<BUS> {
1822
/// Create a new `AtomicCell`
1923
pub fn new(bus: BUS) -> Self {

0 commit comments

Comments
 (0)