From ab85eb4b60cd49ebcd43d2305f42327685f5e5a6 Mon Sep 17 00:00:00 2001
From: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Date: Fri, 5 Apr 2024 00:20:22 +0200
Subject: [PATCH 1/3] nrf: remove mod sealed.

---
 embassy-nrf/src/buffered_uarte.rs | 25 ++++-----
 embassy-nrf/src/gpio.rs           | 82 ++++++++++++++---------------
 embassy-nrf/src/gpiote.rs         | 14 +++--
 embassy-nrf/src/i2s.rs            | 56 +++++++++-----------
 embassy-nrf/src/pdm.rs            | 43 +++++++--------
 embassy-nrf/src/ppi/mod.rs        | 22 ++++----
 embassy-nrf/src/pwm.rs            | 16 +++---
 embassy-nrf/src/qdec.rs           | 43 +++++++--------
 embassy-nrf/src/qspi.rs           | 40 +++++++-------
 embassy-nrf/src/radio/mod.rs      | 38 +++++++-------
 embassy-nrf/src/rng.rs            | 87 ++++++++++++++-----------------
 embassy-nrf/src/saadc.rs          | 16 +++---
 embassy-nrf/src/spim.rs           | 62 ++++++++++------------
 embassy-nrf/src/spis.rs           | 43 +++++++--------
 embassy-nrf/src/timer.rs          | 22 +++-----
 embassy-nrf/src/twim.rs           | 37 ++++++-------
 embassy-nrf/src/twis.rs           | 37 ++++++-------
 embassy-nrf/src/uarte.rs          | 59 +++++++++------------
 embassy-nrf/src/usb/mod.rs        | 13 ++---
 19 files changed, 339 insertions(+), 416 deletions(-)

diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index b04c96e09..385d4015e 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -20,8 +20,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
 // Re-export SVD variants to allow user to directly set values
 pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
 
-use crate::gpio::sealed::Pin;
-use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
+use crate::gpio::{AnyPin, Pin as GpioPin, PselBits, SealedPin};
 use crate::interrupt::typelevel::Interrupt;
 use crate::ppi::{
     self, AnyConfigurableChannel, AnyGroup, Channel, ConfigurableChannel, Event, Group, Ppi, PpiGroup, Task,
@@ -30,19 +29,15 @@ use crate::timer::{Instance as TimerInstance, Timer};
 use crate::uarte::{configure, drop_tx_rx, Config, Instance as UarteInstance};
 use crate::{interrupt, pac, Peripheral};
 
-mod sealed {
-    use super::*;
+pub(crate) struct State {
+    tx_buf: RingBuffer,
+    tx_count: AtomicUsize,
 
-    pub struct State {
-        pub tx_buf: RingBuffer,
-        pub tx_count: AtomicUsize,
-
-        pub rx_buf: RingBuffer,
-        pub rx_started: AtomicBool,
-        pub rx_started_count: AtomicU8,
-        pub rx_ended_count: AtomicU8,
-        pub rx_ppi_ch: AtomicU8,
-    }
+    rx_buf: RingBuffer,
+    rx_started: AtomicBool,
+    rx_started_count: AtomicU8,
+    rx_ended_count: AtomicU8,
+    rx_ppi_ch: AtomicU8,
 }
 
 /// UART error.
@@ -53,8 +48,6 @@ pub enum Error {
     // No errors for now
 }
 
-pub(crate) use sealed::State;
-
 impl State {
     pub(crate) const fn new() -> Self {
         Self {
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index f2353f21d..7b272dca0 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -7,7 +7,6 @@ use core::hint::unreachable_unchecked;
 use cfg_if::cfg_if;
 use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
 
-use self::sealed::Pin as _;
 #[cfg(feature = "nrf51")]
 use crate::pac::gpio;
 #[cfg(feature = "nrf51")]
@@ -361,59 +360,56 @@ impl<'d> Drop for Flex<'d> {
     }
 }
 
-pub(crate) mod sealed {
-    use super::*;
+pub(crate) trait SealedPin {
+    fn pin_port(&self) -> u8;
 
-    pub trait Pin {
-        fn pin_port(&self) -> u8;
-
-        #[inline]
-        fn _pin(&self) -> u8 {
-            cfg_if! {
-                if #[cfg(feature = "_gpio-p1")] {
-                    self.pin_port() % 32
-                } else {
-                    self.pin_port()
-                }
+    #[inline]
+    fn _pin(&self) -> u8 {
+        cfg_if! {
+            if #[cfg(feature = "_gpio-p1")] {
+                self.pin_port() % 32
+            } else {
+                self.pin_port()
             }
         }
+    }
 
-        #[inline]
-        fn block(&self) -> &gpio::RegisterBlock {
-            unsafe {
-                match self.pin_port() / 32 {
-                    #[cfg(feature = "nrf51")]
-                    0 => &*pac::GPIO::ptr(),
-                    #[cfg(not(feature = "nrf51"))]
-                    0 => &*pac::P0::ptr(),
-                    #[cfg(feature = "_gpio-p1")]
-                    1 => &*pac::P1::ptr(),
-                    _ => unreachable_unchecked(),
-                }
+    #[inline]
+    fn block(&self) -> &gpio::RegisterBlock {
+        unsafe {
+            match self.pin_port() / 32 {
+                #[cfg(feature = "nrf51")]
+                0 => &*pac::GPIO::ptr(),
+                #[cfg(not(feature = "nrf51"))]
+                0 => &*pac::P0::ptr(),
+                #[cfg(feature = "_gpio-p1")]
+                1 => &*pac::P1::ptr(),
+                _ => unreachable_unchecked(),
             }
         }
+    }
 
-        #[inline]
-        fn conf(&self) -> &gpio::PIN_CNF {
-            &self.block().pin_cnf[self._pin() as usize]
-        }
+    #[inline]
+    fn conf(&self) -> &gpio::PIN_CNF {
+        &self.block().pin_cnf[self._pin() as usize]
+    }
 
-        /// Set the output as high.
-        #[inline]
-        fn set_high(&self) {
-            unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) }
-        }
+    /// Set the output as high.
+    #[inline]
+    fn set_high(&self) {
+        unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) }
+    }
 
-        /// Set the output as low.
-        #[inline]
-        fn set_low(&self) {
-            unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) }
-        }
+    /// Set the output as low.
+    #[inline]
+    fn set_low(&self) {
+        unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) }
     }
 }
 
 /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin].
-pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static {
     /// Number of the pin within the port (0..31)
     #[inline]
     fn pin(&self) -> u8 {
@@ -464,7 +460,7 @@ impl AnyPin {
 
 impl_peripheral!(AnyPin);
 impl Pin for AnyPin {}
-impl sealed::Pin for AnyPin {
+impl SealedPin for AnyPin {
     #[inline]
     fn pin_port(&self) -> u8 {
         self.pin_port
@@ -502,7 +498,7 @@ pub(crate) fn deconfigure_pin(psel_bits: u32) {
 macro_rules! impl_pin {
     ($type:ident, $port_num:expr, $pin_num:expr) => {
         impl crate::gpio::Pin for peripherals::$type {}
-        impl crate::gpio::sealed::Pin for peripherals::$type {
+        impl crate::gpio::SealedPin for peripherals::$type {
             #[inline]
             fn pin_port(&self) -> u8 {
                 $port_num * 32 + $pin_num
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 4a28279a9..d7f075722 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -7,8 +7,7 @@ use core::task::{Context, Poll};
 use embassy_hal_internal::{impl_peripheral, into_ref, Peripheral, PeripheralRef};
 use embassy_sync::waitqueue::AtomicWaker;
 
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin};
+use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin, SealedPin as _};
 use crate::interrupt::InterruptExt;
 use crate::ppi::{Event, Task};
 use crate::{interrupt, pac, peripherals};
@@ -446,14 +445,13 @@ impl<'d> Flex<'d> {
 
 // =======================
 
-mod sealed {
-    pub trait Channel {}
-}
+trait SealedChannel {}
 
 /// GPIOTE channel trait.
 ///
 /// Implemented by all GPIOTE channels.
-pub trait Channel: sealed::Channel + Into<AnyChannel> + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Channel: SealedChannel + Into<AnyChannel> + Sized + 'static {
     /// Get the channel number.
     fn number(&self) -> usize;
 
@@ -478,7 +476,7 @@ pub struct AnyChannel {
     number: u8,
 }
 impl_peripheral!(AnyChannel);
-impl sealed::Channel for AnyChannel {}
+impl SealedChannel for AnyChannel {}
 impl Channel for AnyChannel {
     fn number(&self) -> usize {
         self.number as usize
@@ -487,7 +485,7 @@ impl Channel for AnyChannel {
 
 macro_rules! impl_channel {
     ($type:ident, $number:expr) => {
-        impl sealed::Channel for peripherals::$type {}
+        impl SealedChannel for peripherals::$type {}
         impl Channel for peripherals::$type {
             fn number(&self) -> usize {
                 $number as usize
diff --git a/embassy-nrf/src/i2s.rs b/embassy-nrf/src/i2s.rs
index 907acdf4c..966271ed9 100644
--- a/embassy-nrf/src/i2s.rs
+++ b/embassy-nrf/src/i2s.rs
@@ -6,11 +6,12 @@ use core::future::poll_fn;
 use core::marker::PhantomData;
 use core::mem::size_of;
 use core::ops::{Deref, DerefMut};
-use core::sync::atomic::{compiler_fence, Ordering};
+use core::sync::atomic::{compiler_fence, AtomicBool, Ordering};
 use core::task::Poll;
 
 use embassy_hal_internal::drop::OnDrop;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 
 use crate::gpio::{AnyPin, Pin as GpioPin};
 use crate::interrupt::typelevel::Interrupt;
@@ -1140,50 +1141,45 @@ impl<S: Sample, const NB: usize, const NS: usize> MultiBuffering<S, NB, NS> {
     }
 }
 
-pub(crate) mod sealed {
-    use core::sync::atomic::AtomicBool;
+/// Peripheral static state
+pub(crate) struct State {
+    started: AtomicBool,
+    rx_waker: AtomicWaker,
+    tx_waker: AtomicWaker,
+    stop_waker: AtomicWaker,
+}
 
-    use embassy_sync::waitqueue::AtomicWaker;
-
-    /// Peripheral static state
-    pub struct State {
-        pub started: AtomicBool,
-        pub rx_waker: AtomicWaker,
-        pub tx_waker: AtomicWaker,
-        pub stop_waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                started: AtomicBool::new(false),
-                rx_waker: AtomicWaker::new(),
-                tx_waker: AtomicWaker::new(),
-                stop_waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            started: AtomicBool::new(false),
+            rx_waker: AtomicWaker::new(),
+            tx_waker: AtomicWaker::new(),
+            stop_waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static crate::pac::i2s::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static crate::pac::i2s::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// I2S peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_i2s {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::i2s::sealed::Instance for peripherals::$type {
+        impl crate::i2s::SealedInstance for peripherals::$type {
             fn regs() -> &'static crate::pac::i2s::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::i2s::sealed::State {
-                static STATE: crate::i2s::sealed::State = crate::i2s::sealed::State::new();
+            fn state() -> &'static crate::i2s::State {
+                static STATE: crate::i2s::State = crate::i2s::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs
index 754d38310..ef2662c85 100644
--- a/embassy-nrf/src/pdm.rs
+++ b/embassy-nrf/src/pdm.rs
@@ -9,11 +9,11 @@ use core::task::Poll;
 
 use embassy_hal_internal::drop::OnDrop;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 use fixed::types::I7F1;
 
 use crate::chip::EASY_DMA_SIZE;
-use crate::gpio::sealed::Pin;
-use crate::gpio::{AnyPin, Pin as GpioPin};
+use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin};
 use crate::interrupt::typelevel::Interrupt;
 use crate::pac::pdm::mode::{EDGE_A, OPERATION_A};
 pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency;
@@ -451,42 +451,39 @@ impl<'d, T: Instance> Drop for Pdm<'d, T> {
     }
 }
 
-pub(crate) mod sealed {
-    use embassy_sync::waitqueue::AtomicWaker;
+/// Peripheral static state
+pub(crate) struct State {
+    waker: AtomicWaker,
+}
 
-    /// Peripheral static state
-    pub struct State {
-        pub waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static crate::pac::pdm::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static crate::pac::pdm::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// PDM peripheral instance
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_pdm {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::pdm::sealed::Instance for peripherals::$type {
+        impl crate::pdm::SealedInstance for peripherals::$type {
             fn regs() -> &'static crate::pac::pdm::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::pdm::sealed::State {
-                static STATE: crate::pdm::sealed::State = crate::pdm::sealed::State::new();
+            fn state() -> &'static crate::pdm::State {
+                static STATE: crate::pdm::State = crate::pdm::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index f5764b8b7..13f7dcc83 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -210,13 +210,12 @@ unsafe impl Send for Event<'_> {}
 // ======================
 //       traits
 
-pub(crate) mod sealed {
-    pub trait Channel {}
-    pub trait Group {}
-}
+pub(crate) trait SealedChannel {}
+pub(crate) trait SealedGroup {}
 
 /// Interface for PPI channels.
-pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Channel: SealedChannel + Peripheral<P = Self> + Sized + 'static {
     /// Returns the number of the channel
     fn number(&self) -> usize;
 }
@@ -234,7 +233,8 @@ pub trait StaticChannel: Channel + Into<AnyStaticChannel> {
 }
 
 /// Interface for a group of PPI channels.
-pub trait Group: sealed::Group + Peripheral<P = Self> + Into<AnyGroup> + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Group: SealedGroup + Peripheral<P = Self> + Into<AnyGroup> + Sized + 'static {
     /// Returns the number of the group.
     fn number(&self) -> usize;
     /// Convert into a type erased group.
@@ -254,7 +254,7 @@ pub struct AnyStaticChannel {
     pub(crate) number: u8,
 }
 impl_peripheral!(AnyStaticChannel);
-impl sealed::Channel for AnyStaticChannel {}
+impl SealedChannel for AnyStaticChannel {}
 impl Channel for AnyStaticChannel {
     fn number(&self) -> usize {
         self.number as usize
@@ -272,7 +272,7 @@ pub struct AnyConfigurableChannel {
     pub(crate) number: u8,
 }
 impl_peripheral!(AnyConfigurableChannel);
-impl sealed::Channel for AnyConfigurableChannel {}
+impl SealedChannel for AnyConfigurableChannel {}
 impl Channel for AnyConfigurableChannel {
     fn number(&self) -> usize {
         self.number as usize
@@ -287,7 +287,7 @@ impl ConfigurableChannel for AnyConfigurableChannel {
 #[cfg(not(feature = "nrf51"))]
 macro_rules! impl_ppi_channel {
     ($type:ident, $number:expr) => {
-        impl crate::ppi::sealed::Channel for peripherals::$type {}
+        impl crate::ppi::SealedChannel for peripherals::$type {}
         impl crate::ppi::Channel for peripherals::$type {
             fn number(&self) -> usize {
                 $number
@@ -338,7 +338,7 @@ pub struct AnyGroup {
     number: u8,
 }
 impl_peripheral!(AnyGroup);
-impl sealed::Group for AnyGroup {}
+impl SealedGroup for AnyGroup {}
 impl Group for AnyGroup {
     fn number(&self) -> usize {
         self.number as usize
@@ -347,7 +347,7 @@ impl Group for AnyGroup {
 
 macro_rules! impl_group {
     ($type:ident, $number:expr) => {
-        impl sealed::Group for peripherals::$type {}
+        impl SealedGroup for peripherals::$type {}
         impl Group for peripherals::$type {
             fn number(&self) -> usize {
                 $number
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 833370d4b..1318d3f94 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -6,8 +6,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
 
 use embassy_hal_internal::{into_ref, PeripheralRef};
 
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
+use crate::gpio::{AnyPin, Pin as GpioPin, PselBits, SealedPin as _};
 use crate::ppi::{Event, Task};
 use crate::util::slice_in_ram_or;
 use crate::{interrupt, pac, Peripheral};
@@ -847,23 +846,20 @@ impl<'a, T: Instance> Drop for SimplePwm<'a, T> {
     }
 }
 
-pub(crate) mod sealed {
-    use super::*;
-
-    pub trait Instance {
-        fn regs() -> &'static pac::pwm0::RegisterBlock;
-    }
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::pwm0::RegisterBlock;
 }
 
 /// PWM peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_pwm {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::pwm::sealed::Instance for peripherals::$type {
+        impl crate::pwm::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::pwm0::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs
index 9455ec925..7409c9b1e 100644
--- a/embassy-nrf/src/qdec.rs
+++ b/embassy-nrf/src/qdec.rs
@@ -7,9 +7,9 @@ use core::marker::PhantomData;
 use core::task::Poll;
 
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{AnyPin, Pin as GpioPin};
+use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _};
 use crate::interrupt::typelevel::Interrupt;
 use crate::{interrupt, Peripheral};
 
@@ -245,42 +245,39 @@ pub enum LedPolarity {
     ActiveLow,
 }
 
-pub(crate) mod sealed {
-    use embassy_sync::waitqueue::AtomicWaker;
+/// Peripheral static state
+pub(crate) struct State {
+    waker: AtomicWaker,
+}
 
-    /// Peripheral static state
-    pub struct State {
-        pub waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static crate::pac::qdec::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static crate::pac::qdec::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// qdec peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_qdec {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::qdec::sealed::Instance for peripherals::$type {
+        impl crate::qdec::SealedInstance for peripherals::$type {
             fn regs() -> &'static crate::pac::qdec::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::qdec::sealed::State {
-                static STATE: crate::qdec::sealed::State = crate::qdec::sealed::State::new();
+            fn state() -> &'static crate::qdec::State {
+                static STATE: crate::qdec::State = crate::qdec::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 4134a4c87..060fe72cd 100755
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -9,6 +9,7 @@ use core::task::Poll;
 
 use embassy_hal_internal::drop::OnDrop;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash};
 
 use crate::gpio::{self, Pin as GpioPin};
@@ -652,42 +653,39 @@ mod _eh1 {
     impl<'d, T: Instance> embedded_storage_async::nor_flash::MultiwriteNorFlash for Qspi<'d, T> {}
 }
 
-pub(crate) mod sealed {
-    use embassy_sync::waitqueue::AtomicWaker;
+/// Peripheral static state
+pub(crate) struct State {
+    waker: AtomicWaker,
+}
 
-    /// Peripheral static state
-    pub struct State {
-        pub waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static crate::pac::qspi::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static crate::pac::qspi::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// QSPI peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_qspi {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::qspi::sealed::Instance for peripherals::$type {
+        impl crate::qspi::SealedInstance for peripherals::$type {
             fn regs() -> &'static crate::pac::qspi::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::qspi::sealed::State {
-                static STATE: crate::qspi::sealed::State = crate::qspi::sealed::State::new();
+            fn state() -> &'static crate::qspi::State {
+                static STATE: crate::qspi::State = crate::qspi::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/radio/mod.rs b/embassy-nrf/src/radio/mod.rs
index 4c0cc3280..8edca1df2 100644
--- a/embassy-nrf/src/radio/mod.rs
+++ b/embassy-nrf/src/radio/mod.rs
@@ -19,6 +19,7 @@ pub mod ieee802154;
 
 use core::marker::PhantomData;
 
+use embassy_sync::waitqueue::AtomicWaker;
 use pac::radio::state::STATE_A as RadioState;
 pub use pac::radio::txpower::TXPOWER_A as TxPower;
 
@@ -56,36 +57,32 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
     }
 }
 
-pub(crate) mod sealed {
-    use embassy_sync::waitqueue::AtomicWaker;
-
-    pub struct State {
-        /// end packet transmission or reception
-        pub event_waker: AtomicWaker,
-    }
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                event_waker: AtomicWaker::new(),
-            }
+pub(crate) struct State {
+    /// end packet transmission or reception
+    event_waker: AtomicWaker,
+}
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            event_waker: AtomicWaker::new(),
         }
     }
+}
 
-    pub trait Instance {
-        fn regs() -> &'static crate::pac::radio::RegisterBlock;
-        fn state() -> &'static State;
-    }
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static crate::pac::radio::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 macro_rules! impl_radio {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::radio::sealed::Instance for peripherals::$type {
+        impl crate::radio::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::radio::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
 
-            fn state() -> &'static crate::radio::sealed::State {
-                static STATE: crate::radio::sealed::State = crate::radio::sealed::State::new();
+            fn state() -> &'static crate::radio::State {
+                static STATE: crate::radio::State = crate::radio::State::new();
                 &STATE
             }
         }
@@ -96,7 +93,8 @@ macro_rules! impl_radio {
 }
 
 /// Radio peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs
index 1c463fb7c..ff61e08f3 100644
--- a/embassy-nrf/src/rng.rs
+++ b/embassy-nrf/src/rng.rs
@@ -2,13 +2,16 @@
 
 #![macro_use]
 
+use core::cell::{RefCell, RefMut};
 use core::future::poll_fn;
 use core::marker::PhantomData;
 use core::ptr;
 use core::task::Poll;
 
+use critical_section::{CriticalSection, Mutex};
 use embassy_hal_internal::drop::OnDrop;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::WakerRegistration;
 
 use crate::interrupt::typelevel::Interrupt;
 use crate::{interrupt, Peripheral};
@@ -205,73 +208,61 @@ impl<'d, T: Instance> rand_core::RngCore for Rng<'d, T> {
 
 impl<'d, T: Instance> rand_core::CryptoRng for Rng<'d, T> {}
 
-pub(crate) mod sealed {
-    use core::cell::{Ref, RefCell, RefMut};
+/// Peripheral static state
+pub(crate) struct State {
+    inner: Mutex<RefCell<InnerState>>,
+}
 
-    use critical_section::{CriticalSection, Mutex};
-    use embassy_sync::waitqueue::WakerRegistration;
+struct InnerState {
+    ptr: *mut u8,
+    end: *mut u8,
+    waker: WakerRegistration,
+}
 
-    use super::*;
+unsafe impl Send for InnerState {}
 
-    /// Peripheral static state
-    pub struct State {
-        inner: Mutex<RefCell<InnerState>>,
-    }
-
-    pub struct InnerState {
-        pub ptr: *mut u8,
-        pub end: *mut u8,
-        pub waker: WakerRegistration,
-    }
-
-    unsafe impl Send for InnerState {}
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                inner: Mutex::new(RefCell::new(InnerState::new())),
-            }
-        }
-
-        pub fn borrow<'cs>(&'cs self, cs: CriticalSection<'cs>) -> Ref<'cs, InnerState> {
-            self.inner.borrow(cs).borrow()
-        }
-
-        pub fn borrow_mut<'cs>(&'cs self, cs: CriticalSection<'cs>) -> RefMut<'cs, InnerState> {
-            self.inner.borrow(cs).borrow_mut()
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            inner: Mutex::new(RefCell::new(InnerState::new())),
         }
     }
 
-    impl InnerState {
-        pub const fn new() -> Self {
-            Self {
-                ptr: ptr::null_mut(),
-                end: ptr::null_mut(),
-                waker: WakerRegistration::new(),
-            }
-        }
-    }
-
-    pub trait Instance {
-        fn regs() -> &'static crate::pac::rng::RegisterBlock;
-        fn state() -> &'static State;
+    fn borrow_mut<'cs>(&'cs self, cs: CriticalSection<'cs>) -> RefMut<'cs, InnerState> {
+        self.inner.borrow(cs).borrow_mut()
     }
 }
 
+impl InnerState {
+    const fn new() -> Self {
+        Self {
+            ptr: ptr::null_mut(),
+            end: ptr::null_mut(),
+            waker: WakerRegistration::new(),
+        }
+    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static crate::pac::rng::RegisterBlock;
+    fn state() -> &'static State;
+}
+
 /// RNG peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_rng {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::rng::sealed::Instance for peripherals::$type {
+        impl crate::rng::SealedInstance for peripherals::$type {
             fn regs() -> &'static crate::pac::rng::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::rng::sealed::State {
-                static STATE: crate::rng::sealed::State = crate::rng::sealed::State::new();
+            fn state() -> &'static crate::rng::State {
+                static STATE: crate::rng::State = crate::rng::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 662b05614..17c65fa3e 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -16,7 +16,6 @@ pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel;
 use saadc::oversample::OVERSAMPLE_A;
 use saadc::resolution::VAL_A;
 
-use self::sealed::Input as _;
 use crate::interrupt::InterruptExt;
 use crate::ppi::{ConfigurableChannel, Event, Ppi, Task};
 use crate::timer::{Frequency, Instance as TimerInstance, Timer};
@@ -662,16 +661,13 @@ pub enum Resolution {
     _14BIT = 3,
 }
 
-pub(crate) mod sealed {
-    use super::*;
-
-    pub trait Input {
-        fn channel(&self) -> InputChannel;
-    }
+pub(crate) trait SealedInput {
+    fn channel(&self) -> InputChannel;
 }
 
 /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
-pub trait Input: sealed::Input + Into<AnyInput> + Peripheral<P = Self> + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Input: SealedInput + Into<AnyInput> + Peripheral<P = Self> + Sized + 'static {
     /// Convert this SAADC input to a type-erased `AnyInput`.
     ///
     /// This allows using several inputs  in situations that might require
@@ -693,7 +689,7 @@ pub struct AnyInput {
 
 impl_peripheral!(AnyInput);
 
-impl sealed::Input for AnyInput {
+impl SealedInput for AnyInput {
     fn channel(&self) -> InputChannel {
         self.channel
     }
@@ -706,7 +702,7 @@ macro_rules! impl_saadc_input {
         impl_saadc_input!(@local, crate::peripherals::$pin, $ch);
     };
     (@local, $pin:ty, $ch:ident) => {
-        impl crate::saadc::sealed::Input for $pin {
+        impl crate::saadc::SealedInput for $pin {
             fn channel(&self) -> crate::saadc::InputChannel {
                 crate::saadc::InputChannel::$ch
             }
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index c45d45e68..373f22642 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -4,18 +4,20 @@
 
 use core::future::poll_fn;
 use core::marker::PhantomData;
+#[cfg(feature = "_nrf52832_anomaly_109")]
+use core::sync::atomic::AtomicU8;
 use core::sync::atomic::{compiler_fence, Ordering};
 use core::task::Poll;
 
 use embassy_embedded_hal::SetConfig;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
 pub use pac::spim0::config::ORDER_A as BitOrder;
 pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
 
 use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits};
+use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _};
 use crate::interrupt::typelevel::Interrupt;
 use crate::util::{slice_in_ram_or, slice_ptr_len, slice_ptr_parts, slice_ptr_parts_mut};
 use crate::{interrupt, pac, Peripheral};
@@ -487,54 +489,46 @@ impl<'d, T: Instance> Drop for Spim<'d, T> {
     }
 }
 
-pub(crate) mod sealed {
+pub(crate) struct State {
+    waker: AtomicWaker,
     #[cfg(feature = "_nrf52832_anomaly_109")]
-    use core::sync::atomic::AtomicU8;
+    rx: AtomicU8,
+    #[cfg(feature = "_nrf52832_anomaly_109")]
+    tx: AtomicU8,
+}
 
-    use embassy_sync::waitqueue::AtomicWaker;
-
-    use super::*;
-
-    pub struct State {
-        pub waker: AtomicWaker,
-        #[cfg(feature = "_nrf52832_anomaly_109")]
-        pub rx: AtomicU8,
-        #[cfg(feature = "_nrf52832_anomaly_109")]
-        pub tx: AtomicU8,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                waker: AtomicWaker::new(),
-                #[cfg(feature = "_nrf52832_anomaly_109")]
-                rx: AtomicU8::new(0),
-                #[cfg(feature = "_nrf52832_anomaly_109")]
-                tx: AtomicU8::new(0),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            waker: AtomicWaker::new(),
+            #[cfg(feature = "_nrf52832_anomaly_109")]
+            rx: AtomicU8::new(0),
+            #[cfg(feature = "_nrf52832_anomaly_109")]
+            tx: AtomicU8::new(0),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static pac::spim0::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::spim0::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// SPIM peripheral instance
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_spim {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::spim::sealed::Instance for peripherals::$type {
+        impl crate::spim::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::spim0::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::spim::sealed::State {
-                static STATE: crate::spim::sealed::State = crate::spim::sealed::State::new();
+            fn state() -> &'static crate::spim::State {
+                static STATE: crate::spim::State = crate::spim::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs
index 772ca40cc..47bbeaf77 100644
--- a/embassy-nrf/src/spis.rs
+++ b/embassy-nrf/src/spis.rs
@@ -8,12 +8,12 @@ use core::task::Poll;
 
 use embassy_embedded_hal::SetConfig;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
 pub use pac::spis0::config::ORDER_A as BitOrder;
 
 use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{self, AnyPin, Pin as GpioPin};
+use crate::gpio::{self, AnyPin, Pin as GpioPin, SealedPin as _};
 use crate::interrupt::typelevel::Interrupt;
 use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut};
 use crate::{interrupt, pac, Peripheral};
@@ -456,43 +456,38 @@ impl<'d, T: Instance> Drop for Spis<'d, T> {
     }
 }
 
-pub(crate) mod sealed {
-    use embassy_sync::waitqueue::AtomicWaker;
+pub(crate) struct State {
+    waker: AtomicWaker,
+}
 
-    use super::*;
-
-    pub struct State {
-        pub waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static pac::spis0::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::spis0::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// SPIS peripheral instance
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_spis {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::spis::sealed::Instance for peripherals::$type {
+        impl crate::spis::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::spis0::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::spis::sealed::State {
-                static STATE: crate::spis::sealed::State = crate::spis::sealed::State::new();
+            fn state() -> &'static crate::spis::State {
+                static STATE: crate::spis::State = crate::spis::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index 2970ad3f2..ac5328ded 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -11,30 +11,25 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
 use crate::ppi::{Event, Task};
 use crate::{pac, Peripheral};
 
-pub(crate) mod sealed {
-
-    use super::*;
-
-    pub trait Instance {
-        /// The number of CC registers this instance has.
-        const CCS: usize;
-        fn regs() -> &'static pac::timer0::RegisterBlock;
-    }
-    pub trait ExtendedInstance {}
+pub(crate) trait SealedInstance {
+    /// The number of CC registers this instance has.
+    const CCS: usize;
+    fn regs() -> &'static pac::timer0::RegisterBlock;
 }
 
 /// Basic Timer instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: crate::interrupt::typelevel::Interrupt;
 }
 
 /// Extended timer instance.
-pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {}
+pub trait ExtendedInstance: Instance {}
 
 macro_rules! impl_timer {
     ($type:ident, $pac_type:ident, $irq:ident, $ccs:literal) => {
-        impl crate::timer::sealed::Instance for peripherals::$type {
+        impl crate::timer::SealedInstance for peripherals::$type {
             const CCS: usize = $ccs;
             fn regs() -> &'static pac::timer0::RegisterBlock {
                 unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) }
@@ -49,7 +44,6 @@ macro_rules! impl_timer {
     };
     ($type:ident, $pac_type:ident, $irq:ident, extended) => {
         impl_timer!($type, $pac_type, $irq, 6);
-        impl crate::timer::sealed::ExtendedInstance for peripherals::$type {}
         impl crate::timer::ExtendedInstance for peripherals::$type {}
     };
 }
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 24810a08c..c64743ecc 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -727,41 +727,38 @@ impl<'a, T: Instance> Drop for Twim<'a, T> {
     }
 }
 
-pub(crate) mod sealed {
-    use super::*;
+pub(crate) struct State {
+    end_waker: AtomicWaker,
+}
 
-    pub struct State {
-        pub end_waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                end_waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            end_waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static pac::twim0::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::twim0::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// TWIM peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_twim {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::twim::sealed::Instance for peripherals::$type {
+        impl crate::twim::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::twim0::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::twim::sealed::State {
-                static STATE: crate::twim::sealed::State = crate::twim::sealed::State::new();
+            fn state() -> &'static crate::twim::State {
+                static STATE: crate::twim::State = crate::twim::State::new();
                 &STATE
             }
         }
diff --git a/embassy-nrf/src/twis.rs b/embassy-nrf/src/twis.rs
index 415150447..f3eab008f 100644
--- a/embassy-nrf/src/twis.rs
+++ b/embassy-nrf/src/twis.rs
@@ -754,41 +754,38 @@ impl<'a, T: Instance> Drop for Twis<'a, T> {
     }
 }
 
-pub(crate) mod sealed {
-    use super::*;
+pub(crate) struct State {
+    waker: AtomicWaker,
+}
 
-    pub struct State {
-        pub waker: AtomicWaker,
-    }
-
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                waker: AtomicWaker::new(),
-            }
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            waker: AtomicWaker::new(),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static pac::twis0::RegisterBlock;
-        fn state() -> &'static State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::twis0::RegisterBlock;
+    fn state() -> &'static State;
 }
 
 /// TWIS peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_twis {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::twis::sealed::Instance for peripherals::$type {
+        impl crate::twis::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::twis0::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::twis::sealed::State {
-                static STATE: crate::twis::sealed::State = crate::twis::sealed::State::new();
+            fn state() -> &'static crate::twis::State {
+                static STATE: crate::twis::State = crate::twis::State::new();
                 &STATE
             }
         }
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 @@
 
 use core::future::poll_fn;
 use core::marker::PhantomData;
-use core::sync::atomic::{compiler_fence, Ordering};
+use core::sync::atomic::{compiler_fence, AtomicU8, Ordering};
 use core::task::Poll;
 
 use embassy_hal_internal::drop::OnDrop;
 use embassy_hal_internal::{into_ref, PeripheralRef};
+use embassy_sync::waitqueue::AtomicWaker;
 use pac::uarte0::RegisterBlock;
 // Re-export SVD variants to allow user to directly set values.
 pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
 
 use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits};
+use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits, SealedPin as _};
 use crate::interrupt::typelevel::Interrupt;
 use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
 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
     }
 }
 
-pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) {
+pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &State) {
     if s.tx_rx_refcount.fetch_sub(1, Ordering::Relaxed) == 1 {
         // Finally we can disable, and we do so for the peripheral
         // i.e. not just rx concerns.
@@ -954,49 +954,42 @@ pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) {
     }
 }
 
-pub(crate) mod sealed {
-    use core::sync::atomic::AtomicU8;
-
-    use embassy_sync::waitqueue::AtomicWaker;
-
-    use super::*;
-
-    pub struct State {
-        pub rx_waker: AtomicWaker,
-        pub tx_waker: AtomicWaker,
-        pub tx_rx_refcount: AtomicU8,
-    }
-    impl State {
-        pub const fn new() -> Self {
-            Self {
-                rx_waker: AtomicWaker::new(),
-                tx_waker: AtomicWaker::new(),
-                tx_rx_refcount: AtomicU8::new(0),
-            }
+pub(crate) struct State {
+    pub(crate) rx_waker: AtomicWaker,
+    pub(crate) tx_waker: AtomicWaker,
+    pub(crate) tx_rx_refcount: AtomicU8,
+}
+impl State {
+    pub(crate) const fn new() -> Self {
+        Self {
+            rx_waker: AtomicWaker::new(),
+            tx_waker: AtomicWaker::new(),
+            tx_rx_refcount: AtomicU8::new(0),
         }
     }
-
-    pub trait Instance {
-        fn regs() -> &'static pac::uarte0::RegisterBlock;
-        fn state() -> &'static State;
-        fn buffered_state() -> &'static crate::buffered_uarte::State;
-    }
+}
+
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::uarte0::RegisterBlock;
+    fn state() -> &'static State;
+    fn buffered_state() -> &'static crate::buffered_uarte::State;
 }
 
 /// UARTE peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_uarte {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::uarte::sealed::Instance for peripherals::$type {
+        impl crate::uarte::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::uarte0::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }
-            fn state() -> &'static crate::uarte::sealed::State {
-                static STATE: crate::uarte::sealed::State = crate::uarte::sealed::State::new();
+            fn state() -> &'static crate::uarte::State {
+                static STATE: crate::uarte::State = crate::uarte::State::new();
                 &STATE
             }
             fn buffered_state() -> &'static crate::buffered_uarte::State {
diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs
index e26b49db3..09cf87e97 100644
--- a/embassy-nrf/src/usb/mod.rs
+++ b/embassy-nrf/src/usb/mod.rs
@@ -793,23 +793,20 @@ impl Allocator {
     }
 }
 
-pub(crate) mod sealed {
-    use super::*;
-
-    pub trait Instance {
-        fn regs() -> &'static pac::usbd::RegisterBlock;
-    }
+pub(crate) trait SealedInstance {
+    fn regs() -> &'static pac::usbd::RegisterBlock;
 }
 
 /// USB peripheral instance.
-pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
 macro_rules! impl_usb {
     ($type:ident, $pac_type:ident, $irq:ident) => {
-        impl crate::usb::sealed::Instance for peripherals::$type {
+        impl crate::usb::SealedInstance for peripherals::$type {
             fn regs() -> &'static pac::usbd::RegisterBlock {
                 unsafe { &*pac::$pac_type::ptr() }
             }

From a84b33995eacc32e0e13d70293fa9bd7b2bd75f8 Mon Sep 17 00:00:00 2001
From: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Date: Fri, 5 Apr 2024 00:35:25 +0200
Subject: [PATCH 2/3] rp: remove mod sealed.

---
 embassy-rp/src/adc.rs              | 24 ++++----
 embassy-rp/src/clocks.rs           | 11 ++--
 embassy-rp/src/dma.rs              | 23 ++++---
 embassy-rp/src/flash.rs            | 16 ++---
 embassy-rp/src/gpio.rs             | 96 ++++++++++++++----------------
 embassy-rp/src/i2c.rs              | 51 +++++++---------
 embassy-rp/src/pio/mod.rs          | 64 ++++++++++----------
 embassy-rp/src/pwm.rs              | 12 ++--
 embassy-rp/src/rtc/mod.rs          | 11 ++--
 embassy-rp/src/spi.rs              | 27 ++++-----
 embassy-rp/src/uart/mod.rs         | 55 ++++++++---------
 embassy-rp/src/usb.rs              | 13 ++--
 examples/rp/src/bin/pio_stepper.rs |  2 +-
 13 files changed, 189 insertions(+), 216 deletions(-)

diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs
index 4c01fe195..101c5b71f 100644
--- a/embassy-rp/src/adc.rs
+++ b/embassy-rp/src/adc.rs
@@ -8,8 +8,7 @@ use core::task::Poll;
 use embassy_hal_internal::{into_ref, PeripheralRef};
 use embassy_sync::waitqueue::AtomicWaker;
 
-use crate::gpio::sealed::Pin as GpioPin;
-use crate::gpio::{self, AnyPin, Pull};
+use crate::gpio::{self, AnyPin, Pull, SealedPin as GpioPin};
 use crate::interrupt::typelevel::Binding;
 use crate::interrupt::InterruptExt;
 use crate::peripherals::{ADC, ADC_TEMP_SENSOR};
@@ -334,29 +333,28 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ADC_IRQ_FIFO> for Inter
     }
 }
 
-mod sealed {
-    pub trait AdcSample: crate::dma::Word {}
-
-    pub trait AdcChannel {}
-}
+trait SealedAdcSample: crate::dma::Word {}
+trait SealedAdcChannel {}
 
 /// ADC sample.
-pub trait AdcSample: sealed::AdcSample {}
+#[allow(private_bounds)]
+pub trait AdcSample: SealedAdcSample {}
 
-impl sealed::AdcSample for u16 {}
+impl SealedAdcSample for u16 {}
 impl AdcSample for u16 {}
 
-impl sealed::AdcSample for u8 {}
+impl SealedAdcSample for u8 {}
 impl AdcSample for u8 {}
 
 /// ADC channel.
-pub trait AdcChannel: sealed::AdcChannel {}
+#[allow(private_bounds)]
+pub trait AdcChannel: SealedAdcChannel {}
 /// ADC pin.
 pub trait AdcPin: AdcChannel + gpio::Pin {}
 
 macro_rules! impl_pin {
     ($pin:ident, $channel:expr) => {
-        impl sealed::AdcChannel for peripherals::$pin {}
+        impl SealedAdcChannel for peripherals::$pin {}
         impl AdcChannel for peripherals::$pin {}
         impl AdcPin for peripherals::$pin {}
     };
@@ -367,5 +365,5 @@ impl_pin!(PIN_27, 1);
 impl_pin!(PIN_28, 2);
 impl_pin!(PIN_29, 3);
 
-impl sealed::AdcChannel for peripherals::ADC_TEMP_SENSOR {}
+impl SealedAdcChannel for peripherals::ADC_TEMP_SENSOR {}
 impl AdcChannel for peripherals::ADC_TEMP_SENSOR {}
diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs
index b7f6aeac9..bedb79464 100644
--- a/embassy-rp/src/clocks.rs
+++ b/embassy-rp/src/clocks.rs
@@ -6,8 +6,7 @@ use core::sync::atomic::{AtomicU16, AtomicU32, Ordering};
 use embassy_hal_internal::{into_ref, PeripheralRef};
 use pac::clocks::vals::*;
 
-use crate::gpio::sealed::Pin;
-use crate::gpio::AnyPin;
+use crate::gpio::{AnyPin, SealedPin};
 use crate::pac::common::{Reg, RW};
 use crate::{pac, reset, Peripheral};
 
@@ -788,14 +787,14 @@ impl_gpinpin!(PIN_20, 20, 0);
 impl_gpinpin!(PIN_22, 22, 1);
 
 /// General purpose clock input driver.
-pub struct Gpin<'d, T: Pin> {
+pub struct Gpin<'d, T: GpinPin> {
     gpin: PeripheralRef<'d, AnyPin>,
     _phantom: PhantomData<T>,
 }
 
-impl<'d, T: Pin> Gpin<'d, T> {
+impl<'d, T: GpinPin> Gpin<'d, T> {
     /// Create new gpin driver.
-    pub fn new<P: GpinPin>(gpin: impl Peripheral<P = P> + 'd) -> Gpin<'d, P> {
+    pub fn new(gpin: impl Peripheral<P = T> + 'd) -> Self {
         into_ref!(gpin);
 
         gpin.gpio().ctrl().write(|w| w.set_funcsel(0x08));
@@ -811,7 +810,7 @@ impl<'d, T: Pin> Gpin<'d, T> {
     // }
 }
 
-impl<'d, T: Pin> Drop for Gpin<'d, T> {
+impl<'d, T: GpinPin> Drop for Gpin<'d, T> {
     fn drop(&mut self) {
         self.gpin
             .gpio()
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs
index 44aabce6b..e6374a86c 100644
--- a/embassy-rp/src/dma.rs
+++ b/embassy-rp/src/dma.rs
@@ -208,14 +208,12 @@ pub(crate) const CHANNEL_COUNT: usize = 12;
 const NEW_AW: AtomicWaker = AtomicWaker::new();
 static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
 
-mod sealed {
-    pub trait Channel {}
-
-    pub trait Word {}
-}
+trait SealedChannel {}
+trait SealedWord {}
 
 /// DMA channel interface.
-pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Channel: Peripheral<P = Self> + SealedChannel + Into<AnyChannel> + Sized + 'static {
     /// Channel number.
     fn number(&self) -> u8;
 
@@ -231,26 +229,27 @@ pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + S
 }
 
 /// DMA word.
-pub trait Word: sealed::Word {
+#[allow(private_bounds)]
+pub trait Word: SealedWord {
     /// Word size.
     fn size() -> vals::DataSize;
 }
 
-impl sealed::Word for u8 {}
+impl SealedWord for u8 {}
 impl Word for u8 {
     fn size() -> vals::DataSize {
         vals::DataSize::SIZE_BYTE
     }
 }
 
-impl sealed::Word for u16 {}
+impl SealedWord for u16 {}
 impl Word for u16 {
     fn size() -> vals::DataSize {
         vals::DataSize::SIZE_HALFWORD
     }
 }
 
-impl sealed::Word for u32 {}
+impl SealedWord for u32 {}
 impl Word for u32 {
     fn size() -> vals::DataSize {
         vals::DataSize::SIZE_WORD
@@ -264,7 +263,7 @@ pub struct AnyChannel {
 
 impl_peripheral!(AnyChannel);
 
-impl sealed::Channel for AnyChannel {}
+impl SealedChannel for AnyChannel {}
 impl Channel for AnyChannel {
     fn number(&self) -> u8 {
         self.number
@@ -273,7 +272,7 @@ impl Channel for AnyChannel {
 
 macro_rules! channel {
     ($name:ident, $num:expr) => {
-        impl sealed::Channel for peripherals::$name {}
+        impl SealedChannel for peripherals::$name {}
         impl Channel for peripherals::$name {
             fn number(&self) -> u8 {
                 $num
diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs
index 422b77400..45b385cb4 100644
--- a/embassy-rp/src/flash.rs
+++ b/embassy-rp/src/flash.rs
@@ -903,22 +903,22 @@ pub(crate) unsafe fn in_ram(operation: impl FnOnce()) -> Result<(), Error> {
     Ok(())
 }
 
-mod sealed {
-    pub trait Instance {}
-    pub trait Mode {}
-}
+trait SealedInstance {}
+trait SealedMode {}
 
 /// Flash instance.
-pub trait Instance: sealed::Instance {}
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance {}
 /// Flash mode.
-pub trait Mode: sealed::Mode {}
+#[allow(private_bounds)]
+pub trait Mode: SealedMode {}
 
-impl sealed::Instance for FLASH {}
+impl SealedInstance for FLASH {}
 impl Instance for FLASH {}
 
 macro_rules! impl_mode {
     ($name:ident) => {
-        impl sealed::Mode for $name {}
+        impl SealedMode for $name {}
         impl Mode for $name {}
     };
 }
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index a84c00a2c..ea87fd9da 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -8,7 +8,6 @@ use core::task::{Context, Poll};
 use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
 use embassy_sync::waitqueue::AtomicWaker;
 
-use self::sealed::Pin as _;
 use crate::interrupt::InterruptExt;
 use crate::pac::common::{Reg, RW};
 use crate::pac::SIO;
@@ -802,68 +801,65 @@ impl<'w> Drop for DormantWake<'w> {
     }
 }
 
-pub(crate) mod sealed {
-    use super::*;
+pub(crate) trait SealedPin: Sized {
+    fn pin_bank(&self) -> u8;
 
-    pub trait Pin: Sized {
-        fn pin_bank(&self) -> u8;
+    #[inline]
+    fn _pin(&self) -> u8 {
+        self.pin_bank() & 0x1f
+    }
 
-        #[inline]
-        fn _pin(&self) -> u8 {
-            self.pin_bank() & 0x1f
+    #[inline]
+    fn _bank(&self) -> Bank {
+        match self.pin_bank() >> 5 {
+            #[cfg(feature = "qspi-as-gpio")]
+            1 => Bank::Qspi,
+            _ => Bank::Bank0,
         }
+    }
 
-        #[inline]
-        fn _bank(&self) -> Bank {
-            match self.pin_bank() >> 5 {
-                #[cfg(feature = "qspi-as-gpio")]
-                1 => Bank::Qspi,
-                _ => Bank::Bank0,
-            }
+    fn io(&self) -> pac::io::Io {
+        match self._bank() {
+            Bank::Bank0 => crate::pac::IO_BANK0,
+            #[cfg(feature = "qspi-as-gpio")]
+            Bank::Qspi => crate::pac::IO_QSPI,
         }
+    }
 
-        fn io(&self) -> pac::io::Io {
-            match self._bank() {
-                Bank::Bank0 => crate::pac::IO_BANK0,
-                #[cfg(feature = "qspi-as-gpio")]
-                Bank::Qspi => crate::pac::IO_QSPI,
-            }
-        }
+    fn gpio(&self) -> pac::io::Gpio {
+        self.io().gpio(self._pin() as _)
+    }
 
-        fn gpio(&self) -> pac::io::Gpio {
-            self.io().gpio(self._pin() as _)
-        }
+    fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> {
+        let block = match self._bank() {
+            Bank::Bank0 => crate::pac::PADS_BANK0,
+            #[cfg(feature = "qspi-as-gpio")]
+            Bank::Qspi => crate::pac::PADS_QSPI,
+        };
+        block.gpio(self._pin() as _)
+    }
 
-        fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> {
-            let block = match self._bank() {
-                Bank::Bank0 => crate::pac::PADS_BANK0,
-                #[cfg(feature = "qspi-as-gpio")]
-                Bank::Qspi => crate::pac::PADS_QSPI,
-            };
-            block.gpio(self._pin() as _)
-        }
+    fn sio_out(&self) -> pac::sio::Gpio {
+        SIO.gpio_out(self._bank() as _)
+    }
 
-        fn sio_out(&self) -> pac::sio::Gpio {
-            SIO.gpio_out(self._bank() as _)
-        }
+    fn sio_oe(&self) -> pac::sio::Gpio {
+        SIO.gpio_oe(self._bank() as _)
+    }
 
-        fn sio_oe(&self) -> pac::sio::Gpio {
-            SIO.gpio_oe(self._bank() as _)
-        }
+    fn sio_in(&self) -> Reg<u32, RW> {
+        SIO.gpio_in(self._bank() as _)
+    }
 
-        fn sio_in(&self) -> Reg<u32, RW> {
-            SIO.gpio_in(self._bank() as _)
-        }
-
-        fn int_proc(&self) -> pac::io::Int {
-            let proc = SIO.cpuid().read();
-            self.io().int_proc(proc as _)
-        }
+    fn int_proc(&self) -> pac::io::Int {
+        let proc = SIO.cpuid().read();
+        self.io().int_proc(proc as _)
     }
 }
 
 /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin].
-pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static {
     /// Degrade to a generic pin struct
     fn degrade(self) -> AnyPin {
         AnyPin {
@@ -903,7 +899,7 @@ impl AnyPin {
 impl_peripheral!(AnyPin);
 
 impl Pin for AnyPin {}
-impl sealed::Pin for AnyPin {
+impl SealedPin for AnyPin {
     fn pin_bank(&self) -> u8 {
         self.pin_bank
     }
@@ -914,7 +910,7 @@ impl sealed::Pin for AnyPin {
 macro_rules! impl_pin {
     ($name:ident, $bank:expr, $pin_num:expr) => {
         impl Pin for peripherals::$name {}
-        impl sealed::Pin for peripherals::$name {
+        impl SealedPin for peripherals::$name {
             #[inline]
             fn pin_bank(&self) -> u8 {
                 ($bank as u8) * 32 + $pin_num
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs
index 26a819b25..256875b4a 100644
--- a/embassy-rp/src/i2c.rs
+++ b/embassy-rp/src/i2c.rs
@@ -784,34 +784,24 @@ pub fn i2c_reserved_addr(addr: u16) -> bool {
     ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0
 }
 
-mod sealed {
-    use embassy_sync::waitqueue::AtomicWaker;
+pub(crate) trait SealedInstance {
+    const TX_DREQ: u8;
+    const RX_DREQ: u8;
 
-    use crate::interrupt;
-
-    pub trait Instance {
-        const TX_DREQ: u8;
-        const RX_DREQ: u8;
-
-        type Interrupt: interrupt::typelevel::Interrupt;
-
-        fn regs() -> crate::pac::i2c::I2c;
-        fn reset() -> crate::pac::resets::regs::Peripherals;
-        fn waker() -> &'static AtomicWaker;
-    }
-
-    pub trait Mode {}
-
-    pub trait SdaPin<T: Instance> {}
-    pub trait SclPin<T: Instance> {}
+    fn regs() -> crate::pac::i2c::I2c;
+    fn reset() -> crate::pac::resets::regs::Peripherals;
+    fn waker() -> &'static AtomicWaker;
 }
 
+trait SealedMode {}
+
 /// Driver mode.
-pub trait Mode: sealed::Mode {}
+#[allow(private_bounds)]
+pub trait Mode: SealedMode {}
 
 macro_rules! impl_mode {
     ($name:ident) => {
-        impl sealed::Mode for $name {}
+        impl SealedMode for $name {}
         impl Mode for $name {}
     };
 }
@@ -825,16 +815,18 @@ impl_mode!(Blocking);
 impl_mode!(Async);
 
 /// I2C instance.
-pub trait Instance: sealed::Instance {}
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance {
+    /// Interrupt for this peripheral.
+    type Interrupt: interrupt::typelevel::Interrupt;
+}
 
 macro_rules! impl_instance {
     ($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => {
-        impl sealed::Instance for peripherals::$type {
+        impl SealedInstance for peripherals::$type {
             const TX_DREQ: u8 = $tx_dreq;
             const RX_DREQ: u8 = $rx_dreq;
 
-            type Interrupt = crate::interrupt::typelevel::$irq;
-
             #[inline]
             fn regs() -> pac::i2c::I2c {
                 pac::$type
@@ -854,7 +846,9 @@ macro_rules! impl_instance {
                 &WAKER
             }
         }
-        impl Instance for peripherals::$type {}
+        impl Instance for peripherals::$type {
+            type Interrupt = crate::interrupt::typelevel::$irq;
+        }
     };
 }
 
@@ -862,13 +856,12 @@ impl_instance!(I2C0, I2C0_IRQ, set_i2c0, 32, 33);
 impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35);
 
 /// SDA pin.
-pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + crate::gpio::Pin {}
+pub trait SdaPin<T: Instance>: crate::gpio::Pin {}
 /// SCL pin.
-pub trait SclPin<T: Instance>: sealed::SclPin<T> + crate::gpio::Pin {}
+pub trait SclPin<T: Instance>: crate::gpio::Pin {}
 
 macro_rules! impl_pin {
     ($pin:ident, $instance:ident, $function:ident) => {
-        impl sealed::$function<peripherals::$instance> for peripherals::$pin {}
         impl $function<peripherals::$instance> for peripherals::$pin {}
     };
 }
diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs
index 7eca700ba..2e5c57a26 100644
--- a/embassy-rp/src/pio/mod.rs
+++ b/embassy-rp/src/pio/mod.rs
@@ -15,8 +15,7 @@ use pac::pio::vals::SmExecctrlStatusSel;
 use pio::{Program, SideSet, Wrap};
 
 use crate::dma::{Channel, Transfer, Word};
-use crate::gpio::sealed::Pin as SealedPin;
-use crate::gpio::{self, AnyPin, Drive, Level, Pull, SlewRate};
+use crate::gpio::{self, AnyPin, Drive, Level, Pull, SealedPin, SlewRate};
 use crate::interrupt::typelevel::{Binding, Handler, Interrupt};
 use crate::pac::dma::vals::TreqSel;
 use crate::relocate::RelocatedProgram;
@@ -695,6 +694,12 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
         }
     }
 
+    /// Set the clock divider for this state machine.
+    pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) {
+        let sm = Self::this_sm();
+        sm.clkdiv().write(|w| w.0 = clock_divider.to_bits() << 8);
+    }
+
     #[inline(always)]
     fn this_sm() -> crate::pac::pio::StateMachine {
         PIO::PIO.sm(SM)
@@ -1148,49 +1153,47 @@ fn on_pio_drop<PIO: Instance>() {
     }
 }
 
-mod sealed {
-    use super::*;
+trait SealedInstance {
+    const PIO_NO: u8;
+    const PIO: &'static crate::pac::pio::Pio;
+    const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel;
 
-    pub trait PioPin {}
+    #[inline]
+    fn wakers() -> &'static Wakers {
+        const NEW_AW: AtomicWaker = AtomicWaker::new();
+        static WAKERS: Wakers = Wakers([NEW_AW; 12]);
 
-    pub trait Instance {
-        const PIO_NO: u8;
-        const PIO: &'static crate::pac::pio::Pio;
-        const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel;
-        type Interrupt: crate::interrupt::typelevel::Interrupt;
+        &WAKERS
+    }
 
-        #[inline]
-        fn wakers() -> &'static Wakers {
-            const NEW_AW: AtomicWaker = AtomicWaker::new();
-            static WAKERS: Wakers = Wakers([NEW_AW; 12]);
+    #[inline]
+    fn state() -> &'static State {
+        static STATE: State = State {
+            users: AtomicU8::new(0),
+            used_pins: AtomicU32::new(0),
+        };
 
-            &WAKERS
-        }
-
-        #[inline]
-        fn state() -> &'static State {
-            static STATE: State = State {
-                users: AtomicU8::new(0),
-                used_pins: AtomicU32::new(0),
-            };
-
-            &STATE
-        }
+        &STATE
     }
 }
 
 /// PIO instance.
-pub trait Instance: sealed::Instance + Sized + Unpin {}
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance + Sized + Unpin {
+    /// Interrupt for this peripheral.
+    type Interrupt: crate::interrupt::typelevel::Interrupt;
+}
 
 macro_rules! impl_pio {
     ($name:ident, $pio:expr, $pac:ident, $funcsel:ident, $irq:ident) => {
-        impl sealed::Instance for peripherals::$name {
+        impl SealedInstance for peripherals::$name {
             const PIO_NO: u8 = $pio;
             const PIO: &'static pac::pio::Pio = &pac::$pac;
             const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel;
+        }
+        impl Instance for peripherals::$name {
             type Interrupt = crate::interrupt::typelevel::$irq;
         }
-        impl Instance for peripherals::$name {}
     };
 }
 
@@ -1198,12 +1201,11 @@ impl_pio!(PIO0, 0, PIO0, PIO0_0, PIO0_IRQ_0);
 impl_pio!(PIO1, 1, PIO1, PIO1_0, PIO1_IRQ_0);
 
 /// PIO pin.
-pub trait PioPin: sealed::PioPin + gpio::Pin {}
+pub trait PioPin: gpio::Pin {}
 
 macro_rules! impl_pio_pin {
     ($( $pin:ident, )*) => {
         $(
-            impl sealed::PioPin for peripherals::$pin {}
             impl PioPin for peripherals::$pin {}
         )*
     };
diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs
index 5aab3ff4f..7613e4e58 100644
--- a/embassy-rp/src/pwm.rs
+++ b/embassy-rp/src/pwm.rs
@@ -6,8 +6,7 @@ use fixed::FixedU16;
 use pac::pwm::regs::{ChDiv, Intr};
 use pac::pwm::vals::Divmode;
 
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{AnyPin, Pin as GpioPin};
+use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _};
 use crate::{pac, peripherals, RegExt};
 
 /// The configuration of a PWM slice.
@@ -300,12 +299,11 @@ impl<'d, T: Slice> Drop for Pwm<'d, T> {
     }
 }
 
-mod sealed {
-    pub trait Slice {}
-}
+trait SealedSlice {}
 
 /// PWM Slice.
-pub trait Slice: Peripheral<P = Self> + sealed::Slice + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Slice: Peripheral<P = Self> + SealedSlice + Sized + 'static {
     /// Slice number.
     fn number(&self) -> u8;
 
@@ -317,7 +315,7 @@ pub trait Slice: Peripheral<P = Self> + sealed::Slice + Sized + 'static {
 
 macro_rules! slice {
     ($name:ident, $num:expr) => {
-        impl sealed::Slice for peripherals::$name {}
+        impl SealedSlice for peripherals::$name {}
         impl Slice for peripherals::$name {
             fn number(&self) -> u8 {
                 $num
diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs
index c8691bdc2..2ce7ac645 100644
--- a/embassy-rp/src/rtc/mod.rs
+++ b/embassy-rp/src/rtc/mod.rs
@@ -188,16 +188,15 @@ pub enum RtcError {
     NotRunning,
 }
 
-mod sealed {
-    pub trait Instance {
-        fn regs(&self) -> crate::pac::rtc::Rtc;
-    }
+trait SealedInstance {
+    fn regs(&self) -> crate::pac::rtc::Rtc;
 }
 
 /// RTC peripheral instance.
-pub trait Instance: sealed::Instance {}
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance {}
 
-impl sealed::Instance for crate::peripherals::RTC {
+impl SealedInstance for crate::peripherals::RTC {
     fn regs(&self) -> crate::pac::rtc::Rtc {
         crate::pac::RTC
     }
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index a2a22ffe5..ef4c644ae 100644
--- a/embassy-rp/src/spi.rs
+++ b/embassy-rp/src/spi.rs
@@ -7,8 +7,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
 pub use embedded_hal_02::spi::{Phase, Polarity};
 
 use crate::dma::{AnyChannel, Channel};
-use crate::gpio::sealed::Pin as _;
-use crate::gpio::{AnyPin, Pin as GpioPin};
+use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _};
 use crate::{pac, peripherals, Peripheral};
 
 /// SPI errors.
@@ -443,28 +442,26 @@ impl<'d, T: Instance> Spi<'d, T, Async> {
     }
 }
 
-mod sealed {
-    use super::*;
+trait SealedMode {}
 
-    pub trait Mode {}
+trait SealedInstance {
+    const TX_DREQ: u8;
+    const RX_DREQ: u8;
 
-    pub trait Instance {
-        const TX_DREQ: u8;
-        const RX_DREQ: u8;
-
-        fn regs(&self) -> pac::spi::Spi;
-    }
+    fn regs(&self) -> pac::spi::Spi;
 }
 
 /// Mode.
-pub trait Mode: sealed::Mode {}
+#[allow(private_bounds)]
+pub trait Mode: SealedMode {}
 
 /// SPI instance trait.
-pub trait Instance: sealed::Instance {}
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance {}
 
 macro_rules! impl_instance {
     ($type:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => {
-        impl sealed::Instance for peripherals::$type {
+        impl SealedInstance for peripherals::$type {
             const TX_DREQ: u8 = $tx_dreq;
             const RX_DREQ: u8 = $rx_dreq;
 
@@ -527,7 +524,7 @@ impl_pin!(PIN_29, SPI1, CsPin);
 
 macro_rules! impl_mode {
     ($name:ident) => {
-        impl sealed::Mode for $name {}
+        impl SealedMode for $name {}
         impl Mode for $name {}
     };
 }
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs
index 65dcf4eb4..ee2dcb27d 100644
--- a/embassy-rp/src/uart/mod.rs
+++ b/embassy-rp/src/uart/mod.rs
@@ -12,8 +12,7 @@ use pac::uart::regs::Uartris;
 
 use crate::clocks::clk_peri_freq;
 use crate::dma::{AnyChannel, Channel};
-use crate::gpio::sealed::Pin;
-use crate::gpio::AnyPin;
+use crate::gpio::{AnyPin, SealedPin};
 use crate::interrupt::typelevel::{Binding, Interrupt};
 use crate::pac::io::vals::{Inover, Outover};
 use crate::{interrupt, pac, peripherals, Peripheral, RegExt};
@@ -1107,35 +1106,26 @@ impl<'d, T: Instance, M: Mode> embedded_hal_nb::serial::Write for Uart<'d, T, M>
     }
 }
 
-mod sealed {
-    use super::*;
+trait SealedMode {}
 
-    pub trait Mode {}
+trait SealedInstance {
+    const TX_DREQ: u8;
+    const RX_DREQ: u8;
 
-    pub trait Instance {
-        const TX_DREQ: u8;
-        const RX_DREQ: u8;
+    fn regs() -> pac::uart::Uart;
 
-        type Interrupt: interrupt::typelevel::Interrupt;
+    fn buffered_state() -> &'static buffered::State;
 
-        fn regs() -> pac::uart::Uart;
-
-        fn buffered_state() -> &'static buffered::State;
-
-        fn dma_state() -> &'static DmaState;
-    }
-    pub trait TxPin<T: Instance> {}
-    pub trait RxPin<T: Instance> {}
-    pub trait CtsPin<T: Instance> {}
-    pub trait RtsPin<T: Instance> {}
+    fn dma_state() -> &'static DmaState;
 }
 
 /// UART mode.
-pub trait Mode: sealed::Mode {}
+#[allow(private_bounds)]
+pub trait Mode: SealedMode {}
 
 macro_rules! impl_mode {
     ($name:ident) => {
-        impl sealed::Mode for $name {}
+        impl SealedMode for $name {}
         impl Mode for $name {}
     };
 }
@@ -1149,16 +1139,18 @@ impl_mode!(Blocking);
 impl_mode!(Async);
 
 /// UART instance.
-pub trait Instance: sealed::Instance {}
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance {
+    /// Interrupt for this instance.
+    type Interrupt: interrupt::typelevel::Interrupt;
+}
 
 macro_rules! impl_instance {
     ($inst:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => {
-        impl sealed::Instance for peripherals::$inst {
+        impl SealedInstance for peripherals::$inst {
             const TX_DREQ: u8 = $tx_dreq;
             const RX_DREQ: u8 = $rx_dreq;
 
-            type Interrupt = crate::interrupt::typelevel::$irq;
-
             fn regs() -> pac::uart::Uart {
                 pac::$inst
             }
@@ -1176,7 +1168,9 @@ macro_rules! impl_instance {
                 &STATE
             }
         }
-        impl Instance for peripherals::$inst {}
+        impl Instance for peripherals::$inst {
+            type Interrupt = crate::interrupt::typelevel::$irq;
+        }
     };
 }
 
@@ -1184,17 +1178,16 @@ impl_instance!(UART0, UART0_IRQ, 20, 21);
 impl_instance!(UART1, UART1_IRQ, 22, 23);
 
 /// Trait for TX pins.
-pub trait TxPin<T: Instance>: sealed::TxPin<T> + crate::gpio::Pin {}
+pub trait TxPin<T: Instance>: crate::gpio::Pin {}
 /// Trait for RX pins.
-pub trait RxPin<T: Instance>: sealed::RxPin<T> + crate::gpio::Pin {}
+pub trait RxPin<T: Instance>: crate::gpio::Pin {}
 /// Trait for Clear To Send (CTS) pins.
-pub trait CtsPin<T: Instance>: sealed::CtsPin<T> + crate::gpio::Pin {}
+pub trait CtsPin<T: Instance>: crate::gpio::Pin {}
 /// Trait for Request To Send (RTS) pins.
-pub trait RtsPin<T: Instance>: sealed::RtsPin<T> + crate::gpio::Pin {}
+pub trait RtsPin<T: Instance>: crate::gpio::Pin {}
 
 macro_rules! impl_pin {
     ($pin:ident, $instance:ident, $function:ident) => {
-        impl sealed::$function<peripherals::$instance> for peripherals::$pin {}
         impl $function<peripherals::$instance> for peripherals::$pin {}
     };
 }
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs
index d68dee4a3..37d37d6d9 100644
--- a/embassy-rp/src/usb.rs
+++ b/embassy-rp/src/usb.rs
@@ -14,20 +14,19 @@ use embassy_usb_driver::{
 use crate::interrupt::typelevel::{Binding, Interrupt};
 use crate::{interrupt, pac, peripherals, Peripheral, RegExt};
 
-pub(crate) mod sealed {
-    pub trait Instance {
-        fn regs() -> crate::pac::usb::Usb;
-        fn dpram() -> crate::pac::usb_dpram::UsbDpram;
-    }
+trait SealedInstance {
+    fn regs() -> crate::pac::usb::Usb;
+    fn dpram() -> crate::pac::usb_dpram::UsbDpram;
 }
 
 /// USB peripheral instance.
-pub trait Instance: sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: SealedInstance + 'static {
     /// Interrupt for this peripheral.
     type Interrupt: interrupt::typelevel::Interrupt;
 }
 
-impl crate::usb::sealed::Instance for peripherals::USB {
+impl crate::usb::SealedInstance for peripherals::USB {
     fn regs() -> pac::usb::Usb {
         pac::USBCTRL_REGS
     }
diff --git a/examples/rp/src/bin/pio_stepper.rs b/examples/rp/src/bin/pio_stepper.rs
index ab9ecf623..4952f4fbd 100644
--- a/examples/rp/src/bin/pio_stepper.rs
+++ b/examples/rp/src/bin/pio_stepper.rs
@@ -69,7 +69,7 @@ impl<'d, T: Instance, const SM: usize> PioStepper<'d, T, SM> {
         let clock_divider: FixedU32<U8> = (125_000_000 / (freq * 136)).to_fixed();
         assert!(clock_divider <= 65536, "clkdiv must be <= 65536");
         assert!(clock_divider >= 1, "clkdiv must be >= 1");
-        T::PIO.sm(SM).clkdiv().write(|w| w.0 = clock_divider.to_bits() << 8);
+        self.sm.set_clock_divider(clock_divider);
         self.sm.clkdiv_restart();
     }
 

From d597815c9aed3c2d6b8729db1b78fd0e843181f6 Mon Sep 17 00:00:00 2001
From: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Date: Fri, 5 Apr 2024 00:48:19 +0200
Subject: [PATCH 3/3] stm32: remove last few mod sealed's.

---
 embassy-stm32/src/cordic/mod.rs     | 118 +++++++++++++++++++++++++++-
 embassy-stm32/src/cordic/sealed.rs  | 116 ---------------------------
 embassy-stm32/src/usart/buffered.rs |  36 ++++-----
 3 files changed, 131 insertions(+), 139 deletions(-)
 delete mode 100644 embassy-stm32/src/cordic/sealed.rs

diff --git a/embassy-stm32/src/cordic/mod.rs b/embassy-stm32/src/cordic/mod.rs
index 6bbc48f2b..9ac10e714 100644
--- a/embassy-stm32/src/cordic/mod.rs
+++ b/embassy-stm32/src/cordic/mod.rs
@@ -3,6 +3,7 @@
 use embassy_hal_internal::drop::OnDrop;
 use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
 
+use crate::pac::cordic::vals;
 use crate::{dma, peripherals};
 
 mod enums;
@@ -11,9 +12,6 @@ pub use enums::*;
 mod errors;
 pub use errors::*;
 
-mod sealed;
-use self::sealed::SealedInstance;
-
 pub mod utils;
 
 /// CORDIC driver
@@ -22,6 +20,120 @@ pub struct Cordic<'d, T: Instance> {
     config: Config,
 }
 
+/// Cordic instance
+trait SealedInstance {
+    /// Get access to CORDIC registers
+    fn regs() -> crate::pac::cordic::Cordic;
+
+    /// Set Function value
+    fn set_func(&self, func: Function) {
+        Self::regs()
+            .csr()
+            .modify(|v| v.set_func(vals::Func::from_bits(func as u8)));
+    }
+
+    /// Set Precision value
+    fn set_precision(&self, precision: Precision) {
+        Self::regs()
+            .csr()
+            .modify(|v| v.set_precision(vals::Precision::from_bits(precision as u8)))
+    }
+
+    /// Set Scale value
+    fn set_scale(&self, scale: Scale) {
+        Self::regs()
+            .csr()
+            .modify(|v| v.set_scale(vals::Scale::from_bits(scale as u8)))
+    }
+
+    /// Enable global interrupt
+    fn enable_irq(&self) {
+        Self::regs().csr().modify(|v| v.set_ien(true))
+    }
+
+    /// Disable global interrupt
+    fn disable_irq(&self) {
+        Self::regs().csr().modify(|v| v.set_ien(false))
+    }
+
+    /// Enable Read DMA
+    fn enable_read_dma(&self) {
+        Self::regs().csr().modify(|v| {
+            v.set_dmaren(true);
+        })
+    }
+
+    /// Disable Read DMA
+    fn disable_read_dma(&self) {
+        Self::regs().csr().modify(|v| {
+            v.set_dmaren(false);
+        })
+    }
+
+    /// Enable Write DMA
+    fn enable_write_dma(&self) {
+        Self::regs().csr().modify(|v| {
+            v.set_dmawen(true);
+        })
+    }
+
+    /// Disable Write DMA
+    fn disable_write_dma(&self) {
+        Self::regs().csr().modify(|v| {
+            v.set_dmawen(false);
+        })
+    }
+
+    /// Set NARGS value
+    fn set_argument_count(&self, n: AccessCount) {
+        Self::regs().csr().modify(|v| {
+            v.set_nargs(match n {
+                AccessCount::One => vals::Num::NUM1,
+                AccessCount::Two => vals::Num::NUM2,
+            })
+        })
+    }
+
+    /// Set NRES value
+    fn set_result_count(&self, n: AccessCount) {
+        Self::regs().csr().modify(|v| {
+            v.set_nres(match n {
+                AccessCount::One => vals::Num::NUM1,
+                AccessCount::Two => vals::Num::NUM2,
+            });
+        })
+    }
+
+    /// Set ARGSIZE and RESSIZE value
+    fn set_data_width(&self, arg: Width, res: Width) {
+        Self::regs().csr().modify(|v| {
+            v.set_argsize(match arg {
+                Width::Bits32 => vals::Size::BITS32,
+                Width::Bits16 => vals::Size::BITS16,
+            });
+            v.set_ressize(match res {
+                Width::Bits32 => vals::Size::BITS32,
+                Width::Bits16 => vals::Size::BITS16,
+            })
+        })
+    }
+
+    /// Read RRDY flag
+    fn ready_to_read(&self) -> bool {
+        Self::regs().csr().read().rrdy()
+    }
+
+    /// Write value to WDATA
+    fn write_argument(&self, arg: u32) {
+        Self::regs().wdata().write_value(arg)
+    }
+
+    /// Read value from RDATA
+    fn read_result(&self) -> u32 {
+        Self::regs().rdata().read()
+    }
+}
+
 /// CORDIC instance trait
 #[allow(private_bounds)]
 pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral {}
diff --git a/embassy-stm32/src/cordic/sealed.rs b/embassy-stm32/src/cordic/sealed.rs
deleted file mode 100644
index 8f0bd1830..000000000
--- a/embassy-stm32/src/cordic/sealed.rs
+++ /dev/null
@@ -1,116 +0,0 @@
-use super::*;
-use crate::pac::cordic::vals;
-
-/// Cordic instance
-pub(super) trait SealedInstance {
-    /// Get access to CORDIC registers
-    fn regs() -> crate::pac::cordic::Cordic;
-
-    /// Set Function value
-    fn set_func(&self, func: Function) {
-        Self::regs()
-            .csr()
-            .modify(|v| v.set_func(vals::Func::from_bits(func as u8)));
-    }
-
-    /// Set Precision value
-    fn set_precision(&self, precision: Precision) {
-        Self::regs()
-            .csr()
-            .modify(|v| v.set_precision(vals::Precision::from_bits(precision as u8)))
-    }
-
-    /// Set Scale value
-    fn set_scale(&self, scale: Scale) {
-        Self::regs()
-            .csr()
-            .modify(|v| v.set_scale(vals::Scale::from_bits(scale as u8)))
-    }
-
-    /// Enable global interrupt
-    fn enable_irq(&self) {
-        Self::regs().csr().modify(|v| v.set_ien(true))
-    }
-
-    /// Disable global interrupt
-    fn disable_irq(&self) {
-        Self::regs().csr().modify(|v| v.set_ien(false))
-    }
-
-    /// Enable Read DMA
-    fn enable_read_dma(&self) {
-        Self::regs().csr().modify(|v| {
-            v.set_dmaren(true);
-        })
-    }
-
-    /// Disable Read DMA
-    fn disable_read_dma(&self) {
-        Self::regs().csr().modify(|v| {
-            v.set_dmaren(false);
-        })
-    }
-
-    /// Enable Write DMA
-    fn enable_write_dma(&self) {
-        Self::regs().csr().modify(|v| {
-            v.set_dmawen(true);
-        })
-    }
-
-    /// Disable Write DMA
-    fn disable_write_dma(&self) {
-        Self::regs().csr().modify(|v| {
-            v.set_dmawen(false);
-        })
-    }
-
-    /// Set NARGS value
-    fn set_argument_count(&self, n: AccessCount) {
-        Self::regs().csr().modify(|v| {
-            v.set_nargs(match n {
-                AccessCount::One => vals::Num::NUM1,
-                AccessCount::Two => vals::Num::NUM2,
-            })
-        })
-    }
-
-    /// Set NRES value
-    fn set_result_count(&self, n: AccessCount) {
-        Self::regs().csr().modify(|v| {
-            v.set_nres(match n {
-                AccessCount::One => vals::Num::NUM1,
-                AccessCount::Two => vals::Num::NUM2,
-            });
-        })
-    }
-
-    /// Set ARGSIZE and RESSIZE value
-    fn set_data_width(&self, arg: Width, res: Width) {
-        Self::regs().csr().modify(|v| {
-            v.set_argsize(match arg {
-                Width::Bits32 => vals::Size::BITS32,
-                Width::Bits16 => vals::Size::BITS16,
-            });
-            v.set_ressize(match res {
-                Width::Bits32 => vals::Size::BITS32,
-                Width::Bits16 => vals::Size::BITS16,
-            })
-        })
-    }
-
-    /// Read RRDY flag
-    fn ready_to_read(&self) -> bool {
-        Self::regs().csr().read().rrdy()
-    }
-
-    /// Write value to WDATA
-    fn write_argument(&self, arg: u32) {
-        Self::regs().wdata().write_value(arg)
-    }
-
-    /// Read value from RDATA
-    fn read_result(&self) -> u32 {
-        Self::regs().rdata().read()
-    }
-}
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index 51862e185..949ac1b13 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -105,27 +105,23 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
     }
 }
 
-pub(crate) use sealed::State;
-pub(crate) mod sealed {
-    use super::*;
-    pub struct State {
-        pub(crate) rx_waker: AtomicWaker,
-        pub(crate) rx_buf: RingBuffer,
-        pub(crate) tx_waker: AtomicWaker,
-        pub(crate) tx_buf: RingBuffer,
-        pub(crate) tx_done: AtomicBool,
-    }
+pub(crate) struct State {
+    pub(crate) rx_waker: AtomicWaker,
+    pub(crate) rx_buf: RingBuffer,
+    pub(crate) tx_waker: AtomicWaker,
+    pub(crate) tx_buf: RingBuffer,
+    pub(crate) tx_done: AtomicBool,
+}
 
-    impl State {
-        /// Create new state
-        pub const fn new() -> Self {
-            Self {
-                rx_buf: RingBuffer::new(),
-                tx_buf: RingBuffer::new(),
-                rx_waker: AtomicWaker::new(),
-                tx_waker: AtomicWaker::new(),
-                tx_done: AtomicBool::new(true),
-            }
+impl State {
+    /// Create new state
+    pub(crate) const fn new() -> Self {
+        Self {
+            rx_buf: RingBuffer::new(),
+            tx_buf: RingBuffer::new(),
+            rx_waker: AtomicWaker::new(),
+            tx_waker: AtomicWaker::new(),
+            tx_done: AtomicBool::new(true),
         }
     }
 }