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] 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), } } }