From 2c928df8f45f0cf4db33b27e7f4ceb70a806854b Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Sun, 28 Sep 2025 17:22:33 -0500 Subject: [PATCH] nrf: expose regs on all peripherals --- embassy-nrf/CHANGELOG.md | 2 +- embassy-nrf/src/egu.rs | 9 +++++++++ embassy-nrf/src/i2s.rs | 9 +++++++++ embassy-nrf/src/ipc.rs | 9 +++++++++ embassy-nrf/src/pdm.rs | 9 +++++++++ embassy-nrf/src/pwm.rs | 9 +++++++++ embassy-nrf/src/qdec.rs | 9 +++++++++ embassy-nrf/src/qspi.rs | 9 +++++++++ embassy-nrf/src/radio/mod.rs | 9 +++++++++ embassy-nrf/src/rng.rs | 9 +++++++++ embassy-nrf/src/rtc.rs | 10 ++++++++++ embassy-nrf/src/spim.rs | 9 +++++++++ embassy-nrf/src/spis.rs | 9 +++++++++ embassy-nrf/src/timer.rs | 9 +++++++++ embassy-nrf/src/twim.rs | 9 +++++++++ embassy-nrf/src/twis.rs | 9 +++++++++ embassy-nrf/src/uarte.rs | 9 +++++++++ embassy-nrf/src/usb/mod.rs | 9 +++++++++ 18 files changed, 155 insertions(+), 1 deletion(-) diff --git a/embassy-nrf/CHANGELOG.md b/embassy-nrf/CHANGELOG.md index 21b299f36b..174622cf10 100644 --- a/embassy-nrf/CHANGELOG.md +++ b/embassy-nrf/CHANGELOG.md @@ -11,12 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - changed: Remove `T: Instance` generic params in all drivers. - changed: nrf54l: Disable glitch detection and enable DC/DC in init. - changed: Add embassy-net-driver-channel implementation for IEEE 802.15.4 -- changed: add persist() method for gpio and ppi - added: basic RTC driver - changed: add persist() method for gpio, gpiote, timer and ppi - changed: impl Drop for Timer - added: expose `regs` for timer driver - added: timer driver CC `clear_events` method +- added: expose `regs` for all peripherals ## 0.7.0 - 2025-08-26 diff --git a/embassy-nrf/src/egu.rs b/embassy-nrf/src/egu.rs index f7372fca1f..936a706cdb 100644 --- a/embassy-nrf/src/egu.rs +++ b/embassy-nrf/src/egu.rs @@ -38,6 +38,7 @@ impl<'d> Egu<'d> { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::egu::Egu; } @@ -46,17 +47,25 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::egu::Egu; } macro_rules! impl_egu { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::egu::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::egu::Egu { pac::$pac_type } } impl crate::egu::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::egu::Egu { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/i2s.rs b/embassy-nrf/src/i2s.rs index 1bfa184911..53217fde84 100644 --- a/embassy-nrf/src/i2s.rs +++ b/embassy-nrf/src/i2s.rs @@ -1160,6 +1160,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::i2s::I2s; fn state() -> &'static State; } @@ -1169,11 +1170,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::i2s::I2s; } macro_rules! impl_i2s { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::i2s::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::i2s::I2s { pac::$pac_type } @@ -1184,6 +1189,10 @@ macro_rules! impl_i2s { } impl crate::i2s::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::i2s::I2s { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/ipc.rs b/embassy-nrf/src/ipc.rs index a40c36c996..e5ca957446 100644 --- a/embassy-nrf/src/ipc.rs +++ b/embassy-nrf/src/ipc.rs @@ -341,6 +341,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::ipc::Ipc; fn state() -> &'static State; } @@ -350,11 +351,15 @@ pub(crate) trait SealedInstance { pub trait Instance: PeripheralType + SealedInstance + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::ipc::Ipc; } macro_rules! impl_ipc { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::ipc::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::ipc::Ipc { pac::$pac_type } @@ -366,6 +371,10 @@ macro_rules! impl_ipc { } impl crate::ipc::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::ipc::Ipc { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs index b6ee528508..c9e50d9a81 100644 --- a/embassy-nrf/src/pdm.rs +++ b/embassy-nrf/src/pdm.rs @@ -443,6 +443,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> crate::pac::pdm::Pdm; fn state() -> &'static State; } @@ -452,11 +453,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> crate::pac::pdm::Pdm; } macro_rules! impl_pdm { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::pdm::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> crate::pac::pdm::Pdm { pac::$pac_type } @@ -467,6 +472,10 @@ macro_rules! impl_pdm { } impl crate::pdm::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> crate::pac::pdm::Pdm { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index d67cb546b9..1cbfbae10b 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -826,6 +826,7 @@ impl<'a> Drop for SimplePwm<'a> { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::pwm::Pwm; } @@ -834,17 +835,25 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::pwm::Pwm; } macro_rules! impl_pwm { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::pwm::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::pwm::Pwm { pac::$pac_type } } impl crate::pwm::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::pwm::Pwm { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index 0ebd7afb84..9df16400ca 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs @@ -271,6 +271,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::qdec::Qdec; fn state() -> &'static State; } @@ -280,11 +281,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::qdec::Qdec; } macro_rules! impl_qdec { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::qdec::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::qdec::Qdec { pac::$pac_type } @@ -295,6 +300,10 @@ macro_rules! impl_qdec { } impl crate::qdec::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::qdec::Qdec { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 94ad3f0d68..a6b049364d 100755 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -651,6 +651,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::qspi::Qspi; fn state() -> &'static State; } @@ -660,11 +661,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::qspi::Qspi; } macro_rules! impl_qspi { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::qspi::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::qspi::Qspi { pac::$pac_type } @@ -675,6 +680,10 @@ macro_rules! impl_qspi { } impl crate::qspi::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::qspi::Qspi { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/radio/mod.rs b/embassy-nrf/src/radio/mod.rs index 608ef90246..3e6f515f59 100644 --- a/embassy-nrf/src/radio/mod.rs +++ b/embassy-nrf/src/radio/mod.rs @@ -69,6 +69,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> crate::pac::radio::Radio; fn state() -> &'static State; } @@ -76,6 +77,7 @@ pub(crate) trait SealedInstance { macro_rules! impl_radio { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::radio::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> crate::pac::radio::Radio { pac::$pac_type } @@ -88,6 +90,10 @@ macro_rules! impl_radio { } impl crate::radio::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> crate::pac::radio::Radio { + pac::$pac_type + } } }; } @@ -97,4 +103,7 @@ macro_rules! impl_radio { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> crate::pac::radio::Radio; } diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 8070c1afe1..11d9d10b6f 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs @@ -293,6 +293,7 @@ impl InnerState { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::rng::Rng; fn state() -> &'static State; } @@ -302,11 +303,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::rng::Rng; } macro_rules! impl_rng { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::rng::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> crate::pac::rng::Rng { pac::$pac_type } @@ -317,6 +322,10 @@ macro_rules! impl_rng { } impl crate::rng::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> crate::pac::rng::Rng { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/rtc.rs b/embassy-nrf/src/rtc.rs index 652de511bd..0ddebb3ade 100644 --- a/embassy-nrf/src/rtc.rs +++ b/embassy-nrf/src/rtc.rs @@ -53,6 +53,7 @@ pub enum CompareChannel { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::rtc::Rtc; } @@ -61,6 +62,9 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: crate::interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::rtc::Rtc; /// Unsafely create a peripheral instance. /// @@ -74,6 +78,7 @@ pub trait Instance: SealedInstance + PeripheralType + 'static + Send { macro_rules! impl_rtc { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::rtc::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] #[inline] fn regs() -> pac::rtc::Rtc { unsafe { pac::rtc::Rtc::from_ptr(pac::$pac_type.as_ptr()) } @@ -82,6 +87,11 @@ macro_rules! impl_rtc { impl crate::rtc::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + #[inline] + fn regs() -> pac::rtc::Rtc { + unsafe { pac::rtc::Rtc::from_ptr(pac::$pac_type.as_ptr()) } + } unsafe fn steal() -> embassy_hal_internal::Peri<'static, Self> { unsafe { peripherals::$type::steal() } diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index c410e49fdf..1d64c48cc2 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -501,6 +501,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::spim::Spim; fn state() -> &'static State; } @@ -510,11 +511,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::spim::Spim; } macro_rules! impl_spim { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::spim::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::spim::Spim { pac::$pac_type } @@ -525,6 +530,10 @@ macro_rules! impl_spim { } impl crate::spim::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::spim::Spim { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs index 713163a557..e5a82d3886 100644 --- a/embassy-nrf/src/spis.rs +++ b/embassy-nrf/src/spis.rs @@ -465,6 +465,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::spis::Spis; fn state() -> &'static State; } @@ -474,11 +475,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::spis::Spis; } macro_rules! impl_spis { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::spis::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::spis::Spis { pac::$pac_type } @@ -489,6 +494,10 @@ macro_rules! impl_spis { } impl crate::spis::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::spis::Spis { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 0b0bb9780e..286e04f491 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs @@ -17,6 +17,7 @@ use crate::ppi::{Event, Task}; pub(crate) trait SealedInstance { /// The number of CC registers this instance has. const CCS: usize; + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::timer::Timer; } @@ -25,6 +26,9 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: crate::interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::timer::Timer; } /// Extended timer instance. @@ -34,12 +38,17 @@ macro_rules! impl_timer { ($type:ident, $pac_type:ident, $irq:ident, $ccs:literal) => { impl crate::timer::SealedInstance for peripherals::$type { const CCS: usize = $ccs; + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::timer::Timer { unsafe { pac::timer::Timer::from_ptr(pac::$pac_type.as_ptr()) } } } impl crate::timer::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::timer::Timer { + unsafe { pac::timer::Timer::from_ptr(pac::$pac_type.as_ptr()) } + } } }; ($type:ident, $pac_type:ident, $irq:ident) => { diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 943ea9d31e..5df75591bd 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -731,6 +731,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::twim::Twim; fn state() -> &'static State; } @@ -740,11 +741,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::twim::Twim; } macro_rules! impl_twim { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::twim::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::twim::Twim { pac::$pac_type } @@ -755,6 +760,10 @@ macro_rules! impl_twim { } impl crate::twim::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::twim::Twim { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/twis.rs b/embassy-nrf/src/twis.rs index dd4978b3e7..dbcbb3b3fb 100644 --- a/embassy-nrf/src/twis.rs +++ b/embassy-nrf/src/twis.rs @@ -786,6 +786,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::twis::Twis; fn state() -> &'static State; } @@ -795,11 +796,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::twis::Twis; } macro_rules! impl_twis { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::twis::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::twis::Twis { pac::$pac_type } @@ -810,6 +815,10 @@ macro_rules! impl_twis { } impl crate::twis::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::twis::Twis { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 66fb3b3f28..3a7de0ee83 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -993,6 +993,7 @@ impl State { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::uarte::Uarte; fn state() -> &'static State; fn buffered_state() -> &'static crate::buffered_uarte::State; @@ -1003,11 +1004,15 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::uarte::Uarte; } macro_rules! impl_uarte { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::uarte::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::uarte::Uarte { pac::$pac_type } @@ -1022,6 +1027,10 @@ macro_rules! impl_uarte { } impl crate::uarte::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::uarte::Uarte { + pac::$pac_type + } } }; } diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs index 2a32fe9225..e09ae5f924 100644 --- a/embassy-nrf/src/usb/mod.rs +++ b/embassy-nrf/src/usb/mod.rs @@ -810,6 +810,7 @@ impl Allocator { } pub(crate) trait SealedInstance { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::usbd::Usbd; } @@ -818,17 +819,25 @@ pub(crate) trait SealedInstance { pub trait Instance: SealedInstance + PeripheralType + 'static + Send { /// Interrupt for this peripheral. type Interrupt: interrupt::typelevel::Interrupt; + /// Direct access to the register block. + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::usbd::Usbd; } macro_rules! impl_usb { ($type:ident, $pac_type:ident, $irq:ident) => { impl crate::usb::SealedInstance for peripherals::$type { + #[cfg(not(feature = "unstable-pac"))] fn regs() -> pac::usbd::Usbd { pac::$pac_type } } impl crate::usb::Instance for peripherals::$type { type Interrupt = crate::interrupt::typelevel::$irq; + #[cfg(feature = "unstable-pac")] + fn regs() -> pac::usbd::Usbd { + pac::$pac_type + } } }; }