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
+ Into + Into + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Channel: SealedChannel + Peripheral + Sized + 'static {
/// Returns the number of the channel
fn number(&self) -> usize;
}
@@ -234,7 +233,8 @@ pub trait StaticChannel: Channel + Into + Into + Into + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Input: SealedInput + Into + 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 + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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 + sealed::Instance + 'static + Send {
+#[allow(private_bounds)]
+pub trait Instance: Peripheral + 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() }
}
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 + 'd) -> Gpin<'d, P> {
+ pub fn new(gpin: impl Peripheral + '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 + sealed::Channel + Into + SealedChannel + Into + sealed::Channel + Into + Into + Into + sealed::Slice + Sized + 'static {
+#[allow(private_bounds)]
+pub trait Slice: Peripheral + SealedSlice + Sized + 'static {
/// Slice number.
fn number(&self) -> u8;
@@ -317,7 +315,7 @@ pub trait Slice: Peripheral + 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 + 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 {
}
}
-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