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