diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:20:22 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:48:46 +0200 |
| commit | ab85eb4b60cd49ebcd43d2305f42327685f5e5a6 (patch) | |
| tree | 3c385a5703edcd1e791ec1934d3232dc4084ab2b /embassy-nrf/src/uarte.rs | |
| parent | 0e1208947e89ea60bd1b5c85e4deb79efb94d89a (diff) | |
nrf: remove mod sealed.
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index cbd5dccbc..fa0a773a8 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -15,18 +15,18 @@ | |||
| 15 | 15 | ||
| 16 | use core::future::poll_fn; | 16 | use core::future::poll_fn; |
| 17 | use core::marker::PhantomData; | 17 | use core::marker::PhantomData; |
| 18 | use core::sync::atomic::{compiler_fence, Ordering}; | 18 | use core::sync::atomic::{compiler_fence, AtomicU8, Ordering}; |
| 19 | use core::task::Poll; | 19 | use core::task::Poll; |
| 20 | 20 | ||
| 21 | use embassy_hal_internal::drop::OnDrop; | 21 | use embassy_hal_internal::drop::OnDrop; |
| 22 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 22 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 23 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 23 | use pac::uarte0::RegisterBlock; | 24 | use pac::uarte0::RegisterBlock; |
| 24 | // Re-export SVD variants to allow user to directly set values. | 25 | // Re-export SVD variants to allow user to directly set values. |
| 25 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | 26 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; |
| 26 | 27 | ||
| 27 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 28 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 28 | use crate::gpio::sealed::Pin as _; | 29 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits, SealedPin as _}; |
| 29 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; | ||
| 30 | use crate::interrupt::typelevel::Interrupt; | 30 | use crate::interrupt::typelevel::Interrupt; |
| 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 32 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 32 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| @@ -939,7 +939,7 @@ pub(crate) fn apply_workaround_for_enable_anomaly(r: &crate::pac::uarte0::Regist | |||
| 939 | } | 939 | } |
| 940 | } | 940 | } |
| 941 | 941 | ||
| 942 | pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) { | 942 | pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &State) { |
| 943 | if s.tx_rx_refcount.fetch_sub(1, Ordering::Relaxed) == 1 { | 943 | if s.tx_rx_refcount.fetch_sub(1, Ordering::Relaxed) == 1 { |
| 944 | // Finally we can disable, and we do so for the peripheral | 944 | // Finally we can disable, and we do so for the peripheral |
| 945 | // i.e. not just rx concerns. | 945 | // i.e. not just rx concerns. |
| @@ -954,49 +954,42 @@ pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) { | |||
| 954 | } | 954 | } |
| 955 | } | 955 | } |
| 956 | 956 | ||
| 957 | pub(crate) mod sealed { | 957 | pub(crate) struct State { |
| 958 | use core::sync::atomic::AtomicU8; | 958 | pub(crate) rx_waker: AtomicWaker, |
| 959 | 959 | pub(crate) tx_waker: AtomicWaker, | |
| 960 | use embassy_sync::waitqueue::AtomicWaker; | 960 | pub(crate) tx_rx_refcount: AtomicU8, |
| 961 | 961 | } | |
| 962 | use super::*; | 962 | impl State { |
| 963 | 963 | pub(crate) const fn new() -> Self { | |
| 964 | pub struct State { | 964 | Self { |
| 965 | pub rx_waker: AtomicWaker, | 965 | rx_waker: AtomicWaker::new(), |
| 966 | pub tx_waker: AtomicWaker, | 966 | tx_waker: AtomicWaker::new(), |
| 967 | pub tx_rx_refcount: AtomicU8, | 967 | tx_rx_refcount: AtomicU8::new(0), |
| 968 | } | ||
| 969 | impl State { | ||
| 970 | pub const fn new() -> Self { | ||
| 971 | Self { | ||
| 972 | rx_waker: AtomicWaker::new(), | ||
| 973 | tx_waker: AtomicWaker::new(), | ||
| 974 | tx_rx_refcount: AtomicU8::new(0), | ||
| 975 | } | ||
| 976 | } | 968 | } |
| 977 | } | 969 | } |
| 970 | } | ||
| 978 | 971 | ||
| 979 | pub trait Instance { | 972 | pub(crate) trait SealedInstance { |
| 980 | fn regs() -> &'static pac::uarte0::RegisterBlock; | 973 | fn regs() -> &'static pac::uarte0::RegisterBlock; |
| 981 | fn state() -> &'static State; | 974 | fn state() -> &'static State; |
| 982 | fn buffered_state() -> &'static crate::buffered_uarte::State; | 975 | fn buffered_state() -> &'static crate::buffered_uarte::State; |
| 983 | } | ||
| 984 | } | 976 | } |
| 985 | 977 | ||
| 986 | /// UARTE peripheral instance. | 978 | /// UARTE peripheral instance. |
| 987 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 979 | #[allow(private_bounds)] |
| 980 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 988 | /// Interrupt for this peripheral. | 981 | /// Interrupt for this peripheral. |
| 989 | type Interrupt: interrupt::typelevel::Interrupt; | 982 | type Interrupt: interrupt::typelevel::Interrupt; |
| 990 | } | 983 | } |
| 991 | 984 | ||
| 992 | macro_rules! impl_uarte { | 985 | macro_rules! impl_uarte { |
| 993 | ($type:ident, $pac_type:ident, $irq:ident) => { | 986 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 994 | impl crate::uarte::sealed::Instance for peripherals::$type { | 987 | impl crate::uarte::SealedInstance for peripherals::$type { |
| 995 | fn regs() -> &'static pac::uarte0::RegisterBlock { | 988 | fn regs() -> &'static pac::uarte0::RegisterBlock { |
| 996 | unsafe { &*pac::$pac_type::ptr() } | 989 | unsafe { &*pac::$pac_type::ptr() } |
| 997 | } | 990 | } |
| 998 | fn state() -> &'static crate::uarte::sealed::State { | 991 | fn state() -> &'static crate::uarte::State { |
| 999 | static STATE: crate::uarte::sealed::State = crate::uarte::sealed::State::new(); | 992 | static STATE: crate::uarte::State = crate::uarte::State::new(); |
| 1000 | &STATE | 993 | &STATE |
| 1001 | } | 994 | } |
| 1002 | fn buffered_state() -> &'static crate::buffered_uarte::State { | 995 | fn buffered_state() -> &'static crate::buffered_uarte::State { |
