aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 14:00:19 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 14:00:19 +0200
commit4901c34d9c4cd326ab9bca02dd099a663da2567f (patch)
tree8225afebb595fb10c1d67148c0d19b7b732853da /embassy-nrf/src
parent8a9d2f59af004902d3978a2922843833b98bcce0 (diff)
Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs24
-rw-r--r--embassy-nrf/src/gpio.rs30
-rw-r--r--embassy-nrf/src/gpiote.rs4
-rw-r--r--embassy-nrf/src/lib.rs2
-rw-r--r--embassy-nrf/src/nvmc.rs8
-rw-r--r--embassy-nrf/src/ppi/dppi.rs12
-rw-r--r--embassy-nrf/src/ppi/mod.rs14
-rw-r--r--embassy-nrf/src/ppi/ppi.rs16
-rw-r--r--embassy-nrf/src/pwm.rs112
-rw-r--r--embassy-nrf/src/qdec.rs38
-rw-r--r--embassy-nrf/src/qspi.rs28
-rw-r--r--embassy-nrf/src/rng.rs10
-rw-r--r--embassy-nrf/src/saadc.rs28
-rw-r--r--embassy-nrf/src/spim.rs50
-rw-r--r--embassy-nrf/src/temp.rs10
-rw-r--r--embassy-nrf/src/timer.rs17
-rw-r--r--embassy-nrf/src/twim.rs16
-rw-r--r--embassy-nrf/src/uarte.rs156
-rw-r--r--embassy-nrf/src/usb.rs14
19 files changed, 291 insertions, 298 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index d251ce347..48ffe5c29 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -22,7 +22,7 @@ use core::task::Poll;
22use embassy::waitqueue::WakerRegistration; 22use embassy::waitqueue::WakerRegistration;
23use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; 23use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
24use embassy_hal_common::ring_buffer::RingBuffer; 24use embassy_hal_common::ring_buffer::RingBuffer;
25use embassy_hal_common::{low_power_wait_until, unborrow}; 25use embassy_hal_common::{into_ref, low_power_wait_until};
26use futures::future::poll_fn; 26use futures::future::poll_fn;
27// Re-export SVD variants to allow user to directly set values 27// Re-export SVD variants to allow user to directly set values
28pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 28pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
@@ -32,7 +32,7 @@ use crate::interrupt::InterruptExt;
32use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 32use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
33use crate::timer::{Frequency, Instance as TimerInstance, Timer}; 33use crate::timer::{Frequency, Instance as TimerInstance, Timer};
34use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; 34use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance};
35use crate::{pac, Unborrow}; 35use crate::{pac, Peripheral};
36 36
37#[derive(Copy, Clone, Debug, PartialEq)] 37#[derive(Copy, Clone, Debug, PartialEq)]
38enum RxState { 38enum RxState {
@@ -78,20 +78,20 @@ impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> {
78impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { 78impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
79 pub fn new( 79 pub fn new(
80 state: &'d mut State<'d, U, T>, 80 state: &'d mut State<'d, U, T>,
81 _uarte: impl Unborrow<Target = U> + 'd, 81 _uarte: impl Peripheral<P = U> + 'd,
82 timer: impl Unborrow<Target = T> + 'd, 82 timer: impl Peripheral<P = T> + 'd,
83 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 83 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
84 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 84 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
85 irq: impl Unborrow<Target = U::Interrupt> + 'd, 85 irq: impl Peripheral<P = U::Interrupt> + 'd,
86 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 86 rxd: impl Peripheral<P = impl GpioPin> + 'd,
87 txd: impl Unborrow<Target = impl GpioPin> + 'd, 87 txd: impl Peripheral<P = impl GpioPin> + 'd,
88 cts: impl Unborrow<Target = impl GpioPin> + 'd, 88 cts: impl Peripheral<P = impl GpioPin> + 'd,
89 rts: impl Unborrow<Target = impl GpioPin> + 'd, 89 rts: impl Peripheral<P = impl GpioPin> + 'd,
90 config: Config, 90 config: Config,
91 rx_buffer: &'d mut [u8], 91 rx_buffer: &'d mut [u8],
92 tx_buffer: &'d mut [u8], 92 tx_buffer: &'d mut [u8],
93 ) -> Self { 93 ) -> Self {
94 unborrow!(ppi_ch1, ppi_ch2, irq, rxd, txd, cts, rts); 94 into_ref!(ppi_ch1, ppi_ch2, irq, rxd, txd, cts, rts);
95 95
96 let r = U::regs(); 96 let r = U::regs();
97 97
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index f6320b8ee..ae08d859a 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -4,12 +4,12 @@ use core::convert::Infallible;
4use core::hint::unreachable_unchecked; 4use core::hint::unreachable_unchecked;
5 5
6use cfg_if::cfg_if; 6use cfg_if::cfg_if;
7use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; 7use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef};
8 8
9use self::sealed::Pin as _; 9use self::sealed::Pin as _;
10use crate::pac::p0 as gpio; 10use crate::pac::p0 as gpio;
11use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; 11use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A};
12use crate::{pac, Unborrow}; 12use crate::{pac, Peripheral};
13 13
14/// A GPIO port with up to 32 pins. 14/// A GPIO port with up to 32 pins.
15#[derive(Debug, Eq, PartialEq)] 15#[derive(Debug, Eq, PartialEq)]
@@ -38,7 +38,7 @@ pub struct Input<'d, T: Pin> {
38 38
39impl<'d, T: Pin> Input<'d, T> { 39impl<'d, T: Pin> Input<'d, T> {
40 #[inline] 40 #[inline]
41 pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { 41 pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self {
42 let mut pin = Flex::new(pin); 42 let mut pin = Flex::new(pin);
43 pin.set_as_input(pull); 43 pin.set_as_input(pull);
44 44
@@ -118,7 +118,7 @@ pub struct Output<'d, T: Pin> {
118 118
119impl<'d, T: Pin> Output<'d, T> { 119impl<'d, T: Pin> Output<'d, T> {
120 #[inline] 120 #[inline]
121 pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self { 121 pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, drive: OutputDrive) -> Self {
122 let mut pin = Flex::new(pin); 122 let mut pin = Flex::new(pin);
123 match initial_output { 123 match initial_output {
124 Level::High => pin.set_high(), 124 Level::High => pin.set_high(),
@@ -193,7 +193,7 @@ fn convert_pull(pull: Pull) -> PULL_A {
193/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output 193/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
194/// mode. 194/// mode.
195pub struct Flex<'d, T: Pin> { 195pub struct Flex<'d, T: Pin> {
196 pub(crate) pin: Unborrowed<'d, T>, 196 pub(crate) pin: PeripheralRef<'d, T>,
197} 197}
198 198
199impl<'d, T: Pin> Flex<'d, T> { 199impl<'d, T: Pin> Flex<'d, T> {
@@ -202,8 +202,8 @@ impl<'d, T: Pin> Flex<'d, T> {
202 /// The pin remains disconnected. The initial output level is unspecified, but can be changed 202 /// The pin remains disconnected. The initial output level is unspecified, but can be changed
203 /// before the pin is put into output mode. 203 /// before the pin is put into output mode.
204 #[inline] 204 #[inline]
205 pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self { 205 pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self {
206 unborrow!(pin); 206 into_ref!(pin);
207 // Pin will be in disconnected state. 207 // Pin will be in disconnected state.
208 Self { pin } 208 Self { pin }
209 } 209 }
@@ -374,7 +374,7 @@ pub(crate) mod sealed {
374 } 374 }
375} 375}
376 376
377pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static { 377pub trait Pin: Peripheral<P = Self> + sealed::Pin + Sized + 'static {
378 /// Number of the pin within the port (0..31) 378 /// Number of the pin within the port (0..31)
379 #[inline] 379 #[inline]
380 fn pin(&self) -> u8 { 380 fn pin(&self) -> u8 {
@@ -417,22 +417,22 @@ impl AnyPin {
417 Self { pin_port } 417 Self { pin_port }
418 } 418 }
419 419
420 pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> { 420 pub(crate) fn into_degraded_ref<'a>(pin: impl Peripheral<P = impl Pin + 'a> + 'a) -> PeripheralRef<'a, Self> {
421 Unborrowed::new(AnyPin { 421 PeripheralRef::new(AnyPin {
422 pin_port: pin.unborrow().pin_port(), 422 pin_port: pin.into_ref().pin_port(),
423 }) 423 })
424 } 424 }
425} 425}
426 426
427macro_rules! unborrow_and_degrade { 427macro_rules! into_degraded_ref {
428 ($($name:ident),*) => { 428 ($($name:ident),*) => {
429 $( 429 $(
430 let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name); 430 let $name = $crate::gpio::AnyPin::into_degraded_ref($name);
431 )* 431 )*
432 }; 432 };
433} 433}
434 434
435impl_unborrow!(AnyPin); 435impl_peripheral!(AnyPin);
436impl Pin for AnyPin {} 436impl Pin for AnyPin {}
437impl sealed::Pin for AnyPin { 437impl sealed::Pin for AnyPin {
438 #[inline] 438 #[inline]
@@ -447,7 +447,7 @@ pub(crate) trait PselBits {
447 fn psel_bits(&self) -> u32; 447 fn psel_bits(&self) -> u32;
448} 448}
449 449
450impl<'a, P: Pin> PselBits for Option<Unborrowed<'a, P>> { 450impl<'a, P: Pin> PselBits for Option<PeripheralRef<'a, P>> {
451 #[inline] 451 #[inline]
452 fn psel_bits(&self) -> u32 { 452 fn psel_bits(&self) -> u32 {
453 match self { 453 match self {
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index d59c2e34d..e89d01685 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -4,7 +4,7 @@ use core::marker::PhantomData;
4use core::task::{Context, Poll}; 4use core::task::{Context, Poll};
5 5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::impl_unborrow; 7use embassy_hal_common::impl_peripheral;
8use futures::future::poll_fn; 8use futures::future::poll_fn;
9 9
10use crate::gpio::sealed::Pin as _; 10use crate::gpio::sealed::Pin as _;
@@ -414,7 +414,7 @@ pub trait Channel: sealed::Channel + Sized {
414pub struct AnyChannel { 414pub struct AnyChannel {
415 number: u8, 415 number: u8,
416} 416}
417impl_unborrow!(AnyChannel); 417impl_peripheral!(AnyChannel);
418impl sealed::Channel for AnyChannel {} 418impl sealed::Channel for AnyChannel {}
419impl Channel for AnyChannel { 419impl Channel for AnyChannel {
420 fn number(&self) -> usize { 420 fn number(&self) -> usize {
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index b6a21caa2..ad6c16c1f 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -135,7 +135,7 @@ pub use chip::pac;
135pub(crate) use chip::pac; 135pub(crate) use chip::pac;
136pub use chip::{peripherals, Peripherals}; 136pub use chip::{peripherals, Peripherals};
137pub use embassy_cortex_m::executor; 137pub use embassy_cortex_m::executor;
138pub use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; 138pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
139pub use embassy_macros::cortex_m_interrupt as interrupt; 139pub use embassy_macros::cortex_m_interrupt as interrupt;
140 140
141pub mod config { 141pub mod config {
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs
index e350f8c99..731def46a 100644
--- a/embassy-nrf/src/nvmc.rs
+++ b/embassy-nrf/src/nvmc.rs
@@ -3,13 +3,13 @@
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::{ptr, slice}; 4use core::{ptr, slice};
5 5
6use embassy_hal_common::unborrow; 6use embassy_hal_common::into_ref;
7use embedded_storage::nor_flash::{ 7use embedded_storage::nor_flash::{
8 ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, 8 ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash,
9}; 9};
10 10
11use crate::peripherals::NVMC; 11use crate::peripherals::NVMC;
12use crate::{pac, Unborrow}; 12use crate::{pac, Peripheral};
13 13
14pub const PAGE_SIZE: usize = 4096; 14pub const PAGE_SIZE: usize = 4096;
15pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; 15pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE;
@@ -35,8 +35,8 @@ pub struct Nvmc<'d> {
35} 35}
36 36
37impl<'d> Nvmc<'d> { 37impl<'d> Nvmc<'d> {
38 pub fn new(_p: impl Unborrow<Target = NVMC> + 'd) -> Self { 38 pub fn new(_p: impl Peripheral<P = NVMC> + 'd) -> Self {
39 unborrow!(_p); 39 into_ref!(_p);
40 40
41 Self { _p: PhantomData } 41 Self { _p: PhantomData }
42 } 42 }
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs
index 87ebb7084..de856c0ca 100644
--- a/embassy-nrf/src/ppi/dppi.rs
+++ b/embassy-nrf/src/ppi/dppi.rs
@@ -1,7 +1,7 @@
1use embassy_hal_common::unborrow; 1use embassy_hal_common::into_ref;
2 2
3use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; 3use super::{Channel, ConfigurableChannel, Event, Ppi, Task};
4use crate::{pac, Unborrow}; 4use crate::{pac, Peripheral};
5 5
6const DPPI_ENABLE_BIT: u32 = 0x8000_0000; 6const DPPI_ENABLE_BIT: u32 = 0x8000_0000;
7const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; 7const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF;
@@ -11,13 +11,13 @@ fn regs() -> &'static pac::dppic::RegisterBlock {
11} 11}
12 12
13impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { 13impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
14 pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self { 14 pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self {
15 Ppi::new_many_to_many(ch, [event], [task]) 15 Ppi::new_many_to_many(ch, [event], [task])
16 } 16 }
17} 17}
18 18
19impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { 19impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
20 pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { 20 pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
21 Ppi::new_many_to_many(ch, [event], [task1, task2]) 21 Ppi::new_many_to_many(ch, [event], [task1, task2])
22 } 22 }
23} 23}
@@ -26,11 +26,11 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi
26 Ppi<'d, C, EVENT_COUNT, TASK_COUNT> 26 Ppi<'d, C, EVENT_COUNT, TASK_COUNT>
27{ 27{
28 pub fn new_many_to_many( 28 pub fn new_many_to_many(
29 ch: impl Unborrow<Target = C> + 'd, 29 ch: impl Peripheral<P = C> + 'd,
30 events: [Event; EVENT_COUNT], 30 events: [Event; EVENT_COUNT],
31 tasks: [Task; TASK_COUNT], 31 tasks: [Task; TASK_COUNT],
32 ) -> Self { 32 ) -> Self {
33 unborrow!(ch); 33 into_ref!(ch);
34 34
35 let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK); 35 let val = DPPI_ENABLE_BIT | (ch.number() as u32 & DPPI_CHANNEL_MASK);
36 for task in tasks { 36 for task in tasks {
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs
index fd1d0cf8c..796de2170 100644
--- a/embassy-nrf/src/ppi/mod.rs
+++ b/embassy-nrf/src/ppi/mod.rs
@@ -17,9 +17,9 @@
17 17
18use core::ptr::NonNull; 18use core::ptr::NonNull;
19 19
20use embassy_hal_common::{impl_unborrow, Unborrowed}; 20use embassy_hal_common::{impl_peripheral, PeripheralRef};
21 21
22use crate::{peripherals, Unborrow}; 22use crate::{peripherals, Peripheral};
23 23
24#[cfg(feature = "_dppi")] 24#[cfg(feature = "_dppi")]
25mod dppi; 25mod dppi;
@@ -27,7 +27,7 @@ mod dppi;
27mod ppi; 27mod ppi;
28 28
29pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { 29pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> {
30 ch: Unborrowed<'d, C>, 30 ch: PeripheralRef<'d, C>,
31 #[cfg(feature = "_dppi")] 31 #[cfg(feature = "_dppi")]
32 events: [Event; EVENT_COUNT], 32 events: [Event; EVENT_COUNT],
33 #[cfg(feature = "_dppi")] 33 #[cfg(feature = "_dppi")]
@@ -87,7 +87,7 @@ pub(crate) mod sealed {
87 pub trait Group {} 87 pub trait Group {}
88} 88}
89 89
90pub trait Channel: sealed::Channel + Unborrow<Target = Self> + Sized { 90pub trait Channel: sealed::Channel + Peripheral<P = Self> + Sized {
91 /// Returns the number of the channel 91 /// Returns the number of the channel
92 fn number(&self) -> usize; 92 fn number(&self) -> usize;
93} 93}
@@ -117,7 +117,7 @@ pub trait Group: sealed::Group + Sized {
117pub struct AnyStaticChannel { 117pub struct AnyStaticChannel {
118 pub(crate) number: u8, 118 pub(crate) number: u8,
119} 119}
120impl_unborrow!(AnyStaticChannel); 120impl_peripheral!(AnyStaticChannel);
121impl sealed::Channel for AnyStaticChannel {} 121impl sealed::Channel for AnyStaticChannel {}
122impl Channel for AnyStaticChannel { 122impl Channel for AnyStaticChannel {
123 fn number(&self) -> usize { 123 fn number(&self) -> usize {
@@ -135,7 +135,7 @@ impl StaticChannel for AnyStaticChannel {
135pub struct AnyConfigurableChannel { 135pub struct AnyConfigurableChannel {
136 pub(crate) number: u8, 136 pub(crate) number: u8,
137} 137}
138impl_unborrow!(AnyConfigurableChannel); 138impl_peripheral!(AnyConfigurableChannel);
139impl sealed::Channel for AnyConfigurableChannel {} 139impl sealed::Channel for AnyConfigurableChannel {}
140impl Channel for AnyConfigurableChannel { 140impl Channel for AnyConfigurableChannel {
141 fn number(&self) -> usize { 141 fn number(&self) -> usize {
@@ -187,7 +187,7 @@ macro_rules! impl_ppi_channel {
187pub struct AnyGroup { 187pub struct AnyGroup {
188 number: u8, 188 number: u8,
189} 189}
190impl_unborrow!(AnyGroup); 190impl_peripheral!(AnyGroup);
191impl sealed::Group for AnyGroup {} 191impl sealed::Group for AnyGroup {}
192impl Group for AnyGroup { 192impl Group for AnyGroup {
193 fn number(&self) -> usize { 193 fn number(&self) -> usize {
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs
index 3b8f44da8..450a290a2 100644
--- a/embassy-nrf/src/ppi/ppi.rs
+++ b/embassy-nrf/src/ppi/ppi.rs
@@ -1,7 +1,7 @@
1use embassy_hal_common::unborrow; 1use embassy_hal_common::into_ref;
2 2
3use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; 3use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task};
4use crate::{pac, Unborrow}; 4use crate::{pac, Peripheral};
5 5
6impl Task { 6impl Task {
7 fn reg_val(&self) -> u32 { 7 fn reg_val(&self) -> u32 {
@@ -20,8 +20,8 @@ fn regs() -> &'static pac::ppi::RegisterBlock {
20 20
21#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task 21#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task
22impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { 22impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> {
23 pub fn new_zero_to_one(ch: impl Unborrow<Target = C> + 'd, task: Task) -> Self { 23 pub fn new_zero_to_one(ch: impl Peripheral<P = C> + 'd, task: Task) -> Self {
24 unborrow!(ch); 24 into_ref!(ch);
25 25
26 let r = regs(); 26 let r = regs();
27 let n = ch.number(); 27 let n = ch.number();
@@ -32,8 +32,8 @@ impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> {
32} 32}
33 33
34impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { 34impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
35 pub fn new_one_to_one(ch: impl Unborrow<Target = C> + 'd, event: Event, task: Task) -> Self { 35 pub fn new_one_to_one(ch: impl Peripheral<P = C> + 'd, event: Event, task: Task) -> Self {
36 unborrow!(ch); 36 into_ref!(ch);
37 37
38 let r = regs(); 38 let r = regs();
39 let n = ch.number(); 39 let n = ch.number();
@@ -46,8 +46,8 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> {
46 46
47#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task 47#[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task
48impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { 48impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> {
49 pub fn new_one_to_two(ch: impl Unborrow<Target = C> + 'd, event: Event, task1: Task, task2: Task) -> Self { 49 pub fn new_one_to_two(ch: impl Peripheral<P = C> + 'd, event: Event, task1: Task, task2: Task) -> Self {
50 unborrow!(ch); 50 into_ref!(ch);
51 51
52 let r = regs(); 52 let r = regs();
53 let n = ch.number(); 53 let n = ch.number();
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 050461ea5..603fd8efd 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -3,34 +3,34 @@
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{compiler_fence, Ordering};
5 5
6use embassy_hal_common::Unborrowed; 6use embassy_hal_common::PeripheralRef;
7 7
8use crate::gpio::sealed::Pin as _; 8use crate::gpio::sealed::Pin as _;
9use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; 9use crate::gpio::{AnyPin, Pin as GpioPin, PselBits};
10use crate::interrupt::Interrupt; 10use crate::interrupt::Interrupt;
11use crate::ppi::{Event, Task}; 11use crate::ppi::{Event, Task};
12use crate::util::slice_in_ram_or; 12use crate::util::slice_in_ram_or;
13use crate::{pac, Unborrow}; 13use crate::{pac, Peripheral};
14 14
15/// SimplePwm is the traditional pwm interface you're probably used to, allowing 15/// SimplePwm is the traditional pwm interface you're probably used to, allowing
16/// to simply set a duty cycle across up to four channels. 16/// to simply set a duty cycle across up to four channels.
17pub struct SimplePwm<'d, T: Instance> { 17pub struct SimplePwm<'d, T: Instance> {
18 phantom: PhantomData<&'d mut T>, 18 phantom: PhantomData<&'d mut T>,
19 duty: [u16; 4], 19 duty: [u16; 4],
20 ch0: Option<Unborrowed<'d, AnyPin>>, 20 ch0: Option<PeripheralRef<'d, AnyPin>>,
21 ch1: Option<Unborrowed<'d, AnyPin>>, 21 ch1: Option<PeripheralRef<'d, AnyPin>>,
22 ch2: Option<Unborrowed<'d, AnyPin>>, 22 ch2: Option<PeripheralRef<'d, AnyPin>>,
23 ch3: Option<Unborrowed<'d, AnyPin>>, 23 ch3: Option<PeripheralRef<'d, AnyPin>>,
24} 24}
25 25
26/// SequencePwm allows you to offload the updating of a sequence of duty cycles 26/// SequencePwm allows you to offload the updating of a sequence of duty cycles
27/// to up to four channels, as well as repeat that sequence n times. 27/// to up to four channels, as well as repeat that sequence n times.
28pub struct SequencePwm<'d, T: Instance> { 28pub struct SequencePwm<'d, T: Instance> {
29 phantom: PhantomData<&'d mut T>, 29 phantom: PhantomData<&'d mut T>,
30 ch0: Option<Unborrowed<'d, AnyPin>>, 30 ch0: Option<PeripheralRef<'d, AnyPin>>,
31 ch1: Option<Unborrowed<'d, AnyPin>>, 31 ch1: Option<PeripheralRef<'d, AnyPin>>,
32 ch2: Option<Unborrowed<'d, AnyPin>>, 32 ch2: Option<PeripheralRef<'d, AnyPin>>,
33 ch3: Option<Unborrowed<'d, AnyPin>>, 33 ch3: Option<PeripheralRef<'d, AnyPin>>,
34} 34}
35 35
36#[derive(Debug, Clone, Copy, PartialEq, Eq)] 36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -51,59 +51,59 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
51 /// Create a new 1-channel PWM 51 /// Create a new 1-channel PWM
52 #[allow(unused_unsafe)] 52 #[allow(unused_unsafe)]
53 pub fn new_1ch( 53 pub fn new_1ch(
54 pwm: impl Unborrow<Target = T> + 'd, 54 pwm: impl Peripheral<P = T> + 'd,
55 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 55 ch0: impl Peripheral<P = impl GpioPin> + 'd,
56 config: Config, 56 config: Config,
57 ) -> Result<Self, Error> { 57 ) -> Result<Self, Error> {
58 unborrow_and_degrade!(ch0); 58 into_degraded_ref!(ch0);
59 Self::new_inner(pwm, Some(ch0), None, None, None, config) 59 Self::new_inner(pwm, Some(ch0), None, None, None, config)
60 } 60 }
61 61
62 /// Create a new 2-channel PWM 62 /// Create a new 2-channel PWM
63 #[allow(unused_unsafe)] 63 #[allow(unused_unsafe)]
64 pub fn new_2ch( 64 pub fn new_2ch(
65 pwm: impl Unborrow<Target = T> + 'd, 65 pwm: impl Peripheral<P = T> + 'd,
66 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 66 ch0: impl Peripheral<P = impl GpioPin> + 'd,
67 ch1: impl Unborrow<Target = impl GpioPin> + 'd, 67 ch1: impl Peripheral<P = impl GpioPin> + 'd,
68 config: Config, 68 config: Config,
69 ) -> Result<Self, Error> { 69 ) -> Result<Self, Error> {
70 unborrow_and_degrade!(ch0, ch1); 70 into_degraded_ref!(ch0, ch1);
71 Self::new_inner(pwm, Some(ch0), Some(ch1), None, None, config) 71 Self::new_inner(pwm, Some(ch0), Some(ch1), None, None, config)
72 } 72 }
73 73
74 /// Create a new 3-channel PWM 74 /// Create a new 3-channel PWM
75 #[allow(unused_unsafe)] 75 #[allow(unused_unsafe)]
76 pub fn new_3ch( 76 pub fn new_3ch(
77 pwm: impl Unborrow<Target = T> + 'd, 77 pwm: impl Peripheral<P = T> + 'd,
78 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 78 ch0: impl Peripheral<P = impl GpioPin> + 'd,
79 ch1: impl Unborrow<Target = impl GpioPin> + 'd, 79 ch1: impl Peripheral<P = impl GpioPin> + 'd,
80 ch2: impl Unborrow<Target = impl GpioPin> + 'd, 80 ch2: impl Peripheral<P = impl GpioPin> + 'd,
81 config: Config, 81 config: Config,
82 ) -> Result<Self, Error> { 82 ) -> Result<Self, Error> {
83 unborrow_and_degrade!(ch0, ch1, ch2); 83 into_degraded_ref!(ch0, ch1, ch2);
84 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None, config) 84 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None, config)
85 } 85 }
86 86
87 /// Create a new 4-channel PWM 87 /// Create a new 4-channel PWM
88 #[allow(unused_unsafe)] 88 #[allow(unused_unsafe)]
89 pub fn new_4ch( 89 pub fn new_4ch(
90 pwm: impl Unborrow<Target = T> + 'd, 90 pwm: impl Peripheral<P = T> + 'd,
91 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 91 ch0: impl Peripheral<P = impl GpioPin> + 'd,
92 ch1: impl Unborrow<Target = impl GpioPin> + 'd, 92 ch1: impl Peripheral<P = impl GpioPin> + 'd,
93 ch2: impl Unborrow<Target = impl GpioPin> + 'd, 93 ch2: impl Peripheral<P = impl GpioPin> + 'd,
94 ch3: impl Unborrow<Target = impl GpioPin> + 'd, 94 ch3: impl Peripheral<P = impl GpioPin> + 'd,
95 config: Config, 95 config: Config,
96 ) -> Result<Self, Error> { 96 ) -> Result<Self, Error> {
97 unborrow_and_degrade!(ch0, ch1, ch2, ch3); 97 into_degraded_ref!(ch0, ch1, ch2, ch3);
98 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3), config) 98 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3), config)
99 } 99 }
100 100
101 fn new_inner( 101 fn new_inner(
102 _pwm: impl Unborrow<Target = T> + 'd, 102 _pwm: impl Peripheral<P = T> + 'd,
103 ch0: Option<Unborrowed<'d, AnyPin>>, 103 ch0: Option<PeripheralRef<'d, AnyPin>>,
104 ch1: Option<Unborrowed<'d, AnyPin>>, 104 ch1: Option<PeripheralRef<'d, AnyPin>>,
105 ch2: Option<Unborrowed<'d, AnyPin>>, 105 ch2: Option<PeripheralRef<'d, AnyPin>>,
106 ch3: Option<Unborrowed<'d, AnyPin>>, 106 ch3: Option<PeripheralRef<'d, AnyPin>>,
107 config: Config, 107 config: Config,
108 ) -> Result<Self, Error> { 108 ) -> Result<Self, Error> {
109 let r = T::regs(); 109 let r = T::regs();
@@ -559,9 +559,9 @@ pub enum CounterMode {
559impl<'d, T: Instance> SimplePwm<'d, T> { 559impl<'d, T: Instance> SimplePwm<'d, T> {
560 /// Create a new 1-channel PWM 560 /// Create a new 1-channel PWM
561 #[allow(unused_unsafe)] 561 #[allow(unused_unsafe)]
562 pub fn new_1ch(pwm: impl Unborrow<Target = T> + 'd, ch0: impl Unborrow<Target = impl GpioPin> + 'd) -> Self { 562 pub fn new_1ch(pwm: impl Peripheral<P = T> + 'd, ch0: impl Peripheral<P = impl GpioPin> + 'd) -> Self {
563 unsafe { 563 unsafe {
564 unborrow_and_degrade!(ch0); 564 into_degraded_ref!(ch0);
565 Self::new_inner(pwm, Some(ch0), None, None, None) 565 Self::new_inner(pwm, Some(ch0), None, None, None)
566 } 566 }
567 } 567 }
@@ -569,24 +569,24 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
569 /// Create a new 2-channel PWM 569 /// Create a new 2-channel PWM
570 #[allow(unused_unsafe)] 570 #[allow(unused_unsafe)]
571 pub fn new_2ch( 571 pub fn new_2ch(
572 pwm: impl Unborrow<Target = T> + 'd, 572 pwm: impl Peripheral<P = T> + 'd,
573 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 573 ch0: impl Peripheral<P = impl GpioPin> + 'd,
574 ch1: impl Unborrow<Target = impl GpioPin> + 'd, 574 ch1: impl Peripheral<P = impl GpioPin> + 'd,
575 ) -> Self { 575 ) -> Self {
576 unborrow_and_degrade!(ch0, ch1); 576 into_degraded_ref!(ch0, ch1);
577 Self::new_inner(pwm, Some(ch0), Some(ch1), None, None) 577 Self::new_inner(pwm, Some(ch0), Some(ch1), None, None)
578 } 578 }
579 579
580 /// Create a new 3-channel PWM 580 /// Create a new 3-channel PWM
581 #[allow(unused_unsafe)] 581 #[allow(unused_unsafe)]
582 pub fn new_3ch( 582 pub fn new_3ch(
583 pwm: impl Unborrow<Target = T> + 'd, 583 pwm: impl Peripheral<P = T> + 'd,
584 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 584 ch0: impl Peripheral<P = impl GpioPin> + 'd,
585 ch1: impl Unborrow<Target = impl GpioPin> + 'd, 585 ch1: impl Peripheral<P = impl GpioPin> + 'd,
586 ch2: impl Unborrow<Target = impl GpioPin> + 'd, 586 ch2: impl Peripheral<P = impl GpioPin> + 'd,
587 ) -> Self { 587 ) -> Self {
588 unsafe { 588 unsafe {
589 unborrow_and_degrade!(ch0, ch1, ch2); 589 into_degraded_ref!(ch0, ch1, ch2);
590 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None) 590 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), None)
591 } 591 }
592 } 592 }
@@ -594,24 +594,24 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
594 /// Create a new 4-channel PWM 594 /// Create a new 4-channel PWM
595 #[allow(unused_unsafe)] 595 #[allow(unused_unsafe)]
596 pub fn new_4ch( 596 pub fn new_4ch(
597 pwm: impl Unborrow<Target = T> + 'd, 597 pwm: impl Peripheral<P = T> + 'd,
598 ch0: impl Unborrow<Target = impl GpioPin> + 'd, 598 ch0: impl Peripheral<P = impl GpioPin> + 'd,
599 ch1: impl Unborrow<Target = impl GpioPin> + 'd, 599 ch1: impl Peripheral<P = impl GpioPin> + 'd,
600 ch2: impl Unborrow<Target = impl GpioPin> + 'd, 600 ch2: impl Peripheral<P = impl GpioPin> + 'd,
601 ch3: impl Unborrow<Target = impl GpioPin> + 'd, 601 ch3: impl Peripheral<P = impl GpioPin> + 'd,
602 ) -> Self { 602 ) -> Self {
603 unsafe { 603 unsafe {
604 unborrow_and_degrade!(ch0, ch1, ch2, ch3); 604 into_degraded_ref!(ch0, ch1, ch2, ch3);
605 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3)) 605 Self::new_inner(pwm, Some(ch0), Some(ch1), Some(ch2), Some(ch3))
606 } 606 }
607 } 607 }
608 608
609 fn new_inner( 609 fn new_inner(
610 _pwm: impl Unborrow<Target = T> + 'd, 610 _pwm: impl Peripheral<P = T> + 'd,
611 ch0: Option<Unborrowed<'d, AnyPin>>, 611 ch0: Option<PeripheralRef<'d, AnyPin>>,
612 ch1: Option<Unborrowed<'d, AnyPin>>, 612 ch1: Option<PeripheralRef<'d, AnyPin>>,
613 ch2: Option<Unborrowed<'d, AnyPin>>, 613 ch2: Option<PeripheralRef<'d, AnyPin>>,
614 ch3: Option<Unborrowed<'d, AnyPin>>, 614 ch3: Option<PeripheralRef<'d, AnyPin>>,
615 ) -> Self { 615 ) -> Self {
616 let r = T::regs(); 616 let r = T::regs();
617 617
@@ -799,7 +799,7 @@ pub(crate) mod sealed {
799 } 799 }
800} 800}
801 801
802pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { 802pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
803 type Interrupt: Interrupt; 803 type Interrupt: Interrupt;
804} 804}
805 805
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs
index da4f12606..2fb31fc2d 100644
--- a/embassy-nrf/src/qdec.rs
+++ b/embassy-nrf/src/qdec.rs
@@ -4,14 +4,14 @@ use core::marker::PhantomData;
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::{unborrow, Unborrowed}; 7use embassy_hal_common::{into_ref, PeripheralRef};
8use futures::future::poll_fn; 8use futures::future::poll_fn;
9 9
10use crate::gpio::sealed::Pin as _; 10use crate::gpio::sealed::Pin as _;
11use crate::gpio::{AnyPin, Pin as GpioPin}; 11use crate::gpio::{AnyPin, Pin as GpioPin};
12use crate::interrupt::InterruptExt; 12use crate::interrupt::InterruptExt;
13use crate::peripherals::QDEC; 13use crate::peripherals::QDEC;
14use crate::{interrupt, pac, Unborrow}; 14use crate::{interrupt, pac, Peripheral};
15 15
16/// Quadrature decoder 16/// Quadrature decoder
17pub struct Qdec<'d> { 17pub struct Qdec<'d> {
@@ -43,37 +43,37 @@ static WAKER: AtomicWaker = AtomicWaker::new();
43 43
44impl<'d> Qdec<'d> { 44impl<'d> Qdec<'d> {
45 pub fn new( 45 pub fn new(
46 qdec: impl Unborrow<Target = QDEC> + 'd, 46 qdec: impl Peripheral<P = QDEC> + 'd,
47 irq: impl Unborrow<Target = interrupt::QDEC> + 'd, 47 irq: impl Peripheral<P = interrupt::QDEC> + 'd,
48 a: impl Unborrow<Target = impl GpioPin> + 'd, 48 a: impl Peripheral<P = impl GpioPin> + 'd,
49 b: impl Unborrow<Target = impl GpioPin> + 'd, 49 b: impl Peripheral<P = impl GpioPin> + 'd,
50 config: Config, 50 config: Config,
51 ) -> Self { 51 ) -> Self {
52 unborrow_and_degrade!(a, b); 52 into_degraded_ref!(a, b);
53 Self::new_inner(qdec, irq, a, b, None, config) 53 Self::new_inner(qdec, irq, a, b, None, config)
54 } 54 }
55 55
56 pub fn new_with_led( 56 pub fn new_with_led(
57 qdec: impl Unborrow<Target = QDEC> + 'd, 57 qdec: impl Peripheral<P = QDEC> + 'd,
58 irq: impl Unborrow<Target = interrupt::QDEC> + 'd, 58 irq: impl Peripheral<P = interrupt::QDEC> + 'd,
59 a: impl Unborrow<Target = impl GpioPin> + 'd, 59 a: impl Peripheral<P = impl GpioPin> + 'd,
60 b: impl Unborrow<Target = impl GpioPin> + 'd, 60 b: impl Peripheral<P = impl GpioPin> + 'd,
61 led: impl Unborrow<Target = impl GpioPin> + 'd, 61 led: impl Peripheral<P = impl GpioPin> + 'd,
62 config: Config, 62 config: Config,
63 ) -> Self { 63 ) -> Self {
64 unborrow_and_degrade!(a, b, led); 64 into_degraded_ref!(a, b, led);
65 Self::new_inner(qdec, irq, a, b, Some(led), config) 65 Self::new_inner(qdec, irq, a, b, Some(led), config)
66 } 66 }
67 67
68 fn new_inner( 68 fn new_inner(
69 _t: impl Unborrow<Target = QDEC> + 'd, 69 _t: impl Peripheral<P = QDEC> + 'd,
70 irq: impl Unborrow<Target = interrupt::QDEC> + 'd, 70 irq: impl Peripheral<P = interrupt::QDEC> + 'd,
71 a: Unborrowed<'d, AnyPin>, 71 a: PeripheralRef<'d, AnyPin>,
72 b: Unborrowed<'d, AnyPin>, 72 b: PeripheralRef<'d, AnyPin>,
73 led: Option<Unborrowed<'d, AnyPin>>, 73 led: Option<PeripheralRef<'d, AnyPin>>,
74 config: Config, 74 config: Config,
75 ) -> Self { 75 ) -> Self {
76 unborrow!(irq); 76 into_ref!(irq);
77 let r = Self::regs(); 77 let r = Self::regs();
78 78
79 // Select pins. 79 // Select pins.
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 2b987b465..51d9446a3 100644
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -4,7 +4,7 @@ use core::ptr;
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_hal_common::drop::DropBomb; 6use embassy_hal_common::drop::DropBomb;
7use embassy_hal_common::{unborrow, Unborrowed}; 7use embassy_hal_common::{into_ref, PeripheralRef};
8use futures::future::poll_fn; 8use futures::future::poll_fn;
9 9
10use crate::gpio::sealed::Pin as _; 10use crate::gpio::sealed::Pin as _;
@@ -13,7 +13,7 @@ use crate::interrupt::{Interrupt, InterruptExt};
13pub use crate::pac::qspi::ifconfig0::{ 13pub use crate::pac::qspi::ifconfig0::{
14 ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode, 14 ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode,
15}; 15};
16use crate::{pac, Unborrow}; 16use crate::{pac, Peripheral};
17 17
18// TODO 18// TODO
19// - config: 19// - config:
@@ -62,27 +62,27 @@ pub enum Error {
62} 62}
63 63
64pub struct Qspi<'d, T: Instance, const FLASH_SIZE: usize> { 64pub struct Qspi<'d, T: Instance, const FLASH_SIZE: usize> {
65 irq: Unborrowed<'d, T::Interrupt>, 65 irq: PeripheralRef<'d, T::Interrupt>,
66 dpm_enabled: bool, 66 dpm_enabled: bool,
67} 67}
68 68
69impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { 69impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> {
70 pub fn new( 70 pub fn new(
71 _qspi: impl Unborrow<Target = T> + 'd, 71 _qspi: impl Peripheral<P = T> + 'd,
72 irq: impl Unborrow<Target = T::Interrupt> + 'd, 72 irq: impl Peripheral<P = T::Interrupt> + 'd,
73 sck: impl Unborrow<Target = impl GpioPin> + 'd, 73 sck: impl Peripheral<P = impl GpioPin> + 'd,
74 csn: impl Unborrow<Target = impl GpioPin> + 'd, 74 csn: impl Peripheral<P = impl GpioPin> + 'd,
75 io0: impl Unborrow<Target = impl GpioPin> + 'd, 75 io0: impl Peripheral<P = impl GpioPin> + 'd,
76 io1: impl Unborrow<Target = impl GpioPin> + 'd, 76 io1: impl Peripheral<P = impl GpioPin> + 'd,
77 io2: impl Unborrow<Target = impl GpioPin> + 'd, 77 io2: impl Peripheral<P = impl GpioPin> + 'd,
78 io3: impl Unborrow<Target = impl GpioPin> + 'd, 78 io3: impl Peripheral<P = impl GpioPin> + 'd,
79 config: Config, 79 config: Config,
80 ) -> Qspi<'d, T, FLASH_SIZE> { 80 ) -> Qspi<'d, T, FLASH_SIZE> {
81 unborrow!(irq, sck, csn, io0, io1, io2, io3); 81 into_ref!(irq, sck, csn, io0, io1, io2, io3);
82 82
83 let r = T::regs(); 83 let r = T::regs();
84 84
85 unborrow_and_degrade!(sck, csn, io0, io1, io2, io3); 85 into_degraded_ref!(sck, csn, io0, io1, io2, io3);
86 86
87 for pin in [&sck, &csn, &io0, &io1, &io2, &io3] { 87 for pin in [&sck, &csn, &io0, &io1, &io2, &io3] {
88 pin.set_high(); 88 pin.set_high();
@@ -528,7 +528,7 @@ pub(crate) mod sealed {
528 } 528 }
529} 529}
530 530
531pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { 531pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
532 type Interrupt: Interrupt; 532 type Interrupt: Interrupt;
533} 533}
534 534
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs
index 111a5424b..9bebd6fa3 100644
--- a/embassy-nrf/src/rng.rs
+++ b/embassy-nrf/src/rng.rs
@@ -4,12 +4,12 @@ use core::task::Poll;
4 4
5use embassy::waitqueue::AtomicWaker; 5use embassy::waitqueue::AtomicWaker;
6use embassy_hal_common::drop::OnDrop; 6use embassy_hal_common::drop::OnDrop;
7use embassy_hal_common::{unborrow, Unborrowed}; 7use embassy_hal_common::{into_ref, PeripheralRef};
8use futures::future::poll_fn; 8use futures::future::poll_fn;
9 9
10use crate::interrupt::InterruptExt; 10use crate::interrupt::InterruptExt;
11use crate::peripherals::RNG; 11use crate::peripherals::RNG;
12use crate::{interrupt, pac, Unborrow}; 12use crate::{interrupt, pac, Peripheral};
13 13
14impl RNG { 14impl RNG {
15 fn regs() -> &'static pac::rng::RegisterBlock { 15 fn regs() -> &'static pac::rng::RegisterBlock {
@@ -33,7 +33,7 @@ struct State {
33/// 33///
34/// It has a non-blocking API, and a blocking api through `rand`. 34/// It has a non-blocking API, and a blocking api through `rand`.
35pub struct Rng<'d> { 35pub struct Rng<'d> {
36 irq: Unborrowed<'d, interrupt::RNG>, 36 irq: PeripheralRef<'d, interrupt::RNG>,
37} 37}
38 38
39impl<'d> Rng<'d> { 39impl<'d> Rng<'d> {
@@ -43,8 +43,8 @@ impl<'d> Rng<'d> {
43 /// e.g. using `mem::forget`. 43 /// e.g. using `mem::forget`.
44 /// 44 ///
45 /// The synchronous API is safe. 45 /// The synchronous API is safe.
46 pub fn new(_rng: impl Unborrow<Target = RNG> + 'd, irq: impl Unborrow<Target = interrupt::RNG> + 'd) -> Self { 46 pub fn new(_rng: impl Peripheral<P = RNG> + 'd, irq: impl Peripheral<P = interrupt::RNG> + 'd) -> Self {
47 unborrow!(irq); 47 into_ref!(irq);
48 48
49 let this = Self { irq }; 49 let this = Self { irq };
50 50
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index 9c7207c84..644ffa1f0 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy::waitqueue::AtomicWaker; 7use embassy::waitqueue::AtomicWaker;
8use embassy_hal_common::{impl_unborrow, unborrow}; 8use embassy_hal_common::{impl_peripheral, into_ref};
9use futures::future::poll_fn; 9use futures::future::poll_fn;
10use pac::{saadc, SAADC}; 10use pac::{saadc, SAADC};
11use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; 11use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A};
@@ -17,7 +17,7 @@ use saadc::resolution::VAL_A;
17use crate::interrupt::InterruptExt; 17use crate::interrupt::InterruptExt;
18use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; 18use crate::ppi::{ConfigurableChannel, Event, Ppi, Task};
19use crate::timer::{Frequency, Instance as TimerInstance, Timer}; 19use crate::timer::{Frequency, Instance as TimerInstance, Timer};
20use crate::{interrupt, pac, peripherals, Unborrow}; 20use crate::{interrupt, pac, peripherals, Peripheral};
21 21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)] 22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23#[cfg_attr(feature = "defmt", derive(defmt::Format))] 23#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -77,7 +77,7 @@ pub struct ChannelConfig<'d> {
77/// internal voltage. 77/// internal voltage.
78pub struct VddInput; 78pub struct VddInput;
79 79
80impl_unborrow!(VddInput); 80impl_peripheral!(VddInput);
81 81
82impl sealed::Input for VddInput { 82impl sealed::Input for VddInput {
83 #[cfg(not(feature = "_nrf9160"))] 83 #[cfg(not(feature = "_nrf9160"))]
@@ -97,7 +97,7 @@ impl Input for VddInput {}
97pub struct VddhDiv5Input; 97pub struct VddhDiv5Input;
98 98
99#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] 99#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
100impl_unborrow!(VddhDiv5Input); 100impl_peripheral!(VddhDiv5Input);
101 101
102#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] 102#[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))]
103impl sealed::Input for VddhDiv5Input { 103impl sealed::Input for VddhDiv5Input {
@@ -113,7 +113,7 @@ pub struct AnyInput {
113 channel: InputChannel, 113 channel: InputChannel,
114} 114}
115 115
116impl_unborrow!(AnyInput); 116impl_peripheral!(AnyInput);
117 117
118impl sealed::Input for AnyInput { 118impl sealed::Input for AnyInput {
119 fn channel(&self) -> InputChannel { 119 fn channel(&self) -> InputChannel {
@@ -125,8 +125,8 @@ impl Input for AnyInput {}
125 125
126impl<'d> ChannelConfig<'d> { 126impl<'d> ChannelConfig<'d> {
127 /// Default configuration for single ended channel sampling. 127 /// Default configuration for single ended channel sampling.
128 pub fn single_ended(input: impl Unborrow<Target = impl Input> + 'd) -> Self { 128 pub fn single_ended(input: impl Peripheral<P = impl Input> + 'd) -> Self {
129 unborrow!(input); 129 into_ref!(input);
130 Self { 130 Self {
131 reference: Reference::INTERNAL, 131 reference: Reference::INTERNAL,
132 gain: Gain::GAIN1_6, 132 gain: Gain::GAIN1_6,
@@ -139,10 +139,10 @@ impl<'d> ChannelConfig<'d> {
139 } 139 }
140 /// Default configuration for differential channel sampling. 140 /// Default configuration for differential channel sampling.
141 pub fn differential( 141 pub fn differential(
142 p_input: impl Unborrow<Target = impl Input> + 'd, 142 p_input: impl Peripheral<P = impl Input> + 'd,
143 n_input: impl Unborrow<Target = impl Input> + 'd, 143 n_input: impl Peripheral<P = impl Input> + 'd,
144 ) -> Self { 144 ) -> Self {
145 unborrow!(p_input, n_input); 145 into_ref!(p_input, n_input);
146 Self { 146 Self {
147 reference: Reference::INTERNAL, 147 reference: Reference::INTERNAL,
148 gain: Gain::GAIN1_6, 148 gain: Gain::GAIN1_6,
@@ -167,12 +167,12 @@ pub enum SamplerState {
167 167
168impl<'d, const N: usize> Saadc<'d, N> { 168impl<'d, const N: usize> Saadc<'d, N> {
169 pub fn new( 169 pub fn new(
170 _saadc: impl Unborrow<Target = peripherals::SAADC> + 'd, 170 _saadc: impl Peripheral<P = peripherals::SAADC> + 'd,
171 irq: impl Unborrow<Target = interrupt::SAADC> + 'd, 171 irq: impl Peripheral<P = interrupt::SAADC> + 'd,
172 config: Config, 172 config: Config,
173 channel_configs: [ChannelConfig; N], 173 channel_configs: [ChannelConfig; N],
174 ) -> Self { 174 ) -> Self {
175 unborrow!(irq); 175 into_ref!(irq);
176 176
177 let r = unsafe { &*SAADC::ptr() }; 177 let r = unsafe { &*SAADC::ptr() };
178 178
@@ -674,7 +674,7 @@ pub(crate) mod sealed {
674} 674}
675 675
676/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal. 676/// An input that can be used as either or negative end of a ADC differential in the SAADC periperhal.
677pub trait Input: sealed::Input + Unborrow<Target = Self> + Sized { 677pub trait Input: sealed::Input + Peripheral<P = Self> + Sized {
678 fn degrade_saadc(self) -> AnyInput { 678 fn degrade_saadc(self) -> AnyInput {
679 AnyInput { 679 AnyInput {
680 channel: self.channel(), 680 channel: self.channel(),
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index 889d04dc0..4bb0f445f 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_embedded_hal::SetConfig; 7use embassy_embedded_hal::SetConfig;
8use embassy_hal_common::{unborrow, Unborrowed}; 8use embassy_hal_common::{into_ref, PeripheralRef};
9pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 9pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
10use futures::future::poll_fn; 10use futures::future::poll_fn;
11pub use pac::spim0::frequency::FREQUENCY_A as Frequency; 11pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
@@ -15,7 +15,7 @@ use crate::gpio::sealed::Pin as _;
15use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; 15use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits};
16use crate::interrupt::{Interrupt, InterruptExt}; 16use crate::interrupt::{Interrupt, InterruptExt};
17use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; 17use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut};
18use crate::{pac, Unborrow}; 18use crate::{pac, Peripheral};
19 19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)] 20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21#[cfg_attr(feature = "defmt", derive(defmt::Format))] 21#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -53,48 +53,48 @@ impl Default for Config {
53 53
54impl<'d, T: Instance> Spim<'d, T> { 54impl<'d, T: Instance> Spim<'d, T> {
55 pub fn new( 55 pub fn new(
56 spim: impl Unborrow<Target = T> + 'd, 56 spim: impl Peripheral<P = T> + 'd,
57 irq: impl Unborrow<Target = T::Interrupt> + 'd, 57 irq: impl Peripheral<P = T::Interrupt> + 'd,
58 sck: impl Unborrow<Target = impl GpioPin> + 'd, 58 sck: impl Peripheral<P = impl GpioPin> + 'd,
59 miso: impl Unborrow<Target = impl GpioPin> + 'd, 59 miso: impl Peripheral<P = impl GpioPin> + 'd,
60 mosi: impl Unborrow<Target = impl GpioPin> + 'd, 60 mosi: impl Peripheral<P = impl GpioPin> + 'd,
61 config: Config, 61 config: Config,
62 ) -> Self { 62 ) -> Self {
63 unborrow_and_degrade!(sck, miso, mosi); 63 into_degraded_ref!(sck, miso, mosi);
64 Self::new_inner(spim, irq, sck, Some(miso), Some(mosi), config) 64 Self::new_inner(spim, irq, sck, Some(miso), Some(mosi), config)
65 } 65 }
66 66
67 pub fn new_txonly( 67 pub fn new_txonly(
68 spim: impl Unborrow<Target = T> + 'd, 68 spim: impl Peripheral<P = T> + 'd,
69 irq: impl Unborrow<Target = T::Interrupt> + 'd, 69 irq: impl Peripheral<P = T::Interrupt> + 'd,
70 sck: impl Unborrow<Target = impl GpioPin> + 'd, 70 sck: impl Peripheral<P = impl GpioPin> + 'd,
71 mosi: impl Unborrow<Target = impl GpioPin> + 'd, 71 mosi: impl Peripheral<P = impl GpioPin> + 'd,
72 config: Config, 72 config: Config,
73 ) -> Self { 73 ) -> Self {
74 unborrow_and_degrade!(sck, mosi); 74 into_degraded_ref!(sck, mosi);
75 Self::new_inner(spim, irq, sck, None, Some(mosi), config) 75 Self::new_inner(spim, irq, sck, None, Some(mosi), config)
76 } 76 }
77 77
78 pub fn new_rxonly( 78 pub fn new_rxonly(
79 spim: impl Unborrow<Target = T> + 'd, 79 spim: impl Peripheral<P = T> + 'd,
80 irq: impl Unborrow<Target = T::Interrupt> + 'd, 80 irq: impl Peripheral<P = T::Interrupt> + 'd,
81 sck: impl Unborrow<Target = impl GpioPin> + 'd, 81 sck: impl Peripheral<P = impl GpioPin> + 'd,
82 miso: impl Unborrow<Target = impl GpioPin> + 'd, 82 miso: impl Peripheral<P = impl GpioPin> + 'd,
83 config: Config, 83 config: Config,
84 ) -> Self { 84 ) -> Self {
85 unborrow_and_degrade!(sck, miso); 85 into_degraded_ref!(sck, miso);
86 Self::new_inner(spim, irq, sck, Some(miso), None, config) 86 Self::new_inner(spim, irq, sck, Some(miso), None, config)
87 } 87 }
88 88
89 fn new_inner( 89 fn new_inner(
90 _spim: impl Unborrow<Target = T> + 'd, 90 _spim: impl Peripheral<P = T> + 'd,
91 irq: impl Unborrow<Target = T::Interrupt> + 'd, 91 irq: impl Peripheral<P = T::Interrupt> + 'd,
92 sck: Unborrowed<'d, AnyPin>, 92 sck: PeripheralRef<'d, AnyPin>,
93 miso: Option<Unborrowed<'d, AnyPin>>, 93 miso: Option<PeripheralRef<'d, AnyPin>>,
94 mosi: Option<Unborrowed<'d, AnyPin>>, 94 mosi: Option<PeripheralRef<'d, AnyPin>>,
95 config: Config, 95 config: Config,
96 ) -> Self { 96 ) -> Self {
97 unborrow!(irq); 97 into_ref!(irq);
98 98
99 let r = T::regs(); 99 let r = T::regs();
100 100
@@ -379,7 +379,7 @@ pub(crate) mod sealed {
379 } 379 }
380} 380}
381 381
382pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { 382pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
383 type Interrupt: Interrupt; 383 type Interrupt: Interrupt;
384} 384}
385 385
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs
index 0bb82a499..a3b25ce05 100644
--- a/embassy-nrf/src/temp.rs
+++ b/embassy-nrf/src/temp.rs
@@ -4,24 +4,24 @@ use core::task::Poll;
4 4
5use embassy::waitqueue::AtomicWaker; 5use embassy::waitqueue::AtomicWaker;
6use embassy_hal_common::drop::OnDrop; 6use embassy_hal_common::drop::OnDrop;
7use embassy_hal_common::{unborrow, Unborrowed}; 7use embassy_hal_common::{into_ref, PeripheralRef};
8use fixed::types::I30F2; 8use fixed::types::I30F2;
9use futures::future::poll_fn; 9use futures::future::poll_fn;
10 10
11use crate::interrupt::InterruptExt; 11use crate::interrupt::InterruptExt;
12use crate::peripherals::TEMP; 12use crate::peripherals::TEMP;
13use crate::{interrupt, pac, Unborrow}; 13use crate::{interrupt, pac, Peripheral};
14 14
15/// Integrated temperature sensor. 15/// Integrated temperature sensor.
16pub struct Temp<'d> { 16pub struct Temp<'d> {
17 _irq: Unborrowed<'d, interrupt::TEMP>, 17 _irq: PeripheralRef<'d, interrupt::TEMP>,
18} 18}
19 19
20static WAKER: AtomicWaker = AtomicWaker::new(); 20static WAKER: AtomicWaker = AtomicWaker::new();
21 21
22impl<'d> Temp<'d> { 22impl<'d> Temp<'d> {
23 pub fn new(_t: impl Unborrow<Target = TEMP> + 'd, irq: impl Unborrow<Target = interrupt::TEMP> + 'd) -> Self { 23 pub fn new(_t: impl Peripheral<P = TEMP> + 'd, irq: impl Peripheral<P = interrupt::TEMP> + 'd) -> Self {
24 unborrow!(_t, irq); 24 into_ref!(_t, irq);
25 25
26 // Enable interrupt that signals temperature values 26 // Enable interrupt that signals temperature values
27 irq.disable(); 27 irq.disable();
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index c8c36dfae..d7a7c4d70 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -5,12 +5,12 @@ use core::task::Poll;
5 5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::drop::OnDrop; 7use embassy_hal_common::drop::OnDrop;
8use embassy_hal_common::unborrow; 8use embassy_hal_common::into_ref;
9use futures::future::poll_fn; 9use futures::future::poll_fn;
10 10
11use crate::interrupt::{Interrupt, InterruptExt}; 11use crate::interrupt::{Interrupt, InterruptExt};
12use crate::ppi::{Event, Task}; 12use crate::ppi::{Event, Task};
13use crate::{pac, Unborrow}; 13use crate::{pac, Peripheral};
14 14
15pub(crate) mod sealed { 15pub(crate) mod sealed {
16 16
@@ -28,7 +28,7 @@ pub(crate) mod sealed {
28 pub trait TimerType {} 28 pub trait TimerType {}
29} 29}
30 30
31pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { 31pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
32 type Interrupt: Interrupt; 32 type Interrupt: Interrupt;
33} 33}
34pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {} 34pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {}
@@ -99,11 +99,8 @@ pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> {
99} 99}
100 100
101impl<'d, T: Instance> Timer<'d, T, Awaitable> { 101impl<'d, T: Instance> Timer<'d, T, Awaitable> {
102 pub fn new_awaitable( 102 pub fn new_awaitable(timer: impl Peripheral<P = T> + 'd, irq: impl Peripheral<P = T::Interrupt> + 'd) -> Self {
103 timer: impl Unborrow<Target = T> + 'd, 103 into_ref!(irq);
104 irq: impl Unborrow<Target = T::Interrupt> + 'd,
105 ) -> Self {
106 unborrow!(irq);
107 104
108 irq.set_handler(Self::on_interrupt); 105 irq.set_handler(Self::on_interrupt);
109 irq.unpend(); 106 irq.unpend();
@@ -117,7 +114,7 @@ impl<'d, T: Instance> Timer<'d, T, NotAwaitable> {
117 /// 114 ///
118 /// This can be useful for triggering tasks via PPI 115 /// This can be useful for triggering tasks via PPI
119 /// `Uarte` uses this internally. 116 /// `Uarte` uses this internally.
120 pub fn new(timer: impl Unborrow<Target = T> + 'd) -> Self { 117 pub fn new(timer: impl Peripheral<P = T> + 'd) -> Self {
121 Self::new_irqless(timer) 118 Self::new_irqless(timer)
122 } 119 }
123} 120}
@@ -126,7 +123,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> {
126 /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work. 123 /// Create a `Timer` without an interrupt, meaning `Cc::wait` won't work.
127 /// 124 ///
128 /// This is used by the public constructors. 125 /// This is used by the public constructors.
129 fn new_irqless(_timer: impl Unborrow<Target = T> + 'd) -> Self { 126 fn new_irqless(_timer: impl Peripheral<P = T> + 'd) -> Self {
130 let regs = T::regs(); 127 let regs = T::regs();
131 128
132 let mut this = Self { phantom: PhantomData }; 129 let mut this = Self { phantom: PhantomData };
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 2088691b2..7699d2a71 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -16,14 +16,14 @@ use core::task::Poll;
16use embassy::time::{Duration, Instant}; 16use embassy::time::{Duration, Instant};
17use embassy::waitqueue::AtomicWaker; 17use embassy::waitqueue::AtomicWaker;
18use embassy_embedded_hal::SetConfig; 18use embassy_embedded_hal::SetConfig;
19use embassy_hal_common::unborrow; 19use embassy_hal_common::into_ref;
20use futures::future::poll_fn; 20use futures::future::poll_fn;
21 21
22use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 22use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
23use crate::gpio::Pin as GpioPin; 23use crate::gpio::Pin as GpioPin;
24use crate::interrupt::{Interrupt, InterruptExt}; 24use crate::interrupt::{Interrupt, InterruptExt};
25use crate::util::{slice_in_ram, slice_in_ram_or}; 25use crate::util::{slice_in_ram, slice_in_ram_or};
26use crate::{gpio, pac, Unborrow}; 26use crate::{gpio, pac, Peripheral};
27 27
28#[derive(Clone, Copy)] 28#[derive(Clone, Copy)]
29pub enum Frequency { 29pub enum Frequency {
@@ -80,13 +80,13 @@ pub struct Twim<'d, T: Instance> {
80 80
81impl<'d, T: Instance> Twim<'d, T> { 81impl<'d, T: Instance> Twim<'d, T> {
82 pub fn new( 82 pub fn new(
83 _twim: impl Unborrow<Target = T> + 'd, 83 _twim: impl Peripheral<P = T> + 'd,
84 irq: impl Unborrow<Target = T::Interrupt> + 'd, 84 irq: impl Peripheral<P = T::Interrupt> + 'd,
85 sda: impl Unborrow<Target = impl GpioPin> + 'd, 85 sda: impl Peripheral<P = impl GpioPin> + 'd,
86 scl: impl Unborrow<Target = impl GpioPin> + 'd, 86 scl: impl Peripheral<P = impl GpioPin> + 'd,
87 config: Config, 87 config: Config,
88 ) -> Self { 88 ) -> Self {
89 unborrow!(irq, sda, scl); 89 into_ref!(irq, sda, scl);
90 90
91 let r = T::regs(); 91 let r = T::regs();
92 92
@@ -707,7 +707,7 @@ pub(crate) mod sealed {
707 } 707 }
708} 708}
709 709
710pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { 710pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static {
711 type Interrupt: Interrupt; 711 type Interrupt: Interrupt;
712} 712}
713 713
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index d5ffb3159..a556d6b9c 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -18,7 +18,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
18use core::task::Poll; 18use core::task::Poll;
19 19
20use embassy_hal_common::drop::OnDrop; 20use embassy_hal_common::drop::OnDrop;
21use embassy_hal_common::{unborrow, Unborrowed}; 21use embassy_hal_common::{into_ref, PeripheralRef};
22use futures::future::poll_fn; 22use futures::future::poll_fn;
23use pac::uarte0::RegisterBlock; 23use pac::uarte0::RegisterBlock;
24// Re-export SVD variants to allow user to directly set values. 24// Re-export SVD variants to allow user to directly set values.
@@ -31,7 +31,7 @@ use crate::interrupt::{Interrupt, InterruptExt};
31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
32use crate::timer::{Frequency, Instance as TimerInstance, Timer}; 32use crate::timer::{Frequency, Instance as TimerInstance, Timer};
33use crate::util::slice_in_ram_or; 33use crate::util::slice_in_ram_or;
34use crate::{pac, Unborrow}; 34use crate::{pac, Peripheral};
35 35
36#[derive(Clone)] 36#[derive(Clone)]
37#[non_exhaustive] 37#[non_exhaustive]
@@ -83,40 +83,40 @@ pub struct UarteRx<'d, T: Instance> {
83impl<'d, T: Instance> Uarte<'d, T> { 83impl<'d, T: Instance> Uarte<'d, T> {
84 /// Create a new UARTE without hardware flow control 84 /// Create a new UARTE without hardware flow control
85 pub fn new( 85 pub fn new(
86 uarte: impl Unborrow<Target = T> + 'd, 86 uarte: impl Peripheral<P = T> + 'd,
87 irq: impl Unborrow<Target = T::Interrupt> + 'd, 87 irq: impl Peripheral<P = T::Interrupt> + 'd,
88 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 88 rxd: impl Peripheral<P = impl GpioPin> + 'd,
89 txd: impl Unborrow<Target = impl GpioPin> + 'd, 89 txd: impl Peripheral<P = impl GpioPin> + 'd,
90 config: Config, 90 config: Config,
91 ) -> Self { 91 ) -> Self {
92 unborrow_and_degrade!(rxd, txd); 92 into_degraded_ref!(rxd, txd);
93 Self::new_inner(uarte, irq, rxd, txd, None, None, config) 93 Self::new_inner(uarte, irq, rxd, txd, None, None, config)
94 } 94 }
95 95
96 /// Create a new UARTE with hardware flow control (RTS/CTS) 96 /// Create a new UARTE with hardware flow control (RTS/CTS)
97 pub fn new_with_rtscts( 97 pub fn new_with_rtscts(
98 uarte: impl Unborrow<Target = T> + 'd, 98 uarte: impl Peripheral<P = T> + 'd,
99 irq: impl Unborrow<Target = T::Interrupt> + 'd, 99 irq: impl Peripheral<P = T::Interrupt> + 'd,
100 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 100 rxd: impl Peripheral<P = impl GpioPin> + 'd,
101 txd: impl Unborrow<Target = impl GpioPin> + 'd, 101 txd: impl Peripheral<P = impl GpioPin> + 'd,
102 cts: impl Unborrow<Target = impl GpioPin> + 'd, 102 cts: impl Peripheral<P = impl GpioPin> + 'd,
103 rts: impl Unborrow<Target = impl GpioPin> + 'd, 103 rts: impl Peripheral<P = impl GpioPin> + 'd,
104 config: Config, 104 config: Config,
105 ) -> Self { 105 ) -> Self {
106 unborrow_and_degrade!(rxd, txd, cts, rts); 106 into_degraded_ref!(rxd, txd, cts, rts);
107 Self::new_inner(uarte, irq, rxd, txd, Some(cts), Some(rts), config) 107 Self::new_inner(uarte, irq, rxd, txd, Some(cts), Some(rts), config)
108 } 108 }
109 109
110 fn new_inner( 110 fn new_inner(
111 _uarte: impl Unborrow<Target = T> + 'd, 111 _uarte: impl Peripheral<P = T> + 'd,
112 irq: impl Unborrow<Target = T::Interrupt> + 'd, 112 irq: impl Peripheral<P = T::Interrupt> + 'd,
113 rxd: Unborrowed<'d, AnyPin>, 113 rxd: PeripheralRef<'d, AnyPin>,
114 txd: Unborrowed<'d, AnyPin>, 114 txd: PeripheralRef<'d, AnyPin>,
115 cts: Option<Unborrowed<'d, AnyPin>>, 115 cts: Option<PeripheralRef<'d, AnyPin>>,
116 rts: Option<Unborrowed<'d, AnyPin>>, 116 rts: Option<PeripheralRef<'d, AnyPin>>,
117 config: Config, 117 config: Config,
118 ) -> Self { 118 ) -> Self {
119 unborrow!(irq); 119 into_ref!(irq);
120 120
121 let r = T::regs(); 121 let r = T::regs();
122 122
@@ -237,35 +237,35 @@ fn configure(r: &RegisterBlock, config: Config, hardware_flow_control: bool) {
237impl<'d, T: Instance> UarteTx<'d, T> { 237impl<'d, T: Instance> UarteTx<'d, T> {
238 /// Create a new tx-only UARTE without hardware flow control 238 /// Create a new tx-only UARTE without hardware flow control
239 pub fn new( 239 pub fn new(
240 uarte: impl Unborrow<Target = T> + 'd, 240 uarte: impl Peripheral<P = T> + 'd,
241 irq: impl Unborrow<Target = T::Interrupt> + 'd, 241 irq: impl Peripheral<P = T::Interrupt> + 'd,
242 txd: impl Unborrow<Target = impl GpioPin> + 'd, 242 txd: impl Peripheral<P = impl GpioPin> + 'd,
243 config: Config, 243 config: Config,
244 ) -> Self { 244 ) -> Self {
245 unborrow_and_degrade!(txd); 245 into_degraded_ref!(txd);
246 Self::new_inner(uarte, irq, txd, None, config) 246 Self::new_inner(uarte, irq, txd, None, config)
247 } 247 }
248 248
249 /// Create a new tx-only UARTE with hardware flow control (RTS/CTS) 249 /// Create a new tx-only UARTE with hardware flow control (RTS/CTS)
250 pub fn new_with_rtscts( 250 pub fn new_with_rtscts(
251 uarte: impl Unborrow<Target = T> + 'd, 251 uarte: impl Peripheral<P = T> + 'd,
252 irq: impl Unborrow<Target = T::Interrupt> + 'd, 252 irq: impl Peripheral<P = T::Interrupt> + 'd,
253 txd: impl Unborrow<Target = impl GpioPin> + 'd, 253 txd: impl Peripheral<P = impl GpioPin> + 'd,
254 cts: impl Unborrow<Target = impl GpioPin> + 'd, 254 cts: impl Peripheral<P = impl GpioPin> + 'd,
255 config: Config, 255 config: Config,
256 ) -> Self { 256 ) -> Self {
257 unborrow_and_degrade!(txd, cts); 257 into_degraded_ref!(txd, cts);
258 Self::new_inner(uarte, irq, txd, Some(cts), config) 258 Self::new_inner(uarte, irq, txd, Some(cts), config)
259 } 259 }
260 260
261 fn new_inner( 261 fn new_inner(
262 _uarte: impl Unborrow<Target = T> + 'd, 262 _uarte: impl Peripheral<P = T> + 'd,
263 irq: impl Unborrow<Target = T::Interrupt> + 'd, 263 irq: impl Peripheral<P = T::Interrupt> + 'd,
264 txd: Unborrowed<'d, AnyPin>, 264 txd: PeripheralRef<'d, AnyPin>,
265 cts: Option<Unborrowed<'d, AnyPin>>, 265 cts: Option<PeripheralRef<'d, AnyPin>>,
266 config: Config, 266 config: Config,
267 ) -> Self { 267 ) -> Self {
268 unborrow!(irq); 268 into_ref!(irq);
269 269
270 let r = T::regs(); 270 let r = T::regs();
271 271
@@ -429,35 +429,35 @@ impl<'a, T: Instance> Drop for UarteTx<'a, T> {
429impl<'d, T: Instance> UarteRx<'d, T> { 429impl<'d, T: Instance> UarteRx<'d, T> {
430 /// Create a new rx-only UARTE without hardware flow control 430 /// Create a new rx-only UARTE without hardware flow control
431 pub fn new( 431 pub fn new(
432 uarte: impl Unborrow<Target = T> + 'd, 432 uarte: impl Peripheral<P = T> + 'd,
433 irq: impl Unborrow<Target = T::Interrupt> + 'd, 433 irq: impl Peripheral<P = T::Interrupt> + 'd,
434 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 434 rxd: impl Peripheral<P = impl GpioPin> + 'd,
435 config: Config, 435 config: Config,
436 ) -> Self { 436 ) -> Self {
437 unborrow_and_degrade!(rxd); 437 into_degraded_ref!(rxd);
438 Self::new_inner(uarte, irq, rxd, None, config) 438 Self::new_inner(uarte, irq, rxd, None, config)
439 } 439 }
440 440
441 /// Create a new rx-only UARTE with hardware flow control (RTS/CTS) 441 /// Create a new rx-only UARTE with hardware flow control (RTS/CTS)
442 pub fn new_with_rtscts( 442 pub fn new_with_rtscts(
443 uarte: impl Unborrow<Target = T> + 'd, 443 uarte: impl Peripheral<P = T> + 'd,
444 irq: impl Unborrow<Target = T::Interrupt> + 'd, 444 irq: impl Peripheral<P = T::Interrupt> + 'd,
445 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 445 rxd: impl Peripheral<P = impl GpioPin> + 'd,
446 rts: impl Unborrow<Target = impl GpioPin> + 'd, 446 rts: impl Peripheral<P = impl GpioPin> + 'd,
447 config: Config, 447 config: Config,
448 ) -> Self { 448 ) -> Self {
449 unborrow_and_degrade!(rxd, rts); 449 into_degraded_ref!(rxd, rts);
450 Self::new_inner(uarte, irq, rxd, Some(rts), config) 450 Self::new_inner(uarte, irq, rxd, Some(rts), config)
451 } 451 }
452 452
453 fn new_inner( 453 fn new_inner(
454 _uarte: impl Unborrow<Target = T> + 'd, 454 _uarte: impl Peripheral<P = T> + 'd,
455 irq: impl Unborrow<Target = T::Interrupt> + 'd, 455 irq: impl Peripheral<P = T::Interrupt> + 'd,
456 rxd: Unborrowed<'d, AnyPin>, 456 rxd: PeripheralRef<'d, AnyPin>,
457 rts: Option<Unborrowed<'d, AnyPin>>, 457 rts: Option<PeripheralRef<'d, AnyPin>>,
458 config: Config, 458 config: Config,
459 ) -> Self { 459 ) -> Self {
460 unborrow!(irq); 460 into_ref!(irq);
461 461
462 let r = T::regs(); 462 let r = T::regs();
463 463
@@ -668,33 +668,33 @@ pub struct UarteWithIdle<'d, U: Instance, T: TimerInstance> {
668impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> { 668impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
669 /// Create a new UARTE without hardware flow control 669 /// Create a new UARTE without hardware flow control
670 pub fn new( 670 pub fn new(
671 uarte: impl Unborrow<Target = U> + 'd, 671 uarte: impl Peripheral<P = U> + 'd,
672 timer: impl Unborrow<Target = T> + 'd, 672 timer: impl Peripheral<P = T> + 'd,
673 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 673 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
674 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 674 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
675 irq: impl Unborrow<Target = U::Interrupt> + 'd, 675 irq: impl Peripheral<P = U::Interrupt> + 'd,
676 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 676 rxd: impl Peripheral<P = impl GpioPin> + 'd,
677 txd: impl Unborrow<Target = impl GpioPin> + 'd, 677 txd: impl Peripheral<P = impl GpioPin> + 'd,
678 config: Config, 678 config: Config,
679 ) -> Self { 679 ) -> Self {
680 unborrow_and_degrade!(rxd, txd); 680 into_degraded_ref!(rxd, txd);
681 Self::new_inner(uarte, timer, ppi_ch1, ppi_ch2, irq, rxd, txd, None, None, config) 681 Self::new_inner(uarte, timer, ppi_ch1, ppi_ch2, irq, rxd, txd, None, None, config)
682 } 682 }
683 683
684 /// Create a new UARTE with hardware flow control (RTS/CTS) 684 /// Create a new UARTE with hardware flow control (RTS/CTS)
685 pub fn new_with_rtscts( 685 pub fn new_with_rtscts(
686 uarte: impl Unborrow<Target = U> + 'd, 686 uarte: impl Peripheral<P = U> + 'd,
687 timer: impl Unborrow<Target = T> + 'd, 687 timer: impl Peripheral<P = T> + 'd,
688 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 688 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
689 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 689 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
690 irq: impl Unborrow<Target = U::Interrupt> + 'd, 690 irq: impl Peripheral<P = U::Interrupt> + 'd,
691 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 691 rxd: impl Peripheral<P = impl GpioPin> + 'd,
692 txd: impl Unborrow<Target = impl GpioPin> + 'd, 692 txd: impl Peripheral<P = impl GpioPin> + 'd,
693 cts: impl Unborrow<Target = impl GpioPin> + 'd, 693 cts: impl Peripheral<P = impl GpioPin> + 'd,
694 rts: impl Unborrow<Target = impl GpioPin> + 'd, 694 rts: impl Peripheral<P = impl GpioPin> + 'd,
695 config: Config, 695 config: Config,
696 ) -> Self { 696 ) -> Self {
697 unborrow_and_degrade!(rxd, txd, cts, rts); 697 into_degraded_ref!(rxd, txd, cts, rts);
698 Self::new_inner( 698 Self::new_inner(
699 uarte, 699 uarte,
700 timer, 700 timer,
@@ -710,15 +710,15 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
710 } 710 }
711 711
712 fn new_inner( 712 fn new_inner(
713 uarte: impl Unborrow<Target = U> + 'd, 713 uarte: impl Peripheral<P = U> + 'd,
714 timer: impl Unborrow<Target = T> + 'd, 714 timer: impl Peripheral<P = T> + 'd,
715 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 715 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
716 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 716 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
717 irq: impl Unborrow<Target = U::Interrupt> + 'd, 717 irq: impl Peripheral<P = U::Interrupt> + 'd,
718 rxd: Unborrowed<'d, AnyPin>, 718 rxd: PeripheralRef<'d, AnyPin>,
719 txd: Unborrowed<'d, AnyPin>, 719 txd: PeripheralRef<'d, AnyPin>,
720 cts: Option<Unborrowed<'d, AnyPin>>, 720 cts: Option<PeripheralRef<'d, AnyPin>>,
721 rts: Option<Unborrowed<'d, AnyPin>>, 721 rts: Option<PeripheralRef<'d, AnyPin>>,
722 config: Config, 722 config: Config,
723 ) -> Self { 723 ) -> Self {
724 let baudrate = config.baudrate; 724 let baudrate = config.baudrate;
@@ -726,7 +726,7 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
726 726
727 let mut timer = Timer::new(timer); 727 let mut timer = Timer::new(timer);
728 728
729 unborrow!(ppi_ch1, ppi_ch2); 729 into_ref!(ppi_ch1, ppi_ch2);
730 730
731 let r = U::regs(); 731 let r = U::regs();
732 732
@@ -939,7 +939,7 @@ pub(crate) mod sealed {
939 } 939 }
940} 940}
941 941
942pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { 942pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
943 type Interrupt: Interrupt; 943 type Interrupt: Interrupt;
944} 944}
945 945
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs
index a039427f1..eaecda570 100644
--- a/embassy-nrf/src/usb.rs
+++ b/embassy-nrf/src/usb.rs
@@ -7,7 +7,7 @@ use core::task::Poll;
7 7
8use cortex_m::peripheral::NVIC; 8use cortex_m::peripheral::NVIC;
9use embassy::waitqueue::AtomicWaker; 9use embassy::waitqueue::AtomicWaker;
10use embassy_hal_common::unborrow; 10use embassy_hal_common::into_ref;
11pub use embassy_usb; 11pub use embassy_usb;
12use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; 12use embassy_usb::driver::{self, EndpointError, Event, Unsupported};
13use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; 13use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection};
@@ -17,7 +17,7 @@ use pac::usbd::RegisterBlock;
17 17
18use crate::interrupt::{Interrupt, InterruptExt}; 18use crate::interrupt::{Interrupt, InterruptExt};
19use crate::util::slice_in_ram; 19use crate::util::slice_in_ram;
20use crate::{pac, Unborrow}; 20use crate::{pac, Peripheral};
21 21
22const NEW_AW: AtomicWaker = AtomicWaker::new(); 22const NEW_AW: AtomicWaker = AtomicWaker::new();
23static BUS_WAKER: AtomicWaker = NEW_AW; 23static BUS_WAKER: AtomicWaker = NEW_AW;
@@ -166,12 +166,8 @@ impl UsbSupply for SignalledSupply {
166} 166}
167 167
168impl<'d, T: Instance, P: UsbSupply> Driver<'d, T, P> { 168impl<'d, T: Instance, P: UsbSupply> Driver<'d, T, P> {
169 pub fn new( 169 pub fn new(_usb: impl Peripheral<P = T> + 'd, irq: impl Peripheral<P = T::Interrupt> + 'd, usb_supply: P) -> Self {
170 _usb: impl Unborrow<Target = T> + 'd, 170 into_ref!(irq);
171 irq: impl Unborrow<Target = T::Interrupt> + 'd,
172 usb_supply: P,
173 ) -> Self {
174 unborrow!(irq);
175 irq.set_handler(Self::on_interrupt); 171 irq.set_handler(Self::on_interrupt);
176 irq.unpend(); 172 irq.unpend();
177 irq.enable(); 173 irq.enable();
@@ -950,7 +946,7 @@ pub(crate) mod sealed {
950 } 946 }
951} 947}
952 948
953pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { 949pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
954 type Interrupt: Interrupt; 950 type Interrupt: Interrupt;
955} 951}
956 952