diff options
35 files changed, 648 insertions, 760 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 | } |
diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 4c01fe195..101c5b71f 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs | |||
| @@ -8,8 +8,7 @@ use core::task::Poll; | |||
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use crate::gpio::sealed::Pin as GpioPin; | 11 | use crate::gpio::{self, AnyPin, Pull, SealedPin as GpioPin}; |
| 12 | use crate::gpio::{self, AnyPin, Pull}; | ||
| 13 | use crate::interrupt::typelevel::Binding; | 12 | use crate::interrupt::typelevel::Binding; |
| 14 | use crate::interrupt::InterruptExt; | 13 | use crate::interrupt::InterruptExt; |
| 15 | use crate::peripherals::{ADC, ADC_TEMP_SENSOR}; | 14 | use crate::peripherals::{ADC, ADC_TEMP_SENSOR}; |
| @@ -334,29 +333,28 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ADC_IRQ_FIFO> for Inter | |||
| 334 | } | 333 | } |
| 335 | } | 334 | } |
| 336 | 335 | ||
| 337 | mod sealed { | 336 | trait SealedAdcSample: crate::dma::Word {} |
| 338 | pub trait AdcSample: crate::dma::Word {} | 337 | trait SealedAdcChannel {} |
| 339 | |||
| 340 | pub trait AdcChannel {} | ||
| 341 | } | ||
| 342 | 338 | ||
| 343 | /// ADC sample. | 339 | /// ADC sample. |
| 344 | pub trait AdcSample: sealed::AdcSample {} | 340 | #[allow(private_bounds)] |
| 341 | pub trait AdcSample: SealedAdcSample {} | ||
| 345 | 342 | ||
| 346 | impl sealed::AdcSample for u16 {} | 343 | impl SealedAdcSample for u16 {} |
| 347 | impl AdcSample for u16 {} | 344 | impl AdcSample for u16 {} |
| 348 | 345 | ||
| 349 | impl sealed::AdcSample for u8 {} | 346 | impl SealedAdcSample for u8 {} |
| 350 | impl AdcSample for u8 {} | 347 | impl AdcSample for u8 {} |
| 351 | 348 | ||
| 352 | /// ADC channel. | 349 | /// ADC channel. |
| 353 | pub trait AdcChannel: sealed::AdcChannel {} | 350 | #[allow(private_bounds)] |
| 351 | pub trait AdcChannel: SealedAdcChannel {} | ||
| 354 | /// ADC pin. | 352 | /// ADC pin. |
| 355 | pub trait AdcPin: AdcChannel + gpio::Pin {} | 353 | pub trait AdcPin: AdcChannel + gpio::Pin {} |
| 356 | 354 | ||
| 357 | macro_rules! impl_pin { | 355 | macro_rules! impl_pin { |
| 358 | ($pin:ident, $channel:expr) => { | 356 | ($pin:ident, $channel:expr) => { |
| 359 | impl sealed::AdcChannel for peripherals::$pin {} | 357 | impl SealedAdcChannel for peripherals::$pin {} |
| 360 | impl AdcChannel for peripherals::$pin {} | 358 | impl AdcChannel for peripherals::$pin {} |
| 361 | impl AdcPin for peripherals::$pin {} | 359 | impl AdcPin for peripherals::$pin {} |
| 362 | }; | 360 | }; |
| @@ -367,5 +365,5 @@ impl_pin!(PIN_27, 1); | |||
| 367 | impl_pin!(PIN_28, 2); | 365 | impl_pin!(PIN_28, 2); |
| 368 | impl_pin!(PIN_29, 3); | 366 | impl_pin!(PIN_29, 3); |
| 369 | 367 | ||
| 370 | impl sealed::AdcChannel for peripherals::ADC_TEMP_SENSOR {} | 368 | impl SealedAdcChannel for peripherals::ADC_TEMP_SENSOR {} |
| 371 | impl AdcChannel for peripherals::ADC_TEMP_SENSOR {} | 369 | impl AdcChannel for peripherals::ADC_TEMP_SENSOR {} |
diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index b7f6aeac9..bedb79464 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs | |||
| @@ -6,8 +6,7 @@ use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; | |||
| 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 7 | use pac::clocks::vals::*; | 7 | use pac::clocks::vals::*; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin; | 9 | use crate::gpio::{AnyPin, SealedPin}; |
| 10 | use crate::gpio::AnyPin; | ||
| 11 | use crate::pac::common::{Reg, RW}; | 10 | use crate::pac::common::{Reg, RW}; |
| 12 | use crate::{pac, reset, Peripheral}; | 11 | use crate::{pac, reset, Peripheral}; |
| 13 | 12 | ||
| @@ -788,14 +787,14 @@ impl_gpinpin!(PIN_20, 20, 0); | |||
| 788 | impl_gpinpin!(PIN_22, 22, 1); | 787 | impl_gpinpin!(PIN_22, 22, 1); |
| 789 | 788 | ||
| 790 | /// General purpose clock input driver. | 789 | /// General purpose clock input driver. |
| 791 | pub struct Gpin<'d, T: Pin> { | 790 | pub struct Gpin<'d, T: GpinPin> { |
| 792 | gpin: PeripheralRef<'d, AnyPin>, | 791 | gpin: PeripheralRef<'d, AnyPin>, |
| 793 | _phantom: PhantomData<T>, | 792 | _phantom: PhantomData<T>, |
| 794 | } | 793 | } |
| 795 | 794 | ||
| 796 | impl<'d, T: Pin> Gpin<'d, T> { | 795 | impl<'d, T: GpinPin> Gpin<'d, T> { |
| 797 | /// Create new gpin driver. | 796 | /// Create new gpin driver. |
| 798 | pub fn new<P: GpinPin>(gpin: impl Peripheral<P = P> + 'd) -> Gpin<'d, P> { | 797 | pub fn new(gpin: impl Peripheral<P = T> + 'd) -> Self { |
| 799 | into_ref!(gpin); | 798 | into_ref!(gpin); |
| 800 | 799 | ||
| 801 | gpin.gpio().ctrl().write(|w| w.set_funcsel(0x08)); | 800 | gpin.gpio().ctrl().write(|w| w.set_funcsel(0x08)); |
| @@ -811,7 +810,7 @@ impl<'d, T: Pin> Gpin<'d, T> { | |||
| 811 | // } | 810 | // } |
| 812 | } | 811 | } |
| 813 | 812 | ||
| 814 | impl<'d, T: Pin> Drop for Gpin<'d, T> { | 813 | impl<'d, T: GpinPin> Drop for Gpin<'d, T> { |
| 815 | fn drop(&mut self) { | 814 | fn drop(&mut self) { |
| 816 | self.gpin | 815 | self.gpin |
| 817 | .gpio() | 816 | .gpio() |
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 44aabce6b..e6374a86c 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs | |||
| @@ -208,14 +208,12 @@ pub(crate) const CHANNEL_COUNT: usize = 12; | |||
| 208 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 208 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 209 | static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT]; | 209 | static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT]; |
| 210 | 210 | ||
| 211 | mod sealed { | 211 | trait SealedChannel {} |
| 212 | pub trait Channel {} | 212 | trait SealedWord {} |
| 213 | |||
| 214 | pub trait Word {} | ||
| 215 | } | ||
| 216 | 213 | ||
| 217 | /// DMA channel interface. | 214 | /// DMA channel interface. |
| 218 | pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + Sized + 'static { | 215 | #[allow(private_bounds)] |
| 216 | pub trait Channel: Peripheral<P = Self> + SealedChannel + Into<AnyChannel> + Sized + 'static { | ||
| 219 | /// Channel number. | 217 | /// Channel number. |
| 220 | fn number(&self) -> u8; | 218 | fn number(&self) -> u8; |
| 221 | 219 | ||
| @@ -231,26 +229,27 @@ pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + S | |||
| 231 | } | 229 | } |
| 232 | 230 | ||
| 233 | /// DMA word. | 231 | /// DMA word. |
| 234 | pub trait Word: sealed::Word { | 232 | #[allow(private_bounds)] |
| 233 | pub trait Word: SealedWord { | ||
| 235 | /// Word size. | 234 | /// Word size. |
| 236 | fn size() -> vals::DataSize; | 235 | fn size() -> vals::DataSize; |
| 237 | } | 236 | } |
| 238 | 237 | ||
| 239 | impl sealed::Word for u8 {} | 238 | impl SealedWord for u8 {} |
| 240 | impl Word for u8 { | 239 | impl Word for u8 { |
| 241 | fn size() -> vals::DataSize { | 240 | fn size() -> vals::DataSize { |
| 242 | vals::DataSize::SIZE_BYTE | 241 | vals::DataSize::SIZE_BYTE |
| 243 | } | 242 | } |
| 244 | } | 243 | } |
| 245 | 244 | ||
| 246 | impl sealed::Word for u16 {} | 245 | impl SealedWord for u16 {} |
| 247 | impl Word for u16 { | 246 | impl Word for u16 { |
| 248 | fn size() -> vals::DataSize { | 247 | fn size() -> vals::DataSize { |
| 249 | vals::DataSize::SIZE_HALFWORD | 248 | vals::DataSize::SIZE_HALFWORD |
| 250 | } | 249 | } |
| 251 | } | 250 | } |
| 252 | 251 | ||
| 253 | impl sealed::Word for u32 {} | 252 | impl SealedWord for u32 {} |
| 254 | impl Word for u32 { | 253 | impl Word for u32 { |
| 255 | fn size() -> vals::DataSize { | 254 | fn size() -> vals::DataSize { |
| 256 | vals::DataSize::SIZE_WORD | 255 | vals::DataSize::SIZE_WORD |
| @@ -264,7 +263,7 @@ pub struct AnyChannel { | |||
| 264 | 263 | ||
| 265 | impl_peripheral!(AnyChannel); | 264 | impl_peripheral!(AnyChannel); |
| 266 | 265 | ||
| 267 | impl sealed::Channel for AnyChannel {} | 266 | impl SealedChannel for AnyChannel {} |
| 268 | impl Channel for AnyChannel { | 267 | impl Channel for AnyChannel { |
| 269 | fn number(&self) -> u8 { | 268 | fn number(&self) -> u8 { |
| 270 | self.number | 269 | self.number |
| @@ -273,7 +272,7 @@ impl Channel for AnyChannel { | |||
| 273 | 272 | ||
| 274 | macro_rules! channel { | 273 | macro_rules! channel { |
| 275 | ($name:ident, $num:expr) => { | 274 | ($name:ident, $num:expr) => { |
| 276 | impl sealed::Channel for peripherals::$name {} | 275 | impl SealedChannel for peripherals::$name {} |
| 277 | impl Channel for peripherals::$name { | 276 | impl Channel for peripherals::$name { |
| 278 | fn number(&self) -> u8 { | 277 | fn number(&self) -> u8 { |
| 279 | $num | 278 | $num |
diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs index 422b77400..45b385cb4 100644 --- a/embassy-rp/src/flash.rs +++ b/embassy-rp/src/flash.rs | |||
| @@ -903,22 +903,22 @@ pub(crate) unsafe fn in_ram(operation: impl FnOnce()) -> Result<(), Error> { | |||
| 903 | Ok(()) | 903 | Ok(()) |
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | mod sealed { | 906 | trait SealedInstance {} |
| 907 | pub trait Instance {} | 907 | trait SealedMode {} |
| 908 | pub trait Mode {} | ||
| 909 | } | ||
| 910 | 908 | ||
| 911 | /// Flash instance. | 909 | /// Flash instance. |
| 912 | pub trait Instance: sealed::Instance {} | 910 | #[allow(private_bounds)] |
| 911 | pub trait Instance: SealedInstance {} | ||
| 913 | /// Flash mode. | 912 | /// Flash mode. |
| 914 | pub trait Mode: sealed::Mode {} | 913 | #[allow(private_bounds)] |
| 914 | pub trait Mode: SealedMode {} | ||
| 915 | 915 | ||
| 916 | impl sealed::Instance for FLASH {} | 916 | impl SealedInstance for FLASH {} |
| 917 | impl Instance for FLASH {} | 917 | impl Instance for FLASH {} |
| 918 | 918 | ||
| 919 | macro_rules! impl_mode { | 919 | macro_rules! impl_mode { |
| 920 | ($name:ident) => { | 920 | ($name:ident) => { |
| 921 | impl sealed::Mode for $name {} | 921 | impl SealedMode for $name {} |
| 922 | impl Mode for $name {} | 922 | impl Mode for $name {} |
| 923 | }; | 923 | }; |
| 924 | } | 924 | } |
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index a84c00a2c..ea87fd9da 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -8,7 +8,6 @@ use core::task::{Context, Poll}; | |||
| 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use self::sealed::Pin as _; | ||
| 12 | use crate::interrupt::InterruptExt; | 11 | use crate::interrupt::InterruptExt; |
| 13 | use crate::pac::common::{Reg, RW}; | 12 | use crate::pac::common::{Reg, RW}; |
| 14 | use crate::pac::SIO; | 13 | use crate::pac::SIO; |
| @@ -802,68 +801,65 @@ impl<'w> Drop for DormantWake<'w> { | |||
| 802 | } | 801 | } |
| 803 | } | 802 | } |
| 804 | 803 | ||
| 805 | pub(crate) mod sealed { | 804 | pub(crate) trait SealedPin: Sized { |
| 806 | use super::*; | 805 | fn pin_bank(&self) -> u8; |
| 807 | |||
| 808 | pub trait Pin: Sized { | ||
| 809 | fn pin_bank(&self) -> u8; | ||
| 810 | 806 | ||
| 811 | #[inline] | 807 | #[inline] |
| 812 | fn _pin(&self) -> u8 { | 808 | fn _pin(&self) -> u8 { |
| 813 | self.pin_bank() & 0x1f | 809 | self.pin_bank() & 0x1f |
| 814 | } | 810 | } |
| 815 | 811 | ||
| 816 | #[inline] | 812 | #[inline] |
| 817 | fn _bank(&self) -> Bank { | 813 | fn _bank(&self) -> Bank { |
| 818 | match self.pin_bank() >> 5 { | 814 | match self.pin_bank() >> 5 { |
| 819 | #[cfg(feature = "qspi-as-gpio")] | 815 | #[cfg(feature = "qspi-as-gpio")] |
| 820 | 1 => Bank::Qspi, | 816 | 1 => Bank::Qspi, |
| 821 | _ => Bank::Bank0, | 817 | _ => Bank::Bank0, |
| 822 | } | ||
| 823 | } | 818 | } |
| 819 | } | ||
| 824 | 820 | ||
| 825 | fn io(&self) -> pac::io::Io { | 821 | fn io(&self) -> pac::io::Io { |
| 826 | match self._bank() { | 822 | match self._bank() { |
| 827 | Bank::Bank0 => crate::pac::IO_BANK0, | 823 | Bank::Bank0 => crate::pac::IO_BANK0, |
| 828 | #[cfg(feature = "qspi-as-gpio")] | 824 | #[cfg(feature = "qspi-as-gpio")] |
| 829 | Bank::Qspi => crate::pac::IO_QSPI, | 825 | Bank::Qspi => crate::pac::IO_QSPI, |
| 830 | } | ||
| 831 | } | 826 | } |
| 827 | } | ||
| 832 | 828 | ||
| 833 | fn gpio(&self) -> pac::io::Gpio { | 829 | fn gpio(&self) -> pac::io::Gpio { |
| 834 | self.io().gpio(self._pin() as _) | 830 | self.io().gpio(self._pin() as _) |
| 835 | } | 831 | } |
| 836 | 832 | ||
| 837 | fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> { | 833 | fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> { |
| 838 | let block = match self._bank() { | 834 | let block = match self._bank() { |
| 839 | Bank::Bank0 => crate::pac::PADS_BANK0, | 835 | Bank::Bank0 => crate::pac::PADS_BANK0, |
| 840 | #[cfg(feature = "qspi-as-gpio")] | 836 | #[cfg(feature = "qspi-as-gpio")] |
| 841 | Bank::Qspi => crate::pac::PADS_QSPI, | 837 | Bank::Qspi => crate::pac::PADS_QSPI, |
| 842 | }; | 838 | }; |
| 843 | block.gpio(self._pin() as _) | 839 | block.gpio(self._pin() as _) |
| 844 | } | 840 | } |
| 845 | 841 | ||
| 846 | fn sio_out(&self) -> pac::sio::Gpio { | 842 | fn sio_out(&self) -> pac::sio::Gpio { |
| 847 | SIO.gpio_out(self._bank() as _) | 843 | SIO.gpio_out(self._bank() as _) |
| 848 | } | 844 | } |
| 849 | 845 | ||
| 850 | fn sio_oe(&self) -> pac::sio::Gpio { | 846 | fn sio_oe(&self) -> pac::sio::Gpio { |
| 851 | SIO.gpio_oe(self._bank() as _) | 847 | SIO.gpio_oe(self._bank() as _) |
| 852 | } | 848 | } |
| 853 | 849 | ||
| 854 | fn sio_in(&self) -> Reg<u32, RW> { | 850 | fn sio_in(&self) -> Reg<u32, RW> { |
| 855 | SIO.gpio_in(self._bank() as _) | 851 | SIO.gpio_in(self._bank() as _) |
| 856 | } | 852 | } |
| 857 | 853 | ||
| 858 | fn int_proc(&self) -> pac::io::Int { | 854 | fn int_proc(&self) -> pac::io::Int { |
| 859 | let proc = SIO.cpuid().read(); | 855 | let proc = SIO.cpuid().read(); |
| 860 | self.io().int_proc(proc as _) | 856 | self.io().int_proc(proc as _) |
| 861 | } | ||
| 862 | } | 857 | } |
| 863 | } | 858 | } |
| 864 | 859 | ||
| 865 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | 860 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. |
| 866 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { | 861 | #[allow(private_bounds)] |
| 862 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | ||
| 867 | /// Degrade to a generic pin struct | 863 | /// Degrade to a generic pin struct |
| 868 | fn degrade(self) -> AnyPin { | 864 | fn degrade(self) -> AnyPin { |
| 869 | AnyPin { | 865 | AnyPin { |
| @@ -903,7 +899,7 @@ impl AnyPin { | |||
| 903 | impl_peripheral!(AnyPin); | 899 | impl_peripheral!(AnyPin); |
| 904 | 900 | ||
| 905 | impl Pin for AnyPin {} | 901 | impl Pin for AnyPin {} |
| 906 | impl sealed::Pin for AnyPin { | 902 | impl SealedPin for AnyPin { |
| 907 | fn pin_bank(&self) -> u8 { | 903 | fn pin_bank(&self) -> u8 { |
| 908 | self.pin_bank | 904 | self.pin_bank |
| 909 | } | 905 | } |
| @@ -914,7 +910,7 @@ impl sealed::Pin for AnyPin { | |||
| 914 | macro_rules! impl_pin { | 910 | macro_rules! impl_pin { |
| 915 | ($name:ident, $bank:expr, $pin_num:expr) => { | 911 | ($name:ident, $bank:expr, $pin_num:expr) => { |
| 916 | impl Pin for peripherals::$name {} | 912 | impl Pin for peripherals::$name {} |
| 917 | impl sealed::Pin for peripherals::$name { | 913 | impl SealedPin for peripherals::$name { |
| 918 | #[inline] | 914 | #[inline] |
| 919 | fn pin_bank(&self) -> u8 { | 915 | fn pin_bank(&self) -> u8 { |
| 920 | ($bank as u8) * 32 + $pin_num | 916 | ($bank as u8) * 32 + $pin_num |
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 26a819b25..256875b4a 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -784,34 +784,24 @@ pub fn i2c_reserved_addr(addr: u16) -> bool { | |||
| 784 | ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0 | 784 | ((addr & 0x78) == 0 || (addr & 0x78) == 0x78) && addr != 0 |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | mod sealed { | 787 | pub(crate) trait SealedInstance { |
| 788 | use embassy_sync::waitqueue::AtomicWaker; | 788 | const TX_DREQ: u8; |
| 789 | const RX_DREQ: u8; | ||
| 789 | 790 | ||
| 790 | use crate::interrupt; | 791 | fn regs() -> crate::pac::i2c::I2c; |
| 791 | 792 | fn reset() -> crate::pac::resets::regs::Peripherals; | |
| 792 | pub trait Instance { | 793 | fn waker() -> &'static AtomicWaker; |
| 793 | const TX_DREQ: u8; | ||
| 794 | const RX_DREQ: u8; | ||
| 795 | |||
| 796 | type Interrupt: interrupt::typelevel::Interrupt; | ||
| 797 | |||
| 798 | fn regs() -> crate::pac::i2c::I2c; | ||
| 799 | fn reset() -> crate::pac::resets::regs::Peripherals; | ||
| 800 | fn waker() -> &'static AtomicWaker; | ||
| 801 | } | ||
| 802 | |||
| 803 | pub trait Mode {} | ||
| 804 | |||
| 805 | pub trait SdaPin<T: Instance> {} | ||
| 806 | pub trait SclPin<T: Instance> {} | ||
| 807 | } | 794 | } |
| 808 | 795 | ||
| 796 | trait SealedMode {} | ||
| 797 | |||
| 809 | /// Driver mode. | 798 | /// Driver mode. |
| 810 | pub trait Mode: sealed::Mode {} | 799 | #[allow(private_bounds)] |
| 800 | pub trait Mode: SealedMode {} | ||
| 811 | 801 | ||
| 812 | macro_rules! impl_mode { | 802 | macro_rules! impl_mode { |
| 813 | ($name:ident) => { | 803 | ($name:ident) => { |
| 814 | impl sealed::Mode for $name {} | 804 | impl SealedMode for $name {} |
| 815 | impl Mode for $name {} | 805 | impl Mode for $name {} |
| 816 | }; | 806 | }; |
| 817 | } | 807 | } |
| @@ -825,16 +815,18 @@ impl_mode!(Blocking); | |||
| 825 | impl_mode!(Async); | 815 | impl_mode!(Async); |
| 826 | 816 | ||
| 827 | /// I2C instance. | 817 | /// I2C instance. |
| 828 | pub trait Instance: sealed::Instance {} | 818 | #[allow(private_bounds)] |
| 819 | pub trait Instance: SealedInstance { | ||
| 820 | /// Interrupt for this peripheral. | ||
| 821 | type Interrupt: interrupt::typelevel::Interrupt; | ||
| 822 | } | ||
| 829 | 823 | ||
| 830 | macro_rules! impl_instance { | 824 | macro_rules! impl_instance { |
| 831 | ($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 825 | ($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 832 | impl sealed::Instance for peripherals::$type { | 826 | impl SealedInstance for peripherals::$type { |
| 833 | const TX_DREQ: u8 = $tx_dreq; | 827 | const TX_DREQ: u8 = $tx_dreq; |
| 834 | const RX_DREQ: u8 = $rx_dreq; | 828 | const RX_DREQ: u8 = $rx_dreq; |
| 835 | 829 | ||
| 836 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 837 | |||
| 838 | #[inline] | 830 | #[inline] |
| 839 | fn regs() -> pac::i2c::I2c { | 831 | fn regs() -> pac::i2c::I2c { |
| 840 | pac::$type | 832 | pac::$type |
| @@ -854,7 +846,9 @@ macro_rules! impl_instance { | |||
| 854 | &WAKER | 846 | &WAKER |
| 855 | } | 847 | } |
| 856 | } | 848 | } |
| 857 | impl Instance for peripherals::$type {} | 849 | impl Instance for peripherals::$type { |
| 850 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 851 | } | ||
| 858 | }; | 852 | }; |
| 859 | } | 853 | } |
| 860 | 854 | ||
| @@ -862,13 +856,12 @@ impl_instance!(I2C0, I2C0_IRQ, set_i2c0, 32, 33); | |||
| 862 | impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35); | 856 | impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35); |
| 863 | 857 | ||
| 864 | /// SDA pin. | 858 | /// SDA pin. |
| 865 | pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + crate::gpio::Pin {} | 859 | pub trait SdaPin<T: Instance>: crate::gpio::Pin {} |
| 866 | /// SCL pin. | 860 | /// SCL pin. |
| 867 | pub trait SclPin<T: Instance>: sealed::SclPin<T> + crate::gpio::Pin {} | 861 | pub trait SclPin<T: Instance>: crate::gpio::Pin {} |
| 868 | 862 | ||
| 869 | macro_rules! impl_pin { | 863 | macro_rules! impl_pin { |
| 870 | ($pin:ident, $instance:ident, $function:ident) => { | 864 | ($pin:ident, $instance:ident, $function:ident) => { |
| 871 | impl sealed::$function<peripherals::$instance> for peripherals::$pin {} | ||
| 872 | impl $function<peripherals::$instance> for peripherals::$pin {} | 865 | impl $function<peripherals::$instance> for peripherals::$pin {} |
| 873 | }; | 866 | }; |
| 874 | } | 867 | } |
diff --git a/embassy-rp/src/pio/mod.rs b/embassy-rp/src/pio/mod.rs index 7eca700ba..2e5c57a26 100644 --- a/embassy-rp/src/pio/mod.rs +++ b/embassy-rp/src/pio/mod.rs | |||
| @@ -15,8 +15,7 @@ use pac::pio::vals::SmExecctrlStatusSel; | |||
| 15 | use pio::{Program, SideSet, Wrap}; | 15 | use pio::{Program, SideSet, Wrap}; |
| 16 | 16 | ||
| 17 | use crate::dma::{Channel, Transfer, Word}; | 17 | use crate::dma::{Channel, Transfer, Word}; |
| 18 | use crate::gpio::sealed::Pin as SealedPin; | 18 | use crate::gpio::{self, AnyPin, Drive, Level, Pull, SealedPin, SlewRate}; |
| 19 | use crate::gpio::{self, AnyPin, Drive, Level, Pull, SlewRate}; | ||
| 20 | use crate::interrupt::typelevel::{Binding, Handler, Interrupt}; | 19 | use crate::interrupt::typelevel::{Binding, Handler, Interrupt}; |
| 21 | use crate::pac::dma::vals::TreqSel; | 20 | use crate::pac::dma::vals::TreqSel; |
| 22 | use crate::relocate::RelocatedProgram; | 21 | use crate::relocate::RelocatedProgram; |
| @@ -695,6 +694,12 @@ impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { | |||
| 695 | } | 694 | } |
| 696 | } | 695 | } |
| 697 | 696 | ||
| 697 | /// Set the clock divider for this state machine. | ||
| 698 | pub fn set_clock_divider(&mut self, clock_divider: FixedU32<U8>) { | ||
| 699 | let sm = Self::this_sm(); | ||
| 700 | sm.clkdiv().write(|w| w.0 = clock_divider.to_bits() << 8); | ||
| 701 | } | ||
| 702 | |||
| 698 | #[inline(always)] | 703 | #[inline(always)] |
| 699 | fn this_sm() -> crate::pac::pio::StateMachine { | 704 | fn this_sm() -> crate::pac::pio::StateMachine { |
| 700 | PIO::PIO.sm(SM) | 705 | PIO::PIO.sm(SM) |
| @@ -1148,49 +1153,47 @@ fn on_pio_drop<PIO: Instance>() { | |||
| 1148 | } | 1153 | } |
| 1149 | } | 1154 | } |
| 1150 | 1155 | ||
| 1151 | mod sealed { | 1156 | trait SealedInstance { |
| 1152 | use super::*; | 1157 | const PIO_NO: u8; |
| 1153 | 1158 | const PIO: &'static crate::pac::pio::Pio; | |
| 1154 | pub trait PioPin {} | 1159 | const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; |
| 1155 | 1160 | ||
| 1156 | pub trait Instance { | 1161 | #[inline] |
| 1157 | const PIO_NO: u8; | 1162 | fn wakers() -> &'static Wakers { |
| 1158 | const PIO: &'static crate::pac::pio::Pio; | 1163 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 1159 | const FUNCSEL: crate::pac::io::vals::Gpio0ctrlFuncsel; | 1164 | static WAKERS: Wakers = Wakers([NEW_AW; 12]); |
| 1160 | type Interrupt: crate::interrupt::typelevel::Interrupt; | ||
| 1161 | |||
| 1162 | #[inline] | ||
| 1163 | fn wakers() -> &'static Wakers { | ||
| 1164 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | ||
| 1165 | static WAKERS: Wakers = Wakers([NEW_AW; 12]); | ||
| 1166 | 1165 | ||
| 1167 | &WAKERS | 1166 | &WAKERS |
| 1168 | } | 1167 | } |
| 1169 | 1168 | ||
| 1170 | #[inline] | 1169 | #[inline] |
| 1171 | fn state() -> &'static State { | 1170 | fn state() -> &'static State { |
| 1172 | static STATE: State = State { | 1171 | static STATE: State = State { |
| 1173 | users: AtomicU8::new(0), | 1172 | users: AtomicU8::new(0), |
| 1174 | used_pins: AtomicU32::new(0), | 1173 | used_pins: AtomicU32::new(0), |
| 1175 | }; | 1174 | }; |
| 1176 | 1175 | ||
| 1177 | &STATE | 1176 | &STATE |
| 1178 | } | ||
| 1179 | } | 1177 | } |
| 1180 | } | 1178 | } |
| 1181 | 1179 | ||
| 1182 | /// PIO instance. | 1180 | /// PIO instance. |
| 1183 | pub trait Instance: sealed::Instance + Sized + Unpin {} | 1181 | #[allow(private_bounds)] |
| 1182 | pub trait Instance: SealedInstance + Sized + Unpin { | ||
| 1183 | /// Interrupt for this peripheral. | ||
| 1184 | type Interrupt: crate::interrupt::typelevel::Interrupt; | ||
| 1185 | } | ||
| 1184 | 1186 | ||
| 1185 | macro_rules! impl_pio { | 1187 | macro_rules! impl_pio { |
| 1186 | ($name:ident, $pio:expr, $pac:ident, $funcsel:ident, $irq:ident) => { | 1188 | ($name:ident, $pio:expr, $pac:ident, $funcsel:ident, $irq:ident) => { |
| 1187 | impl sealed::Instance for peripherals::$name { | 1189 | impl SealedInstance for peripherals::$name { |
| 1188 | const PIO_NO: u8 = $pio; | 1190 | const PIO_NO: u8 = $pio; |
| 1189 | const PIO: &'static pac::pio::Pio = &pac::$pac; | 1191 | const PIO: &'static pac::pio::Pio = &pac::$pac; |
| 1190 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel; | 1192 | const FUNCSEL: pac::io::vals::Gpio0ctrlFuncsel = pac::io::vals::Gpio0ctrlFuncsel::$funcsel; |
| 1193 | } | ||
| 1194 | impl Instance for peripherals::$name { | ||
| 1191 | type Interrupt = crate::interrupt::typelevel::$irq; | 1195 | type Interrupt = crate::interrupt::typelevel::$irq; |
| 1192 | } | 1196 | } |
| 1193 | impl Instance for peripherals::$name {} | ||
| 1194 | }; | 1197 | }; |
| 1195 | } | 1198 | } |
| 1196 | 1199 | ||
| @@ -1198,12 +1201,11 @@ impl_pio!(PIO0, 0, PIO0, PIO0_0, PIO0_IRQ_0); | |||
| 1198 | impl_pio!(PIO1, 1, PIO1, PIO1_0, PIO1_IRQ_0); | 1201 | impl_pio!(PIO1, 1, PIO1, PIO1_0, PIO1_IRQ_0); |
| 1199 | 1202 | ||
| 1200 | /// PIO pin. | 1203 | /// PIO pin. |
| 1201 | pub trait PioPin: sealed::PioPin + gpio::Pin {} | 1204 | pub trait PioPin: gpio::Pin {} |
| 1202 | 1205 | ||
| 1203 | macro_rules! impl_pio_pin { | 1206 | macro_rules! impl_pio_pin { |
| 1204 | ($( $pin:ident, )*) => { | 1207 | ($( $pin:ident, )*) => { |
| 1205 | $( | 1208 | $( |
| 1206 | impl sealed::PioPin for peripherals::$pin {} | ||
| 1207 | impl PioPin for peripherals::$pin {} | 1209 | impl PioPin for peripherals::$pin {} |
| 1208 | )* | 1210 | )* |
| 1209 | }; | 1211 | }; |
diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs index 5aab3ff4f..7613e4e58 100644 --- a/embassy-rp/src/pwm.rs +++ b/embassy-rp/src/pwm.rs | |||
| @@ -6,8 +6,7 @@ use fixed::FixedU16; | |||
| 6 | use pac::pwm::regs::{ChDiv, Intr}; | 6 | use pac::pwm::regs::{ChDiv, Intr}; |
| 7 | use pac::pwm::vals::Divmode; | 7 | use pac::pwm::vals::Divmode; |
| 8 | 8 | ||
| 9 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; |
| 10 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 11 | use crate::{pac, peripherals, RegExt}; | 10 | use crate::{pac, peripherals, RegExt}; |
| 12 | 11 | ||
| 13 | /// The configuration of a PWM slice. | 12 | /// The configuration of a PWM slice. |
| @@ -300,12 +299,11 @@ impl<'d, T: Slice> Drop for Pwm<'d, T> { | |||
| 300 | } | 299 | } |
| 301 | } | 300 | } |
| 302 | 301 | ||
| 303 | mod sealed { | 302 | trait SealedSlice {} |
| 304 | pub trait Slice {} | ||
| 305 | } | ||
| 306 | 303 | ||
| 307 | /// PWM Slice. | 304 | /// PWM Slice. |
| 308 | pub trait Slice: Peripheral<P = Self> + sealed::Slice + Sized + 'static { | 305 | #[allow(private_bounds)] |
| 306 | pub trait Slice: Peripheral<P = Self> + SealedSlice + Sized + 'static { | ||
| 309 | /// Slice number. | 307 | /// Slice number. |
| 310 | fn number(&self) -> u8; | 308 | fn number(&self) -> u8; |
| 311 | 309 | ||
| @@ -317,7 +315,7 @@ pub trait Slice: Peripheral<P = Self> + sealed::Slice + Sized + 'static { | |||
| 317 | 315 | ||
| 318 | macro_rules! slice { | 316 | macro_rules! slice { |
| 319 | ($name:ident, $num:expr) => { | 317 | ($name:ident, $num:expr) => { |
| 320 | impl sealed::Slice for peripherals::$name {} | 318 | impl SealedSlice for peripherals::$name {} |
| 321 | impl Slice for peripherals::$name { | 319 | impl Slice for peripherals::$name { |
| 322 | fn number(&self) -> u8 { | 320 | fn number(&self) -> u8 { |
| 323 | $num | 321 | $num |
diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs index c8691bdc2..2ce7ac645 100644 --- a/embassy-rp/src/rtc/mod.rs +++ b/embassy-rp/src/rtc/mod.rs | |||
| @@ -188,16 +188,15 @@ pub enum RtcError { | |||
| 188 | NotRunning, | 188 | NotRunning, |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | mod sealed { | 191 | trait SealedInstance { |
| 192 | pub trait Instance { | 192 | fn regs(&self) -> crate::pac::rtc::Rtc; |
| 193 | fn regs(&self) -> crate::pac::rtc::Rtc; | ||
| 194 | } | ||
| 195 | } | 193 | } |
| 196 | 194 | ||
| 197 | /// RTC peripheral instance. | 195 | /// RTC peripheral instance. |
| 198 | pub trait Instance: sealed::Instance {} | 196 | #[allow(private_bounds)] |
| 197 | pub trait Instance: SealedInstance {} | ||
| 199 | 198 | ||
| 200 | impl sealed::Instance for crate::peripherals::RTC { | 199 | impl SealedInstance for crate::peripherals::RTC { |
| 201 | fn regs(&self) -> crate::pac::rtc::Rtc { | 200 | fn regs(&self) -> crate::pac::rtc::Rtc { |
| 202 | crate::pac::RTC | 201 | crate::pac::RTC |
| 203 | } | 202 | } |
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index a2a22ffe5..ef4c644ae 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -7,8 +7,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef}; | |||
| 7 | pub use embedded_hal_02::spi::{Phase, Polarity}; | 7 | pub use embedded_hal_02::spi::{Phase, Polarity}; |
| 8 | 8 | ||
| 9 | use crate::dma::{AnyChannel, Channel}; | 9 | use crate::dma::{AnyChannel, Channel}; |
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::{AnyPin, Pin as GpioPin, SealedPin as _}; |
| 11 | use crate::gpio::{AnyPin, Pin as GpioPin}; | ||
| 12 | use crate::{pac, peripherals, Peripheral}; | 11 | use crate::{pac, peripherals, Peripheral}; |
| 13 | 12 | ||
| 14 | /// SPI errors. | 13 | /// SPI errors. |
| @@ -443,28 +442,26 @@ impl<'d, T: Instance> Spi<'d, T, Async> { | |||
| 443 | } | 442 | } |
| 444 | } | 443 | } |
| 445 | 444 | ||
| 446 | mod sealed { | 445 | trait SealedMode {} |
| 447 | use super::*; | ||
| 448 | 446 | ||
| 449 | pub trait Mode {} | 447 | trait SealedInstance { |
| 448 | const TX_DREQ: u8; | ||
| 449 | const RX_DREQ: u8; | ||
| 450 | 450 | ||
| 451 | pub trait Instance { | 451 | fn regs(&self) -> pac::spi::Spi; |
| 452 | const TX_DREQ: u8; | ||
| 453 | const RX_DREQ: u8; | ||
| 454 | |||
| 455 | fn regs(&self) -> pac::spi::Spi; | ||
| 456 | } | ||
| 457 | } | 452 | } |
| 458 | 453 | ||
| 459 | /// Mode. | 454 | /// Mode. |
| 460 | pub trait Mode: sealed::Mode {} | 455 | #[allow(private_bounds)] |
| 456 | pub trait Mode: SealedMode {} | ||
| 461 | 457 | ||
| 462 | /// SPI instance trait. | 458 | /// SPI instance trait. |
| 463 | pub trait Instance: sealed::Instance {} | 459 | #[allow(private_bounds)] |
| 460 | pub trait Instance: SealedInstance {} | ||
| 464 | 461 | ||
| 465 | macro_rules! impl_instance { | 462 | macro_rules! impl_instance { |
| 466 | ($type:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 463 | ($type:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 467 | impl sealed::Instance for peripherals::$type { | 464 | impl SealedInstance for peripherals::$type { |
| 468 | const TX_DREQ: u8 = $tx_dreq; | 465 | const TX_DREQ: u8 = $tx_dreq; |
| 469 | const RX_DREQ: u8 = $rx_dreq; | 466 | const RX_DREQ: u8 = $rx_dreq; |
| 470 | 467 | ||
| @@ -527,7 +524,7 @@ impl_pin!(PIN_29, SPI1, CsPin); | |||
| 527 | 524 | ||
| 528 | macro_rules! impl_mode { | 525 | macro_rules! impl_mode { |
| 529 | ($name:ident) => { | 526 | ($name:ident) => { |
| 530 | impl sealed::Mode for $name {} | 527 | impl SealedMode for $name {} |
| 531 | impl Mode for $name {} | 528 | impl Mode for $name {} |
| 532 | }; | 529 | }; |
| 533 | } | 530 | } |
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 65dcf4eb4..ee2dcb27d 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs | |||
| @@ -12,8 +12,7 @@ use pac::uart::regs::Uartris; | |||
| 12 | 12 | ||
| 13 | use crate::clocks::clk_peri_freq; | 13 | use crate::clocks::clk_peri_freq; |
| 14 | use crate::dma::{AnyChannel, Channel}; | 14 | use crate::dma::{AnyChannel, Channel}; |
| 15 | use crate::gpio::sealed::Pin; | 15 | use crate::gpio::{AnyPin, SealedPin}; |
| 16 | use crate::gpio::AnyPin; | ||
| 17 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 16 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 18 | use crate::pac::io::vals::{Inover, Outover}; | 17 | use crate::pac::io::vals::{Inover, Outover}; |
| 19 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; | 18 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; |
| @@ -1107,35 +1106,26 @@ impl<'d, T: Instance, M: Mode> embedded_hal_nb::serial::Write for Uart<'d, T, M> | |||
| 1107 | } | 1106 | } |
| 1108 | } | 1107 | } |
| 1109 | 1108 | ||
| 1110 | mod sealed { | 1109 | trait SealedMode {} |
| 1111 | use super::*; | ||
| 1112 | 1110 | ||
| 1113 | pub trait Mode {} | 1111 | trait SealedInstance { |
| 1112 | const TX_DREQ: u8; | ||
| 1113 | const RX_DREQ: u8; | ||
| 1114 | 1114 | ||
| 1115 | pub trait Instance { | 1115 | fn regs() -> pac::uart::Uart; |
| 1116 | const TX_DREQ: u8; | ||
| 1117 | const RX_DREQ: u8; | ||
| 1118 | 1116 | ||
| 1119 | type Interrupt: interrupt::typelevel::Interrupt; | 1117 | fn buffered_state() -> &'static buffered::State; |
| 1120 | 1118 | ||
| 1121 | fn regs() -> pac::uart::Uart; | 1119 | fn dma_state() -> &'static DmaState; |
| 1122 | |||
| 1123 | fn buffered_state() -> &'static buffered::State; | ||
| 1124 | |||
| 1125 | fn dma_state() -> &'static DmaState; | ||
| 1126 | } | ||
| 1127 | pub trait TxPin<T: Instance> {} | ||
| 1128 | pub trait RxPin<T: Instance> {} | ||
| 1129 | pub trait CtsPin<T: Instance> {} | ||
| 1130 | pub trait RtsPin<T: Instance> {} | ||
| 1131 | } | 1120 | } |
| 1132 | 1121 | ||
| 1133 | /// UART mode. | 1122 | /// UART mode. |
| 1134 | pub trait Mode: sealed::Mode {} | 1123 | #[allow(private_bounds)] |
| 1124 | pub trait Mode: SealedMode {} | ||
| 1135 | 1125 | ||
| 1136 | macro_rules! impl_mode { | 1126 | macro_rules! impl_mode { |
| 1137 | ($name:ident) => { | 1127 | ($name:ident) => { |
| 1138 | impl sealed::Mode for $name {} | 1128 | impl SealedMode for $name {} |
| 1139 | impl Mode for $name {} | 1129 | impl Mode for $name {} |
| 1140 | }; | 1130 | }; |
| 1141 | } | 1131 | } |
| @@ -1149,16 +1139,18 @@ impl_mode!(Blocking); | |||
| 1149 | impl_mode!(Async); | 1139 | impl_mode!(Async); |
| 1150 | 1140 | ||
| 1151 | /// UART instance. | 1141 | /// UART instance. |
| 1152 | pub trait Instance: sealed::Instance {} | 1142 | #[allow(private_bounds)] |
| 1143 | pub trait Instance: SealedInstance { | ||
| 1144 | /// Interrupt for this instance. | ||
| 1145 | type Interrupt: interrupt::typelevel::Interrupt; | ||
| 1146 | } | ||
| 1153 | 1147 | ||
| 1154 | macro_rules! impl_instance { | 1148 | macro_rules! impl_instance { |
| 1155 | ($inst:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 1149 | ($inst:ident, $irq:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 1156 | impl sealed::Instance for peripherals::$inst { | 1150 | impl SealedInstance for peripherals::$inst { |
| 1157 | const TX_DREQ: u8 = $tx_dreq; | 1151 | const TX_DREQ: u8 = $tx_dreq; |
| 1158 | const RX_DREQ: u8 = $rx_dreq; | 1152 | const RX_DREQ: u8 = $rx_dreq; |
| 1159 | 1153 | ||
| 1160 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 1161 | |||
| 1162 | fn regs() -> pac::uart::Uart { | 1154 | fn regs() -> pac::uart::Uart { |
| 1163 | pac::$inst | 1155 | pac::$inst |
| 1164 | } | 1156 | } |
| @@ -1176,7 +1168,9 @@ macro_rules! impl_instance { | |||
| 1176 | &STATE | 1168 | &STATE |
| 1177 | } | 1169 | } |
| 1178 | } | 1170 | } |
| 1179 | impl Instance for peripherals::$inst {} | 1171 | impl Instance for peripherals::$inst { |
| 1172 | type Interrupt = crate::interrupt::typelevel::$irq; | ||
| 1173 | } | ||
| 1180 | }; | 1174 | }; |
| 1181 | } | 1175 | } |
| 1182 | 1176 | ||
| @@ -1184,17 +1178,16 @@ impl_instance!(UART0, UART0_IRQ, 20, 21); | |||
| 1184 | impl_instance!(UART1, UART1_IRQ, 22, 23); | 1178 | impl_instance!(UART1, UART1_IRQ, 22, 23); |
| 1185 | 1179 | ||
| 1186 | /// Trait for TX pins. | 1180 | /// Trait for TX pins. |
| 1187 | pub trait TxPin<T: Instance>: sealed::TxPin<T> + crate::gpio::Pin {} | 1181 | pub trait TxPin<T: Instance>: crate::gpio::Pin {} |
| 1188 | /// Trait for RX pins. | 1182 | /// Trait for RX pins. |
| 1189 | pub trait RxPin<T: Instance>: sealed::RxPin<T> + crate::gpio::Pin {} | 1183 | pub trait RxPin<T: Instance>: crate::gpio::Pin {} |
| 1190 | /// Trait for Clear To Send (CTS) pins. | 1184 | /// Trait for Clear To Send (CTS) pins. |
| 1191 | pub trait CtsPin<T: Instance>: sealed::CtsPin<T> + crate::gpio::Pin {} | 1185 | pub trait CtsPin<T: Instance>: crate::gpio::Pin {} |
| 1192 | /// Trait for Request To Send (RTS) pins. | 1186 | /// Trait for Request To Send (RTS) pins. |
| 1193 | pub trait RtsPin<T: Instance>: sealed::RtsPin<T> + crate::gpio::Pin {} | 1187 | pub trait RtsPin<T: Instance>: crate::gpio::Pin {} |
| 1194 | 1188 | ||
| 1195 | macro_rules! impl_pin { | 1189 | macro_rules! impl_pin { |
| 1196 | ($pin:ident, $instance:ident, $function:ident) => { | 1190 | ($pin:ident, $instance:ident, $function:ident) => { |
| 1197 | impl sealed::$function<peripherals::$instance> for peripherals::$pin {} | ||
| 1198 | impl $function<peripherals::$instance> for peripherals::$pin {} | 1191 | impl $function<peripherals::$instance> for peripherals::$pin {} |
| 1199 | }; | 1192 | }; |
| 1200 | } | 1193 | } |
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index d68dee4a3..37d37d6d9 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs | |||
| @@ -14,20 +14,19 @@ use embassy_usb_driver::{ | |||
| 14 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 14 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 15 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; | 15 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; |
| 16 | 16 | ||
| 17 | pub(crate) mod sealed { | 17 | trait SealedInstance { |
| 18 | pub trait Instance { | 18 | fn regs() -> crate::pac::usb::Usb; |
| 19 | fn regs() -> crate::pac::usb::Usb; | 19 | fn dpram() -> crate::pac::usb_dpram::UsbDpram; |
| 20 | fn dpram() -> crate::pac::usb_dpram::UsbDpram; | ||
| 21 | } | ||
| 22 | } | 20 | } |
| 23 | 21 | ||
| 24 | /// USB peripheral instance. | 22 | /// USB peripheral instance. |
| 25 | pub trait Instance: sealed::Instance + 'static { | 23 | #[allow(private_bounds)] |
| 24 | pub trait Instance: SealedInstance + 'static { | ||
| 26 | /// Interrupt for this peripheral. | 25 | /// Interrupt for this peripheral. |
| 27 | type Interrupt: interrupt::typelevel::Interrupt; | 26 | type Interrupt: interrupt::typelevel::Interrupt; |
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | impl crate::usb::sealed::Instance for peripherals::USB { | 29 | impl crate::usb::SealedInstance for peripherals::USB { |
| 31 | fn regs() -> pac::usb::Usb { | 30 | fn regs() -> pac::usb::Usb { |
| 32 | pac::USBCTRL_REGS | 31 | pac::USBCTRL_REGS |
| 33 | } | 32 | } |
diff --git a/embassy-stm32/src/cordic/mod.rs b/embassy-stm32/src/cordic/mod.rs index 6bbc48f2b..9ac10e714 100644 --- a/embassy-stm32/src/cordic/mod.rs +++ b/embassy-stm32/src/cordic/mod.rs | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | use embassy_hal_internal::drop::OnDrop; | 3 | use embassy_hal_internal::drop::OnDrop; |
| 4 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 4 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; |
| 5 | 5 | ||
| 6 | use crate::pac::cordic::vals; | ||
| 6 | use crate::{dma, peripherals}; | 7 | use crate::{dma, peripherals}; |
| 7 | 8 | ||
| 8 | mod enums; | 9 | mod enums; |
| @@ -11,9 +12,6 @@ pub use enums::*; | |||
| 11 | mod errors; | 12 | mod errors; |
| 12 | pub use errors::*; | 13 | pub use errors::*; |
| 13 | 14 | ||
| 14 | mod sealed; | ||
| 15 | use self::sealed::SealedInstance; | ||
| 16 | |||
| 17 | pub mod utils; | 15 | pub mod utils; |
| 18 | 16 | ||
| 19 | /// CORDIC driver | 17 | /// CORDIC driver |
| @@ -22,6 +20,120 @@ pub struct Cordic<'d, T: Instance> { | |||
| 22 | config: Config, | 20 | config: Config, |
| 23 | } | 21 | } |
| 24 | 22 | ||
| 23 | /// Cordic instance | ||
| 24 | trait SealedInstance { | ||
| 25 | /// Get access to CORDIC registers | ||
| 26 | fn regs() -> crate::pac::cordic::Cordic; | ||
| 27 | |||
| 28 | /// Set Function value | ||
| 29 | fn set_func(&self, func: Function) { | ||
| 30 | Self::regs() | ||
| 31 | .csr() | ||
| 32 | .modify(|v| v.set_func(vals::Func::from_bits(func as u8))); | ||
| 33 | } | ||
| 34 | |||
| 35 | /// Set Precision value | ||
| 36 | fn set_precision(&self, precision: Precision) { | ||
| 37 | Self::regs() | ||
| 38 | .csr() | ||
| 39 | .modify(|v| v.set_precision(vals::Precision::from_bits(precision as u8))) | ||
| 40 | } | ||
| 41 | |||
| 42 | /// Set Scale value | ||
| 43 | fn set_scale(&self, scale: Scale) { | ||
| 44 | Self::regs() | ||
| 45 | .csr() | ||
| 46 | .modify(|v| v.set_scale(vals::Scale::from_bits(scale as u8))) | ||
| 47 | } | ||
| 48 | |||
| 49 | /// Enable global interrupt | ||
| 50 | fn enable_irq(&self) { | ||
| 51 | Self::regs().csr().modify(|v| v.set_ien(true)) | ||
| 52 | } | ||
| 53 | |||
| 54 | /// Disable global interrupt | ||
| 55 | fn disable_irq(&self) { | ||
| 56 | Self::regs().csr().modify(|v| v.set_ien(false)) | ||
| 57 | } | ||
| 58 | |||
| 59 | /// Enable Read DMA | ||
| 60 | fn enable_read_dma(&self) { | ||
| 61 | Self::regs().csr().modify(|v| { | ||
| 62 | v.set_dmaren(true); | ||
| 63 | }) | ||
| 64 | } | ||
| 65 | |||
| 66 | /// Disable Read DMA | ||
| 67 | fn disable_read_dma(&self) { | ||
| 68 | Self::regs().csr().modify(|v| { | ||
| 69 | v.set_dmaren(false); | ||
| 70 | }) | ||
| 71 | } | ||
| 72 | |||
| 73 | /// Enable Write DMA | ||
| 74 | fn enable_write_dma(&self) { | ||
| 75 | Self::regs().csr().modify(|v| { | ||
| 76 | v.set_dmawen(true); | ||
| 77 | }) | ||
| 78 | } | ||
| 79 | |||
| 80 | /// Disable Write DMA | ||
| 81 | fn disable_write_dma(&self) { | ||
| 82 | Self::regs().csr().modify(|v| { | ||
| 83 | v.set_dmawen(false); | ||
| 84 | }) | ||
| 85 | } | ||
| 86 | |||
| 87 | /// Set NARGS value | ||
| 88 | fn set_argument_count(&self, n: AccessCount) { | ||
| 89 | Self::regs().csr().modify(|v| { | ||
| 90 | v.set_nargs(match n { | ||
| 91 | AccessCount::One => vals::Num::NUM1, | ||
| 92 | AccessCount::Two => vals::Num::NUM2, | ||
| 93 | }) | ||
| 94 | }) | ||
| 95 | } | ||
| 96 | |||
| 97 | /// Set NRES value | ||
| 98 | fn set_result_count(&self, n: AccessCount) { | ||
| 99 | Self::regs().csr().modify(|v| { | ||
| 100 | v.set_nres(match n { | ||
| 101 | AccessCount::One => vals::Num::NUM1, | ||
| 102 | AccessCount::Two => vals::Num::NUM2, | ||
| 103 | }); | ||
| 104 | }) | ||
| 105 | } | ||
| 106 | |||
| 107 | /// Set ARGSIZE and RESSIZE value | ||
| 108 | fn set_data_width(&self, arg: Width, res: Width) { | ||
| 109 | Self::regs().csr().modify(|v| { | ||
| 110 | v.set_argsize(match arg { | ||
| 111 | Width::Bits32 => vals::Size::BITS32, | ||
| 112 | Width::Bits16 => vals::Size::BITS16, | ||
| 113 | }); | ||
| 114 | v.set_ressize(match res { | ||
| 115 | Width::Bits32 => vals::Size::BITS32, | ||
| 116 | Width::Bits16 => vals::Size::BITS16, | ||
| 117 | }) | ||
| 118 | }) | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Read RRDY flag | ||
| 122 | fn ready_to_read(&self) -> bool { | ||
| 123 | Self::regs().csr().read().rrdy() | ||
| 124 | } | ||
| 125 | |||
| 126 | /// Write value to WDATA | ||
| 127 | fn write_argument(&self, arg: u32) { | ||
| 128 | Self::regs().wdata().write_value(arg) | ||
| 129 | } | ||
| 130 | |||
| 131 | /// Read value from RDATA | ||
| 132 | fn read_result(&self) -> u32 { | ||
| 133 | Self::regs().rdata().read() | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 25 | /// CORDIC instance trait | 137 | /// CORDIC instance trait |
| 26 | #[allow(private_bounds)] | 138 | #[allow(private_bounds)] |
| 27 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral {} | 139 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral {} |
diff --git a/embassy-stm32/src/cordic/sealed.rs b/embassy-stm32/src/cordic/sealed.rs deleted file mode 100644 index 8f0bd1830..000000000 --- a/embassy-stm32/src/cordic/sealed.rs +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | use super::*; | ||
| 2 | use crate::pac::cordic::vals; | ||
| 3 | |||
| 4 | /// Cordic instance | ||
| 5 | pub(super) trait SealedInstance { | ||
| 6 | /// Get access to CORDIC registers | ||
| 7 | fn regs() -> crate::pac::cordic::Cordic; | ||
| 8 | |||
| 9 | /// Set Function value | ||
| 10 | fn set_func(&self, func: Function) { | ||
| 11 | Self::regs() | ||
| 12 | .csr() | ||
| 13 | .modify(|v| v.set_func(vals::Func::from_bits(func as u8))); | ||
| 14 | } | ||
| 15 | |||
| 16 | /// Set Precision value | ||
| 17 | fn set_precision(&self, precision: Precision) { | ||
| 18 | Self::regs() | ||
| 19 | .csr() | ||
| 20 | .modify(|v| v.set_precision(vals::Precision::from_bits(precision as u8))) | ||
| 21 | } | ||
| 22 | |||
| 23 | /// Set Scale value | ||
| 24 | fn set_scale(&self, scale: Scale) { | ||
| 25 | Self::regs() | ||
| 26 | .csr() | ||
| 27 | .modify(|v| v.set_scale(vals::Scale::from_bits(scale as u8))) | ||
| 28 | } | ||
| 29 | |||
| 30 | /// Enable global interrupt | ||
| 31 | fn enable_irq(&self) { | ||
| 32 | Self::regs().csr().modify(|v| v.set_ien(true)) | ||
| 33 | } | ||
| 34 | |||
| 35 | /// Disable global interrupt | ||
| 36 | fn disable_irq(&self) { | ||
| 37 | Self::regs().csr().modify(|v| v.set_ien(false)) | ||
| 38 | } | ||
| 39 | |||
| 40 | /// Enable Read DMA | ||
| 41 | fn enable_read_dma(&self) { | ||
| 42 | Self::regs().csr().modify(|v| { | ||
| 43 | v.set_dmaren(true); | ||
| 44 | }) | ||
| 45 | } | ||
| 46 | |||
| 47 | /// Disable Read DMA | ||
| 48 | fn disable_read_dma(&self) { | ||
| 49 | Self::regs().csr().modify(|v| { | ||
| 50 | v.set_dmaren(false); | ||
| 51 | }) | ||
| 52 | } | ||
| 53 | |||
| 54 | /// Enable Write DMA | ||
| 55 | fn enable_write_dma(&self) { | ||
| 56 | Self::regs().csr().modify(|v| { | ||
| 57 | v.set_dmawen(true); | ||
| 58 | }) | ||
| 59 | } | ||
| 60 | |||
| 61 | /// Disable Write DMA | ||
| 62 | fn disable_write_dma(&self) { | ||
| 63 | Self::regs().csr().modify(|v| { | ||
| 64 | v.set_dmawen(false); | ||
| 65 | }) | ||
| 66 | } | ||
| 67 | |||
| 68 | /// Set NARGS value | ||
| 69 | fn set_argument_count(&self, n: AccessCount) { | ||
| 70 | Self::regs().csr().modify(|v| { | ||
| 71 | v.set_nargs(match n { | ||
| 72 | AccessCount::One => vals::Num::NUM1, | ||
| 73 | AccessCount::Two => vals::Num::NUM2, | ||
| 74 | }) | ||
| 75 | }) | ||
| 76 | } | ||
| 77 | |||
| 78 | /// Set NRES value | ||
| 79 | fn set_result_count(&self, n: AccessCount) { | ||
| 80 | Self::regs().csr().modify(|v| { | ||
| 81 | v.set_nres(match n { | ||
| 82 | AccessCount::One => vals::Num::NUM1, | ||
| 83 | AccessCount::Two => vals::Num::NUM2, | ||
| 84 | }); | ||
| 85 | }) | ||
| 86 | } | ||
| 87 | |||
| 88 | /// Set ARGSIZE and RESSIZE value | ||
| 89 | fn set_data_width(&self, arg: Width, res: Width) { | ||
| 90 | Self::regs().csr().modify(|v| { | ||
| 91 | v.set_argsize(match arg { | ||
| 92 | Width::Bits32 => vals::Size::BITS32, | ||
| 93 | Width::Bits16 => vals::Size::BITS16, | ||
| 94 | }); | ||
| 95 | v.set_ressize(match res { | ||
| 96 | Width::Bits32 => vals::Size::BITS32, | ||
| 97 | Width::Bits16 => vals::Size::BITS16, | ||
| 98 | }) | ||
| 99 | }) | ||
| 100 | } | ||
| 101 | |||
| 102 | /// Read RRDY flag | ||
| 103 | fn ready_to_read(&self) -> bool { | ||
| 104 | Self::regs().csr().read().rrdy() | ||
| 105 | } | ||
| 106 | |||
| 107 | /// Write value to WDATA | ||
| 108 | fn write_argument(&self, arg: u32) { | ||
| 109 | Self::regs().wdata().write_value(arg) | ||
| 110 | } | ||
| 111 | |||
| 112 | /// Read value from RDATA | ||
| 113 | fn read_result(&self) -> u32 { | ||
| 114 | Self::regs().rdata().read() | ||
| 115 | } | ||
| 116 | } | ||
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 51862e185..949ac1b13 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -105,27 +105,23 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt | |||
| 105 | } | 105 | } |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | pub(crate) use sealed::State; | 108 | pub(crate) struct State { |
| 109 | pub(crate) mod sealed { | 109 | pub(crate) rx_waker: AtomicWaker, |
| 110 | use super::*; | 110 | pub(crate) rx_buf: RingBuffer, |
| 111 | pub struct State { | 111 | pub(crate) tx_waker: AtomicWaker, |
| 112 | pub(crate) rx_waker: AtomicWaker, | 112 | pub(crate) tx_buf: RingBuffer, |
| 113 | pub(crate) rx_buf: RingBuffer, | 113 | pub(crate) tx_done: AtomicBool, |
| 114 | pub(crate) tx_waker: AtomicWaker, | 114 | } |
| 115 | pub(crate) tx_buf: RingBuffer, | 115 | |
| 116 | pub(crate) tx_done: AtomicBool, | 116 | impl State { |
| 117 | } | 117 | /// Create new state |
| 118 | 118 | pub(crate) const fn new() -> Self { | |
| 119 | impl State { | 119 | Self { |
| 120 | /// Create new state | 120 | rx_buf: RingBuffer::new(), |
| 121 | pub const fn new() -> Self { | 121 | tx_buf: RingBuffer::new(), |
| 122 | Self { | 122 | rx_waker: AtomicWaker::new(), |
| 123 | rx_buf: RingBuffer::new(), | 123 | tx_waker: AtomicWaker::new(), |
| 124 | tx_buf: RingBuffer::new(), | 124 | tx_done: AtomicBool::new(true), |
| 125 | rx_waker: AtomicWaker::new(), | ||
| 126 | tx_waker: AtomicWaker::new(), | ||
| 127 | tx_done: AtomicBool::new(true), | ||
| 128 | } | ||
| 129 | } | 125 | } |
| 130 | } | 126 | } |
| 131 | } | 127 | } |
diff --git a/examples/rp/src/bin/pio_stepper.rs b/examples/rp/src/bin/pio_stepper.rs index ab9ecf623..4952f4fbd 100644 --- a/examples/rp/src/bin/pio_stepper.rs +++ b/examples/rp/src/bin/pio_stepper.rs | |||
| @@ -69,7 +69,7 @@ impl<'d, T: Instance, const SM: usize> PioStepper<'d, T, SM> { | |||
| 69 | let clock_divider: FixedU32<U8> = (125_000_000 / (freq * 136)).to_fixed(); | 69 | let clock_divider: FixedU32<U8> = (125_000_000 / (freq * 136)).to_fixed(); |
| 70 | assert!(clock_divider <= 65536, "clkdiv must be <= 65536"); | 70 | assert!(clock_divider <= 65536, "clkdiv must be <= 65536"); |
| 71 | assert!(clock_divider >= 1, "clkdiv must be >= 1"); | 71 | assert!(clock_divider >= 1, "clkdiv must be >= 1"); |
| 72 | T::PIO.sm(SM).clkdiv().write(|w| w.0 = clock_divider.to_bits() << 8); | 72 | self.sm.set_clock_divider(clock_divider); |
| 73 | self.sm.clkdiv_restart(); | 73 | self.sm.clkdiv_restart(); |
| 74 | } | 74 | } |
| 75 | 75 | ||
