diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:20:22 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-05 00:48:46 +0200 |
| commit | ab85eb4b60cd49ebcd43d2305f42327685f5e5a6 (patch) | |
| tree | 3c385a5703edcd1e791ec1934d3232dc4084ab2b | |
| parent | 0e1208947e89ea60bd1b5c85e4deb79efb94d89a (diff) | |
nrf: remove mod sealed.
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 25 | ||||
| -rw-r--r-- | embassy-nrf/src/gpio.rs | 82 | ||||
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 14 | ||||
| -rw-r--r-- | embassy-nrf/src/i2s.rs | 54 | ||||
| -rw-r--r-- | embassy-nrf/src/pdm.rs | 41 | ||||
| -rw-r--r-- | embassy-nrf/src/ppi/mod.rs | 22 | ||||
| -rw-r--r-- | embassy-nrf/src/pwm.rs | 16 | ||||
| -rw-r--r-- | embassy-nrf/src/qdec.rs | 41 | ||||
| -rwxr-xr-x | embassy-nrf/src/qspi.rs | 38 | ||||
| -rw-r--r-- | embassy-nrf/src/radio/mod.rs | 38 | ||||
| -rw-r--r-- | embassy-nrf/src/rng.rs | 81 | ||||
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 16 | ||||
| -rw-r--r-- | embassy-nrf/src/spim.rs | 60 | ||||
| -rw-r--r-- | embassy-nrf/src/spis.rs | 41 | ||||
| -rw-r--r-- | embassy-nrf/src/timer.rs | 22 | ||||
| -rw-r--r-- | embassy-nrf/src/twim.rs | 35 | ||||
| -rw-r--r-- | embassy-nrf/src/twis.rs | 35 | ||||
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 57 | ||||
| -rw-r--r-- | embassy-nrf/src/usb/mod.rs | 13 |
19 files changed, 327 insertions, 404 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}; | |||
| 20 | // Re-export SVD variants to allow user to directly set values | 20 | // Re-export SVD variants to allow user to directly set values |
| 21 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | 21 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; |
| 22 | 22 | ||
| 23 | use crate::gpio::sealed::Pin; | 23 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits, SealedPin}; |
| 24 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; | ||
| 25 | use crate::interrupt::typelevel::Interrupt; | 24 | use crate::interrupt::typelevel::Interrupt; |
| 26 | use crate::ppi::{ | 25 | use crate::ppi::{ |
| 27 | self, AnyConfigurableChannel, AnyGroup, Channel, ConfigurableChannel, Event, Group, Ppi, PpiGroup, Task, | 26 | self, AnyConfigurableChannel, AnyGroup, Channel, ConfigurableChannel, Event, Group, Ppi, PpiGroup, Task, |
| @@ -30,19 +29,15 @@ use crate::timer::{Instance as TimerInstance, Timer}; | |||
| 30 | use crate::uarte::{configure, drop_tx_rx, Config, Instance as UarteInstance}; | 29 | use crate::uarte::{configure, drop_tx_rx, Config, Instance as UarteInstance}; |
| 31 | use crate::{interrupt, pac, Peripheral}; | 30 | use crate::{interrupt, pac, Peripheral}; |
| 32 | 31 | ||
| 33 | mod sealed { | 32 | pub(crate) struct State { |
| 34 | use super::*; | 33 | tx_buf: RingBuffer, |
| 35 | 34 | tx_count: AtomicUsize, | |
| 36 | pub struct State { | ||
| 37 | pub tx_buf: RingBuffer, | ||
| 38 | pub tx_count: AtomicUsize, | ||
| 39 | 35 | ||
| 40 | pub rx_buf: RingBuffer, | 36 | rx_buf: RingBuffer, |
| 41 | pub rx_started: AtomicBool, | 37 | rx_started: AtomicBool, |
| 42 | pub rx_started_count: AtomicU8, | 38 | rx_started_count: AtomicU8, |
| 43 | pub rx_ended_count: AtomicU8, | 39 | rx_ended_count: AtomicU8, |
| 44 | pub rx_ppi_ch: AtomicU8, | 40 | rx_ppi_ch: AtomicU8, |
| 45 | } | ||
| 46 | } | 41 | } |
| 47 | 42 | ||
| 48 | /// UART error. | 43 | /// UART error. |
| @@ -53,8 +48,6 @@ pub enum Error { | |||
| 53 | // No errors for now | 48 | // No errors for now |
| 54 | } | 49 | } |
| 55 | 50 | ||
| 56 | pub(crate) use sealed::State; | ||
| 57 | |||
| 58 | impl State { | 51 | impl State { |
| 59 | pub(crate) const fn new() -> Self { | 52 | pub(crate) const fn new() -> Self { |
| 60 | Self { | 53 | 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; | |||
| 7 | use cfg_if::cfg_if; | 7 | use cfg_if::cfg_if; |
| 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; |
| 9 | 9 | ||
| 10 | use self::sealed::Pin as _; | ||
| 11 | #[cfg(feature = "nrf51")] | 10 | #[cfg(feature = "nrf51")] |
| 12 | use crate::pac::gpio; | 11 | use crate::pac::gpio; |
| 13 | #[cfg(feature = "nrf51")] | 12 | #[cfg(feature = "nrf51")] |
| @@ -361,59 +360,56 @@ impl<'d> Drop for Flex<'d> { | |||
| 361 | } | 360 | } |
| 362 | } | 361 | } |
| 363 | 362 | ||
| 364 | pub(crate) mod sealed { | 363 | pub(crate) trait SealedPin { |
| 365 | use super::*; | 364 | fn pin_port(&self) -> u8; |
| 366 | |||
| 367 | pub trait Pin { | ||
| 368 | fn pin_port(&self) -> u8; | ||
| 369 | 365 | ||
| 370 | #[inline] | 366 | #[inline] |
| 371 | fn _pin(&self) -> u8 { | 367 | fn _pin(&self) -> u8 { |
| 372 | cfg_if! { | 368 | cfg_if! { |
| 373 | if #[cfg(feature = "_gpio-p1")] { | 369 | if #[cfg(feature = "_gpio-p1")] { |
| 374 | self.pin_port() % 32 | 370 | self.pin_port() % 32 |
| 375 | } else { | 371 | } else { |
| 376 | self.pin_port() | 372 | self.pin_port() |
| 377 | } | ||
| 378 | } | 373 | } |
| 379 | } | 374 | } |
| 375 | } | ||
| 380 | 376 | ||
| 381 | #[inline] | 377 | #[inline] |
| 382 | fn block(&self) -> &gpio::RegisterBlock { | 378 | fn block(&self) -> &gpio::RegisterBlock { |
| 383 | unsafe { | 379 | unsafe { |
| 384 | match self.pin_port() / 32 { | 380 | match self.pin_port() / 32 { |
| 385 | #[cfg(feature = "nrf51")] | 381 | #[cfg(feature = "nrf51")] |
| 386 | 0 => &*pac::GPIO::ptr(), | 382 | 0 => &*pac::GPIO::ptr(), |
| 387 | #[cfg(not(feature = "nrf51"))] | 383 | #[cfg(not(feature = "nrf51"))] |
| 388 | 0 => &*pac::P0::ptr(), | 384 | 0 => &*pac::P0::ptr(), |
| 389 | #[cfg(feature = "_gpio-p1")] | 385 | #[cfg(feature = "_gpio-p1")] |
| 390 | 1 => &*pac::P1::ptr(), | 386 | 1 => &*pac::P1::ptr(), |
| 391 | _ => unreachable_unchecked(), | 387 | _ => unreachable_unchecked(), |
| 392 | } | ||
| 393 | } | 388 | } |
| 394 | } | 389 | } |
| 390 | } | ||
| 395 | 391 | ||
| 396 | #[inline] | 392 | #[inline] |
| 397 | fn conf(&self) -> &gpio::PIN_CNF { | 393 | fn conf(&self) -> &gpio::PIN_CNF { |
| 398 | &self.block().pin_cnf[self._pin() as usize] | 394 | &self.block().pin_cnf[self._pin() as usize] |
| 399 | } | 395 | } |
| 400 | 396 | ||
| 401 | /// Set the output as high. | 397 | /// Set the output as high. |
| 402 | #[inline] | 398 | #[inline] |
| 403 | fn set_high(&self) { | 399 | fn set_high(&self) { |
| 404 | unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) } | 400 | unsafe { self.block().outset.write(|w| w.bits(1u32 << self._pin())) } |
| 405 | } | 401 | } |
| 406 | 402 | ||
| 407 | /// Set the output as low. | 403 | /// Set the output as low. |
| 408 | #[inline] | 404 | #[inline] |
| 409 | fn set_low(&self) { | 405 | fn set_low(&self) { |
| 410 | unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) } | 406 | unsafe { self.block().outclr.write(|w| w.bits(1u32 << self._pin())) } |
| 411 | } | ||
| 412 | } | 407 | } |
| 413 | } | 408 | } |
| 414 | 409 | ||
| 415 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | 410 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. |
| 416 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { | 411 | #[allow(private_bounds)] |
| 412 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | ||
| 417 | /// Number of the pin within the port (0..31) | 413 | /// Number of the pin within the port (0..31) |
| 418 | #[inline] | 414 | #[inline] |
| 419 | fn pin(&self) -> u8 { | 415 | fn pin(&self) -> u8 { |
| @@ -464,7 +460,7 @@ impl AnyPin { | |||
| 464 | 460 | ||
| 465 | impl_peripheral!(AnyPin); | 461 | impl_peripheral!(AnyPin); |
| 466 | impl Pin for AnyPin {} | 462 | impl Pin for AnyPin {} |
| 467 | impl sealed::Pin for AnyPin { | 463 | impl SealedPin for AnyPin { |
| 468 | #[inline] | 464 | #[inline] |
| 469 | fn pin_port(&self) -> u8 { | 465 | fn pin_port(&self) -> u8 { |
| 470 | self.pin_port | 466 | self.pin_port |
| @@ -502,7 +498,7 @@ pub(crate) fn deconfigure_pin(psel_bits: u32) { | |||
| 502 | macro_rules! impl_pin { | 498 | macro_rules! impl_pin { |
| 503 | ($type:ident, $port_num:expr, $pin_num:expr) => { | 499 | ($type:ident, $port_num:expr, $pin_num:expr) => { |
| 504 | impl crate::gpio::Pin for peripherals::$type {} | 500 | impl crate::gpio::Pin for peripherals::$type {} |
| 505 | impl crate::gpio::sealed::Pin for peripherals::$type { | 501 | impl crate::gpio::SealedPin for peripherals::$type { |
| 506 | #[inline] | 502 | #[inline] |
| 507 | fn pin_port(&self) -> u8 { | 503 | fn pin_port(&self) -> u8 { |
| 508 | $port_num * 32 + $pin_num | 504 | $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}; | |||
| 7 | use embassy_hal_internal::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; | 7 | use embassy_hal_internal::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; |
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin, SealedPin as _}; |
| 11 | use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin}; | ||
| 12 | use crate::interrupt::InterruptExt; | 11 | use crate::interrupt::InterruptExt; |
| 13 | use crate::ppi::{Event, Task}; | 12 | use crate::ppi::{Event, Task}; |
| 14 | use crate::{interrupt, pac, peripherals}; | 13 | use crate::{interrupt, pac, peripherals}; |
| @@ -446,14 +445,13 @@ impl<'d> Flex<'d> { | |||
| 446 | 445 | ||
| 447 | // ======================= | 446 | // ======================= |
| 448 | 447 | ||
| 449 | mod sealed { | 448 | trait SealedChannel {} |
| 450 | pub trait Channel {} | ||
| 451 | } | ||
| 452 | 449 | ||
| 453 | /// GPIOTE channel trait. | 450 | /// GPIOTE channel trait. |
| 454 | /// | 451 | /// |
| 455 | /// Implemented by all GPIOTE channels. | 452 | /// Implemented by all GPIOTE channels. |
| 456 | pub trait Channel: sealed::Channel + Into<AnyChannel> + Sized + 'static { | 453 | #[allow(private_bounds)] |
| 454 | pub trait Channel: SealedChannel + Into<AnyChannel> + Sized + 'static { | ||
| 457 | /// Get the channel number. | 455 | /// Get the channel number. |
| 458 | fn number(&self) -> usize; | 456 | fn number(&self) -> usize; |
| 459 | 457 | ||
| @@ -478,7 +476,7 @@ pub struct AnyChannel { | |||
| 478 | number: u8, | 476 | number: u8, |
| 479 | } | 477 | } |
| 480 | impl_peripheral!(AnyChannel); | 478 | impl_peripheral!(AnyChannel); |
| 481 | impl sealed::Channel for AnyChannel {} | 479 | impl SealedChannel for AnyChannel {} |
| 482 | impl Channel for AnyChannel { | 480 | impl Channel for AnyChannel { |
| 483 | fn number(&self) -> usize { | 481 | fn number(&self) -> usize { |
| 484 | self.number as usize | 482 | self.number as usize |
| @@ -487,7 +485,7 @@ impl Channel for AnyChannel { | |||
| 487 | 485 | ||
| 488 | macro_rules! impl_channel { | 486 | macro_rules! impl_channel { |
| 489 | ($type:ident, $number:expr) => { | 487 | ($type:ident, $number:expr) => { |
| 490 | impl sealed::Channel for peripherals::$type {} | 488 | impl SealedChannel for peripherals::$type {} |
| 491 | impl Channel for peripherals::$type { | 489 | impl Channel for peripherals::$type { |
| 492 | fn number(&self) -> usize { | 490 | fn number(&self) -> usize { |
| 493 | $number as usize | 491 | $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; | |||
| 6 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 7 | use core::mem::size_of; | 7 | use core::mem::size_of; |
| 8 | use core::ops::{Deref, DerefMut}; | 8 | use core::ops::{Deref, DerefMut}; |
| 9 | use core::sync::atomic::{compiler_fence, Ordering}; | 9 | use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; |
| 10 | use core::task::Poll; | 10 | use core::task::Poll; |
| 11 | 11 | ||
| 12 | use embassy_hal_internal::drop::OnDrop; | 12 | use embassy_hal_internal::drop::OnDrop; |
| 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 14 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 14 | 15 | ||
| 15 | use crate::gpio::{AnyPin, Pin as GpioPin}; | 16 | use crate::gpio::{AnyPin, Pin as GpioPin}; |
| 16 | use crate::interrupt::typelevel::Interrupt; | 17 | use crate::interrupt::typelevel::Interrupt; |
| @@ -1140,50 +1141,45 @@ impl<S: Sample, const NB: usize, const NS: usize> MultiBuffering<S, NB, NS> { | |||
| 1140 | } | 1141 | } |
| 1141 | } | 1142 | } |
| 1142 | 1143 | ||
| 1143 | pub(crate) mod sealed { | 1144 | /// Peripheral static state |
| 1144 | use core::sync::atomic::AtomicBool; | 1145 | pub(crate) struct State { |
| 1145 | 1146 | started: AtomicBool, | |
| 1146 | use embassy_sync::waitqueue::AtomicWaker; | 1147 | rx_waker: AtomicWaker, |
| 1147 | 1148 | tx_waker: AtomicWaker, | |
| 1148 | /// Peripheral static state | 1149 | stop_waker: AtomicWaker, |
| 1149 | pub struct State { | 1150 | } |
| 1150 | pub started: AtomicBool, | ||
| 1151 | pub rx_waker: AtomicWaker, | ||
| 1152 | pub tx_waker: AtomicWaker, | ||
| 1153 | pub stop_waker: AtomicWaker, | ||
| 1154 | } | ||
| 1155 | 1151 | ||
| 1156 | impl State { | 1152 | impl State { |
| 1157 | pub const fn new() -> Self { | 1153 | pub(crate) const fn new() -> Self { |
| 1158 | Self { | 1154 | Self { |
| 1159 | started: AtomicBool::new(false), | 1155 | started: AtomicBool::new(false), |
| 1160 | rx_waker: AtomicWaker::new(), | 1156 | rx_waker: AtomicWaker::new(), |
| 1161 | tx_waker: AtomicWaker::new(), | 1157 | tx_waker: AtomicWaker::new(), |
| 1162 | stop_waker: AtomicWaker::new(), | 1158 | stop_waker: AtomicWaker::new(), |
| 1163 | } | ||
| 1164 | } | 1159 | } |
| 1165 | } | 1160 | } |
| 1161 | } | ||
| 1166 | 1162 | ||
| 1167 | pub trait Instance { | 1163 | pub(crate) trait SealedInstance { |
| 1168 | fn regs() -> &'static crate::pac::i2s::RegisterBlock; | 1164 | fn regs() -> &'static crate::pac::i2s::RegisterBlock; |
| 1169 | fn state() -> &'static State; | 1165 | fn state() -> &'static State; |
| 1170 | } | ||
| 1171 | } | 1166 | } |
| 1172 | 1167 | ||
| 1173 | /// I2S peripheral instance. | 1168 | /// I2S peripheral instance. |
| 1174 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 1169 | #[allow(private_bounds)] |
| 1170 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 1175 | /// Interrupt for this peripheral. | 1171 | /// Interrupt for this peripheral. |
| 1176 | type Interrupt: interrupt::typelevel::Interrupt; | 1172 | type Interrupt: interrupt::typelevel::Interrupt; |
| 1177 | } | 1173 | } |
| 1178 | 1174 | ||
| 1179 | macro_rules! impl_i2s { | 1175 | macro_rules! impl_i2s { |
| 1180 | ($type:ident, $pac_type:ident, $irq:ident) => { | 1176 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 1181 | impl crate::i2s::sealed::Instance for peripherals::$type { | 1177 | impl crate::i2s::SealedInstance for peripherals::$type { |
| 1182 | fn regs() -> &'static crate::pac::i2s::RegisterBlock { | 1178 | fn regs() -> &'static crate::pac::i2s::RegisterBlock { |
| 1183 | unsafe { &*pac::$pac_type::ptr() } | 1179 | unsafe { &*pac::$pac_type::ptr() } |
| 1184 | } | 1180 | } |
| 1185 | fn state() -> &'static crate::i2s::sealed::State { | 1181 | fn state() -> &'static crate::i2s::State { |
| 1186 | static STATE: crate::i2s::sealed::State = crate::i2s::sealed::State::new(); | 1182 | static STATE: crate::i2s::State = crate::i2s::State::new(); |
| 1187 | &STATE | 1183 | &STATE |
| 1188 | } | 1184 | } |
| 1189 | } | 1185 | } |
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; | |||
| 9 | 9 | ||
| 10 | use embassy_hal_internal::drop::OnDrop; | 10 | use embassy_hal_internal::drop::OnDrop; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 12 | use fixed::types::I7F1; | 13 | use fixed::types::I7F1; |
| 13 | 14 | ||
| 14 | use crate::chip::EASY_DMA_SIZE; | 15 | use crate::chip::EASY_DMA_SIZE; |
| 15 | use crate::gpio::sealed::Pin; | 16 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin}; |
| 16 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 17 | use crate::interrupt::typelevel::Interrupt; | 17 | use crate::interrupt::typelevel::Interrupt; |
| 18 | use crate::pac::pdm::mode::{EDGE_A, OPERATION_A}; | 18 | use crate::pac::pdm::mode::{EDGE_A, OPERATION_A}; |
| 19 | pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency; | 19 | pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency; |
| @@ -451,42 +451,39 @@ impl<'d, T: Instance> Drop for Pdm<'d, T> { | |||
| 451 | } | 451 | } |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | pub(crate) mod sealed { | 454 | /// Peripheral static state |
| 455 | use embassy_sync::waitqueue::AtomicWaker; | 455 | pub(crate) struct State { |
| 456 | 456 | waker: AtomicWaker, | |
| 457 | /// Peripheral static state | 457 | } |
| 458 | pub struct State { | ||
| 459 | pub waker: AtomicWaker, | ||
| 460 | } | ||
| 461 | 458 | ||
| 462 | impl State { | 459 | impl State { |
| 463 | pub const fn new() -> Self { | 460 | pub(crate) const fn new() -> Self { |
| 464 | Self { | 461 | Self { |
| 465 | waker: AtomicWaker::new(), | 462 | waker: AtomicWaker::new(), |
| 466 | } | ||
| 467 | } | 463 | } |
| 468 | } | 464 | } |
| 465 | } | ||
| 469 | 466 | ||
| 470 | pub trait Instance { | 467 | pub(crate) trait SealedInstance { |
| 471 | fn regs() -> &'static crate::pac::pdm::RegisterBlock; | 468 | fn regs() -> &'static crate::pac::pdm::RegisterBlock; |
| 472 | fn state() -> &'static State; | 469 | fn state() -> &'static State; |
| 473 | } | ||
| 474 | } | 470 | } |
| 475 | 471 | ||
| 476 | /// PDM peripheral instance | 472 | /// PDM peripheral instance |
| 477 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 473 | #[allow(private_bounds)] |
| 474 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 478 | /// Interrupt for this peripheral | 475 | /// Interrupt for this peripheral |
| 479 | type Interrupt: interrupt::typelevel::Interrupt; | 476 | type Interrupt: interrupt::typelevel::Interrupt; |
| 480 | } | 477 | } |
| 481 | 478 | ||
| 482 | macro_rules! impl_pdm { | 479 | macro_rules! impl_pdm { |
| 483 | ($type:ident, $pac_type:ident, $irq:ident) => { | 480 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 484 | impl crate::pdm::sealed::Instance for peripherals::$type { | 481 | impl crate::pdm::SealedInstance for peripherals::$type { |
| 485 | fn regs() -> &'static crate::pac::pdm::RegisterBlock { | 482 | fn regs() -> &'static crate::pac::pdm::RegisterBlock { |
| 486 | unsafe { &*pac::$pac_type::ptr() } | 483 | unsafe { &*pac::$pac_type::ptr() } |
| 487 | } | 484 | } |
| 488 | fn state() -> &'static crate::pdm::sealed::State { | 485 | fn state() -> &'static crate::pdm::State { |
| 489 | static STATE: crate::pdm::sealed::State = crate::pdm::sealed::State::new(); | 486 | static STATE: crate::pdm::State = crate::pdm::State::new(); |
| 490 | &STATE | 487 | &STATE |
| 491 | } | 488 | } |
| 492 | } | 489 | } |
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<'_> {} | |||
| 210 | // ====================== | 210 | // ====================== |
| 211 | // traits | 211 | // traits |
| 212 | 212 | ||
| 213 | pub(crate) mod sealed { | 213 | pub(crate) trait SealedChannel {} |
| 214 | pub trait Channel {} | 214 | pub(crate) trait SealedGroup {} |
| 215 | pub trait Group {} | ||
| 216 | } | ||
| 217 | 215 | ||
| 218 | /// Interface for PPI channels. | 216 | /// Interface for PPI channels. |
| 219 | pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized + 'static { | 217 | #[allow(private_bounds)] |
| 218 | pub trait Channel: SealedChannel + Peripheral<P = Self> + Sized + 'static { | ||
| 220 | /// Returns the number of the channel | 219 | /// Returns the number of the channel |
| 221 | fn number(&self) -> usize; | 220 | fn number(&self) -> usize; |
| 222 | } | 221 | } |
| @@ -234,7 +233,8 @@ pub trait StaticChannel: Channel + Into<AnyStaticChannel> { | |||
| 234 | } | 233 | } |
| 235 | 234 | ||
| 236 | /// Interface for a group of PPI channels. | 235 | /// Interface for a group of PPI channels. |
| 237 | pub trait Group: sealed::Group + Peripheral<P = Self> + Into<AnyGroup> + Sized + 'static { | 236 | #[allow(private_bounds)] |
| 237 | pub trait Group: SealedGroup + Peripheral<P = Self> + Into<AnyGroup> + Sized + 'static { | ||
| 238 | /// Returns the number of the group. | 238 | /// Returns the number of the group. |
| 239 | fn number(&self) -> usize; | 239 | fn number(&self) -> usize; |
| 240 | /// Convert into a type erased group. | 240 | /// Convert into a type erased group. |
| @@ -254,7 +254,7 @@ pub struct AnyStaticChannel { | |||
| 254 | pub(crate) number: u8, | 254 | pub(crate) number: u8, |
| 255 | } | 255 | } |
| 256 | impl_peripheral!(AnyStaticChannel); | 256 | impl_peripheral!(AnyStaticChannel); |
| 257 | impl sealed::Channel for AnyStaticChannel {} | 257 | impl SealedChannel for AnyStaticChannel {} |
| 258 | impl Channel for AnyStaticChannel { | 258 | impl Channel for AnyStaticChannel { |
| 259 | fn number(&self) -> usize { | 259 | fn number(&self) -> usize { |
| 260 | self.number as usize | 260 | self.number as usize |
| @@ -272,7 +272,7 @@ pub struct AnyConfigurableChannel { | |||
| 272 | pub(crate) number: u8, | 272 | pub(crate) number: u8, |
| 273 | } | 273 | } |
| 274 | impl_peripheral!(AnyConfigurableChannel); | 274 | impl_peripheral!(AnyConfigurableChannel); |
| 275 | impl sealed::Channel for AnyConfigurableChannel {} | 275 | impl SealedChannel for AnyConfigurableChannel {} |
| 276 | impl Channel for AnyConfigurableChannel { | 276 | impl Channel for AnyConfigurableChannel { |
| 277 | fn number(&self) -> usize { | 277 | fn number(&self) -> usize { |
| 278 | self.number as usize | 278 | self.number as usize |
| @@ -287,7 +287,7 @@ impl ConfigurableChannel for AnyConfigurableChannel { | |||
| 287 | #[cfg(not(feature = "nrf51"))] | 287 | #[cfg(not(feature = "nrf51"))] |
| 288 | macro_rules! impl_ppi_channel { | 288 | macro_rules! impl_ppi_channel { |
| 289 | ($type:ident, $number:expr) => { | 289 | ($type:ident, $number:expr) => { |
| 290 | impl crate::ppi::sealed::Channel for peripherals::$type {} | 290 | impl crate::ppi::SealedChannel for peripherals::$type {} |
| 291 | impl crate::ppi::Channel for peripherals::$type { | 291 | impl crate::ppi::Channel for peripherals::$type { |
| 292 | fn number(&self) -> usize { | 292 | fn number(&self) -> usize { |
| 293 | $number | 293 | $number |
| @@ -338,7 +338,7 @@ pub struct AnyGroup { | |||
| 338 | number: u8, | 338 | number: u8, |
| 339 | } | 339 | } |
| 340 | impl_peripheral!(AnyGroup); | 340 | impl_peripheral!(AnyGroup); |
| 341 | impl sealed::Group for AnyGroup {} | 341 | impl SealedGroup for AnyGroup {} |
| 342 | impl Group for AnyGroup { | 342 | impl Group for AnyGroup { |
| 343 | fn number(&self) -> usize { | 343 | fn number(&self) -> usize { |
| 344 | self.number as usize | 344 | self.number as usize |
| @@ -347,7 +347,7 @@ impl Group for AnyGroup { | |||
| 347 | 347 | ||
| 348 | macro_rules! impl_group { | 348 | macro_rules! impl_group { |
| 349 | ($type:ident, $number:expr) => { | 349 | ($type:ident, $number:expr) => { |
| 350 | impl sealed::Group for peripherals::$type {} | 350 | impl SealedGroup for peripherals::$type {} |
| 351 | impl Group for peripherals::$type { | 351 | impl Group for peripherals::$type { |
| 352 | fn number(&self) -> usize { | 352 | fn number(&self) -> usize { |
| 353 | $number | 353 | $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}; | |||
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits, SealedPin as _}; |
| 10 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; | ||
| 11 | use crate::ppi::{Event, Task}; | 10 | use crate::ppi::{Event, Task}; |
| 12 | use crate::util::slice_in_ram_or; | 11 | use crate::util::slice_in_ram_or; |
| 13 | use crate::{interrupt, pac, Peripheral}; | 12 | use crate::{interrupt, pac, Peripheral}; |
| @@ -847,23 +846,20 @@ impl<'a, T: Instance> Drop for SimplePwm<'a, T> { | |||
| 847 | } | 846 | } |
| 848 | } | 847 | } |
| 849 | 848 | ||
| 850 | pub(crate) mod sealed { | 849 | pub(crate) trait SealedInstance { |
| 851 | use super::*; | 850 | fn regs() -> &'static pac::pwm0::RegisterBlock; |
| 852 | |||
| 853 | pub trait Instance { | ||
| 854 | fn regs() -> &'static pac::pwm0::RegisterBlock; | ||
| 855 | } | ||
| 856 | } | 851 | } |
| 857 | 852 | ||
| 858 | /// PWM peripheral instance. | 853 | /// PWM peripheral instance. |
| 859 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static { | 854 | #[allow(private_bounds)] |
| 855 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | ||
| 860 | /// Interrupt for this peripheral. | 856 | /// Interrupt for this peripheral. |
| 861 | type Interrupt: interrupt::typelevel::Interrupt; | 857 | type Interrupt: interrupt::typelevel::Interrupt; |
| 862 | } | 858 | } |
| 863 | 859 | ||
| 864 | macro_rules! impl_pwm { | 860 | macro_rules! impl_pwm { |
| 865 | ($type:ident, $pac_type:ident, $irq:ident) => { | 861 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 866 | impl crate::pwm::sealed::Instance for peripherals::$type { | 862 | impl crate::pwm::SealedInstance for peripherals::$type { |
| 867 | fn regs() -> &'static pac::pwm0::RegisterBlock { | 863 | fn regs() -> &'static pac::pwm0::RegisterBlock { |
| 868 | unsafe { &*pac::$pac_type::ptr() } | 864 | unsafe { &*pac::$pac_type::ptr() } |
| 869 | } | 865 | } |
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; | |||
| 7 | use core::task::Poll; | 7 | use core::task::Poll; |
| 8 | 8 | ||
| 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 10 | 11 | ||
| 11 | use crate::gpio::sealed::Pin as _; | 12 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; |
| 12 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 13 | use crate::interrupt::typelevel::Interrupt; | 13 | use crate::interrupt::typelevel::Interrupt; |
| 14 | use crate::{interrupt, Peripheral}; | 14 | use crate::{interrupt, Peripheral}; |
| 15 | 15 | ||
| @@ -245,42 +245,39 @@ pub enum LedPolarity { | |||
| 245 | ActiveLow, | 245 | ActiveLow, |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | pub(crate) mod sealed { | 248 | /// Peripheral static state |
| 249 | use embassy_sync::waitqueue::AtomicWaker; | 249 | pub(crate) struct State { |
| 250 | 250 | waker: AtomicWaker, | |
| 251 | /// Peripheral static state | 251 | } |
| 252 | pub struct State { | ||
| 253 | pub waker: AtomicWaker, | ||
| 254 | } | ||
| 255 | 252 | ||
| 256 | impl State { | 253 | impl State { |
| 257 | pub const fn new() -> Self { | 254 | pub(crate) const fn new() -> Self { |
| 258 | Self { | 255 | Self { |
| 259 | waker: AtomicWaker::new(), | 256 | waker: AtomicWaker::new(), |
| 260 | } | ||
| 261 | } | 257 | } |
| 262 | } | 258 | } |
| 259 | } | ||
| 263 | 260 | ||
| 264 | pub trait Instance { | 261 | pub(crate) trait SealedInstance { |
| 265 | fn regs() -> &'static crate::pac::qdec::RegisterBlock; | 262 | fn regs() -> &'static crate::pac::qdec::RegisterBlock; |
| 266 | fn state() -> &'static State; | 263 | fn state() -> &'static State; |
| 267 | } | ||
| 268 | } | 264 | } |
| 269 | 265 | ||
| 270 | /// qdec peripheral instance. | 266 | /// qdec peripheral instance. |
| 271 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 267 | #[allow(private_bounds)] |
| 268 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 272 | /// Interrupt for this peripheral. | 269 | /// Interrupt for this peripheral. |
| 273 | type Interrupt: interrupt::typelevel::Interrupt; | 270 | type Interrupt: interrupt::typelevel::Interrupt; |
| 274 | } | 271 | } |
| 275 | 272 | ||
| 276 | macro_rules! impl_qdec { | 273 | macro_rules! impl_qdec { |
| 277 | ($type:ident, $pac_type:ident, $irq:ident) => { | 274 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 278 | impl crate::qdec::sealed::Instance for peripherals::$type { | 275 | impl crate::qdec::SealedInstance for peripherals::$type { |
| 279 | fn regs() -> &'static crate::pac::qdec::RegisterBlock { | 276 | fn regs() -> &'static crate::pac::qdec::RegisterBlock { |
| 280 | unsafe { &*pac::$pac_type::ptr() } | 277 | unsafe { &*pac::$pac_type::ptr() } |
| 281 | } | 278 | } |
| 282 | fn state() -> &'static crate::qdec::sealed::State { | 279 | fn state() -> &'static crate::qdec::State { |
| 283 | static STATE: crate::qdec::sealed::State = crate::qdec::sealed::State::new(); | 280 | static STATE: crate::qdec::State = crate::qdec::State::new(); |
| 284 | &STATE | 281 | &STATE |
| 285 | } | 282 | } |
| 286 | } | 283 | } |
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; | |||
| 9 | 9 | ||
| 10 | use embassy_hal_internal::drop::OnDrop; | 10 | use embassy_hal_internal::drop::OnDrop; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 12 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; | 13 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; |
| 13 | 14 | ||
| 14 | use crate::gpio::{self, Pin as GpioPin}; | 15 | use crate::gpio::{self, Pin as GpioPin}; |
| @@ -652,42 +653,39 @@ mod _eh1 { | |||
| 652 | impl<'d, T: Instance> embedded_storage_async::nor_flash::MultiwriteNorFlash for Qspi<'d, T> {} | 653 | impl<'d, T: Instance> embedded_storage_async::nor_flash::MultiwriteNorFlash for Qspi<'d, T> {} |
| 653 | } | 654 | } |
| 654 | 655 | ||
| 655 | pub(crate) mod sealed { | 656 | /// Peripheral static state |
| 656 | use embassy_sync::waitqueue::AtomicWaker; | 657 | pub(crate) struct State { |
| 657 | 658 | waker: AtomicWaker, | |
| 658 | /// Peripheral static state | 659 | } |
| 659 | pub struct State { | ||
| 660 | pub waker: AtomicWaker, | ||
| 661 | } | ||
| 662 | 660 | ||
| 663 | impl State { | 661 | impl State { |
| 664 | pub const fn new() -> Self { | 662 | pub(crate) const fn new() -> Self { |
| 665 | Self { | 663 | Self { |
| 666 | waker: AtomicWaker::new(), | 664 | waker: AtomicWaker::new(), |
| 667 | } | ||
| 668 | } | 665 | } |
| 669 | } | 666 | } |
| 667 | } | ||
| 670 | 668 | ||
| 671 | pub trait Instance { | 669 | pub(crate) trait SealedInstance { |
| 672 | fn regs() -> &'static crate::pac::qspi::RegisterBlock; | 670 | fn regs() -> &'static crate::pac::qspi::RegisterBlock; |
| 673 | fn state() -> &'static State; | 671 | fn state() -> &'static State; |
| 674 | } | ||
| 675 | } | 672 | } |
| 676 | 673 | ||
| 677 | /// QSPI peripheral instance. | 674 | /// QSPI peripheral instance. |
| 678 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 675 | #[allow(private_bounds)] |
| 676 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 679 | /// Interrupt for this peripheral. | 677 | /// Interrupt for this peripheral. |
| 680 | type Interrupt: interrupt::typelevel::Interrupt; | 678 | type Interrupt: interrupt::typelevel::Interrupt; |
| 681 | } | 679 | } |
| 682 | 680 | ||
| 683 | macro_rules! impl_qspi { | 681 | macro_rules! impl_qspi { |
| 684 | ($type:ident, $pac_type:ident, $irq:ident) => { | 682 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 685 | impl crate::qspi::sealed::Instance for peripherals::$type { | 683 | impl crate::qspi::SealedInstance for peripherals::$type { |
| 686 | fn regs() -> &'static crate::pac::qspi::RegisterBlock { | 684 | fn regs() -> &'static crate::pac::qspi::RegisterBlock { |
| 687 | unsafe { &*pac::$pac_type::ptr() } | 685 | unsafe { &*pac::$pac_type::ptr() } |
| 688 | } | 686 | } |
| 689 | fn state() -> &'static crate::qspi::sealed::State { | 687 | fn state() -> &'static crate::qspi::State { |
| 690 | static STATE: crate::qspi::sealed::State = crate::qspi::sealed::State::new(); | 688 | static STATE: crate::qspi::State = crate::qspi::State::new(); |
| 691 | &STATE | 689 | &STATE |
| 692 | } | 690 | } |
| 693 | } | 691 | } |
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; | |||
| 19 | 19 | ||
| 20 | use core::marker::PhantomData; | 20 | use core::marker::PhantomData; |
| 21 | 21 | ||
| 22 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 22 | use pac::radio::state::STATE_A as RadioState; | 23 | use pac::radio::state::STATE_A as RadioState; |
| 23 | pub use pac::radio::txpower::TXPOWER_A as TxPower; | 24 | pub use pac::radio::txpower::TXPOWER_A as TxPower; |
| 24 | 25 | ||
| @@ -56,36 +57,32 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 56 | } | 57 | } |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | pub(crate) mod sealed { | 60 | pub(crate) struct State { |
| 60 | use embassy_sync::waitqueue::AtomicWaker; | 61 | /// end packet transmission or reception |
| 61 | 62 | event_waker: AtomicWaker, | |
| 62 | pub struct State { | 63 | } |
| 63 | /// end packet transmission or reception | 64 | impl State { |
| 64 | pub event_waker: AtomicWaker, | 65 | pub(crate) const fn new() -> Self { |
| 65 | } | 66 | Self { |
| 66 | impl State { | 67 | event_waker: AtomicWaker::new(), |
| 67 | pub const fn new() -> Self { | ||
| 68 | Self { | ||
| 69 | event_waker: AtomicWaker::new(), | ||
| 70 | } | ||
| 71 | } | 68 | } |
| 72 | } | 69 | } |
| 70 | } | ||
| 73 | 71 | ||
| 74 | pub trait Instance { | 72 | pub(crate) trait SealedInstance { |
| 75 | fn regs() -> &'static crate::pac::radio::RegisterBlock; | 73 | fn regs() -> &'static crate::pac::radio::RegisterBlock; |
| 76 | fn state() -> &'static State; | 74 | fn state() -> &'static State; |
| 77 | } | ||
| 78 | } | 75 | } |
| 79 | 76 | ||
| 80 | macro_rules! impl_radio { | 77 | macro_rules! impl_radio { |
| 81 | ($type:ident, $pac_type:ident, $irq:ident) => { | 78 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 82 | impl crate::radio::sealed::Instance for peripherals::$type { | 79 | impl crate::radio::SealedInstance for peripherals::$type { |
| 83 | fn regs() -> &'static pac::radio::RegisterBlock { | 80 | fn regs() -> &'static pac::radio::RegisterBlock { |
| 84 | unsafe { &*pac::$pac_type::ptr() } | 81 | unsafe { &*pac::$pac_type::ptr() } |
| 85 | } | 82 | } |
| 86 | 83 | ||
| 87 | fn state() -> &'static crate::radio::sealed::State { | 84 | fn state() -> &'static crate::radio::State { |
| 88 | static STATE: crate::radio::sealed::State = crate::radio::sealed::State::new(); | 85 | static STATE: crate::radio::State = crate::radio::State::new(); |
| 89 | &STATE | 86 | &STATE |
| 90 | } | 87 | } |
| 91 | } | 88 | } |
| @@ -96,7 +93,8 @@ macro_rules! impl_radio { | |||
| 96 | } | 93 | } |
| 97 | 94 | ||
| 98 | /// Radio peripheral instance. | 95 | /// Radio peripheral instance. |
| 99 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 96 | #[allow(private_bounds)] |
| 97 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 100 | /// Interrupt for this peripheral. | 98 | /// Interrupt for this peripheral. |
| 101 | type Interrupt: interrupt::typelevel::Interrupt; | 99 | type Interrupt: interrupt::typelevel::Interrupt; |
| 102 | } | 100 | } |
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 @@ | |||
| 2 | 2 | ||
| 3 | #![macro_use] | 3 | #![macro_use] |
| 4 | 4 | ||
| 5 | use core::cell::{RefCell, RefMut}; | ||
| 5 | use core::future::poll_fn; | 6 | use core::future::poll_fn; |
| 6 | use core::marker::PhantomData; | 7 | use core::marker::PhantomData; |
| 7 | use core::ptr; | 8 | use core::ptr; |
| 8 | use core::task::Poll; | 9 | use core::task::Poll; |
| 9 | 10 | ||
| 11 | use critical_section::{CriticalSection, Mutex}; | ||
| 10 | use embassy_hal_internal::drop::OnDrop; | 12 | use embassy_hal_internal::drop::OnDrop; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 14 | use embassy_sync::waitqueue::WakerRegistration; | ||
| 12 | 15 | ||
| 13 | use crate::interrupt::typelevel::Interrupt; | 16 | use crate::interrupt::typelevel::Interrupt; |
| 14 | use crate::{interrupt, Peripheral}; | 17 | use crate::{interrupt, Peripheral}; |
| @@ -205,73 +208,61 @@ impl<'d, T: Instance> rand_core::RngCore for Rng<'d, T> { | |||
| 205 | 208 | ||
| 206 | impl<'d, T: Instance> rand_core::CryptoRng for Rng<'d, T> {} | 209 | impl<'d, T: Instance> rand_core::CryptoRng for Rng<'d, T> {} |
| 207 | 210 | ||
| 208 | pub(crate) mod sealed { | 211 | /// Peripheral static state |
| 209 | use core::cell::{Ref, RefCell, RefMut}; | 212 | pub(crate) struct State { |
| 210 | 213 | inner: Mutex<RefCell<InnerState>>, | |
| 211 | use critical_section::{CriticalSection, Mutex}; | 214 | } |
| 212 | use embassy_sync::waitqueue::WakerRegistration; | ||
| 213 | |||
| 214 | use super::*; | ||
| 215 | |||
| 216 | /// Peripheral static state | ||
| 217 | pub struct State { | ||
| 218 | inner: Mutex<RefCell<InnerState>>, | ||
| 219 | } | ||
| 220 | |||
| 221 | pub struct InnerState { | ||
| 222 | pub ptr: *mut u8, | ||
| 223 | pub end: *mut u8, | ||
| 224 | pub waker: WakerRegistration, | ||
| 225 | } | ||
| 226 | 215 | ||
| 227 | unsafe impl Send for InnerState {} | 216 | struct InnerState { |
| 217 | ptr: *mut u8, | ||
| 218 | end: *mut u8, | ||
| 219 | waker: WakerRegistration, | ||
| 220 | } | ||
| 228 | 221 | ||
| 229 | impl State { | 222 | unsafe impl Send for InnerState {} |
| 230 | pub const fn new() -> Self { | ||
| 231 | Self { | ||
| 232 | inner: Mutex::new(RefCell::new(InnerState::new())), | ||
| 233 | } | ||
| 234 | } | ||
| 235 | 223 | ||
| 236 | pub fn borrow<'cs>(&'cs self, cs: CriticalSection<'cs>) -> Ref<'cs, InnerState> { | 224 | impl State { |
| 237 | self.inner.borrow(cs).borrow() | 225 | pub(crate) const fn new() -> Self { |
| 226 | Self { | ||
| 227 | inner: Mutex::new(RefCell::new(InnerState::new())), | ||
| 238 | } | 228 | } |
| 229 | } | ||
| 239 | 230 | ||
| 240 | pub fn borrow_mut<'cs>(&'cs self, cs: CriticalSection<'cs>) -> RefMut<'cs, InnerState> { | 231 | fn borrow_mut<'cs>(&'cs self, cs: CriticalSection<'cs>) -> RefMut<'cs, InnerState> { |
| 241 | self.inner.borrow(cs).borrow_mut() | 232 | self.inner.borrow(cs).borrow_mut() |
| 242 | } | ||
| 243 | } | 233 | } |
| 234 | } | ||
| 244 | 235 | ||
| 245 | impl InnerState { | 236 | impl InnerState { |
| 246 | pub const fn new() -> Self { | 237 | const fn new() -> Self { |
| 247 | Self { | 238 | Self { |
| 248 | ptr: ptr::null_mut(), | 239 | ptr: ptr::null_mut(), |
| 249 | end: ptr::null_mut(), | 240 | end: ptr::null_mut(), |
| 250 | waker: WakerRegistration::new(), | 241 | waker: WakerRegistration::new(), |
| 251 | } | ||
| 252 | } | 242 | } |
| 253 | } | 243 | } |
| 244 | } | ||
| 254 | 245 | ||
| 255 | pub trait Instance { | 246 | pub(crate) trait SealedInstance { |
| 256 | fn regs() -> &'static crate::pac::rng::RegisterBlock; | 247 | fn regs() -> &'static crate::pac::rng::RegisterBlock; |
| 257 | fn state() -> &'static State; | 248 | fn state() -> &'static State; |
| 258 | } | ||
| 259 | } | 249 | } |
| 260 | 250 | ||
| 261 | /// RNG peripheral instance. | 251 | /// RNG peripheral instance. |
| 262 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 252 | #[allow(private_bounds)] |
| 253 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 263 | /// Interrupt for this peripheral. | 254 | /// Interrupt for this peripheral. |
| 264 | type Interrupt: interrupt::typelevel::Interrupt; | 255 | type Interrupt: interrupt::typelevel::Interrupt; |
| 265 | } | 256 | } |
| 266 | 257 | ||
| 267 | macro_rules! impl_rng { | 258 | macro_rules! impl_rng { |
| 268 | ($type:ident, $pac_type:ident, $irq:ident) => { | 259 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 269 | impl crate::rng::sealed::Instance for peripherals::$type { | 260 | impl crate::rng::SealedInstance for peripherals::$type { |
| 270 | fn regs() -> &'static crate::pac::rng::RegisterBlock { | 261 | fn regs() -> &'static crate::pac::rng::RegisterBlock { |
| 271 | unsafe { &*pac::$pac_type::ptr() } | 262 | unsafe { &*pac::$pac_type::ptr() } |
| 272 | } | 263 | } |
| 273 | fn state() -> &'static crate::rng::sealed::State { | 264 | fn state() -> &'static crate::rng::State { |
| 274 | static STATE: crate::rng::sealed::State = crate::rng::sealed::State::new(); | 265 | static STATE: crate::rng::State = crate::rng::State::new(); |
| 275 | &STATE | 266 | &STATE |
| 276 | } | 267 | } |
| 277 | } | 268 | } |
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; | |||
| 16 | use saadc::oversample::OVERSAMPLE_A; | 16 | use saadc::oversample::OVERSAMPLE_A; |
| 17 | use saadc::resolution::VAL_A; | 17 | use saadc::resolution::VAL_A; |
| 18 | 18 | ||
| 19 | use self::sealed::Input as _; | ||
| 20 | use crate::interrupt::InterruptExt; | 19 | use crate::interrupt::InterruptExt; |
| 21 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; | 20 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; |
| 22 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 21 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| @@ -662,16 +661,13 @@ pub enum Resolution { | |||
| 662 | _14BIT = 3, | 661 | _14BIT = 3, |
| 663 | } | 662 | } |
| 664 | 663 | ||
| 665 | pub(crate) mod sealed { | 664 | pub(crate) trait SealedInput { |
| 666 | use super::*; | 665 | fn channel(&self) -> InputChannel; |
| 667 | |||
| 668 | pub trait Input { | ||
| 669 | fn channel(&self) -> InputChannel; | ||
| 670 | } | ||
| 671 | } | 666 | } |
| 672 | 667 | ||
| 673 | /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. | 668 | /// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. |
| 674 | pub trait Input: sealed::Input + Into<AnyInput> + Peripheral<P = Self> + Sized + 'static { | 669 | #[allow(private_bounds)] |
| 670 | pub trait Input: SealedInput + Into<AnyInput> + Peripheral<P = Self> + Sized + 'static { | ||
| 675 | /// Convert this SAADC input to a type-erased `AnyInput`. | 671 | /// Convert this SAADC input to a type-erased `AnyInput`. |
| 676 | /// | 672 | /// |
| 677 | /// This allows using several inputs in situations that might require | 673 | /// This allows using several inputs in situations that might require |
| @@ -693,7 +689,7 @@ pub struct AnyInput { | |||
| 693 | 689 | ||
| 694 | impl_peripheral!(AnyInput); | 690 | impl_peripheral!(AnyInput); |
| 695 | 691 | ||
| 696 | impl sealed::Input for AnyInput { | 692 | impl SealedInput for AnyInput { |
| 697 | fn channel(&self) -> InputChannel { | 693 | fn channel(&self) -> InputChannel { |
| 698 | self.channel | 694 | self.channel |
| 699 | } | 695 | } |
| @@ -706,7 +702,7 @@ macro_rules! impl_saadc_input { | |||
| 706 | impl_saadc_input!(@local, crate::peripherals::$pin, $ch); | 702 | impl_saadc_input!(@local, crate::peripherals::$pin, $ch); |
| 707 | }; | 703 | }; |
| 708 | (@local, $pin:ty, $ch:ident) => { | 704 | (@local, $pin:ty, $ch:ident) => { |
| 709 | impl crate::saadc::sealed::Input for $pin { | 705 | impl crate::saadc::SealedInput for $pin { |
| 710 | fn channel(&self) -> crate::saadc::InputChannel { | 706 | fn channel(&self) -> crate::saadc::InputChannel { |
| 711 | crate::saadc::InputChannel::$ch | 707 | crate::saadc::InputChannel::$ch |
| 712 | } | 708 | } |
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 @@ | |||
| 4 | 4 | ||
| 5 | use core::future::poll_fn; | 5 | use core::future::poll_fn; |
| 6 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 7 | #[cfg(feature = "_nrf52832_anomaly_109")] | ||
| 8 | use core::sync::atomic::AtomicU8; | ||
| 7 | use core::sync::atomic::{compiler_fence, Ordering}; | 9 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 8 | use core::task::Poll; | 10 | use core::task::Poll; |
| 9 | 11 | ||
| 10 | use embassy_embedded_hal::SetConfig; | 12 | use embassy_embedded_hal::SetConfig; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 13 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 14 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 12 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 15 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 13 | pub use pac::spim0::config::ORDER_A as BitOrder; | 16 | pub use pac::spim0::config::ORDER_A as BitOrder; |
| 14 | pub use pac::spim0::frequency::FREQUENCY_A as Frequency; | 17 | pub use pac::spim0::frequency::FREQUENCY_A as Frequency; |
| 15 | 18 | ||
| 16 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 19 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 17 | use crate::gpio::sealed::Pin as _; | 20 | use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits, SealedPin as _}; |
| 18 | use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits}; | ||
| 19 | use crate::interrupt::typelevel::Interrupt; | 21 | use crate::interrupt::typelevel::Interrupt; |
| 20 | use crate::util::{slice_in_ram_or, slice_ptr_len, slice_ptr_parts, slice_ptr_parts_mut}; | 22 | use crate::util::{slice_in_ram_or, slice_ptr_len, slice_ptr_parts, slice_ptr_parts_mut}; |
| 21 | use crate::{interrupt, pac, Peripheral}; | 23 | use crate::{interrupt, pac, Peripheral}; |
| @@ -487,54 +489,46 @@ impl<'d, T: Instance> Drop for Spim<'d, T> { | |||
| 487 | } | 489 | } |
| 488 | } | 490 | } |
| 489 | 491 | ||
| 490 | pub(crate) mod sealed { | 492 | pub(crate) struct State { |
| 493 | waker: AtomicWaker, | ||
| 491 | #[cfg(feature = "_nrf52832_anomaly_109")] | 494 | #[cfg(feature = "_nrf52832_anomaly_109")] |
| 492 | use core::sync::atomic::AtomicU8; | 495 | rx: AtomicU8, |
| 493 | 496 | #[cfg(feature = "_nrf52832_anomaly_109")] | |
| 494 | use embassy_sync::waitqueue::AtomicWaker; | 497 | tx: AtomicU8, |
| 495 | 498 | } | |
| 496 | use super::*; | ||
| 497 | |||
| 498 | pub struct State { | ||
| 499 | pub waker: AtomicWaker, | ||
| 500 | #[cfg(feature = "_nrf52832_anomaly_109")] | ||
| 501 | pub rx: AtomicU8, | ||
| 502 | #[cfg(feature = "_nrf52832_anomaly_109")] | ||
| 503 | pub tx: AtomicU8, | ||
| 504 | } | ||
| 505 | 499 | ||
| 506 | impl State { | 500 | impl State { |
| 507 | pub const fn new() -> Self { | 501 | pub(crate) const fn new() -> Self { |
| 508 | Self { | 502 | Self { |
| 509 | waker: AtomicWaker::new(), | 503 | waker: AtomicWaker::new(), |
| 510 | #[cfg(feature = "_nrf52832_anomaly_109")] | 504 | #[cfg(feature = "_nrf52832_anomaly_109")] |
| 511 | rx: AtomicU8::new(0), | 505 | rx: AtomicU8::new(0), |
| 512 | #[cfg(feature = "_nrf52832_anomaly_109")] | 506 | #[cfg(feature = "_nrf52832_anomaly_109")] |
| 513 | tx: AtomicU8::new(0), | 507 | tx: AtomicU8::new(0), |
| 514 | } | ||
| 515 | } | 508 | } |
| 516 | } | 509 | } |
| 510 | } | ||
| 517 | 511 | ||
| 518 | pub trait Instance { | 512 | pub(crate) trait SealedInstance { |
| 519 | fn regs() -> &'static pac::spim0::RegisterBlock; | 513 | fn regs() -> &'static pac::spim0::RegisterBlock; |
| 520 | fn state() -> &'static State; | 514 | fn state() -> &'static State; |
| 521 | } | ||
| 522 | } | 515 | } |
| 523 | 516 | ||
| 524 | /// SPIM peripheral instance | 517 | /// SPIM peripheral instance |
| 525 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static { | 518 | #[allow(private_bounds)] |
| 519 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | ||
| 526 | /// Interrupt for this peripheral. | 520 | /// Interrupt for this peripheral. |
| 527 | type Interrupt: interrupt::typelevel::Interrupt; | 521 | type Interrupt: interrupt::typelevel::Interrupt; |
| 528 | } | 522 | } |
| 529 | 523 | ||
| 530 | macro_rules! impl_spim { | 524 | macro_rules! impl_spim { |
| 531 | ($type:ident, $pac_type:ident, $irq:ident) => { | 525 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 532 | impl crate::spim::sealed::Instance for peripherals::$type { | 526 | impl crate::spim::SealedInstance for peripherals::$type { |
| 533 | fn regs() -> &'static pac::spim0::RegisterBlock { | 527 | fn regs() -> &'static pac::spim0::RegisterBlock { |
| 534 | unsafe { &*pac::$pac_type::ptr() } | 528 | unsafe { &*pac::$pac_type::ptr() } |
| 535 | } | 529 | } |
| 536 | fn state() -> &'static crate::spim::sealed::State { | 530 | fn state() -> &'static crate::spim::State { |
| 537 | static STATE: crate::spim::sealed::State = crate::spim::sealed::State::new(); | 531 | static STATE: crate::spim::State = crate::spim::State::new(); |
| 538 | &STATE | 532 | &STATE |
| 539 | } | 533 | } |
| 540 | } | 534 | } |
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; | |||
| 8 | 8 | ||
| 9 | use embassy_embedded_hal::SetConfig; | 9 | use embassy_embedded_hal::SetConfig; |
| 10 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 10 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 11 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 11 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 12 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 12 | pub use pac::spis0::config::ORDER_A as BitOrder; | 13 | pub use pac::spis0::config::ORDER_A as BitOrder; |
| 13 | 14 | ||
| 14 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 15 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 15 | use crate::gpio::sealed::Pin as _; | 16 | use crate::gpio::{self, AnyPin, Pin as GpioPin, SealedPin as _}; |
| 16 | use crate::gpio::{self, AnyPin, Pin as GpioPin}; | ||
| 17 | use crate::interrupt::typelevel::Interrupt; | 17 | use crate::interrupt::typelevel::Interrupt; |
| 18 | use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; | 18 | use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; |
| 19 | use crate::{interrupt, pac, Peripheral}; | 19 | use crate::{interrupt, pac, Peripheral}; |
| @@ -456,43 +456,38 @@ impl<'d, T: Instance> Drop for Spis<'d, T> { | |||
| 456 | } | 456 | } |
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | pub(crate) mod sealed { | 459 | pub(crate) struct State { |
| 460 | use embassy_sync::waitqueue::AtomicWaker; | 460 | waker: AtomicWaker, |
| 461 | 461 | } | |
| 462 | use super::*; | ||
| 463 | |||
| 464 | pub struct State { | ||
| 465 | pub waker: AtomicWaker, | ||
| 466 | } | ||
| 467 | 462 | ||
| 468 | impl State { | 463 | impl State { |
| 469 | pub const fn new() -> Self { | 464 | pub(crate) const fn new() -> Self { |
| 470 | Self { | 465 | Self { |
| 471 | waker: AtomicWaker::new(), | 466 | waker: AtomicWaker::new(), |
| 472 | } | ||
| 473 | } | 467 | } |
| 474 | } | 468 | } |
| 469 | } | ||
| 475 | 470 | ||
| 476 | pub trait Instance { | 471 | pub(crate) trait SealedInstance { |
| 477 | fn regs() -> &'static pac::spis0::RegisterBlock; | 472 | fn regs() -> &'static pac::spis0::RegisterBlock; |
| 478 | fn state() -> &'static State; | 473 | fn state() -> &'static State; |
| 479 | } | ||
| 480 | } | 474 | } |
| 481 | 475 | ||
| 482 | /// SPIS peripheral instance | 476 | /// SPIS peripheral instance |
| 483 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static { | 477 | #[allow(private_bounds)] |
| 478 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | ||
| 484 | /// Interrupt for this peripheral. | 479 | /// Interrupt for this peripheral. |
| 485 | type Interrupt: interrupt::typelevel::Interrupt; | 480 | type Interrupt: interrupt::typelevel::Interrupt; |
| 486 | } | 481 | } |
| 487 | 482 | ||
| 488 | macro_rules! impl_spis { | 483 | macro_rules! impl_spis { |
| 489 | ($type:ident, $pac_type:ident, $irq:ident) => { | 484 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 490 | impl crate::spis::sealed::Instance for peripherals::$type { | 485 | impl crate::spis::SealedInstance for peripherals::$type { |
| 491 | fn regs() -> &'static pac::spis0::RegisterBlock { | 486 | fn regs() -> &'static pac::spis0::RegisterBlock { |
| 492 | unsafe { &*pac::$pac_type::ptr() } | 487 | unsafe { &*pac::$pac_type::ptr() } |
| 493 | } | 488 | } |
| 494 | fn state() -> &'static crate::spis::sealed::State { | 489 | fn state() -> &'static crate::spis::State { |
| 495 | static STATE: crate::spis::sealed::State = crate::spis::sealed::State::new(); | 490 | static STATE: crate::spis::State = crate::spis::State::new(); |
| 496 | &STATE | 491 | &STATE |
| 497 | } | 492 | } |
| 498 | } | 493 | } |
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}; | |||
| 11 | use crate::ppi::{Event, Task}; | 11 | use crate::ppi::{Event, Task}; |
| 12 | use crate::{pac, Peripheral}; | 12 | use crate::{pac, Peripheral}; |
| 13 | 13 | ||
| 14 | pub(crate) mod sealed { | 14 | pub(crate) trait SealedInstance { |
| 15 | 15 | /// The number of CC registers this instance has. | |
| 16 | use super::*; | 16 | const CCS: usize; |
| 17 | 17 | fn regs() -> &'static pac::timer0::RegisterBlock; | |
| 18 | pub trait Instance { | ||
| 19 | /// The number of CC registers this instance has. | ||
| 20 | const CCS: usize; | ||
| 21 | fn regs() -> &'static pac::timer0::RegisterBlock; | ||
| 22 | } | ||
| 23 | pub trait ExtendedInstance {} | ||
| 24 | } | 18 | } |
| 25 | 19 | ||
| 26 | /// Basic Timer instance. | 20 | /// Basic Timer instance. |
| 27 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 21 | #[allow(private_bounds)] |
| 22 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 28 | /// Interrupt for this peripheral. | 23 | /// Interrupt for this peripheral. |
| 29 | type Interrupt: crate::interrupt::typelevel::Interrupt; | 24 | type Interrupt: crate::interrupt::typelevel::Interrupt; |
| 30 | } | 25 | } |
| 31 | 26 | ||
| 32 | /// Extended timer instance. | 27 | /// Extended timer instance. |
| 33 | pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {} | 28 | pub trait ExtendedInstance: Instance {} |
| 34 | 29 | ||
| 35 | macro_rules! impl_timer { | 30 | macro_rules! impl_timer { |
| 36 | ($type:ident, $pac_type:ident, $irq:ident, $ccs:literal) => { | 31 | ($type:ident, $pac_type:ident, $irq:ident, $ccs:literal) => { |
| 37 | impl crate::timer::sealed::Instance for peripherals::$type { | 32 | impl crate::timer::SealedInstance for peripherals::$type { |
| 38 | const CCS: usize = $ccs; | 33 | const CCS: usize = $ccs; |
| 39 | fn regs() -> &'static pac::timer0::RegisterBlock { | 34 | fn regs() -> &'static pac::timer0::RegisterBlock { |
| 40 | unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) } | 35 | unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) } |
| @@ -49,7 +44,6 @@ macro_rules! impl_timer { | |||
| 49 | }; | 44 | }; |
| 50 | ($type:ident, $pac_type:ident, $irq:ident, extended) => { | 45 | ($type:ident, $pac_type:ident, $irq:ident, extended) => { |
| 51 | impl_timer!($type, $pac_type, $irq, 6); | 46 | impl_timer!($type, $pac_type, $irq, 6); |
| 52 | impl crate::timer::sealed::ExtendedInstance for peripherals::$type {} | ||
| 53 | impl crate::timer::ExtendedInstance for peripherals::$type {} | 47 | impl crate::timer::ExtendedInstance for peripherals::$type {} |
| 54 | }; | 48 | }; |
| 55 | } | 49 | } |
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> { | |||
| 727 | } | 727 | } |
| 728 | } | 728 | } |
| 729 | 729 | ||
| 730 | pub(crate) mod sealed { | 730 | pub(crate) struct State { |
| 731 | use super::*; | 731 | end_waker: AtomicWaker, |
| 732 | 732 | } | |
| 733 | pub struct State { | ||
| 734 | pub end_waker: AtomicWaker, | ||
| 735 | } | ||
| 736 | 733 | ||
| 737 | impl State { | 734 | impl State { |
| 738 | pub const fn new() -> Self { | 735 | pub(crate) const fn new() -> Self { |
| 739 | Self { | 736 | Self { |
| 740 | end_waker: AtomicWaker::new(), | 737 | end_waker: AtomicWaker::new(), |
| 741 | } | ||
| 742 | } | 738 | } |
| 743 | } | 739 | } |
| 740 | } | ||
| 744 | 741 | ||
| 745 | pub trait Instance { | 742 | pub(crate) trait SealedInstance { |
| 746 | fn regs() -> &'static pac::twim0::RegisterBlock; | 743 | fn regs() -> &'static pac::twim0::RegisterBlock; |
| 747 | fn state() -> &'static State; | 744 | fn state() -> &'static State; |
| 748 | } | ||
| 749 | } | 745 | } |
| 750 | 746 | ||
| 751 | /// TWIM peripheral instance. | 747 | /// TWIM peripheral instance. |
| 752 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static { | 748 | #[allow(private_bounds)] |
| 749 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | ||
| 753 | /// Interrupt for this peripheral. | 750 | /// Interrupt for this peripheral. |
| 754 | type Interrupt: interrupt::typelevel::Interrupt; | 751 | type Interrupt: interrupt::typelevel::Interrupt; |
| 755 | } | 752 | } |
| 756 | 753 | ||
| 757 | macro_rules! impl_twim { | 754 | macro_rules! impl_twim { |
| 758 | ($type:ident, $pac_type:ident, $irq:ident) => { | 755 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 759 | impl crate::twim::sealed::Instance for peripherals::$type { | 756 | impl crate::twim::SealedInstance for peripherals::$type { |
| 760 | fn regs() -> &'static pac::twim0::RegisterBlock { | 757 | fn regs() -> &'static pac::twim0::RegisterBlock { |
| 761 | unsafe { &*pac::$pac_type::ptr() } | 758 | unsafe { &*pac::$pac_type::ptr() } |
| 762 | } | 759 | } |
| 763 | fn state() -> &'static crate::twim::sealed::State { | 760 | fn state() -> &'static crate::twim::State { |
| 764 | static STATE: crate::twim::sealed::State = crate::twim::sealed::State::new(); | 761 | static STATE: crate::twim::State = crate::twim::State::new(); |
| 765 | &STATE | 762 | &STATE |
| 766 | } | 763 | } |
| 767 | } | 764 | } |
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> { | |||
| 754 | } | 754 | } |
| 755 | } | 755 | } |
| 756 | 756 | ||
| 757 | pub(crate) mod sealed { | 757 | pub(crate) struct State { |
| 758 | use super::*; | 758 | waker: AtomicWaker, |
| 759 | 759 | } | |
| 760 | pub struct State { | ||
| 761 | pub waker: AtomicWaker, | ||
| 762 | } | ||
| 763 | 760 | ||
| 764 | impl State { | 761 | impl State { |
| 765 | pub const fn new() -> Self { | 762 | pub(crate) const fn new() -> Self { |
| 766 | Self { | 763 | Self { |
| 767 | waker: AtomicWaker::new(), | 764 | waker: AtomicWaker::new(), |
| 768 | } | ||
| 769 | } | 765 | } |
| 770 | } | 766 | } |
| 767 | } | ||
| 771 | 768 | ||
| 772 | pub trait Instance { | 769 | pub(crate) trait SealedInstance { |
| 773 | fn regs() -> &'static pac::twis0::RegisterBlock; | 770 | fn regs() -> &'static pac::twis0::RegisterBlock; |
| 774 | fn state() -> &'static State; | 771 | fn state() -> &'static State; |
| 775 | } | ||
| 776 | } | 772 | } |
| 777 | 773 | ||
| 778 | /// TWIS peripheral instance. | 774 | /// TWIS peripheral instance. |
| 779 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static { | 775 | #[allow(private_bounds)] |
| 776 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { | ||
| 780 | /// Interrupt for this peripheral. | 777 | /// Interrupt for this peripheral. |
| 781 | type Interrupt: interrupt::typelevel::Interrupt; | 778 | type Interrupt: interrupt::typelevel::Interrupt; |
| 782 | } | 779 | } |
| 783 | 780 | ||
| 784 | macro_rules! impl_twis { | 781 | macro_rules! impl_twis { |
| 785 | ($type:ident, $pac_type:ident, $irq:ident) => { | 782 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 786 | impl crate::twis::sealed::Instance for peripherals::$type { | 783 | impl crate::twis::SealedInstance for peripherals::$type { |
| 787 | fn regs() -> &'static pac::twis0::RegisterBlock { | 784 | fn regs() -> &'static pac::twis0::RegisterBlock { |
| 788 | unsafe { &*pac::$pac_type::ptr() } | 785 | unsafe { &*pac::$pac_type::ptr() } |
| 789 | } | 786 | } |
| 790 | fn state() -> &'static crate::twis::sealed::State { | 787 | fn state() -> &'static crate::twis::State { |
| 791 | static STATE: crate::twis::sealed::State = crate::twis::sealed::State::new(); | 788 | static STATE: crate::twis::State = crate::twis::State::new(); |
| 792 | &STATE | 789 | &STATE |
| 793 | } | 790 | } |
| 794 | } | 791 | } |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index cbd5dccbc..fa0a773a8 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -15,18 +15,18 @@ | |||
| 15 | 15 | ||
| 16 | use core::future::poll_fn; | 16 | use core::future::poll_fn; |
| 17 | use core::marker::PhantomData; | 17 | use core::marker::PhantomData; |
| 18 | use core::sync::atomic::{compiler_fence, Ordering}; | 18 | use core::sync::atomic::{compiler_fence, AtomicU8, Ordering}; |
| 19 | use core::task::Poll; | 19 | use core::task::Poll; |
| 20 | 20 | ||
| 21 | use embassy_hal_internal::drop::OnDrop; | 21 | use embassy_hal_internal::drop::OnDrop; |
| 22 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 22 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 23 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 23 | use pac::uarte0::RegisterBlock; | 24 | use pac::uarte0::RegisterBlock; |
| 24 | // Re-export SVD variants to allow user to directly set values. | 25 | // Re-export SVD variants to allow user to directly set values. |
| 25 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | 26 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; |
| 26 | 27 | ||
| 27 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 28 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 28 | use crate::gpio::sealed::Pin as _; | 29 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits, SealedPin as _}; |
| 29 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; | ||
| 30 | use crate::interrupt::typelevel::Interrupt; | 30 | use crate::interrupt::typelevel::Interrupt; |
| 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 32 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 32 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| @@ -939,7 +939,7 @@ pub(crate) fn apply_workaround_for_enable_anomaly(r: &crate::pac::uarte0::Regist | |||
| 939 | } | 939 | } |
| 940 | } | 940 | } |
| 941 | 941 | ||
| 942 | pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) { | 942 | pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &State) { |
| 943 | if s.tx_rx_refcount.fetch_sub(1, Ordering::Relaxed) == 1 { | 943 | if s.tx_rx_refcount.fetch_sub(1, Ordering::Relaxed) == 1 { |
| 944 | // Finally we can disable, and we do so for the peripheral | 944 | // Finally we can disable, and we do so for the peripheral |
| 945 | // i.e. not just rx concerns. | 945 | // i.e. not just rx concerns. |
| @@ -954,49 +954,42 @@ pub(crate) fn drop_tx_rx(r: &pac::uarte0::RegisterBlock, s: &sealed::State) { | |||
| 954 | } | 954 | } |
| 955 | } | 955 | } |
| 956 | 956 | ||
| 957 | pub(crate) mod sealed { | 957 | pub(crate) struct State { |
| 958 | use core::sync::atomic::AtomicU8; | 958 | pub(crate) rx_waker: AtomicWaker, |
| 959 | 959 | pub(crate) tx_waker: AtomicWaker, | |
| 960 | use embassy_sync::waitqueue::AtomicWaker; | 960 | pub(crate) tx_rx_refcount: AtomicU8, |
| 961 | 961 | } | |
| 962 | use super::*; | 962 | impl State { |
| 963 | 963 | pub(crate) const fn new() -> Self { | |
| 964 | pub struct State { | 964 | Self { |
| 965 | pub rx_waker: AtomicWaker, | 965 | rx_waker: AtomicWaker::new(), |
| 966 | pub tx_waker: AtomicWaker, | 966 | tx_waker: AtomicWaker::new(), |
| 967 | pub tx_rx_refcount: AtomicU8, | 967 | tx_rx_refcount: AtomicU8::new(0), |
| 968 | } | ||
| 969 | impl State { | ||
| 970 | pub const fn new() -> Self { | ||
| 971 | Self { | ||
| 972 | rx_waker: AtomicWaker::new(), | ||
| 973 | tx_waker: AtomicWaker::new(), | ||
| 974 | tx_rx_refcount: AtomicU8::new(0), | ||
| 975 | } | ||
| 976 | } | 968 | } |
| 977 | } | 969 | } |
| 970 | } | ||
| 978 | 971 | ||
| 979 | pub trait Instance { | 972 | pub(crate) trait SealedInstance { |
| 980 | fn regs() -> &'static pac::uarte0::RegisterBlock; | 973 | fn regs() -> &'static pac::uarte0::RegisterBlock; |
| 981 | fn state() -> &'static State; | 974 | fn state() -> &'static State; |
| 982 | fn buffered_state() -> &'static crate::buffered_uarte::State; | 975 | fn buffered_state() -> &'static crate::buffered_uarte::State; |
| 983 | } | ||
| 984 | } | 976 | } |
| 985 | 977 | ||
| 986 | /// UARTE peripheral instance. | 978 | /// UARTE peripheral instance. |
| 987 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 979 | #[allow(private_bounds)] |
| 980 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 988 | /// Interrupt for this peripheral. | 981 | /// Interrupt for this peripheral. |
| 989 | type Interrupt: interrupt::typelevel::Interrupt; | 982 | type Interrupt: interrupt::typelevel::Interrupt; |
| 990 | } | 983 | } |
| 991 | 984 | ||
| 992 | macro_rules! impl_uarte { | 985 | macro_rules! impl_uarte { |
| 993 | ($type:ident, $pac_type:ident, $irq:ident) => { | 986 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 994 | impl crate::uarte::sealed::Instance for peripherals::$type { | 987 | impl crate::uarte::SealedInstance for peripherals::$type { |
| 995 | fn regs() -> &'static pac::uarte0::RegisterBlock { | 988 | fn regs() -> &'static pac::uarte0::RegisterBlock { |
| 996 | unsafe { &*pac::$pac_type::ptr() } | 989 | unsafe { &*pac::$pac_type::ptr() } |
| 997 | } | 990 | } |
| 998 | fn state() -> &'static crate::uarte::sealed::State { | 991 | fn state() -> &'static crate::uarte::State { |
| 999 | static STATE: crate::uarte::sealed::State = crate::uarte::sealed::State::new(); | 992 | static STATE: crate::uarte::State = crate::uarte::State::new(); |
| 1000 | &STATE | 993 | &STATE |
| 1001 | } | 994 | } |
| 1002 | fn buffered_state() -> &'static crate::buffered_uarte::State { | 995 | fn buffered_state() -> &'static crate::buffered_uarte::State { |
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 { | |||
| 793 | } | 793 | } |
| 794 | } | 794 | } |
| 795 | 795 | ||
| 796 | pub(crate) mod sealed { | 796 | pub(crate) trait SealedInstance { |
| 797 | use super::*; | 797 | fn regs() -> &'static pac::usbd::RegisterBlock; |
| 798 | |||
| 799 | pub trait Instance { | ||
| 800 | fn regs() -> &'static pac::usbd::RegisterBlock; | ||
| 801 | } | ||
| 802 | } | 798 | } |
| 803 | 799 | ||
| 804 | /// USB peripheral instance. | 800 | /// USB peripheral instance. |
| 805 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { | 801 | #[allow(private_bounds)] |
| 802 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | ||
| 806 | /// Interrupt for this peripheral. | 803 | /// Interrupt for this peripheral. |
| 807 | type Interrupt: interrupt::typelevel::Interrupt; | 804 | type Interrupt: interrupt::typelevel::Interrupt; |
| 808 | } | 805 | } |
| 809 | 806 | ||
| 810 | macro_rules! impl_usb { | 807 | macro_rules! impl_usb { |
| 811 | ($type:ident, $pac_type:ident, $irq:ident) => { | 808 | ($type:ident, $pac_type:ident, $irq:ident) => { |
| 812 | impl crate::usb::sealed::Instance for peripherals::$type { | 809 | impl crate::usb::SealedInstance for peripherals::$type { |
| 813 | fn regs() -> &'static pac::usbd::RegisterBlock { | 810 | fn regs() -> &'static pac::usbd::RegisterBlock { |
| 814 | unsafe { &*pac::$pac_type::ptr() } | 811 | unsafe { &*pac::$pac_type::ptr() } |
| 815 | } | 812 | } |
