aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/uarte.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-05 00:20:22 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-05 00:48:46 +0200
commitab85eb4b60cd49ebcd43d2305f42327685f5e5a6 (patch)
tree3c385a5703edcd1e791ec1934d3232dc4084ab2b /embassy-nrf/src/uarte.rs
parent0e1208947e89ea60bd1b5c85e4deb79efb94d89a (diff)
nrf: remove mod sealed.
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
-rw-r--r--embassy-nrf/src/uarte.rs57
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
16use core::future::poll_fn; 16use core::future::poll_fn;
17use core::marker::PhantomData; 17use core::marker::PhantomData;
18use core::sync::atomic::{compiler_fence, Ordering}; 18use core::sync::atomic::{compiler_fence, AtomicU8, Ordering};
19use core::task::Poll; 19use core::task::Poll;
20 20
21use embassy_hal_internal::drop::OnDrop; 21use embassy_hal_internal::drop::OnDrop;
22use embassy_hal_internal::{into_ref, PeripheralRef}; 22use embassy_hal_internal::{into_ref, PeripheralRef};
23use embassy_sync::waitqueue::AtomicWaker;
23use pac::uarte0::RegisterBlock; 24use 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.
25pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 26pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
26 27
27use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 28use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
28use crate::gpio::sealed::Pin as _; 29use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits, SealedPin as _};
29use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits};
30use crate::interrupt::typelevel::Interrupt; 30use crate::interrupt::typelevel::Interrupt;
31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
32use crate::timer::{Frequency, Instance as TimerInstance, Timer}; 32use 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
942pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) { 942pub(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
957pub(crate) mod sealed { 957pub(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::*; 962impl 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 { 972pub(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.
987pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { 979#[allow(private_bounds)]
980pub 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
992macro_rules! impl_uarte { 985macro_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 {