Skip to content

Commit

Permalink
Remove features that enable atomic-polyfill flags
Browse files Browse the repository at this point in the history
  • Loading branch information
9names committed Jul 27, 2024
1 parent d346553 commit 3ddc31a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
20 changes: 7 additions & 13 deletions embedded-hal-bus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@ version = "0.2.0"
[features]
# Enable shared bus implementations using `std::sync::Mutex`, and implement `std::error::Error` for `DeviceError`
std = []
# Enable shared bus implementations that require Atomic CAS operations
atomic-device = []
# Use `portable-atomic` to enable `atomic-device` on devices without native atomic CAS
#
# `portable-atomic` emulates atomic CAS functionality, allowing `embedded-hal-bus` to use `atomic-device` on hardware
# that does not natively support atomic CAS. If you enable this, you must also add `portable-atomic` to your crate with
# a feature flag such as `unsafe-assume-single-core` or `critical-section` to choose how atomic CAS is implemented.
# See https://docs.rs/portable-atomic/1.7.0/portable_atomic/#optional-features for more info.
portable-atomic = []
# Enable `embedded-hal-async` support.
async = ["dep:embedded-hal-async"]
# Derive `defmt::Format` from `defmt` 0.3 for enums and structs. See https://github.com/knurling-rs/defmt for more info
defmt-03 = ["dep:defmt-03", "embedded-hal/defmt-03", "embedded-hal-async?/defmt-03"]
# Enable critical-section feature in portable-atomic.
#
# `portable-atomic` emulates atomic CAS functionality, allowing `embedded-hal-bus` to use `atomic-device` on hardware that does not natively support atomic CAS.
# This feature requires a critical-section implementation, which is most often provided by your arch crate (cortex-m / riscv / msp430 / avr-device / etc) when the `critical-section-single-core` feature is enabled.
# A list of critical-section impls is available [in the critical section docs](https://github.com/rust-embedded/critical-section?tab=readme-ov-file#usage-in-no-std-binaries)
portable-atomic-critical-section = ["atomic-device", "portable-atomic/critical-section"]
# Enable unsafe-assume-single-core feature of portable-atomic.
#
# `portable-atomic` emulates atomic CAS functionality, allowing `embedded-hal-bus` to use `atomic-device` on hardware that does not natively support atomic CAS.
# This feature is only safe on single core systems
portable-atomic-unsafe-assume-single-core = ["atomic-device", "portable-atomic/unsafe-assume-single-core"]

[dependencies]
embedded-hal = { version = "1.0.0", path = "../embedded-hal" }
Expand Down
14 changes: 5 additions & 9 deletions embedded-hal-bus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ provides mechanisms to obtain multiple `I2c` instances out of a single `I2c` ins
## Optional Cargo features

- **`async`**: enable `embedded-hal-async` support.
- **`atomic-device`**: enable shared bus implementations that require Atomic CAS operations.
- **`defmt-03`**: Derive `defmt::Format` from `defmt` 0.3 for enums and structs.
- **`portable-atomic-critical-section`**: Enable critical-section feature in portable-atomic.
- **`portable-atomic`**: Use `portable-atomic` to enable `atomic-device` on devices without native atomic CAS

`portable-atomic` emulates atomic CAS functionality, allowing `embedded-hal-bus` to use `atomic-device` on hardware that does not natively support atomic CAS.
This feature requires a critical-section implementation, which is most often provided by your arch crate (cortex-m / riscv / msp430 / avr-device / etc) when the `critical-section-single-core` feature is enabled.
A list of critical-section impls is available [in the critical section docs](https://github.com/rust-embedded/critical-section?tab=readme-ov-file#usage-in-no-std-binaries)
- **`portable-atomic-unsafe-assume-single-core`**: Enable unsafe-assume-single-core feature of portable-atomic.

`portable-atomic` emulates atomic CAS functionality, allowing `embedded-hal-bus` to use `atomic-device` on hardware that does not natively support atomic CAS.
This feature is only safe on single core systems
`portable-atomic` emulates atomic CAS functionality, allowing `embedded-hal-bus` to use `atomic-device` on hardware
that does not natively support atomic CAS. If you enable this, you must also add `portable-atomic` to your crate with
a feature flag such as `unsafe-assume-single-core` or `critical-section` to choose how atomic CAS is implemented.
See https://docs.rs/portable-atomic/1.7.0/portable_atomic/#optional-features for more info.
- **`std`**: enable shared bus implementations using `std::sync::Mutex`, and implement
`std::error::Error` for `DeviceError`.

Expand Down
4 changes: 2 additions & 2 deletions embedded-hal-bus/src/i2c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod mutex;
pub use mutex::*;
mod critical_section;
pub use self::critical_section::*;
#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
mod atomic;
#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
pub use atomic::*;
4 changes: 2 additions & 2 deletions embedded-hal-bus/src/spi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub use refcell::*;
mod mutex;
#[cfg(feature = "std")]
pub use mutex::*;
#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
mod atomic;
mod critical_section;
mod shared;
#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
pub use atomic::*;

pub use self::critical_section::*;
Expand Down
8 changes: 4 additions & 4 deletions embedded-hal-bus/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[allow(unused_imports)]
use core::cell::UnsafeCell;

#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
/// Cell type used by [`spi::AtomicDevice`](crate::spi::AtomicDevice) and [`i2c::AtomicDevice`](crate::i2c::AtomicDevice).
///
/// To use `AtomicDevice`, you must wrap the bus with this struct, and then
Expand All @@ -12,12 +12,12 @@ pub struct AtomicCell<BUS> {
pub(crate) bus: UnsafeCell<BUS>,
pub(crate) busy: portable_atomic::AtomicBool,
}
#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
unsafe impl<BUS: Send> Send for AtomicCell<BUS> {}
#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
unsafe impl<BUS: Send> Sync for AtomicCell<BUS> {}

#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))]
#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))]
impl<BUS> AtomicCell<BUS> {
/// Create a new `AtomicCell`
pub fn new(bus: BUS) -> Self {
Expand Down

0 comments on commit 3ddc31a

Please sign in to comment.