Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral

This commit is contained in:
Dario Nieuwenhuis
2022-07-23 14:00:19 +02:00
parent 8a9d2f59af
commit 4901c34d9c
62 changed files with 970 additions and 918 deletions

View File

@ -22,7 +22,7 @@ use core::task::Poll;
use embassy::waitqueue::WakerRegistration;
use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
use embassy_hal_common::ring_buffer::RingBuffer;
use embassy_hal_common::{low_power_wait_until, unborrow};
use embassy_hal_common::{into_ref, low_power_wait_until};
use futures::future::poll_fn;
// 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};
@ -32,7 +32,7 @@ use crate::interrupt::InterruptExt;
use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
use crate::timer::{Frequency, Instance as TimerInstance, Timer};
use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
#[derive(Copy, Clone, Debug, PartialEq)]
enum RxState {
@ -78,20 +78,20 @@ impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {
impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
pub fn new(
state: &'d mut State<'d, U, T>,
_uarte: impl Unborrow<Target = U> + 'd,
timer: impl Unborrow<Target = T> + 'd,
ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
irq: impl Unborrow<Target = U::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
cts: impl Unborrow<Target = impl GpioPin> + 'd,
rts: impl Unborrow<Target = impl GpioPin> + 'd,
_uarte: impl Peripheral<P = U> + 'd,
timer: impl Peripheral<P = T> + 'd,
ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
irq: impl Peripheral<P = U::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
cts: impl Peripheral<P = impl GpioPin> + 'd,
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
rx_buffer: &'d mut [u8],
tx_buffer: &'d mut [u8],
) -> Self {
unborrow!(ppi_ch1, ppi_ch2, irq, rxd, txd, cts, rts);
into_ref!(ppi_ch1, ppi_ch2, irq, rxd, txd, cts, rts);
let r = U::regs();

View File

@ -4,12 +4,12 @@ use core::convert::Infallible;
use core::hint::unreachable_unchecked;
use cfg_if::cfg_if;
use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed};
use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef};
use self::sealed::Pin as _;
use crate::pac::p0 as gpio;
use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
/// A GPIO port with up to 32 pins.
#[derive(Debug, Eq, PartialEq)]
@ -38,7 +38,7 @@ pub struct Input<'d, T: Pin> {
impl<'d, T: Pin> Input<'d, T> {
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self {
let mut pin = Flex::new(pin);
pin.set_as_input(pull);
@ -118,7 +118,7 @@ pub struct Output<'d, T: Pin> {
impl<'d, T: Pin> Output<'d, T> {
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self {
let mut pin = Flex::new(pin);
match initial_output {
Level::High => pin.set_high(),
@ -193,7 +193,7 @@ fn convert_pull(pull: Pull) -> PULL_A {
/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
/// mode.
pub struct Flex<'d, T: Pin> {
pub(crate) pin: Unborrowed<'d, T>,
pub(crate) pin: PeripheralRef<'d, T>,
}
impl<'d, T: Pin> Flex<'d, T> {
@ -202,8 +202,8 @@ impl<'d, T: Pin> Flex<'d, T> {
/// The pin remains disconnected. The initial output level is unspecified, but can be changed
/// before the pin is put into output mode.
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self {
unborrow!(pin);
pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(pin);
// Pin will be in disconnected state.
Self { pin }
}
@ -374,7 +374,7 @@ pub(crate) mod sealed {
}
}
pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static {
pub trait Pin: Peripheral<P = Self> + sealed::Pin + Sized + 'static {
/// Number of the pin within the port (0..31)
#[inline]
fn pin(&self) -> u8 {
@ -417,22 +417,22 @@ impl AnyPin {
Self { pin_port }
}
pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
Unborrowed::new(AnyPin {
pin_port: pin.unborrow().pin_port(),
pub(crate) fn into_degraded_ref<'a>(pin: impl Peripheral<P = impl Pin + 'a> + 'a) -> PeripheralRef<'a, Self> {
PeripheralRef::new(AnyPin {
pin_port: pin.into_ref().pin_port(),
})
}
}
macro_rules! unborrow_and_degrade {
macro_rules! into_degraded_ref {
($($name:ident),*) => {
$(
let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name);
let $name = $crate::gpio::AnyPin::into_degraded_ref($name);
)*
};
}
impl_unborrow!(AnyPin);
impl_peripheral!(AnyPin);
impl Pin for AnyPin {}
impl sealed::Pin for AnyPin {
#[inline]
@ -447,7 +447,7 @@ pub(crate) trait PselBits {
fn psel_bits(&self) -> u32;
}
impl<'a, P: Pin> PselBits for Option<Unborrowed<'a, P>> {
impl<'a, P: Pin> PselBits for Option<PeripheralRef<'a, P>> {
#[inline]
fn psel_bits(&self) -> u32 {
match self {

View File

@ -4,7 +4,7 @@ use core::marker::PhantomData;
use core::task::{Context, Poll};
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::impl_unborrow;
use embassy_hal_common::impl_peripheral;
use futures::future::poll_fn;
use crate::gpio::sealed::Pin as _;
@ -414,7 +414,7 @@ pub trait Channel: sealed::Channel + Sized {
pub struct AnyChannel {
number: u8,
}
impl_unborrow!(AnyChannel);
impl_peripheral!(AnyChannel);
impl sealed::Channel for AnyChannel {}
impl Channel for AnyChannel {
fn number(&self) -> usize {

View File

@ -135,7 +135,7 @@ pub use chip::pac;
pub(crate) use chip::pac;
pub use chip::{peripherals, Peripherals};
pub use embassy_cortex_m::executor;
pub use embassy_hal_common::{unborrow, Unborrow, Unborrowed};
pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
pub use embassy_macros::cortex_m_interrupt as interrupt;
pub mod config {

View File

@ -3,13 +3,13 @@
use core::marker::PhantomData;
use core::{ptr, slice};
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use embedded_storage::nor_flash::{
ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash,
};
use crate::peripherals::NVMC;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
pub const PAGE_SIZE: usize = 4096;
pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE;
@ -35,8 +35,8 @@ pub struct Nvmc<'d> {
}
impl<'d> Nvmc<'d> {
pub fn new(_p: impl Unborrow<Target = NVMC> + 'd) -> Self {
unborrow!(_p);
pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self {
into_ref!(_p);
Self { _p: PhantomData }
}

View File

@ -1,7 +1,7 @@
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use super::{Channel, ConfigurableChannel, Event, Ppi, Task};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
const DPPI_ENABLE_BIT: u32 = 0x8000_0000;
const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF;
@ -11,13 +11,13 @@ fn regs() -> &'static pac::dppic::RegisterBlock {
}
impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self {
pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self {
Ppi::new_many_to_many(ch, [event], [task])
}
}
impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
Ppi::new_many_to_many(ch, [event], [task1, task2])
}
}
@ -26,11 +26,11 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi
Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
{
pub fn new_many_to_many(
ch: impl Unborrow<Target = C> + 'd,
ch: impl Peripheral<P = C> + 'd,
events: [Event; EVENT_COUNT],
tasks: [Task; TASK_COUNT],
) -> Self {
unborrow!(ch);
into_ref!(ch);
let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK);
for task in tasks {

View File

@ -17,9 +17,9 @@
use core::ptr::NonNull;
use embassy_hal_common::{impl_unborrow, Unborrowed};
use embassy_hal_common::{impl_peripheral, PeripheralRef};
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
#[cfg(feature = "_dppi")]
mod dppi;
@ -27,7 +27,7 @@ mod dppi;
mod ppi;
pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> {
ch: Unborrowed<'d, C>,
ch: PeripheralRef<'d, C>,
#[cfg(feature = "_dppi")]
events: [Event; EVENT_COUNT],
#[cfg(feature = "_dppi")]
@ -87,7 +87,7 @@ pub(crate) mod sealed {
pub trait Group {}
}
pub trait Channel: sealed::Channel + Unborrow<Target = Self> + Sized {
pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized {
/// Returns the number of the channel
fn number(&self) -> usize;
}
@ -117,7 +117,7 @@ pub trait Group: sealed::Group + Sized {
pub struct AnyStaticChannel {
pub(crate) number: u8,
}
impl_unborrow!(AnyStaticChannel);
impl_peripheral!(AnyStaticChannel);
impl sealed::Channel for AnyStaticChannel {}
impl Channel for AnyStaticChannel {
fn number(&self) -> usize {
@ -135,7 +135,7 @@ impl StaticChannel for AnyStaticChannel {
pub struct AnyConfigurableChannel {
pub(crate) number: u8,
}
impl_unborrow!(AnyConfigurableChannel);
impl_peripheral!(AnyConfigurableChannel);
impl sealed::Channel for AnyConfigurableChannel {}
impl Channel for AnyConfigurableChannel {
fn number(&self) -> usize {
@ -187,7 +187,7 @@ macro_rules! impl_ppi_channel {
pub struct AnyGroup {
number: u8,
}
impl_unborrow!(AnyGroup);
impl_peripheral!(AnyGroup);
impl sealed::Group for AnyGroup {}
impl Group for AnyGroup {
fn number(&self) -> usize {

View File

@ -1,7 +1,7 @@
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
impl Task {
fn reg_val(&self) -> u32 {
@ -20,8 +20,8 @@ fn regs() -> &'static pac::ppi::RegisterBlock {
#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task
impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> {
pub fn new_zero_to_one(ch: impl Unborrow<Target = C> + 'd, task: Task) -> Self {
unborrow!(ch);
pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self {
into_ref!(ch);
let r = regs();
let n = ch.number();
@ -32,8 +32,8 @@ impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> {
}
impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self {
unborrow!(ch);
pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self {
into_ref!(ch);
let r = regs();
let n = ch.number();
@ -46,8 +46,8 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task
impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
unborrow!(ch);
pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
into_ref!(ch);
let r = regs();
let n = ch.number();

View File

@ -3,34 +3,34 @@
use core::marker::PhantomData;
use core::sync::atomic::{compiler_fence, Ordering};
use embassy_hal_common::Unborrowed;
use embassy_hal_common::PeripheralRef;
use crate::gpio::sealed::Pin as _;
use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
use crate::interrupt::Interrupt;
use crate::ppi::{Event, Task};
use crate::util::slice_in_ram_or;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
/// SimplePwm is the traditional pwm interface you're probably used to, allowing
/// to simply set a duty cycle across up to four channels.
pub struct SimplePwm<'d, T: Instance> {
phantom: PhantomData<&'d mut T>,
duty: [u16; 4],
ch0: Option<Unborrowed<'d, AnyPin>>,
ch1: Option<Unborrowed<'d, AnyPin>>,
ch2: Option<Unborrowed<'d, AnyPin>>,
ch3: Option<Unborrowed<'d, AnyPin>>,
ch0: Option<PeripheralRef<'d, AnyPin>>,
ch1: Option<PeripheralRef<'d, AnyPin>>,
ch2: Option<PeripheralRef<'d, AnyPin>>,
ch3: Option<PeripheralRef<'d, AnyPin>>,
}
/// SequencePwm allows you to offload the updating of a sequence of duty cycles
/// to up to four channels, as well as repeat that sequence n times.
pub struct SequencePwm<'d, T: Instance> {
phantom: PhantomData<&'d mut T>,
ch0: Option<Unborrowed<'d, AnyPin>>,
ch1: Option<Unborrowed<'d, AnyPin>>,
ch2: Option<Unborrowed<'d, AnyPin>>,
ch3: Option<Unborrowed<'d, AnyPin>>,
ch0: Option<PeripheralRef<'d, AnyPin>>,
ch1: Option<PeripheralRef<'d, AnyPin>>,
ch2: Option<PeripheralRef<'d, AnyPin>>,
ch3: Option<PeripheralRef<'d, AnyPin>>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -51,59 +51,59 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
/// Create a new 1-channel PWM
#[allow(unused_unsafe)]
pub fn new_1ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
unborrow_and_degrade!(ch0);
into_degraded_ref!(ch0);
Self::new_inner(pwm, Some(ch0), None, None, None, config)
}
/// Create a new 2-channel PWM
#[allow(unused_unsafe)]
pub fn new_2ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
ch1: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
unborrow_and_degrade!(ch0, ch1);
into_degraded_ref!(ch0, ch1);
Self::new_inner(pwm, Some(ch0), Some(ch1), None, None, config)
}
/// Create a new 3-channel PWM
#[allow(unused_unsafe)]
pub fn new_3ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
ch1: impl Unborrow<Target = impl GpioPin> + 'd,
ch2: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
ch2: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
unborrow_and_degrade!(ch0, ch1, ch2);
into_degraded_ref!(ch0, ch1, ch2);
Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None, config)
}
/// Create a new 4-channel PWM
#[allow(unused_unsafe)]
pub fn new_4ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
ch1: impl Unborrow<Target = impl GpioPin> + 'd,
ch2: impl Unborrow<Target = impl GpioPin> + 'd,
ch3: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
ch2: impl Peripheral<P = impl GpioPin> + 'd,
ch3: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Result<Self, Error> {
unborrow_and_degrade!(ch0, ch1, ch2, ch3);
into_degraded_ref!(ch0, ch1, ch2, ch3);
Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3), config)
}
fn new_inner(
_pwm: impl Unborrow<Target = T> + 'd,
ch0: Option<Unborrowed<'d, AnyPin>>,
ch1: Option<Unborrowed<'d, AnyPin>>,
ch2: Option<Unborrowed<'d, AnyPin>>,
ch3: Option<Unborrowed<'d, AnyPin>>,
_pwm: impl Peripheral<P = T> + 'd,
ch0: Option<PeripheralRef<'d, AnyPin>>,
ch1: Option<PeripheralRef<'d, AnyPin>>,
ch2: Option<PeripheralRef<'d, AnyPin>>,
ch3: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Result<Self, Error> {
let r = T::regs();
@ -559,9 +559,9 @@ pub enum CounterMode {
impl<'d, T: Instance> SimplePwm<'d, T> {
/// Create a new 1-channel PWM
#[allow(unused_unsafe)]
pub fn new_1ch(pwm: impl Unborrow<Target = T> + 'd, ch0: impl Unborrow<Target = impl GpioPin> + 'd) -> Self {
pub fn new_1ch(pwm: impl Peripheral<P = T> + 'd, ch0: impl Peripheral<P = impl GpioPin> + 'd) -> Self {
unsafe {
unborrow_and_degrade!(ch0);
into_degraded_ref!(ch0);
Self::new_inner(pwm, Some(ch0), None, None, None)
}
}
@ -569,24 +569,24 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
/// Create a new 2-channel PWM
#[allow(unused_unsafe)]
pub fn new_2ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
ch1: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
) -> Self {
unborrow_and_degrade!(ch0, ch1);
into_degraded_ref!(ch0, ch1);
Self::new_inner(pwm, Some(ch0), Some(ch1), None, None)
}
/// Create a new 3-channel PWM
#[allow(unused_unsafe)]
pub fn new_3ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
ch1: impl Unborrow<Target = impl GpioPin> + 'd,
ch2: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
ch2: impl Peripheral<P = impl GpioPin> + 'd,
) -> Self {
unsafe {
unborrow_and_degrade!(ch0, ch1, ch2);
into_degraded_ref!(ch0, ch1, ch2);
Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None)
}
}
@ -594,24 +594,24 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
/// Create a new 4-channel PWM
#[allow(unused_unsafe)]
pub fn new_4ch(
pwm: impl Unborrow<Target = T> + 'd,
ch0: impl Unborrow<Target = impl GpioPin> + 'd,
ch1: impl Unborrow<Target = impl GpioPin> + 'd,
ch2: impl Unborrow<Target = impl GpioPin> + 'd,
ch3: impl Unborrow<Target = impl GpioPin> + 'd,
pwm: impl Peripheral<P = T> + 'd,
ch0: impl Peripheral<P = impl GpioPin> + 'd,
ch1: impl Peripheral<P = impl GpioPin> + 'd,
ch2: impl Peripheral<P = impl GpioPin> + 'd,
ch3: impl Peripheral<P = impl GpioPin> + 'd,
) -> Self {
unsafe {
unborrow_and_degrade!(ch0, ch1, ch2, ch3);
into_degraded_ref!(ch0, ch1, ch2, ch3);
Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3))
}
}
fn new_inner(
_pwm: impl Unborrow<Target = T> + 'd,
ch0: Option<Unborrowed<'d, AnyPin>>,
ch1: Option<Unborrowed<'d, AnyPin>>,
ch2: Option<Unborrowed<'d, AnyPin>>,
ch3: Option<Unborrowed<'d, AnyPin>>,
_pwm: impl Peripheral<P = T> + 'd,
ch0: Option<PeripheralRef<'d, AnyPin>>,
ch1: Option<PeripheralRef<'d, AnyPin>>,
ch2: Option<PeripheralRef<'d, AnyPin>>,
ch3: Option<PeripheralRef<'d, AnyPin>>,
) -> Self {
let r = T::regs();
@ -799,7 +799,7 @@ pub(crate) mod sealed {
}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
type Interrupt: Interrupt;
}

View File

@ -4,14 +4,14 @@ use core::marker::PhantomData;
use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use crate::gpio::sealed::Pin as _;
use crate::gpio::{AnyPin, Pin as GpioPin};
use crate::interrupt::InterruptExt;
use crate::peripherals::QDEC;
use crate::{interrupt, pac, Unborrow};
use crate::{interrupt, pac, Peripheral};
/// Quadrature decoder
pub struct Qdec<'d> {
@ -43,37 +43,37 @@ static WAKER: AtomicWaker = AtomicWaker::new();
impl<'d> Qdec<'d> {
pub fn new(
qdec: impl Unborrow<Target = QDEC> + 'd,
irq: impl Unborrow<Target = interrupt::QDEC> + 'd,
a: impl Unborrow<Target = impl GpioPin> + 'd,
b: impl Unborrow<Target = impl GpioPin> + 'd,
qdec: impl Peripheral<P = QDEC> + 'd,
irq: impl Peripheral<P = interrupt::QDEC> + 'd,
a: impl Peripheral<P = impl GpioPin> + 'd,
b: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(a, b);
into_degraded_ref!(a, b);
Self::new_inner(qdec, irq, a, b, None, config)
}
pub fn new_with_led(
qdec: impl Unborrow<Target = QDEC> + 'd,
irq: impl Unborrow<Target = interrupt::QDEC> + 'd,
a: impl Unborrow<Target = impl GpioPin> + 'd,
b: impl Unborrow<Target = impl GpioPin> + 'd,
led: impl Unborrow<Target = impl GpioPin> + 'd,
qdec: impl Peripheral<P = QDEC> + 'd,
irq: impl Peripheral<P = interrupt::QDEC> + 'd,
a: impl Peripheral<P = impl GpioPin> + 'd,
b: impl Peripheral<P = impl GpioPin> + 'd,
led: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(a, b, led);
into_degraded_ref!(a, b, led);
Self::new_inner(qdec, irq, a, b, Some(led), config)
}
fn new_inner(
_t: impl Unborrow<Target = QDEC> + 'd,
irq: impl Unborrow<Target = interrupt::QDEC> + 'd,
a: Unborrowed<'d, AnyPin>,
b: Unborrowed<'d, AnyPin>,
led: Option<Unborrowed<'d, AnyPin>>,
_t: impl Peripheral<P = QDEC> + 'd,
irq: impl Peripheral<P = interrupt::QDEC> + 'd,
a: PeripheralRef<'d, AnyPin>,
b: PeripheralRef<'d, AnyPin>,
led: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(irq);
into_ref!(irq);
let r = Self::regs();
// Select pins.

View File

@ -4,7 +4,7 @@ use core::ptr;
use core::task::Poll;
use embassy_hal_common::drop::DropBomb;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use crate::gpio::sealed::Pin as _;
@ -13,7 +13,7 @@ use crate::interrupt::{Interrupt, InterruptExt};
pub use crate::pac::qspi::ifconfig0::{
ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode,
};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
// TODO
// - config:
@ -62,27 +62,27 @@ pub enum Error {
}
pub struct Qspi<'d, T: Instance, const FLASH_SIZE: usize> {
irq: Unborrowed<'d, T::Interrupt>,
irq: PeripheralRef<'d, T::Interrupt>,
dpm_enabled: bool,
}
impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
pub fn new(
_qspi: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: impl Unborrow<Target = impl GpioPin> + 'd,
csn: impl Unborrow<Target = impl GpioPin> + 'd,
io0: impl Unborrow<Target = impl GpioPin> + 'd,
io1: impl Unborrow<Target = impl GpioPin> + 'd,
io2: impl Unborrow<Target = impl GpioPin> + 'd,
io3: impl Unborrow<Target = impl GpioPin> + 'd,
_qspi: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
sck: impl Peripheral<P = impl GpioPin> + 'd,
csn: impl Peripheral<P = impl GpioPin> + 'd,
io0: impl Peripheral<P = impl GpioPin> + 'd,
io1: impl Peripheral<P = impl GpioPin> + 'd,
io2: impl Peripheral<P = impl GpioPin> + 'd,
io3: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Qspi<'d, T, FLASH_SIZE> {
unborrow!(irq, sck, csn, io0, io1, io2, io3);
into_ref!(irq, sck, csn, io0, io1, io2, io3);
let r = T::regs();
unborrow_and_degrade!(sck, csn, io0, io1, io2, io3);
into_degraded_ref!(sck, csn, io0, io1, io2, io3);
for pin in [&sck, &csn, &io0, &io1, &io2, &io3] {
pin.set_high();
@ -528,7 +528,7 @@ pub(crate) mod sealed {
}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
type Interrupt: Interrupt;
}

View File

@ -4,12 +4,12 @@ use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use crate::interrupt::InterruptExt;
use crate::peripherals::RNG;
use crate::{interrupt, pac, Unborrow};
use crate::{interrupt, pac, Peripheral};
impl RNG {
fn regs() -> &'static pac::rng::RegisterBlock {
@ -33,7 +33,7 @@ struct State {
///
/// It has a non-blocking API, and a blocking api through `rand`.
pub struct Rng<'d> {
irq: Unborrowed<'d, interrupt::RNG>,
irq: PeripheralRef<'d, interrupt::RNG>,
}
impl<'d> Rng<'d> {
@ -43,8 +43,8 @@ impl<'d> Rng<'d> {
/// e.g. using `mem::forget`.
///
/// The synchronous API is safe.
pub fn new(_rng: impl Unborrow<Target = RNG> + 'd, irq: impl Unborrow<Target = interrupt::RNG> + 'd) -> Self {
unborrow!(irq);
pub fn new(_rng: impl Peripheral<P = RNG> + 'd, irq: impl Peripheral<P = interrupt::RNG> + 'd) -> Self {
into_ref!(irq);
let this = Self { irq };

View File

@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::{impl_unborrow, unborrow};
use embassy_hal_common::{impl_peripheral, into_ref};
use futures::future::poll_fn;
use pac::{saadc, SAADC};
use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A};
@ -17,7 +17,7 @@ use saadc::resolution::VAL_A;
use crate::interrupt::InterruptExt;
use crate::ppi::{ConfigurableChannel, Event, Ppi, Task};
use crate::timer::{Frequency, Instance as TimerInstance, Timer};
use crate::{interrupt, pac, peripherals, Unborrow};
use crate::{interrupt, pac, peripherals, Peripheral};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -77,7 +77,7 @@ pub struct ChannelConfig<'d> {
/// internal voltage.
pub struct VddInput;
impl_unborrow!(VddInput);
impl_peripheral!(VddInput);
impl sealed::Input for VddInput {
#[cfg(not(feature = "_nrf9160"))]
@ -97,7 +97,7 @@ impl Input for VddInput {}
pub struct VddhDiv5Input;
#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
impl_unborrow!(VddhDiv5Input);
impl_peripheral!(VddhDiv5Input);
#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
impl sealed::Input for VddhDiv5Input {
@ -113,7 +113,7 @@ pub struct AnyInput {
channel: InputChannel,
}
impl_unborrow!(AnyInput);
impl_peripheral!(AnyInput);
impl sealed::Input for AnyInput {
fn channel(&self) -> InputChannel {
@ -125,8 +125,8 @@ impl Input for AnyInput {}
impl<'d> ChannelConfig<'d> {
/// Default configuration for single ended channel sampling.
pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self {
unborrow!(input);
pub fn single_ended(input: impl Peripheral<P = impl Input> + 'd) -> Self {
into_ref!(input);
Self {
reference: Reference::INTERNAL,
gain: Gain::GAIN1_6,
@ -139,10 +139,10 @@ impl<'d> ChannelConfig<'d> {
}
/// Default configuration for differential channel sampling.
pub fn differential(
p_input: impl Unborrow<Target = impl Input> + 'd,
n_input: impl Unborrow<Target = impl Input> + 'd,
p_input: impl Peripheral<P = impl Input> + 'd,
n_input: impl Peripheral<P = impl Input> + 'd,
) -> Self {
unborrow!(p_input, n_input);
into_ref!(p_input, n_input);
Self {
reference: Reference::INTERNAL,
gain: Gain::GAIN1_6,
@ -167,12 +167,12 @@ pub enum SamplerState {
impl<'d, const N: usize> Saadc<'d, N> {
pub fn new(
_saadc: impl Unborrow<Target = peripherals::SAADC> + 'd,
irq: impl Unborrow<Target = interrupt::SAADC> + 'd,
_saadc: impl Peripheral<P = peripherals::SAADC> + 'd,
irq: impl Peripheral<P = interrupt::SAADC> + 'd,
config: Config,
channel_configs: [ChannelConfig; N],
) -> Self {
unborrow!(irq);
into_ref!(irq);
let r = unsafe { &*SAADC::ptr() };
@ -674,7 +674,7 @@ pub(crate) mod sealed {
}
/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
pub trait Input: sealed::Input + Unborrow<Target = Self> + Sized {
pub trait Input: sealed::Input + Peripheral<P = Self> + Sized {
fn degrade_saadc(self) -> AnyInput {
AnyInput {
channel: self.channel(),

View File

@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
use futures::future::poll_fn;
pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
@ -15,7 +15,7 @@ use crate::gpio::sealed::Pin as _;
use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits};
use crate::interrupt::{Interrupt, InterruptExt};
use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -53,48 +53,48 @@ impl Default for Config {
impl<'d, T: Instance> Spim<'d, T> {
pub fn new(
spim: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: impl Unborrow<Target = impl GpioPin> + 'd,
miso: impl Unborrow<Target = impl GpioPin> + 'd,
mosi: impl Unborrow<Target = impl GpioPin> + 'd,
spim: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
sck: impl Peripheral<P = impl GpioPin> + 'd,
miso: impl Peripheral<P = impl GpioPin> + 'd,
mosi: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(sck, miso, mosi);
into_degraded_ref!(sck, miso, mosi);
Self::new_inner(spim, irq, sck, Some(miso), Some(mosi), config)
}
pub fn new_txonly(
spim: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: impl Unborrow<Target = impl GpioPin> + 'd,
mosi: impl Unborrow<Target = impl GpioPin> + 'd,
spim: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
sck: impl Peripheral<P = impl GpioPin> + 'd,
mosi: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(sck, mosi);
into_degraded_ref!(sck, mosi);
Self::new_inner(spim, irq, sck, None, Some(mosi), config)
}
pub fn new_rxonly(
spim: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: impl Unborrow<Target = impl GpioPin> + 'd,
miso: impl Unborrow<Target = impl GpioPin> + 'd,
spim: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
sck: impl Peripheral<P = impl GpioPin> + 'd,
miso: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(sck, miso);
into_degraded_ref!(sck, miso);
Self::new_inner(spim, irq, sck, Some(miso), None, config)
}
fn new_inner(
_spim: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: Unborrowed<'d, AnyPin>,
miso: Option<Unborrowed<'d, AnyPin>>,
mosi: Option<Unborrowed<'d, AnyPin>>,
_spim: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
sck: PeripheralRef<'d, AnyPin>,
miso: Option<PeripheralRef<'d, AnyPin>>,
mosi: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(irq);
into_ref!(irq);
let r = T::regs();
@ -379,7 +379,7 @@ pub(crate) mod sealed {
}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
type Interrupt: Interrupt;
}

View File

@ -4,24 +4,24 @@ use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use fixed::types::I30F2;
use futures::future::poll_fn;
use crate::interrupt::InterruptExt;
use crate::peripherals::TEMP;
use crate::{interrupt, pac, Unborrow};
use crate::{interrupt, pac, Peripheral};
/// Integrated temperature sensor.
pub struct Temp<'d> {
_irq: Unborrowed<'d, interrupt::TEMP>,
_irq: PeripheralRef<'d, interrupt::TEMP>,
}
static WAKER: AtomicWaker = AtomicWaker::new();
impl<'d> Temp<'d> {
pub fn new(_t: impl Unborrow<Target = TEMP> + 'd, irq: impl Unborrow<Target = interrupt::TEMP> + 'd) -> Self {
unborrow!(_t, irq);
pub fn new(_t: impl Peripheral<P = TEMP> + 'd, irq: impl Peripheral<P = interrupt::TEMP> + 'd) -> Self {
into_ref!(_t, irq);
// Enable interrupt that signals temperature values
irq.disable();

View File

@ -5,12 +5,12 @@ use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use futures::future::poll_fn;
use crate::interrupt::{Interrupt, InterruptExt};
use crate::ppi::{Event, Task};
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
pub(crate) mod sealed {
@ -28,7 +28,7 @@ pub(crate) mod sealed {
pub trait TimerType {}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
type Interrupt: Interrupt;
}
pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {}
@ -99,11 +99,8 @@ pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> {
}
impl<'d, T: Instance> Timer<'d, T, Awaitable> {
pub fn new_awaitable(
timer: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
) -> Self {
unborrow!(irq);
pub fn new_awaitable(timer: impl Peripheral<P = T> + 'd, irq: impl Peripheral<P = T::Interrupt> + 'd) -> Self {
into_ref!(irq);
irq.set_handler(Self::on_interrupt);
irq.unpend();
@ -117,7 +114,7 @@ impl<'d, T: Instance> Timer<'d, T, NotAwaitable> {
///
/// This can be useful for triggering tasks via PPI
/// `Uarte` uses this internally.
pub fn new(timer: impl Unborrow<Target = T> + 'd) -> Self {
pub fn new(timer: impl Peripheral<P = T> + 'd) -> Self {
Self::new_irqless(timer)
}
}
@ -126,7 +123,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
/// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work.
///
/// This is used by the public constructors.
fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self {
fn new_irqless(_timer: impl Peripheral<P = T> + 'd) -> Self {
let regs = T::regs();
let mut this = Self { phantom: PhantomData };

View File

@ -16,14 +16,14 @@ use core::task::Poll;
use embassy::time::{Duration, Instant};
use embassy::waitqueue::AtomicWaker;
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use futures::future::poll_fn;
use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
use crate::gpio::Pin as GpioPin;
use crate::interrupt::{Interrupt, InterruptExt};
use crate::util::{slice_in_ram, slice_in_ram_or};
use crate::{gpio, pac, Unborrow};
use crate::{gpio, pac, Peripheral};
#[derive(Clone, Copy)]
pub enum Frequency {
@ -80,13 +80,13 @@ pub struct Twim<'d, T: Instance> {
impl<'d, T: Instance> Twim<'d, T> {
pub fn new(
_twim: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
sda: impl Unborrow<Target = impl GpioPin> + 'd,
scl: impl Unborrow<Target = impl GpioPin> + 'd,
_twim: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
sda: impl Peripheral<P = impl GpioPin> + 'd,
scl: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow!(irq, sda, scl);
into_ref!(irq, sda, scl);
let r = T::regs();
@ -707,7 +707,7 @@ pub(crate) mod sealed {
}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
type Interrupt: Interrupt;
}

View File

@ -18,7 +18,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use pac::uarte0::RegisterBlock;
// Re-export SVD variants to allow user to directly set values.
@ -31,7 +31,7 @@ use crate::interrupt::{Interrupt, InterruptExt};
use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
use crate::timer::{Frequency, Instance as TimerInstance, Timer};
use crate::util::slice_in_ram_or;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
#[derive(Clone)]
#[non_exhaustive]
@ -83,40 +83,40 @@ pub struct UarteRx<'d, T: Instance> {
impl<'d, T: Instance> Uarte<'d, T> {
/// Create a new UARTE without hardware flow control
pub fn new(
uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(rxd, txd);
into_degraded_ref!(rxd, txd);
Self::new_inner(uarte, irq, rxd, txd, None, None, config)
}
/// Create a new UARTE with hardware flow control (RTS/CTS)
pub fn new_with_rtscts(
uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
cts: impl Unborrow<Target = impl GpioPin> + 'd,
rts: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
cts: impl Peripheral<P = impl GpioPin> + 'd,
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(rxd, txd, cts, rts);
into_degraded_ref!(rxd, txd, cts, rts);
Self::new_inner(uarte, irq, rxd, txd, Some(cts), Some(rts), config)
}
fn new_inner(
_uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: Unborrowed<'d, AnyPin>,
txd: Unborrowed<'d, AnyPin>,
cts: Option<Unborrowed<'d, AnyPin>>,
rts: Option<Unborrowed<'d, AnyPin>>,
_uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
rxd: PeripheralRef<'d, AnyPin>,
txd: PeripheralRef<'d, AnyPin>,
cts: Option<PeripheralRef<'d, AnyPin>>,
rts: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(irq);
into_ref!(irq);
let r = T::regs();
@ -237,35 +237,35 @@ fn configure(r: &RegisterBlock, config: Config, hardware_flow_control: bool) {
impl<'d, T: Instance> UarteTx<'d, T> {
/// Create a new tx-only UARTE without hardware flow control
pub fn new(
uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(txd);
into_degraded_ref!(txd);
Self::new_inner(uarte, irq, txd, None, config)
}
/// Create a new tx-only UARTE with hardware flow control (RTS/CTS)
pub fn new_with_rtscts(
uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
cts: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
cts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(txd, cts);
into_degraded_ref!(txd, cts);
Self::new_inner(uarte, irq, txd, Some(cts), config)
}
fn new_inner(
_uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
txd: Unborrowed<'d, AnyPin>,
cts: Option<Unborrowed<'d, AnyPin>>,
_uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
txd: PeripheralRef<'d, AnyPin>,
cts: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(irq);
into_ref!(irq);
let r = T::regs();
@ -429,35 +429,35 @@ impl<'a, T: Instance> Drop for UarteTx<'a, T> {
impl<'d, T: Instance> UarteRx<'d, T> {
/// Create a new rx-only UARTE without hardware flow control
pub fn new(
uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(rxd);
into_degraded_ref!(rxd);
Self::new_inner(uarte, irq, rxd, None, config)
}
/// Create a new rx-only UARTE with hardware flow control (RTS/CTS)
pub fn new_with_rtscts(
uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
rts: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(rxd, rts);
into_degraded_ref!(rxd, rts);
Self::new_inner(uarte, irq, rxd, Some(rts), config)
}
fn new_inner(
_uarte: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: Unborrowed<'d, AnyPin>,
rts: Option<Unborrowed<'d, AnyPin>>,
_uarte: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
rxd: PeripheralRef<'d, AnyPin>,
rts: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(irq);
into_ref!(irq);
let r = T::regs();
@ -668,33 +668,33 @@ pub struct UarteWithIdle<'d, U: Instance, T: TimerInstance> {
impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
/// Create a new UARTE without hardware flow control
pub fn new(
uarte: impl Unborrow<Target = U> + 'd,
timer: impl Unborrow<Target = T> + 'd,
ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
irq: impl Unborrow<Target = U::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = U> + 'd,
timer: impl Peripheral<P = T> + 'd,
ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
irq: impl Peripheral<P = U::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(rxd, txd);
into_degraded_ref!(rxd, txd);
Self::new_inner(uarte, timer, ppi_ch1, ppi_ch2, irq, rxd, txd, None, None, config)
}
/// Create a new UARTE with hardware flow control (RTS/CTS)
pub fn new_with_rtscts(
uarte: impl Unborrow<Target = U> + 'd,
timer: impl Unborrow<Target = T> + 'd,
ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
irq: impl Unborrow<Target = U::Interrupt> + 'd,
rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl Unborrow<Target = impl GpioPin> + 'd,
cts: impl Unborrow<Target = impl GpioPin> + 'd,
rts: impl Unborrow<Target = impl GpioPin> + 'd,
uarte: impl Peripheral<P = U> + 'd,
timer: impl Peripheral<P = T> + 'd,
ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
irq: impl Peripheral<P = U::Interrupt> + 'd,
rxd: impl Peripheral<P = impl GpioPin> + 'd,
txd: impl Peripheral<P = impl GpioPin> + 'd,
cts: impl Peripheral<P = impl GpioPin> + 'd,
rts: impl Peripheral<P = impl GpioPin> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(rxd, txd, cts, rts);
into_degraded_ref!(rxd, txd, cts, rts);
Self::new_inner(
uarte,
timer,
@ -710,15 +710,15 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
}
fn new_inner(
uarte: impl Unborrow<Target = U> + 'd,
timer: impl Unborrow<Target = T> + 'd,
ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd,
irq: impl Unborrow<Target = U::Interrupt> + 'd,
rxd: Unborrowed<'d, AnyPin>,
txd: Unborrowed<'d, AnyPin>,
cts: Option<Unborrowed<'d, AnyPin>>,
rts: Option<Unborrowed<'d, AnyPin>>,
uarte: impl Peripheral<P = U> + 'd,
timer: impl Peripheral<P = T> + 'd,
ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
irq: impl Peripheral<P = U::Interrupt> + 'd,
rxd: PeripheralRef<'d, AnyPin>,
txd: PeripheralRef<'d, AnyPin>,
cts: Option<PeripheralRef<'d, AnyPin>>,
rts: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
let baudrate = config.baudrate;
@ -726,7 +726,7 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
let mut timer = Timer::new(timer);
unborrow!(ppi_ch1, ppi_ch2);
into_ref!(ppi_ch1, ppi_ch2);
let r = U::regs();
@ -939,7 +939,7 @@ pub(crate) mod sealed {
}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
type Interrupt: Interrupt;
}

View File

@ -7,7 +7,7 @@ use core::task::Poll;
use cortex_m::peripheral::NVIC;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
pub use embassy_usb;
use embassy_usb::driver::{self, EndpointError, Event, Unsupported};
use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection};
@ -17,7 +17,7 @@ use pac::usbd::RegisterBlock;
use crate::interrupt::{Interrupt, InterruptExt};
use crate::util::slice_in_ram;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
const NEW_AW: AtomicWaker = AtomicWaker::new();
static BUS_WAKER: AtomicWaker = NEW_AW;
@ -166,12 +166,8 @@ impl UsbSupply for SignalledSupply {
}
impl<'d, T: Instance, P: UsbSupply> Driver<'d, T, P> {
pub fn new(
_usb: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
usb_supply: P,
) -> Self {
unborrow!(irq);
pub fn new(_usb: impl Peripheral<P = T> + 'd, irq: impl Peripheral<P = T::Interrupt> + 'd, usb_supply: P) -> Self {
into_ref!(irq);
irq.set_handler(Self::on_interrupt);
irq.unpend();
irq.enable();
@ -950,7 +946,7 @@ pub(crate) mod sealed {
}
}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send {
pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
type Interrupt: Interrupt;
}