From e229494bbf36173d0abde91055b435a4f2c80329 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 8 Jun 2024 21:37:28 +1000 Subject: [PATCH 01/11] Feature gate embedded-hal-bus atomic impls --- embedded-hal-bus/Cargo.toml | 3 ++- embedded-hal-bus/src/i2c/mod.rs | 2 ++ embedded-hal-bus/src/spi/mod.rs | 2 ++ embedded-hal-bus/src/util.rs | 6 +++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 2c54bfbd..3460062e 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -16,6 +16,7 @@ version = "0.2.0" [features] std = [] +atomic-device = [] async = ["dep:embedded-hal-async"] defmt-03 = ["dep:defmt-03", "embedded-hal/defmt-03", "embedded-hal-async?/defmt-03"] @@ -27,5 +28,5 @@ defmt-03 = { package = "defmt", version = "0.3", optional = true } portable-atomic = {version = "1", default-features = false} [package.metadata.docs.rs] -features = ["std", "async"] +features = ["std", "async", "atomic-device"] rustdoc-args = ["--cfg", "docsrs"] diff --git a/embedded-hal-bus/src/i2c/mod.rs b/embedded-hal-bus/src/i2c/mod.rs index 5295492f..5e2c1402 100644 --- a/embedded-hal-bus/src/i2c/mod.rs +++ b/embedded-hal-bus/src/i2c/mod.rs @@ -8,5 +8,7 @@ mod mutex; pub use mutex::*; mod critical_section; pub use self::critical_section::*; +#[cfg(feature = "atomic-device")] mod atomic; +#[cfg(feature = "atomic-device")] pub use atomic::*; diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index d55fa5ea..23cd824d 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -11,9 +11,11 @@ pub use refcell::*; mod mutex; #[cfg(feature = "std")] pub use mutex::*; +#[cfg(feature = "atomic-device")] mod atomic; mod critical_section; mod shared; +#[cfg(feature = "atomic-device")] pub use atomic::*; pub use self::critical_section::*; diff --git a/embedded-hal-bus/src/util.rs b/embedded-hal-bus/src/util.rs index 739f4b1b..70dac74e 100644 --- a/embedded-hal-bus/src/util.rs +++ b/embedded-hal-bus/src/util.rs @@ -1,7 +1,9 @@ //! Utilities shared by all bus types. +#[allow(unused_imports)] use core::cell::UnsafeCell; +#[cfg(feature = "atomic-device")] /// 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 @@ -10,10 +12,12 @@ pub struct AtomicCell { pub(crate) bus: UnsafeCell, pub(crate) busy: portable_atomic::AtomicBool, } - +#[cfg(feature = "atomic-device")] unsafe impl Send for AtomicCell {} +#[cfg(feature = "atomic-device")] unsafe impl Sync for AtomicCell {} +#[cfg(feature = "atomic-device")] impl AtomicCell { /// Create a new `AtomicCell` pub fn new(bus: BUS) -> Self { From f0eec219bb1ff9a5642e12b8e92dcc98c4d1640c Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 8 Jun 2024 21:38:28 +1000 Subject: [PATCH 02/11] Add features for selecting portable-atomic features --- embedded-hal-bus/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 3460062e..44b9a028 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -19,6 +19,8 @@ std = [] atomic-device = [] async = ["dep:embedded-hal-async"] defmt-03 = ["dep:defmt-03", "embedded-hal/defmt-03", "embedded-hal-async?/defmt-03"] +portable-atomic-critical-section = ["atomic-device", "portable-atomic/critical-section"] +portable-atomic-unsafe-assume-single-core = ["atomic-device", "portable-atomic/unsafe-assume-single-core"] [dependencies] embedded-hal = { version = "1.0.0", path = "../embedded-hal" } From 797dc9559040df979aab69dc876b1c22f5499fc5 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 8 Jun 2024 21:47:41 +1000 Subject: [PATCH 03/11] Document embedded-hal-bus features in README.md and Cargo.toml --- embedded-hal-bus/Cargo.toml | 13 +++++++++++++ embedded-hal-bus/README.md | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 44b9a028..07bff536 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -15,11 +15,24 @@ repository = "https://github.com/rust-embedded/embedded-hal" 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 = [] +# 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] diff --git a/embedded-hal-bus/README.md b/embedded-hal-bus/README.md index ce71eec9..4922c7f5 100644 --- a/embedded-hal-bus/README.md +++ b/embedded-hal-bus/README.md @@ -30,10 +30,20 @@ provides mechanisms to obtain multiple `I2c` instances out of a single `I2c` ins ## Optional Cargo features -- **`std`**: enable shared bus implementations using `std::sync::Mutex`, and implement - `std::error::Error` for `DeviceError`. - **`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` 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 +- **`std`**: enable shared bus implementations using `std::sync::Mutex`, and implement + `std::error::Error` for `DeviceError`. ## Minimum Supported Rust Version (MSRV) From d346553c0cc8a0ad6fde4551af8d62a733633770 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:03:05 +1000 Subject: [PATCH 04/11] Also enable Atomic* when target_has_atomic=8 --- embedded-hal-bus/src/i2c/mod.rs | 4 ++-- embedded-hal-bus/src/spi/mod.rs | 4 ++-- embedded-hal-bus/src/util.rs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/embedded-hal-bus/src/i2c/mod.rs b/embedded-hal-bus/src/i2c/mod.rs index 5e2c1402..ef8f7ae9 100644 --- a/embedded-hal-bus/src/i2c/mod.rs +++ b/embedded-hal-bus/src/i2c/mod.rs @@ -8,7 +8,7 @@ mod mutex; pub use mutex::*; mod critical_section; pub use self::critical_section::*; -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] mod atomic; -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] pub use atomic::*; diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index 23cd824d..a7ad6b98 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -11,11 +11,11 @@ pub use refcell::*; mod mutex; #[cfg(feature = "std")] pub use mutex::*; -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] mod atomic; mod critical_section; mod shared; -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] pub use atomic::*; pub use self::critical_section::*; diff --git a/embedded-hal-bus/src/util.rs b/embedded-hal-bus/src/util.rs index 70dac74e..f0cb8f16 100644 --- a/embedded-hal-bus/src/util.rs +++ b/embedded-hal-bus/src/util.rs @@ -3,7 +3,7 @@ #[allow(unused_imports)] use core::cell::UnsafeCell; -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", 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 @@ -12,12 +12,12 @@ pub struct AtomicCell { pub(crate) bus: UnsafeCell, pub(crate) busy: portable_atomic::AtomicBool, } -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] unsafe impl Send for AtomicCell {} -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] unsafe impl Sync for AtomicCell {} -#[cfg(feature = "atomic-device")] +#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] impl AtomicCell { /// Create a new `AtomicCell` pub fn new(bus: BUS) -> Self { From 3ddc31a81087b92effcc00cee5f0a0003f73fbd4 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:03:20 +1000 Subject: [PATCH 05/11] Remove features that enable atomic-polyfill flags --- embedded-hal-bus/Cargo.toml | 20 +++++++------------- embedded-hal-bus/README.md | 14 +++++--------- embedded-hal-bus/src/i2c/mod.rs | 4 ++-- embedded-hal-bus/src/spi/mod.rs | 4 ++-- embedded-hal-bus/src/util.rs | 8 ++++---- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 07bff536..1ef572e9 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -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" } diff --git a/embedded-hal-bus/README.md b/embedded-hal-bus/README.md index 4922c7f5..c2d9a77c 100644 --- a/embedded-hal-bus/README.md +++ b/embedded-hal-bus/README.md @@ -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`. diff --git a/embedded-hal-bus/src/i2c/mod.rs b/embedded-hal-bus/src/i2c/mod.rs index ef8f7ae9..0353ea71 100644 --- a/embedded-hal-bus/src/i2c/mod.rs +++ b/embedded-hal-bus/src/i2c/mod.rs @@ -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::*; diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index a7ad6b98..c14c8fdc 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -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::*; diff --git a/embedded-hal-bus/src/util.rs b/embedded-hal-bus/src/util.rs index f0cb8f16..91add232 100644 --- a/embedded-hal-bus/src/util.rs +++ b/embedded-hal-bus/src/util.rs @@ -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 @@ -12,12 +12,12 @@ pub struct AtomicCell { pub(crate) bus: UnsafeCell, 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 Send for AtomicCell {} -#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] +#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))] unsafe impl Sync for AtomicCell {} -#[cfg(any(feature = "atomic-device", target_has_atomic = "8"))] +#[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))] impl AtomicCell { /// Create a new `AtomicCell` pub fn new(bus: BUS) -> Self { From 33f5255ce8fe88f33755078c0386eb46d2ee0a08 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:18:37 +1000 Subject: [PATCH 06/11] Fix broken URL in README.md --- embedded-hal-bus/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded-hal-bus/README.md b/embedded-hal-bus/README.md index 02761264..2e6d9db0 100644 --- a/embedded-hal-bus/README.md +++ b/embedded-hal-bus/README.md @@ -38,7 +38,7 @@ provides mechanisms to obtain multiple `I2c` instances out of a single `I2c` ins `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. + See for more info. - **`std`**: enable shared bus implementations using `std::sync::Mutex`, and implement `std::error::Error` for `DeviceError`. From 54fa71e32ae3334088b9f8c9e59dfca5fe4e8e53 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:20:52 +1000 Subject: [PATCH 07/11] Add feature require-cas to portable-atomic --- embedded-hal-bus/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 61f59f3e..8898d961 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -36,7 +36,7 @@ embedded-hal = { version = "1.0.0", path = "../embedded-hal" } embedded-hal-async = { version = "1.0.0", path = "../embedded-hal-async", optional = true } critical-section = { version = "1.0" } defmt-03 = { package = "defmt", version = "0.3", optional = true } -portable-atomic = {version = "1", default-features = false} +portable-atomic = {version = "1", default-features = false, features = ["require-cas"]} [package.metadata.docs.rs] features = ["std", "async", "atomic-device"] From a6be9a76bb09aba26337fb0c42990f4ea4537f43 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:24:46 +1000 Subject: [PATCH 08/11] Set minimum portable-atomic version to allow 'require-cas' --- embedded-hal-bus/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 8898d961..333aef89 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -36,7 +36,7 @@ embedded-hal = { version = "1.0.0", path = "../embedded-hal" } embedded-hal-async = { version = "1.0.0", path = "../embedded-hal-async", optional = true } critical-section = { version = "1.0" } defmt-03 = { package = "defmt", version = "0.3", optional = true } -portable-atomic = {version = "1", default-features = false, features = ["require-cas"]} +portable-atomic = {version = "1.3", default-features = false, features = ["require-cas"]} [package.metadata.docs.rs] features = ["std", "async", "atomic-device"] From e7cbd52fb889de617566495dc405abac7de7c52d Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:27:29 +1000 Subject: [PATCH 09/11] Remove atomic-device feature from docs.rs metadata --- embedded-hal-bus/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 333aef89..0b3d444c 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -39,5 +39,5 @@ defmt-03 = { package = "defmt", version = "0.3", optional = true } portable-atomic = {version = "1.3", default-features = false, features = ["require-cas"]} [package.metadata.docs.rs] -features = ["std", "async", "atomic-device"] +features = ["std", "async"] rustdoc-args = ["--cfg", "docsrs"] From cc868a31cd9999bd86467463e62cae8eeeb4e9c3 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:13:26 +1000 Subject: [PATCH 10/11] Make portable-atomic optional --- embedded-hal-bus/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embedded-hal-bus/Cargo.toml b/embedded-hal-bus/Cargo.toml index 0b3d444c..d0ebecf7 100644 --- a/embedded-hal-bus/Cargo.toml +++ b/embedded-hal-bus/Cargo.toml @@ -23,7 +23,7 @@ std = ["alloc"] # 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 = [] +portable-atomic = ["dep: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 @@ -36,7 +36,7 @@ embedded-hal = { version = "1.0.0", path = "../embedded-hal" } embedded-hal-async = { version = "1.0.0", path = "../embedded-hal-async", optional = true } critical-section = { version = "1.0" } defmt-03 = { package = "defmt", version = "0.3", optional = true } -portable-atomic = {version = "1.3", default-features = false, features = ["require-cas"]} +portable-atomic = {version = "1.3", default-features = false, optional = true, features = ["require-cas"]} [package.metadata.docs.rs] features = ["std", "async"] From 2acbd7773cb30b3c8c5e78720a9fbc6b304954d8 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:19:09 +1000 Subject: [PATCH 11/11] Use AtomicBool from core if not using portable-atomic --- embedded-hal-bus/src/util.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/embedded-hal-bus/src/util.rs b/embedded-hal-bus/src/util.rs index 91add232..bb16577c 100644 --- a/embedded-hal-bus/src/util.rs +++ b/embedded-hal-bus/src/util.rs @@ -3,6 +3,11 @@ #[allow(unused_imports)] use core::cell::UnsafeCell; +#[cfg(not(feature = "portable-atomic"))] +use core::sync::atomic::AtomicBool; +#[cfg(feature = "portable-atomic")] +use portable_atomic::AtomicBool; + #[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))] /// Cell type used by [`spi::AtomicDevice`](crate::spi::AtomicDevice) and [`i2c::AtomicDevice`](crate::i2c::AtomicDevice). /// @@ -10,7 +15,7 @@ use core::cell::UnsafeCell; /// construct multiple `AtomicDevice` instances with references to it. pub struct AtomicCell { pub(crate) bus: UnsafeCell, - pub(crate) busy: portable_atomic::AtomicBool, + pub(crate) busy: AtomicBool, } #[cfg(any(feature = "portable-atomic", target_has_atomic = "8"))] unsafe impl Send for AtomicCell {} @@ -23,7 +28,7 @@ impl AtomicCell { pub fn new(bus: BUS) -> Self { Self { bus: UnsafeCell::new(bus), - busy: portable_atomic::AtomicBool::from(false), + busy: AtomicBool::from(false), } } }