diff options
62 files changed, 970 insertions, 918 deletions
diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index 715f00381..7358caa46 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs | |||
| @@ -3,7 +3,7 @@ use core::{mem, ptr}; | |||
| 3 | 3 | ||
| 4 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; | 4 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; |
| 5 | use cortex_m::peripheral::NVIC; | 5 | use cortex_m::peripheral::NVIC; |
| 6 | use embassy_hal_common::Unborrow; | 6 | use embassy_hal_common::Peripheral; |
| 7 | pub use embassy_macros::cortex_m_interrupt_take as take; | 7 | pub use embassy_macros::cortex_m_interrupt_take as take; |
| 8 | 8 | ||
| 9 | /// Implementation detail, do not use outside embassy crates. | 9 | /// Implementation detail, do not use outside embassy crates. |
| @@ -32,7 +32,7 @@ unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { | |||
| 32 | 32 | ||
| 33 | /// Represents an interrupt type that can be configured by embassy to handle | 33 | /// Represents an interrupt type that can be configured by embassy to handle |
| 34 | /// interrupts. | 34 | /// interrupts. |
| 35 | pub unsafe trait Interrupt: Unborrow<Target = Self> { | 35 | pub unsafe trait Interrupt: Peripheral<P = Self> { |
| 36 | /// Return the NVIC interrupt number for this interrupt. | 36 | /// Return the NVIC interrupt number for this interrupt. |
| 37 | fn number(&self) -> u16; | 37 | fn number(&self) -> u16; |
| 38 | /// Steal an instance of this interrupt | 38 | /// Steal an instance of this interrupt |
diff --git a/embassy-cortex-m/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs index c5fa20e71..e2f295579 100644 --- a/embassy-cortex-m/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs | |||
| @@ -3,7 +3,7 @@ use core::mem::MaybeUninit; | |||
| 3 | 3 | ||
| 4 | use cortex_m::peripheral::scb::VectActive; | 4 | use cortex_m::peripheral::scb::VectActive; |
| 5 | use cortex_m::peripheral::{NVIC, SCB}; | 5 | use cortex_m::peripheral::{NVIC, SCB}; |
| 6 | use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; | 6 | use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 7 | 7 | ||
| 8 | use crate::interrupt::{Interrupt, InterruptExt, Priority}; | 8 | use crate::interrupt::{Interrupt, InterruptExt, Priority}; |
| 9 | 9 | ||
| @@ -33,7 +33,7 @@ impl<S> StateStorage<S> { | |||
| 33 | /// a safe way. | 33 | /// a safe way. |
| 34 | pub struct PeripheralMutex<'a, S: PeripheralState> { | 34 | pub struct PeripheralMutex<'a, S: PeripheralState> { |
| 35 | state: *mut S, | 35 | state: *mut S, |
| 36 | irq: Unborrowed<'a, S::Interrupt>, | 36 | irq: PeripheralRef<'a, S::Interrupt>, |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /// Whether `irq` can be preempted by the current interrupt. | 39 | /// Whether `irq` can be preempted by the current interrupt. |
| @@ -62,11 +62,11 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { | |||
| 62 | /// | 62 | /// |
| 63 | /// Registers `on_interrupt` as the `irq`'s handler, and enables it. | 63 | /// Registers `on_interrupt` as the `irq`'s handler, and enables it. |
| 64 | pub fn new( | 64 | pub fn new( |
| 65 | irq: impl Unborrow<Target = S::Interrupt> + 'a, | 65 | irq: impl Peripheral<P = S::Interrupt> + 'a, |
| 66 | storage: &'a mut StateStorage<S>, | 66 | storage: &'a mut StateStorage<S>, |
| 67 | init: impl FnOnce() -> S, | 67 | init: impl FnOnce() -> S, |
| 68 | ) -> Self { | 68 | ) -> Self { |
| 69 | unborrow!(irq); | 69 | into_ref!(irq); |
| 70 | 70 | ||
| 71 | if can_be_preempted(&*irq) { | 71 | if can_be_preempted(&*irq) { |
| 72 | panic!( | 72 | panic!( |
diff --git a/embassy-hal-common/src/lib.rs b/embassy-hal-common/src/lib.rs index da7ae9919..d3d9e0a84 100644 --- a/embassy-hal-common/src/lib.rs +++ b/embassy-hal-common/src/lib.rs | |||
| @@ -6,10 +6,10 @@ pub(crate) mod fmt; | |||
| 6 | 6 | ||
| 7 | pub mod drop; | 7 | pub mod drop; |
| 8 | mod macros; | 8 | mod macros; |
| 9 | mod peripheral; | ||
| 9 | pub mod ratio; | 10 | pub mod ratio; |
| 10 | pub mod ring_buffer; | 11 | pub mod ring_buffer; |
| 11 | mod unborrow; | 12 | pub use peripheral::{Peripheral, PeripheralRef}; |
| 12 | pub use unborrow::{Unborrow, Unborrowed}; | ||
| 13 | 13 | ||
| 14 | /// Low power blocking wait loop using WFE/SEV. | 14 | /// Low power blocking wait loop using WFE/SEV. |
| 15 | pub fn low_power_wait_until(mut condition: impl FnMut() -> bool) { | 15 | pub fn low_power_wait_until(mut condition: impl FnMut() -> bool) { |
diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index d8e2a06e7..7af85f782 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs | |||
| @@ -21,7 +21,7 @@ macro_rules! peripherals { | |||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | $(#[$cfg])? | 23 | $(#[$cfg])? |
| 24 | $crate::impl_unborrow!($name); | 24 | $crate::impl_peripheral!($name); |
| 25 | )* | 25 | )* |
| 26 | } | 26 | } |
| 27 | 27 | ||
| @@ -71,22 +71,22 @@ macro_rules! peripherals { | |||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | #[macro_export] | 73 | #[macro_export] |
| 74 | macro_rules! unborrow { | 74 | macro_rules! into_ref { |
| 75 | ($($name:ident),*) => { | 75 | ($($name:ident),*) => { |
| 76 | $( | 76 | $( |
| 77 | let mut $name = $name.unborrow(); | 77 | let mut $name = $name.into_ref(); |
| 78 | )* | 78 | )* |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | #[macro_export] | 82 | #[macro_export] |
| 83 | macro_rules! impl_unborrow { | 83 | macro_rules! impl_peripheral { |
| 84 | ($type:ident) => { | 84 | ($type:ident) => { |
| 85 | impl $crate::Unborrow for $type { | 85 | impl $crate::Peripheral for $type { |
| 86 | type Target = $type; | 86 | type P = $type; |
| 87 | 87 | ||
| 88 | #[inline] | 88 | #[inline] |
| 89 | unsafe fn unborrow_unchecked(&mut self) -> Self::Target { | 89 | unsafe fn clone_unchecked(&mut self) -> Self::P { |
| 90 | $type { ..*self } | 90 | $type { ..*self } |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-hal-common/src/peripheral.rs new file mode 100644 index 000000000..620047382 --- /dev/null +++ b/embassy-hal-common/src/peripheral.rs | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | use core::ops::{Deref, DerefMut}; | ||
| 3 | |||
| 4 | /// An exclusive reference to a peripheral. | ||
| 5 | /// | ||
| 6 | /// This is functionally the same as a `&'a mut T`. The reason for having a | ||
| 7 | /// dedicated struct is memory efficiency: | ||
| 8 | /// | ||
| 9 | /// Peripheral singletons are typically either zero-sized (for concrete peripehrals | ||
| 10 | /// like `PA9` or `Spi4`) or very small (for example `AnyPin` which is 1 byte). | ||
| 11 | /// However `&mut T` is always 4 bytes for 32-bit targets, even if T is zero-sized. | ||
| 12 | /// PeripheralRef stores a copy of `T` instead, so it's the same size. | ||
| 13 | /// | ||
| 14 | /// but it is the size of `T` not the size | ||
| 15 | /// of a pointer. This is useful if T is a zero sized type. | ||
| 16 | pub struct PeripheralRef<'a, T> { | ||
| 17 | inner: T, | ||
| 18 | _lifetime: PhantomData<&'a mut T>, | ||
| 19 | } | ||
| 20 | |||
| 21 | impl<'a, T> PeripheralRef<'a, T> { | ||
| 22 | #[inline] | ||
| 23 | pub fn new(inner: T) -> Self { | ||
| 24 | Self { | ||
| 25 | inner, | ||
| 26 | _lifetime: PhantomData, | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | #[inline] | ||
| 31 | pub fn map_into<U>(self) -> PeripheralRef<'a, U> | ||
| 32 | where | ||
| 33 | T: Into<U>, | ||
| 34 | { | ||
| 35 | PeripheralRef { | ||
| 36 | inner: self.inner.into(), | ||
| 37 | _lifetime: PhantomData, | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | pub unsafe fn into_inner(self) -> T { | ||
| 42 | self.inner | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | impl<'a, T> Deref for PeripheralRef<'a, T> { | ||
| 47 | type Target = T; | ||
| 48 | |||
| 49 | #[inline] | ||
| 50 | fn deref(&self) -> &Self::Target { | ||
| 51 | &self.inner | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | impl<'a, T> DerefMut for PeripheralRef<'a, T> { | ||
| 56 | #[inline] | ||
| 57 | fn deref_mut(&mut self) -> &mut Self::Target { | ||
| 58 | &mut self.inner | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Trait for any type that can be used as a peripheral of type `P`. | ||
| 63 | /// | ||
| 64 | /// This is used in driver constructors, to allow passing either owned peripherals (e.g. `TWISPI0`), | ||
| 65 | /// or borrowed peripherals (e.g. `&mut TWISPI0`). | ||
| 66 | /// | ||
| 67 | /// For example, if you have a driver with a constructor like this: | ||
| 68 | /// | ||
| 69 | /// ```ignore | ||
| 70 | /// impl<'d, T: Instance> Twim<'d, T> { | ||
| 71 | /// pub fn new( | ||
| 72 | /// twim: impl Peripheral<P = T> + 'd, | ||
| 73 | /// irq: impl Peripheral<P = T::Interrupt> + 'd, | ||
| 74 | /// sda: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 75 | /// scl: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 76 | /// config: Config, | ||
| 77 | /// ) -> Self { .. } | ||
| 78 | /// } | ||
| 79 | /// ``` | ||
| 80 | /// | ||
| 81 | /// You may call it with owned peripherals, which yields an instance that can live forever (`'static`): | ||
| 82 | /// | ||
| 83 | /// ```ignore | ||
| 84 | /// let mut twi: Twim<'static, ...> = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); | ||
| 85 | /// ``` | ||
| 86 | /// | ||
| 87 | /// Or you may call it with borrowed peripherals, which yields an instance that can only live for as long | ||
| 88 | /// as the borrows last: | ||
| 89 | /// | ||
| 90 | /// ```ignore | ||
| 91 | /// let mut twi: Twim<'_, ...> = Twim::new(&mut p.TWISPI0, &mut irq, &mut p.P0_03, &mut p.P0_04, config); | ||
| 92 | /// ``` | ||
| 93 | /// | ||
| 94 | /// # Implementation details, for HAL authors | ||
| 95 | /// | ||
| 96 | /// When writing a HAL, the intended way to use this trait is to take `impl Peripheral<P = ..>` in | ||
| 97 | /// the HAL's public API (such as driver constructors), calling `.into_ref()` to obtain a `PeripheralRef`, | ||
| 98 | /// and storing that in the driver struct. | ||
| 99 | /// | ||
| 100 | /// `.into_ref()` on an owned `T` yields a `PeripheralRef<'static, T>`. | ||
| 101 | /// `.into_ref()` on an `&'a mut T` yields a `PeripheralRef<'a, T>`. | ||
| 102 | pub trait Peripheral: Sized { | ||
| 103 | /// Peripheral singleton type | ||
| 104 | type P; | ||
| 105 | |||
| 106 | /// Unsafely clone (duplicate) a peripheral singleton. | ||
| 107 | /// | ||
| 108 | /// # Safety | ||
| 109 | /// | ||
| 110 | /// This returns an owned clone of the peripheral. You must manually ensure | ||
| 111 | /// only one copy of the peripheral is in use at a time. For example, don't | ||
| 112 | /// create two SPI drivers on `SPI1`, because they will "fight" each other. | ||
| 113 | /// | ||
| 114 | /// You should strongly prefer using `into_ref()` instead. It returns a | ||
| 115 | /// `PeripheralRef`, which allows the borrow checker to enforce this at compile time. | ||
| 116 | unsafe fn clone_unchecked(&mut self) -> Self::P; | ||
| 117 | |||
| 118 | /// Convert a value into a `PeripheralRef`. | ||
| 119 | /// | ||
| 120 | /// When called on an owned `T`, yields a `PeripheralRef<'static, T>`. | ||
| 121 | /// When called on an `&'a mut T`, yields a `PeripheralRef<'a, T>`. | ||
| 122 | #[inline] | ||
| 123 | fn into_ref<'a>(mut self) -> PeripheralRef<'a, Self::P> | ||
| 124 | where | ||
| 125 | Self: 'a, | ||
| 126 | { | ||
| 127 | PeripheralRef::new(unsafe { self.clone_unchecked() }) | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | impl<'b, T: DerefMut> Peripheral for T | ||
| 132 | where | ||
| 133 | T::Target: Peripheral, | ||
| 134 | { | ||
| 135 | type P = <T::Target as Peripheral>::P; | ||
| 136 | |||
| 137 | #[inline] | ||
| 138 | unsafe fn clone_unchecked(&mut self) -> Self::P { | ||
| 139 | self.deref_mut().clone_unchecked() | ||
| 140 | } | ||
| 141 | } | ||
diff --git a/embassy-hal-common/src/unborrow.rs b/embassy-hal-common/src/unborrow.rs deleted file mode 100644 index 06e8d0c82..000000000 --- a/embassy-hal-common/src/unborrow.rs +++ /dev/null | |||
| @@ -1,82 +0,0 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | use core::ops::{Deref, DerefMut}; | ||
| 3 | |||
| 4 | /// This is essentially a `&mut T`, but it is the size of `T` not the size | ||
| 5 | /// of a pointer. This is useful if T is a zero sized type. | ||
| 6 | pub struct Unborrowed<'a, T> { | ||
| 7 | inner: T, | ||
| 8 | _lifetime: PhantomData<&'a mut T>, | ||
| 9 | } | ||
| 10 | |||
| 11 | impl<'a, T> Unborrowed<'a, T> { | ||
| 12 | pub fn new(inner: T) -> Self { | ||
| 13 | Self { | ||
| 14 | inner, | ||
| 15 | _lifetime: PhantomData, | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | pub fn map_into<U>(self) -> Unborrowed<'a, U> | ||
| 20 | where | ||
| 21 | T: Into<U>, | ||
| 22 | { | ||
| 23 | Unborrowed { | ||
| 24 | inner: self.inner.into(), | ||
| 25 | _lifetime: PhantomData, | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | pub unsafe fn into_inner(self) -> T { | ||
| 30 | self.inner | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | impl<'a, T> Deref for Unborrowed<'a, T> { | ||
| 35 | type Target = T; | ||
| 36 | |||
| 37 | fn deref(&self) -> &Self::Target { | ||
| 38 | &self.inner | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | impl<'a, T> DerefMut for Unborrowed<'a, T> { | ||
| 43 | fn deref_mut(&mut self) -> &mut Self::Target { | ||
| 44 | &mut self.inner | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | /// Unsafely unborrow an owned singleton out of a `&mut`. | ||
| 49 | /// | ||
| 50 | /// It is intended to be implemented for owned peripheral singletons, such as `USART3` or `AnyPin`. | ||
| 51 | /// Unborrowing an owned `T` yields an `Unborrowed<'static, T>`. | ||
| 52 | /// Unborrowing a `&'a mut T` yields an `Unborrowed<'a, T>`. | ||
| 53 | /// | ||
| 54 | /// This allows writing HAL drivers that either own or borrow their peripherals, but that don't have | ||
| 55 | /// to store pointers in the borrowed case. | ||
| 56 | pub trait Unborrow: Sized { | ||
| 57 | /// Unborrow result type | ||
| 58 | type Target; | ||
| 59 | |||
| 60 | unsafe fn unborrow_unchecked(&mut self) -> Self::Target; | ||
| 61 | |||
| 62 | /// Unborrow a value. | ||
| 63 | #[inline] | ||
| 64 | fn unborrow<'a>(mut self) -> Unborrowed<'a, Self::Target> | ||
| 65 | where | ||
| 66 | Self: 'a, | ||
| 67 | { | ||
| 68 | Unborrowed::new(unsafe { self.unborrow_unchecked() }) | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | impl<'b, T: DerefMut> Unborrow for T | ||
| 73 | where | ||
| 74 | T::Target: Unborrow, | ||
| 75 | { | ||
| 76 | type Target = <T::Target as Unborrow>::Target; | ||
| 77 | |||
| 78 | #[inline] | ||
| 79 | unsafe fn unborrow_unchecked(&mut self) -> Self::Target { | ||
| 80 | self.deref_mut().unborrow_unchecked() | ||
| 81 | } | ||
| 82 | } | ||
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index 49991db13..b0d101b77 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs | |||
| @@ -3,7 +3,7 @@ use core::future::Future; | |||
| 3 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
| 4 | 4 | ||
| 5 | use embassy::channel::signal::Signal; | 5 | use embassy::channel::signal::Signal; |
| 6 | use embassy_hal_common::{unborrow, Unborrowed}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 7 | use embassy_stm32::dma::NoDma; | 7 | use embassy_stm32::dma::NoDma; |
| 8 | use embassy_stm32::gpio::{AnyPin, Output}; | 8 | use embassy_stm32::gpio::{AnyPin, Output}; |
| 9 | use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO}; | 9 | use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO}; |
| @@ -12,7 +12,7 @@ use embassy_stm32::subghz::{ | |||
| 12 | LoRaSyncWord, Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, | 12 | LoRaSyncWord, Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, |
| 13 | Status, SubGhz, TcxoMode, TcxoTrim, Timeout, TxParams, | 13 | Status, SubGhz, TcxoMode, TcxoTrim, Timeout, TxParams, |
| 14 | }; | 14 | }; |
| 15 | use embassy_stm32::Unborrow; | 15 | use embassy_stm32::Peripheral; |
| 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; | 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; |
| 17 | use lorawan_device::async_device::Timings; | 17 | use lorawan_device::async_device::Timings; |
| 18 | 18 | ||
| @@ -46,7 +46,7 @@ impl<'d> SubGhzState<'d> { | |||
| 46 | /// The radio peripheral keeping the radio state and owning the radio IRQ. | 46 | /// The radio peripheral keeping the radio state and owning the radio IRQ. |
| 47 | pub struct SubGhzRadio<'d> { | 47 | pub struct SubGhzRadio<'d> { |
| 48 | state: *mut StateInner<'d>, | 48 | state: *mut StateInner<'d>, |
| 49 | _irq: Unborrowed<'d, SUBGHZ_RADIO>, | 49 | _irq: PeripheralRef<'d, SUBGHZ_RADIO>, |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | impl<'d> SubGhzRadio<'d> { | 52 | impl<'d> SubGhzRadio<'d> { |
| @@ -58,9 +58,9 @@ impl<'d> SubGhzRadio<'d> { | |||
| 58 | state: &'d mut SubGhzState<'d>, | 58 | state: &'d mut SubGhzState<'d>, |
| 59 | radio: SubGhz<'d, NoDma, NoDma>, | 59 | radio: SubGhz<'d, NoDma, NoDma>, |
| 60 | switch: RadioSwitch<'d>, | 60 | switch: RadioSwitch<'d>, |
| 61 | irq: impl Unborrow<Target = SUBGHZ_RADIO> + 'd, | 61 | irq: impl Peripheral<P = SUBGHZ_RADIO> + 'd, |
| 62 | ) -> Self { | 62 | ) -> Self { |
| 63 | unborrow!(irq); | 63 | into_ref!(irq); |
| 64 | 64 | ||
| 65 | let mut inner = StateInner { radio, switch }; | 65 | let mut inner = StateInner { radio, switch }; |
| 66 | inner.radio.reset(); | 66 | inner.radio.reset(); |
diff --git a/embassy-macros/src/macros/cortex_m_interrupt_declare.rs b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs index 13150634b..ab61ad5da 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_declare.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs | |||
| @@ -25,7 +25,7 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> { | |||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | ::embassy_hal_common::impl_unborrow!(#name_interrupt); | 28 | ::embassy_hal_common::impl_peripheral!(#name_interrupt); |
| 29 | }; | 29 | }; |
| 30 | Ok(result) | 30 | Ok(result) |
| 31 | } | 31 | } |
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; | |||
| 22 | use embassy::waitqueue::WakerRegistration; | 22 | use embassy::waitqueue::WakerRegistration; |
| 23 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 23 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 24 | use embassy_hal_common::ring_buffer::RingBuffer; | 24 | use embassy_hal_common::ring_buffer::RingBuffer; |
| 25 | use embassy_hal_common::{low_power_wait_until, unborrow}; | 25 | use embassy_hal_common::{into_ref, low_power_wait_until}; |
| 26 | use futures::future::poll_fn; | 26 | use 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 |
| 28 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; | 28 | pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; |
| @@ -32,7 +32,7 @@ use crate::interrupt::InterruptExt; | |||
| 32 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 32 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 33 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 33 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 34 | use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; | 34 | use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; |
| 35 | use crate::{pac, Unborrow}; | 35 | use crate::{pac, Peripheral}; |
| 36 | 36 | ||
| 37 | #[derive(Copy, Clone, Debug, PartialEq)] | 37 | #[derive(Copy, Clone, Debug, PartialEq)] |
| 38 | enum RxState { | 38 | enum RxState { |
| @@ -78,20 +78,20 @@ impl<'d, U: UarteInstance, T: TimerInstance> Unpin for BufferedUarte<'d, U, T> { | |||
| 78 | impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | 78 | impl<'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; | |||
| 4 | use core::hint::unreachable_unchecked; | 4 | use core::hint::unreachable_unchecked; |
| 5 | 5 | ||
| 6 | use cfg_if::cfg_if; | 6 | use cfg_if::cfg_if; |
| 7 | use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; | 7 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; |
| 8 | 8 | ||
| 9 | use self::sealed::Pin as _; | 9 | use self::sealed::Pin as _; |
| 10 | use crate::pac::p0 as gpio; | 10 | use crate::pac::p0 as gpio; |
| 11 | use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; | 11 | use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; |
| 12 | use crate::{pac, Unborrow}; | 12 | use 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 | ||
| 39 | impl<'d, T: Pin> Input<'d, T> { | 39 | impl<'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 | ||
| 119 | impl<'d, T: Pin> Output<'d, T> { | 119 | impl<'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. |
| 195 | pub struct Flex<'d, T: Pin> { | 195 | pub struct Flex<'d, T: Pin> { |
| 196 | pub(crate) pin: Unborrowed<'d, T>, | 196 | pub(crate) pin: PeripheralRef<'d, T>, |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | impl<'d, T: Pin> Flex<'d, T> { | 199 | impl<'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 | ||
| 377 | pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static { | 377 | pub 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 | ||
| 427 | macro_rules! unborrow_and_degrade { | 427 | macro_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 | ||
| 435 | impl_unborrow!(AnyPin); | 435 | impl_peripheral!(AnyPin); |
| 436 | impl Pin for AnyPin {} | 436 | impl Pin for AnyPin {} |
| 437 | impl sealed::Pin for AnyPin { | 437 | impl 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 | ||
| 450 | impl<'a, P: Pin> PselBits for Option<Unborrowed<'a, P>> { | 450 | impl<'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; | |||
| 4 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | 5 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::impl_unborrow; | 7 | use embassy_hal_common::impl_peripheral; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::sealed::Pin as _; |
| @@ -414,7 +414,7 @@ pub trait Channel: sealed::Channel + Sized { | |||
| 414 | pub struct AnyChannel { | 414 | pub struct AnyChannel { |
| 415 | number: u8, | 415 | number: u8, |
| 416 | } | 416 | } |
| 417 | impl_unborrow!(AnyChannel); | 417 | impl_peripheral!(AnyChannel); |
| 418 | impl sealed::Channel for AnyChannel {} | 418 | impl sealed::Channel for AnyChannel {} |
| 419 | impl Channel for AnyChannel { | 419 | impl 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; | |||
| 135 | pub(crate) use chip::pac; | 135 | pub(crate) use chip::pac; |
| 136 | pub use chip::{peripherals, Peripherals}; | 136 | pub use chip::{peripherals, Peripherals}; |
| 137 | pub use embassy_cortex_m::executor; | 137 | pub use embassy_cortex_m::executor; |
| 138 | pub use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; | 138 | pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 139 | pub use embassy_macros::cortex_m_interrupt as interrupt; | 139 | pub use embassy_macros::cortex_m_interrupt as interrupt; |
| 140 | 140 | ||
| 141 | pub mod config { | 141 | pub 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 @@ | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::{ptr, slice}; | 4 | use core::{ptr, slice}; |
| 5 | 5 | ||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::into_ref; |
| 7 | use embedded_storage::nor_flash::{ | 7 | use embedded_storage::nor_flash::{ |
| 8 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, | 8 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | use crate::peripherals::NVMC; | 11 | use crate::peripherals::NVMC; |
| 12 | use crate::{pac, Unborrow}; | 12 | use crate::{pac, Peripheral}; |
| 13 | 13 | ||
| 14 | pub const PAGE_SIZE: usize = 4096; | 14 | pub const PAGE_SIZE: usize = 4096; |
| 15 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; | 15 | pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; |
| @@ -35,8 +35,8 @@ pub struct Nvmc<'d> { | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | impl<'d> Nvmc<'d> { | 37 | impl<'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 @@ | |||
| 1 | use embassy_hal_common::unborrow; | 1 | use embassy_hal_common::into_ref; |
| 2 | 2 | ||
| 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; | 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; |
| 4 | use crate::{pac, Unborrow}; | 4 | use crate::{pac, Peripheral}; |
| 5 | 5 | ||
| 6 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; | 6 | const DPPI_ENABLE_BIT: u32 = 0x8000_0000; |
| 7 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; | 7 | const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; |
| @@ -11,13 +11,13 @@ fn regs() -> &'static pac::dppic::RegisterBlock { | |||
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 13 | impl<'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 | ||
| 19 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 19 | impl<'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 | ||
| 18 | use core::ptr::NonNull; | 18 | use core::ptr::NonNull; |
| 19 | 19 | ||
| 20 | use embassy_hal_common::{impl_unborrow, Unborrowed}; | 20 | use embassy_hal_common::{impl_peripheral, PeripheralRef}; |
| 21 | 21 | ||
| 22 | use crate::{peripherals, Unborrow}; | 22 | use crate::{peripherals, Peripheral}; |
| 23 | 23 | ||
| 24 | #[cfg(feature = "_dppi")] | 24 | #[cfg(feature = "_dppi")] |
| 25 | mod dppi; | 25 | mod dppi; |
| @@ -27,7 +27,7 @@ mod dppi; | |||
| 27 | mod ppi; | 27 | mod ppi; |
| 28 | 28 | ||
| 29 | pub struct Ppi<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> { | 29 | pub 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 | ||
| 90 | pub trait Channel: sealed::Channel + Unborrow<Target = Self> + Sized { | 90 | pub 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 { | |||
| 117 | pub struct AnyStaticChannel { | 117 | pub struct AnyStaticChannel { |
| 118 | pub(crate) number: u8, | 118 | pub(crate) number: u8, |
| 119 | } | 119 | } |
| 120 | impl_unborrow!(AnyStaticChannel); | 120 | impl_peripheral!(AnyStaticChannel); |
| 121 | impl sealed::Channel for AnyStaticChannel {} | 121 | impl sealed::Channel for AnyStaticChannel {} |
| 122 | impl Channel for AnyStaticChannel { | 122 | impl Channel for AnyStaticChannel { |
| 123 | fn number(&self) -> usize { | 123 | fn number(&self) -> usize { |
| @@ -135,7 +135,7 @@ impl StaticChannel for AnyStaticChannel { | |||
| 135 | pub struct AnyConfigurableChannel { | 135 | pub struct AnyConfigurableChannel { |
| 136 | pub(crate) number: u8, | 136 | pub(crate) number: u8, |
| 137 | } | 137 | } |
| 138 | impl_unborrow!(AnyConfigurableChannel); | 138 | impl_peripheral!(AnyConfigurableChannel); |
| 139 | impl sealed::Channel for AnyConfigurableChannel {} | 139 | impl sealed::Channel for AnyConfigurableChannel {} |
| 140 | impl Channel for AnyConfigurableChannel { | 140 | impl Channel for AnyConfigurableChannel { |
| 141 | fn number(&self) -> usize { | 141 | fn number(&self) -> usize { |
| @@ -187,7 +187,7 @@ macro_rules! impl_ppi_channel { | |||
| 187 | pub struct AnyGroup { | 187 | pub struct AnyGroup { |
| 188 | number: u8, | 188 | number: u8, |
| 189 | } | 189 | } |
| 190 | impl_unborrow!(AnyGroup); | 190 | impl_peripheral!(AnyGroup); |
| 191 | impl sealed::Group for AnyGroup {} | 191 | impl sealed::Group for AnyGroup {} |
| 192 | impl Group for AnyGroup { | 192 | impl 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 @@ | |||
| 1 | use embassy_hal_common::unborrow; | 1 | use embassy_hal_common::into_ref; |
| 2 | 2 | ||
| 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; | 3 | use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; |
| 4 | use crate::{pac, Unborrow}; | 4 | use crate::{pac, Peripheral}; |
| 5 | 5 | ||
| 6 | impl Task { | 6 | impl 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 |
| 22 | impl<'d, C: StaticChannel> Ppi<'d, C, 0, 1> { | 22 | impl<'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 | ||
| 34 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { | 34 | impl<'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 |
| 48 | impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { | 48 | impl<'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 @@ | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | 5 | ||
| 6 | use embassy_hal_common::Unborrowed; | 6 | use embassy_hal_common::PeripheralRef; |
| 7 | 7 | ||
| 8 | use crate::gpio::sealed::Pin as _; | 8 | use crate::gpio::sealed::Pin as _; |
| 9 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; | 9 | use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; |
| 10 | use crate::interrupt::Interrupt; | 10 | use crate::interrupt::Interrupt; |
| 11 | use crate::ppi::{Event, Task}; | 11 | use crate::ppi::{Event, Task}; |
| 12 | use crate::util::slice_in_ram_or; | 12 | use crate::util::slice_in_ram_or; |
| 13 | use crate::{pac, Unborrow}; | 13 | use 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. |
| 17 | pub struct SimplePwm<'d, T: Instance> { | 17 | pub 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. |
| 28 | pub struct SequencePwm<'d, T: Instance> { | 28 | pub 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 { | |||
| 559 | impl<'d, T: Instance> SimplePwm<'d, T> { | 559 | impl<'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 | ||
| 802 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { | 802 | pub 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; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::{unborrow, Unborrowed}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::sealed::Pin as _; |
| 11 | use crate::gpio::{AnyPin, Pin as GpioPin}; | 11 | use crate::gpio::{AnyPin, Pin as GpioPin}; |
| 12 | use crate::interrupt::InterruptExt; | 12 | use crate::interrupt::InterruptExt; |
| 13 | use crate::peripherals::QDEC; | 13 | use crate::peripherals::QDEC; |
| 14 | use crate::{interrupt, pac, Unborrow}; | 14 | use crate::{interrupt, pac, Peripheral}; |
| 15 | 15 | ||
| 16 | /// Quadrature decoder | 16 | /// Quadrature decoder |
| 17 | pub struct Qdec<'d> { | 17 | pub struct Qdec<'d> { |
| @@ -43,37 +43,37 @@ static WAKER: AtomicWaker = AtomicWaker::new(); | |||
| 43 | 43 | ||
| 44 | impl<'d> Qdec<'d> { | 44 | impl<'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; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_common::drop::DropBomb; | 6 | use embassy_hal_common::drop::DropBomb; |
| 7 | use embassy_hal_common::{unborrow, Unborrowed}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::Pin as _; | 10 | use crate::gpio::sealed::Pin as _; |
| @@ -13,7 +13,7 @@ use crate::interrupt::{Interrupt, InterruptExt}; | |||
| 13 | pub use crate::pac::qspi::ifconfig0::{ | 13 | pub 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 | }; |
| 16 | use crate::{pac, Unborrow}; | 16 | use crate::{pac, Peripheral}; |
| 17 | 17 | ||
| 18 | // TODO | 18 | // TODO |
| 19 | // - config: | 19 | // - config: |
| @@ -62,27 +62,27 @@ pub enum Error { | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | pub struct Qspi<'d, T: Instance, const FLASH_SIZE: usize> { | 64 | pub 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 | ||
| 69 | impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { | 69 | impl<'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 | ||
| 531 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { | 531 | pub 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 | ||
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | use embassy_hal_common::drop::OnDrop; | 6 | use embassy_hal_common::drop::OnDrop; |
| 7 | use embassy_hal_common::{unborrow, Unborrowed}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | 9 | ||
| 10 | use crate::interrupt::InterruptExt; | 10 | use crate::interrupt::InterruptExt; |
| 11 | use crate::peripherals::RNG; | 11 | use crate::peripherals::RNG; |
| 12 | use crate::{interrupt, pac, Unborrow}; | 12 | use crate::{interrupt, pac, Peripheral}; |
| 13 | 13 | ||
| 14 | impl RNG { | 14 | impl 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`. |
| 35 | pub struct Rng<'d> { | 35 | pub struct Rng<'d> { |
| 36 | irq: Unborrowed<'d, interrupt::RNG>, | 36 | irq: PeripheralRef<'d, interrupt::RNG>, |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | impl<'d> Rng<'d> { | 39 | impl<'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}; | |||
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy::waitqueue::AtomicWaker; | 7 | use embassy::waitqueue::AtomicWaker; |
| 8 | use embassy_hal_common::{impl_unborrow, unborrow}; | 8 | use embassy_hal_common::{impl_peripheral, into_ref}; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | use pac::{saadc, SAADC}; | 10 | use pac::{saadc, SAADC}; |
| 11 | use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; | 11 | use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; |
| @@ -17,7 +17,7 @@ use saadc::resolution::VAL_A; | |||
| 17 | use crate::interrupt::InterruptExt; | 17 | use crate::interrupt::InterruptExt; |
| 18 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; | 18 | use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; |
| 19 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 19 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 20 | use crate::{interrupt, pac, peripherals, Unborrow}; | 20 | use 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. |
| 78 | pub struct VddInput; | 78 | pub struct VddInput; |
| 79 | 79 | ||
| 80 | impl_unborrow!(VddInput); | 80 | impl_peripheral!(VddInput); |
| 81 | 81 | ||
| 82 | impl sealed::Input for VddInput { | 82 | impl sealed::Input for VddInput { |
| 83 | #[cfg(not(feature = "_nrf9160"))] | 83 | #[cfg(not(feature = "_nrf9160"))] |
| @@ -97,7 +97,7 @@ impl Input for VddInput {} | |||
| 97 | pub struct VddhDiv5Input; | 97 | pub struct VddhDiv5Input; |
| 98 | 98 | ||
| 99 | #[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] | 99 | #[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] |
| 100 | impl_unborrow!(VddhDiv5Input); | 100 | impl_peripheral!(VddhDiv5Input); |
| 101 | 101 | ||
| 102 | #[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] | 102 | #[cfg(any(feature = "_nrf5340-app", feature = "nrf52833", feature = "nrf52840"))] |
| 103 | impl sealed::Input for VddhDiv5Input { | 103 | impl sealed::Input for VddhDiv5Input { |
| @@ -113,7 +113,7 @@ pub struct AnyInput { | |||
| 113 | channel: InputChannel, | 113 | channel: InputChannel, |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | impl_unborrow!(AnyInput); | 116 | impl_peripheral!(AnyInput); |
| 117 | 117 | ||
| 118 | impl sealed::Input for AnyInput { | 118 | impl sealed::Input for AnyInput { |
| 119 | fn channel(&self) -> InputChannel { | 119 | fn channel(&self) -> InputChannel { |
| @@ -125,8 +125,8 @@ impl Input for AnyInput {} | |||
| 125 | 125 | ||
| 126 | impl<'d> ChannelConfig<'d> { | 126 | impl<'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 | ||
| 168 | impl<'d, const N: usize> Saadc<'d, N> { | 168 | impl<'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. |
| 677 | pub trait Input: sealed::Input + Unborrow<Target = Self> + Sized { | 677 | pub 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}; | |||
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy_embedded_hal::SetConfig; | 7 | use embassy_embedded_hal::SetConfig; |
| 8 | use embassy_hal_common::{unborrow, Unborrowed}; | 8 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 9 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 9 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 10 | use futures::future::poll_fn; | 10 | use futures::future::poll_fn; |
| 11 | pub use pac::spim0::frequency::FREQUENCY_A as Frequency; | 11 | pub use pac::spim0::frequency::FREQUENCY_A as Frequency; |
| @@ -15,7 +15,7 @@ use crate::gpio::sealed::Pin as _; | |||
| 15 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; | 15 | use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; |
| 16 | use crate::interrupt::{Interrupt, InterruptExt}; | 16 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 17 | use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; | 17 | use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; |
| 18 | use crate::{pac, Unborrow}; | 18 | use 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 | ||
| 54 | impl<'d, T: Instance> Spim<'d, T> { | 54 | impl<'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 | ||
| 382 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { | 382 | pub 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 | ||
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | use embassy_hal_common::drop::OnDrop; | 6 | use embassy_hal_common::drop::OnDrop; |
| 7 | use embassy_hal_common::{unborrow, Unborrowed}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use fixed::types::I30F2; | 8 | use fixed::types::I30F2; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
| 11 | use crate::interrupt::InterruptExt; | 11 | use crate::interrupt::InterruptExt; |
| 12 | use crate::peripherals::TEMP; | 12 | use crate::peripherals::TEMP; |
| 13 | use crate::{interrupt, pac, Unborrow}; | 13 | use crate::{interrupt, pac, Peripheral}; |
| 14 | 14 | ||
| 15 | /// Integrated temperature sensor. | 15 | /// Integrated temperature sensor. |
| 16 | pub struct Temp<'d> { | 16 | pub struct Temp<'d> { |
| 17 | _irq: Unborrowed<'d, interrupt::TEMP>, | 17 | _irq: PeripheralRef<'d, interrupt::TEMP>, |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | static WAKER: AtomicWaker = AtomicWaker::new(); | 20 | static WAKER: AtomicWaker = AtomicWaker::new(); |
| 21 | 21 | ||
| 22 | impl<'d> Temp<'d> { | 22 | impl<'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 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::drop::OnDrop; | 7 | use embassy_hal_common::drop::OnDrop; |
| 8 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::into_ref; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
| 11 | use crate::interrupt::{Interrupt, InterruptExt}; | 11 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 12 | use crate::ppi::{Event, Task}; | 12 | use crate::ppi::{Event, Task}; |
| 13 | use crate::{pac, Unborrow}; | 13 | use crate::{pac, Peripheral}; |
| 14 | 14 | ||
| 15 | pub(crate) mod sealed { | 15 | pub(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 | ||
| 31 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { | 31 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { |
| 32 | type Interrupt: Interrupt; | 32 | type Interrupt: Interrupt; |
| 33 | } | 33 | } |
| 34 | pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {} | 34 | pub trait ExtendedInstance: Instance + sealed::ExtendedInstance {} |
| @@ -99,11 +99,8 @@ pub struct Timer<'d, T: Instance, I: TimerType = NotAwaitable> { | |||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | impl<'d, T: Instance> Timer<'d, T, Awaitable> { | 101 | impl<'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; | |||
| 16 | use embassy::time::{Duration, Instant}; | 16 | use embassy::time::{Duration, Instant}; |
| 17 | use embassy::waitqueue::AtomicWaker; | 17 | use embassy::waitqueue::AtomicWaker; |
| 18 | use embassy_embedded_hal::SetConfig; | 18 | use embassy_embedded_hal::SetConfig; |
| 19 | use embassy_hal_common::unborrow; | 19 | use embassy_hal_common::into_ref; |
| 20 | use futures::future::poll_fn; | 20 | use futures::future::poll_fn; |
| 21 | 21 | ||
| 22 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; | 22 | use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; |
| 23 | use crate::gpio::Pin as GpioPin; | 23 | use crate::gpio::Pin as GpioPin; |
| 24 | use crate::interrupt::{Interrupt, InterruptExt}; | 24 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 25 | use crate::util::{slice_in_ram, slice_in_ram_or}; | 25 | use crate::util::{slice_in_ram, slice_in_ram_or}; |
| 26 | use crate::{gpio, pac, Unborrow}; | 26 | use crate::{gpio, pac, Peripheral}; |
| 27 | 27 | ||
| 28 | #[derive(Clone, Copy)] | 28 | #[derive(Clone, Copy)] |
| 29 | pub enum Frequency { | 29 | pub enum Frequency { |
| @@ -80,13 +80,13 @@ pub struct Twim<'d, T: Instance> { | |||
| 80 | 80 | ||
| 81 | impl<'d, T: Instance> Twim<'d, T> { | 81 | impl<'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 | ||
| 710 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { | 710 | pub 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}; | |||
| 18 | use core::task::Poll; | 18 | use core::task::Poll; |
| 19 | 19 | ||
| 20 | use embassy_hal_common::drop::OnDrop; | 20 | use embassy_hal_common::drop::OnDrop; |
| 21 | use embassy_hal_common::{unborrow, Unborrowed}; | 21 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 22 | use futures::future::poll_fn; | 22 | use futures::future::poll_fn; |
| 23 | use pac::uarte0::RegisterBlock; | 23 | use 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}; | |||
| 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; | 31 | use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; |
| 32 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; | 32 | use crate::timer::{Frequency, Instance as TimerInstance, Timer}; |
| 33 | use crate::util::slice_in_ram_or; | 33 | use crate::util::slice_in_ram_or; |
| 34 | use crate::{pac, Unborrow}; | 34 | use 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> { | |||
| 83 | impl<'d, T: Instance> Uarte<'d, T> { | 83 | impl<'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) { | |||
| 237 | impl<'d, T: Instance> UarteTx<'d, T> { | 237 | impl<'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> { | |||
| 429 | impl<'d, T: Instance> UarteRx<'d, T> { | 429 | impl<'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> { | |||
| 668 | impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> { | 668 | impl<'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 | ||
| 942 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { | 942 | pub 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 | ||
| 8 | use cortex_m::peripheral::NVIC; | 8 | use cortex_m::peripheral::NVIC; |
| 9 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::into_ref; |
| 11 | pub use embassy_usb; | 11 | pub use embassy_usb; |
| 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; | 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; |
| 13 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 13 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| @@ -17,7 +17,7 @@ use pac::usbd::RegisterBlock; | |||
| 17 | 17 | ||
| 18 | use crate::interrupt::{Interrupt, InterruptExt}; | 18 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 19 | use crate::util::slice_in_ram; | 19 | use crate::util::slice_in_ram; |
| 20 | use crate::{pac, Unborrow}; | 20 | use crate::{pac, Peripheral}; |
| 21 | 21 | ||
| 22 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 22 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| 23 | static BUS_WAKER: AtomicWaker = NEW_AW; | 23 | static BUS_WAKER: AtomicWaker = NEW_AW; |
| @@ -166,12 +166,8 @@ impl UsbSupply for SignalledSupply { | |||
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | impl<'d, T: Instance, P: UsbSupply> Driver<'d, T, P> { | 168 | impl<'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 | ||
| 953 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { | 949 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { |
| 954 | type Interrupt: Interrupt; | 950 | type Interrupt: Interrupt; |
| 955 | } | 951 | } |
| 956 | 952 | ||
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 08a731f40..3588c2f7e 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -5,11 +5,11 @@ use core::task::{Context, Poll}; | |||
| 5 | 5 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; | 7 | use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; |
| 8 | use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; | 8 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; |
| 9 | 9 | ||
| 10 | use crate::pac::common::{Reg, RW}; | 10 | use crate::pac::common::{Reg, RW}; |
| 11 | use crate::pac::SIO; | 11 | use crate::pac::SIO; |
| 12 | use crate::{interrupt, pac, peripherals, Unborrow}; | 12 | use crate::{interrupt, pac, peripherals, Peripheral}; |
| 13 | 13 | ||
| 14 | const PIN_COUNT: usize = 30; | 14 | const PIN_COUNT: usize = 30; |
| 15 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 15 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| @@ -61,7 +61,7 @@ pub struct Input<'d, T: Pin> { | |||
| 61 | 61 | ||
| 62 | impl<'d, T: Pin> Input<'d, T> { | 62 | impl<'d, T: Pin> Input<'d, T> { |
| 63 | #[inline] | 63 | #[inline] |
| 64 | pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { | 64 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { |
| 65 | let mut pin = Flex::new(pin); | 65 | let mut pin = Flex::new(pin); |
| 66 | pin.set_as_input(); | 66 | pin.set_as_input(); |
| 67 | pin.set_pull(pull); | 67 | pin.set_pull(pull); |
| @@ -177,13 +177,13 @@ unsafe fn IO_IRQ_BANK0() { | |||
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | struct InputFuture<'a, T: Pin> { | 179 | struct InputFuture<'a, T: Pin> { |
| 180 | pin: Unborrowed<'a, T>, | 180 | pin: PeripheralRef<'a, T>, |
| 181 | level: InterruptTrigger, | 181 | level: InterruptTrigger, |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | impl<'d, T: Pin> InputFuture<'d, T> { | 184 | impl<'d, T: Pin> InputFuture<'d, T> { |
| 185 | pub fn new(pin: impl Unborrow<Target = T> + 'd, level: InterruptTrigger) -> Self { | 185 | pub fn new(pin: impl Peripheral<P = T> + 'd, level: InterruptTrigger) -> Self { |
| 186 | unborrow!(pin); | 186 | into_ref!(pin); |
| 187 | unsafe { | 187 | unsafe { |
| 188 | let irq = interrupt::IO_IRQ_BANK0::steal(); | 188 | let irq = interrupt::IO_IRQ_BANK0::steal(); |
| 189 | irq.disable(); | 189 | irq.disable(); |
| @@ -290,7 +290,7 @@ pub struct Output<'d, T: Pin> { | |||
| 290 | 290 | ||
| 291 | impl<'d, T: Pin> Output<'d, T> { | 291 | impl<'d, T: Pin> Output<'d, T> { |
| 292 | #[inline] | 292 | #[inline] |
| 293 | pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self { | 293 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level) -> Self { |
| 294 | let mut pin = Flex::new(pin); | 294 | let mut pin = Flex::new(pin); |
| 295 | match initial_output { | 295 | match initial_output { |
| 296 | Level::High => pin.set_high(), | 296 | Level::High => pin.set_high(), |
| @@ -351,7 +351,7 @@ pub struct OutputOpenDrain<'d, T: Pin> { | |||
| 351 | 351 | ||
| 352 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { | 352 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { |
| 353 | #[inline] | 353 | #[inline] |
| 354 | pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self { | 354 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level) -> Self { |
| 355 | let mut pin = Flex::new(pin); | 355 | let mut pin = Flex::new(pin); |
| 356 | pin.set_low(); | 356 | pin.set_low(); |
| 357 | match initial_output { | 357 | match initial_output { |
| @@ -415,13 +415,13 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { | |||
| 415 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output | 415 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output |
| 416 | /// mode. | 416 | /// mode. |
| 417 | pub struct Flex<'d, T: Pin> { | 417 | pub struct Flex<'d, T: Pin> { |
| 418 | pin: Unborrowed<'d, T>, | 418 | pin: PeripheralRef<'d, T>, |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | impl<'d, T: Pin> Flex<'d, T> { | 421 | impl<'d, T: Pin> Flex<'d, T> { |
| 422 | #[inline] | 422 | #[inline] |
| 423 | pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self { | 423 | pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self { |
| 424 | unborrow!(pin); | 424 | into_ref!(pin); |
| 425 | 425 | ||
| 426 | unsafe { | 426 | unsafe { |
| 427 | pin.pad_ctrl().write(|w| { | 427 | pin.pad_ctrl().write(|w| { |
| @@ -647,7 +647,7 @@ pub(crate) mod sealed { | |||
| 647 | } | 647 | } |
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | pub trait Pin: Unborrow<Target = Self> + sealed::Pin { | 650 | pub trait Pin: Peripheral<P = Self> + sealed::Pin { |
| 651 | /// Degrade to a generic pin struct | 651 | /// Degrade to a generic pin struct |
| 652 | fn degrade(self) -> AnyPin { | 652 | fn degrade(self) -> AnyPin { |
| 653 | AnyPin { | 653 | AnyPin { |
| @@ -661,22 +661,22 @@ pub struct AnyPin { | |||
| 661 | } | 661 | } |
| 662 | 662 | ||
| 663 | impl AnyPin { | 663 | impl AnyPin { |
| 664 | pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> { | 664 | pub(crate) fn into_degraded_ref<'a>(pin: impl Peripheral<P = impl Pin + 'a> + 'a) -> PeripheralRef<'a, Self> { |
| 665 | Unborrowed::new(AnyPin { | 665 | PeripheralRef::new(AnyPin { |
| 666 | pin_bank: pin.unborrow().pin_bank(), | 666 | pin_bank: pin.into_ref().pin_bank(), |
| 667 | }) | 667 | }) |
| 668 | } | 668 | } |
| 669 | } | 669 | } |
| 670 | 670 | ||
| 671 | macro_rules! unborrow_and_degrade { | 671 | macro_rules! into_degraded_ref { |
| 672 | ($($name:ident),*) => { | 672 | ($($name:ident),*) => { |
| 673 | $( | 673 | $( |
| 674 | let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name); | 674 | let $name = $crate::gpio::AnyPin::into_degraded_ref($name); |
| 675 | )* | 675 | )* |
| 676 | }; | 676 | }; |
| 677 | } | 677 | } |
| 678 | 678 | ||
| 679 | impl_unborrow!(AnyPin); | 679 | impl_peripheral!(AnyPin); |
| 680 | 680 | ||
| 681 | impl Pin for AnyPin {} | 681 | impl Pin for AnyPin {} |
| 682 | impl sealed::Pin for AnyPin { | 682 | impl sealed::Pin for AnyPin { |
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index e36761ac9..44150be0d 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -17,7 +17,7 @@ mod reset; | |||
| 17 | // Reexports | 17 | // Reexports |
| 18 | 18 | ||
| 19 | pub use embassy_cortex_m::executor; | 19 | pub use embassy_cortex_m::executor; |
| 20 | pub use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; | 20 | pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 21 | pub use embassy_macros::cortex_m_interrupt as interrupt; | 21 | pub use embassy_macros::cortex_m_interrupt as interrupt; |
| 22 | #[cfg(feature = "unstable-pac")] | 22 | #[cfg(feature = "unstable-pac")] |
| 23 | pub use rp2040_pac2 as pac; | 23 | pub use rp2040_pac2 as pac; |
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index df030942e..a984d16a8 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | use embassy_embedded_hal::SetConfig; | 1 | use embassy_embedded_hal::SetConfig; |
| 2 | use embassy_hal_common::{unborrow, Unborrowed}; | 2 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 3 | pub use embedded_hal_02::spi::{Phase, Polarity}; | 3 | pub use embedded_hal_02::spi::{Phase, Polarity}; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::Pin as _; | 5 | use crate::gpio::sealed::Pin as _; |
| 6 | use crate::gpio::{AnyPin, Pin as GpioPin}; | 6 | use crate::gpio::{AnyPin, Pin as GpioPin}; |
| 7 | use crate::{pac, peripherals, Unborrow}; | 7 | use crate::{pac, peripherals, Peripheral}; |
| 8 | 8 | ||
| 9 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 9 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 10 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 10 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -31,7 +31,7 @@ impl Default for Config { | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | pub struct Spi<'d, T: Instance> { | 33 | pub struct Spi<'d, T: Instance> { |
| 34 | inner: Unborrowed<'d, T>, | 34 | inner: PeripheralRef<'d, T>, |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | fn div_roundup(a: u32, b: u32) -> u32 { | 37 | fn div_roundup(a: u32, b: u32) -> u32 { |
| @@ -59,45 +59,45 @@ fn calc_prescs(freq: u32) -> (u8, u8) { | |||
| 59 | 59 | ||
| 60 | impl<'d, T: Instance> Spi<'d, T> { | 60 | impl<'d, T: Instance> Spi<'d, T> { |
| 61 | pub fn new( | 61 | pub fn new( |
| 62 | inner: impl Unborrow<Target = T> + 'd, | 62 | inner: impl Peripheral<P = T> + 'd, |
| 63 | clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd, | 63 | clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, |
| 64 | mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd, | 64 | mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd, |
| 65 | miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd, | 65 | miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd, |
| 66 | config: Config, | 66 | config: Config, |
| 67 | ) -> Self { | 67 | ) -> Self { |
| 68 | unborrow_and_degrade!(clk, mosi, miso); | 68 | into_degraded_ref!(clk, mosi, miso); |
| 69 | Self::new_inner(inner, Some(clk), Some(mosi), Some(miso), None, config) | 69 | Self::new_inner(inner, Some(clk), Some(mosi), Some(miso), None, config) |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | pub fn new_txonly( | 72 | pub fn new_txonly( |
| 73 | inner: impl Unborrow<Target = T> + 'd, | 73 | inner: impl Peripheral<P = T> + 'd, |
| 74 | clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd, | 74 | clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, |
| 75 | mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd, | 75 | mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd, |
| 76 | config: Config, | 76 | config: Config, |
| 77 | ) -> Self { | 77 | ) -> Self { |
| 78 | unborrow_and_degrade!(clk, mosi); | 78 | into_degraded_ref!(clk, mosi); |
| 79 | Self::new_inner(inner, Some(clk), Some(mosi), None, None, config) | 79 | Self::new_inner(inner, Some(clk), Some(mosi), None, None, config) |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | pub fn new_rxonly( | 82 | pub fn new_rxonly( |
| 83 | inner: impl Unborrow<Target = T> + 'd, | 83 | inner: impl Peripheral<P = T> + 'd, |
| 84 | clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd, | 84 | clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, |
| 85 | miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd, | 85 | miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd, |
| 86 | config: Config, | 86 | config: Config, |
| 87 | ) -> Self { | 87 | ) -> Self { |
| 88 | unborrow_and_degrade!(clk, miso); | 88 | into_degraded_ref!(clk, miso); |
| 89 | Self::new_inner(inner, Some(clk), None, Some(miso), None, config) | 89 | Self::new_inner(inner, Some(clk), None, Some(miso), None, config) |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | fn new_inner( | 92 | fn new_inner( |
| 93 | inner: impl Unborrow<Target = T> + 'd, | 93 | inner: impl Peripheral<P = T> + 'd, |
| 94 | clk: Option<Unborrowed<'d, AnyPin>>, | 94 | clk: Option<PeripheralRef<'d, AnyPin>>, |
| 95 | mosi: Option<Unborrowed<'d, AnyPin>>, | 95 | mosi: Option<PeripheralRef<'d, AnyPin>>, |
| 96 | miso: Option<Unborrowed<'d, AnyPin>>, | 96 | miso: Option<PeripheralRef<'d, AnyPin>>, |
| 97 | cs: Option<Unborrowed<'d, AnyPin>>, | 97 | cs: Option<PeripheralRef<'d, AnyPin>>, |
| 98 | config: Config, | 98 | config: Config, |
| 99 | ) -> Self { | 99 | ) -> Self { |
| 100 | unborrow!(inner); | 100 | into_ref!(inner); |
| 101 | 101 | ||
| 102 | unsafe { | 102 | unsafe { |
| 103 | let p = inner.regs(); | 103 | let p = inner.regs(); |
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 33119af6a..b19f043f8 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use embassy_hal_common::{unborrow, Unborrowed}; | 1 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 2 | use gpio::Pin; | 2 | use gpio::Pin; |
| 3 | 3 | ||
| 4 | use crate::{gpio, pac, peripherals, Unborrow}; | 4 | use crate::{gpio, pac, peripherals, Peripheral}; |
| 5 | 5 | ||
| 6 | #[non_exhaustive] | 6 | #[non_exhaustive] |
| 7 | pub struct Config { | 7 | pub struct Config { |
| @@ -21,19 +21,19 @@ impl Default for Config { | |||
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | pub struct Uart<'d, T: Instance> { | 23 | pub struct Uart<'d, T: Instance> { |
| 24 | inner: Unborrowed<'d, T>, | 24 | inner: PeripheralRef<'d, T>, |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | impl<'d, T: Instance> Uart<'d, T> { | 27 | impl<'d, T: Instance> Uart<'d, T> { |
| 28 | pub fn new( | 28 | pub fn new( |
| 29 | inner: impl Unborrow<Target = T> + 'd, | 29 | inner: impl Peripheral<P = T> + 'd, |
| 30 | tx: impl Unborrow<Target = impl TxPin<T>> + 'd, | 30 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, |
| 31 | rx: impl Unborrow<Target = impl RxPin<T>> + 'd, | 31 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, |
| 32 | cts: impl Unborrow<Target = impl CtsPin<T>> + 'd, | 32 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, |
| 33 | rts: impl Unborrow<Target = impl RtsPin<T>> + 'd, | 33 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, |
| 34 | config: Config, | 34 | config: Config, |
| 35 | ) -> Self { | 35 | ) -> Self { |
| 36 | unborrow!(inner, tx, rx, cts, rts); | 36 | into_ref!(inner, tx, rx, cts, rts); |
| 37 | 37 | ||
| 38 | unsafe { | 38 | unsafe { |
| 39 | let p = inner.regs(); | 39 | let p = inner.regs(); |
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index 74cfac136..50d4f9bf9 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::into_ref; |
| 4 | use embedded_hal_02::blocking::delay::DelayUs; | 4 | use embedded_hal_02::blocking::delay::DelayUs; |
| 5 | 5 | ||
| 6 | use crate::adc::{AdcPin, Instance}; | 6 | use crate::adc::{AdcPin, Instance}; |
| 7 | use crate::rcc::get_freqs; | 7 | use crate::rcc::get_freqs; |
| 8 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 9 | use crate::Unborrow; | 9 | use crate::Peripheral; |
| 10 | 10 | ||
| 11 | pub const VDDA_CALIB_MV: u32 = 3300; | 11 | pub const VDDA_CALIB_MV: u32 = 3300; |
| 12 | pub const ADC_MAX: u32 = (1 << 12) - 1; | 12 | pub const ADC_MAX: u32 = (1 << 12) - 1; |
| @@ -91,8 +91,8 @@ pub struct Adc<'d, T: Instance> { | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | impl<'d, T: Instance> Adc<'d, T> { | 93 | impl<'d, T: Instance> Adc<'d, T> { |
| 94 | pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { | 94 | pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { |
| 95 | unborrow!(_peri); | 95 | into_ref!(_peri); |
| 96 | T::enable(); | 96 | T::enable(); |
| 97 | T::reset(); | 97 | T::reset(); |
| 98 | unsafe { | 98 | unsafe { |
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index 936a35562..5c608451b 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::into_ref; |
| 4 | use embedded_hal_02::blocking::delay::DelayUs; | 4 | use embedded_hal_02::blocking::delay::DelayUs; |
| 5 | 5 | ||
| 6 | use crate::adc::{AdcPin, Instance}; | 6 | use crate::adc::{AdcPin, Instance}; |
| 7 | use crate::time::Hertz; | 7 | use crate::time::Hertz; |
| 8 | use crate::Unborrow; | 8 | use crate::Peripheral; |
| 9 | 9 | ||
| 10 | pub const VDDA_CALIB_MV: u32 = 3000; | 10 | pub const VDDA_CALIB_MV: u32 = 3000; |
| 11 | 11 | ||
| @@ -159,8 +159,8 @@ impl<'d, T> Adc<'d, T> | |||
| 159 | where | 159 | where |
| 160 | T: Instance, | 160 | T: Instance, |
| 161 | { | 161 | { |
| 162 | pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { | 162 | pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { |
| 163 | unborrow!(_peri); | 163 | into_ref!(_peri); |
| 164 | enable(); | 164 | enable(); |
| 165 | 165 | ||
| 166 | let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; | 166 | let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; |
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 49d149b18..dbfd18810 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::into_ref; |
| 4 | use embedded_hal_02::blocking::delay::DelayUs; | 4 | use embedded_hal_02::blocking::delay::DelayUs; |
| 5 | 5 | ||
| 6 | use crate::adc::{AdcPin, Instance}; | 6 | use crate::adc::{AdcPin, Instance}; |
| 7 | use crate::Unborrow; | 7 | use crate::Peripheral; |
| 8 | 8 | ||
| 9 | pub const VDDA_CALIB_MV: u32 = 3000; | 9 | pub const VDDA_CALIB_MV: u32 = 3000; |
| 10 | 10 | ||
| @@ -208,8 +208,8 @@ pub struct Adc<'d, T: Instance> { | |||
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | impl<'d, T: Instance> Adc<'d, T> { | 210 | impl<'d, T: Instance> Adc<'d, T> { |
| 211 | pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { | 211 | pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { |
| 212 | unborrow!(_peri); | 212 | into_ref!(_peri); |
| 213 | enable(); | 213 | enable(); |
| 214 | unsafe { | 214 | unsafe { |
| 215 | T::regs().cr().modify(|reg| { | 215 | T::regs().cr().modify(|reg| { |
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 3f933f4fc..92e8ac369 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs | |||
| @@ -7,7 +7,7 @@ use pac::adccommon::vals::Presc; | |||
| 7 | 7 | ||
| 8 | use super::{AdcPin, Instance}; | 8 | use super::{AdcPin, Instance}; |
| 9 | use crate::time::Hertz; | 9 | use crate::time::Hertz; |
| 10 | use crate::{pac, Unborrow}; | 10 | use crate::{pac, Peripheral}; |
| 11 | 11 | ||
| 12 | pub enum Resolution { | 12 | pub enum Resolution { |
| 13 | SixteenBit, | 13 | SixteenBit, |
| @@ -322,8 +322,8 @@ pub struct Adc<'d, T: Instance> { | |||
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { | 324 | impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { |
| 325 | pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u16>) -> Self { | 325 | pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u16>) -> Self { |
| 326 | embassy_hal_common::unborrow!(_peri); | 326 | embassy_hal_common::into_ref!(_peri); |
| 327 | T::enable(); | 327 | T::enable(); |
| 328 | T::reset(); | 328 | T::reset(); |
| 329 | 329 | ||
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 6c0de2ded..c0bd44e0f 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use core::ops::{Deref, DerefMut}; | 1 | use core::ops::{Deref, DerefMut}; |
| 2 | 2 | ||
| 3 | pub use bxcan; | 3 | pub use bxcan; |
| 4 | use embassy_hal_common::{unborrow, Unborrowed}; | 4 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 5 | 5 | ||
| 6 | use crate::gpio::sealed::AFType; | 6 | use crate::gpio::sealed::AFType; |
| 7 | use crate::rcc::RccPeripheral; | 7 | use crate::rcc::RccPeripheral; |
| 8 | use crate::{peripherals, Unborrow}; | 8 | use crate::{peripherals, Peripheral}; |
| 9 | 9 | ||
| 10 | pub struct Can<'d, T: Instance> { | 10 | pub struct Can<'d, T: Instance> { |
| 11 | can: bxcan::Can<BxcanInstance<'d, T>>, | 11 | can: bxcan::Can<BxcanInstance<'d, T>>, |
| @@ -13,11 +13,11 @@ pub struct Can<'d, T: Instance> { | |||
| 13 | 13 | ||
| 14 | impl<'d, T: Instance> Can<'d, T> { | 14 | impl<'d, T: Instance> Can<'d, T> { |
| 15 | pub fn new( | 15 | pub fn new( |
| 16 | peri: impl Unborrow<Target = T> + 'd, | 16 | peri: impl Peripheral<P = T> + 'd, |
| 17 | rx: impl Unborrow<Target = impl RxPin<T>> + 'd, | 17 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, |
| 18 | tx: impl Unborrow<Target = impl TxPin<T>> + 'd, | 18 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, |
| 19 | ) -> Self { | 19 | ) -> Self { |
| 20 | unborrow!(peri, rx, tx); | 20 | into_ref!(peri, rx, tx); |
| 21 | 21 | ||
| 22 | unsafe { | 22 | unsafe { |
| 23 | rx.set_as_af(rx.af_num(), AFType::Input); | 23 | rx.set_as_af(rx.af_num(), AFType::Input); |
| @@ -66,7 +66,7 @@ pub(crate) mod sealed { | |||
| 66 | 66 | ||
| 67 | pub trait Instance: sealed::Instance + RccPeripheral {} | 67 | pub trait Instance: sealed::Instance + RccPeripheral {} |
| 68 | 68 | ||
| 69 | pub struct BxcanInstance<'a, T>(Unborrowed<'a, T>); | 69 | pub struct BxcanInstance<'a, T>(PeripheralRef<'a, T>); |
| 70 | 70 | ||
| 71 | unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> { | 71 | unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> { |
| 72 | const REGISTERS: *mut bxcan::RegisterBlock = T::REGISTERS; | 72 | const REGISTERS: *mut bxcan::RegisterBlock = T::REGISTERS; |
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index 85abf22d1..393089eed 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | use embassy_hal_common::{unborrow, Unborrowed}; | 1 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 2 | 2 | ||
| 3 | use crate::pac::CRC as PAC_CRC; | 3 | use crate::pac::CRC as PAC_CRC; |
| 4 | use crate::peripherals::CRC; | 4 | use crate::peripherals::CRC; |
| 5 | use crate::rcc::sealed::RccPeripheral; | 5 | use crate::rcc::sealed::RccPeripheral; |
| 6 | use crate::Unborrow; | 6 | use crate::Peripheral; |
| 7 | 7 | ||
| 8 | pub struct Crc<'d> { | 8 | pub struct Crc<'d> { |
| 9 | _peri: Unborrowed<'d, CRC>, | 9 | _peri: PeripheralRef<'d, CRC>, |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | impl<'d> Crc<'d> { | 12 | impl<'d> Crc<'d> { |
| 13 | /// Instantiates the CRC32 peripheral and initializes it to default values. | 13 | /// Instantiates the CRC32 peripheral and initializes it to default values. |
| 14 | pub fn new(peripheral: impl Unborrow<Target = CRC> + 'd) -> Self { | 14 | pub fn new(peripheral: impl Peripheral<P = CRC> + 'd) -> Self { |
| 15 | unborrow!(peripheral); | 15 | into_ref!(peripheral); |
| 16 | 16 | ||
| 17 | // Note: enable and reset come from RccPeripheral. | 17 | // Note: enable and reset come from RccPeripheral. |
| 18 | // enable CRC clock in RCC. | 18 | // enable CRC clock in RCC. |
| 19 | CRC::enable(); | 19 | CRC::enable(); |
| 20 | // Reset CRC to default values. | 20 | // Reset CRC to default values. |
| 21 | CRC::reset(); | 21 | CRC::reset(); |
| 22 | // Unborrow the peripheral | 22 | // Peripheral the peripheral |
| 23 | let mut instance = Self { _peri: peripheral }; | 23 | let mut instance = Self { _peri: peripheral }; |
| 24 | instance.reset(); | 24 | instance.reset(); |
| 25 | instance | 25 | instance |
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index 06da29c17..8acb3a770 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | use embassy_hal_common::{unborrow, Unborrowed}; | 1 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 2 | 2 | ||
| 3 | use crate::pac::crc::vals; | 3 | use crate::pac::crc::vals; |
| 4 | use crate::pac::CRC as PAC_CRC; | 4 | use crate::pac::CRC as PAC_CRC; |
| 5 | use crate::peripherals::CRC; | 5 | use crate::peripherals::CRC; |
| 6 | use crate::rcc::sealed::RccPeripheral; | 6 | use crate::rcc::sealed::RccPeripheral; |
| 7 | use crate::Unborrow; | 7 | use crate::Peripheral; |
| 8 | 8 | ||
| 9 | pub struct Crc<'d> { | 9 | pub struct Crc<'d> { |
| 10 | _peripheral: Unborrowed<'d, CRC>, | 10 | _peripheral: PeripheralRef<'d, CRC>, |
| 11 | _config: Config, | 11 | _config: Config, |
| 12 | } | 12 | } |
| 13 | 13 | ||
| @@ -67,13 +67,13 @@ pub enum PolySize { | |||
| 67 | 67 | ||
| 68 | impl<'d> Crc<'d> { | 68 | impl<'d> Crc<'d> { |
| 69 | /// Instantiates the CRC32 peripheral and initializes it to default values. | 69 | /// Instantiates the CRC32 peripheral and initializes it to default values. |
| 70 | pub fn new(peripheral: impl Unborrow<Target = CRC> + 'd, config: Config) -> Self { | 70 | pub fn new(peripheral: impl Peripheral<P = CRC> + 'd, config: Config) -> Self { |
| 71 | // Note: enable and reset come from RccPeripheral. | 71 | // Note: enable and reset come from RccPeripheral. |
| 72 | // enable CRC clock in RCC. | 72 | // enable CRC clock in RCC. |
| 73 | CRC::enable(); | 73 | CRC::enable(); |
| 74 | // Reset CRC to default values. | 74 | // Reset CRC to default values. |
| 75 | CRC::reset(); | 75 | CRC::reset(); |
| 76 | unborrow!(peripheral); | 76 | into_ref!(peripheral); |
| 77 | let mut instance = Self { | 77 | let mut instance = Self { |
| 78 | _peripheral: peripheral, | 78 | _peripheral: peripheral, |
| 79 | _config: config, | 79 | _config: config, |
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index 798eefbf9..6b7f41c63 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use embassy_hal_common::{unborrow, Unborrowed}; | 1 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 2 | 2 | ||
| 3 | use crate::dac::{DacPin, Instance}; | 3 | use crate::dac::{DacPin, Instance}; |
| 4 | use crate::pac::dac; | 4 | use crate::pac::dac; |
| 5 | use crate::Unborrow; | 5 | use crate::Peripheral; |
| 6 | 6 | ||
| 7 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 7 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -88,7 +88,7 @@ pub enum Value { | |||
| 88 | 88 | ||
| 89 | pub struct Dac<'d, T: Instance> { | 89 | pub struct Dac<'d, T: Instance> { |
| 90 | channels: u8, | 90 | channels: u8, |
| 91 | _peri: Unborrowed<'d, T>, | 91 | _peri: PeripheralRef<'d, T>, |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | macro_rules! enable { | 94 | macro_rules! enable { |
| @@ -100,21 +100,21 @@ macro_rules! enable { | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | impl<'d, T: Instance> Dac<'d, T> { | 102 | impl<'d, T: Instance> Dac<'d, T> { |
| 103 | pub fn new_1ch(peri: impl Unborrow<Target = T> + 'd, _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd) -> Self { | 103 | pub fn new_1ch(peri: impl Peripheral<P = T> + 'd, _ch1: impl Peripheral<P = impl DacPin<T, 1>> + 'd) -> Self { |
| 104 | unborrow!(peri); | 104 | into_ref!(peri); |
| 105 | Self::new_inner(peri, 1) | 105 | Self::new_inner(peri, 1) |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | pub fn new_2ch( | 108 | pub fn new_2ch( |
| 109 | peri: impl Unborrow<Target = T> + 'd, | 109 | peri: impl Peripheral<P = T> + 'd, |
| 110 | _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd, | 110 | _ch1: impl Peripheral<P = impl DacPin<T, 1>> + 'd, |
| 111 | _ch2: impl Unborrow<Target = impl DacPin<T, 2>> + 'd, | 111 | _ch2: impl Peripheral<P = impl DacPin<T, 2>> + 'd, |
| 112 | ) -> Self { | 112 | ) -> Self { |
| 113 | unborrow!(peri); | 113 | into_ref!(peri); |
| 114 | Self::new_inner(peri, 2) | 114 | Self::new_inner(peri, 2) |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | fn new_inner(peri: Unborrowed<'d, T>, channels: u8) -> Self { | 117 | fn new_inner(peri: PeripheralRef<'d, T>, channels: u8) -> Self { |
| 118 | unsafe { | 118 | unsafe { |
| 119 | // Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent DAC clock | 119 | // Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent DAC clock |
| 120 | // configuration. | 120 | // configuration. |
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index bcf723498..e28225426 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | use core::task::Poll; | 1 | use core::task::Poll; |
| 2 | 2 | ||
| 3 | use embassy::waitqueue::AtomicWaker; | 3 | use embassy::waitqueue::AtomicWaker; |
| 4 | use embassy_hal_common::{unborrow, Unborrowed}; | 4 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 5 | use futures::future::poll_fn; | 5 | use futures::future::poll_fn; |
| 6 | 6 | ||
| 7 | use crate::gpio::sealed::AFType; | 7 | use crate::gpio::sealed::AFType; |
| 8 | use crate::gpio::Speed; | 8 | use crate::gpio::Speed; |
| 9 | use crate::interrupt::{Interrupt, InterruptExt}; | 9 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 10 | use crate::Unborrow; | 10 | use crate::Peripheral; |
| 11 | 11 | ||
| 12 | /// The level on the VSync pin when the data is not valid on the parallel interface. | 12 | /// The level on the VSync pin when the data is not valid on the parallel interface. |
| 13 | #[derive(Clone, Copy, PartialEq)] | 13 | #[derive(Clone, Copy, PartialEq)] |
| @@ -69,7 +69,7 @@ impl Default for Config { | |||
| 69 | 69 | ||
| 70 | macro_rules! config_pins { | 70 | macro_rules! config_pins { |
| 71 | ($($pin:ident),*) => { | 71 | ($($pin:ident),*) => { |
| 72 | unborrow!($($pin),*); | 72 | into_ref!($($pin),*); |
| 73 | // NOTE(unsafe) Exclusive access to the registers | 73 | // NOTE(unsafe) Exclusive access to the registers |
| 74 | critical_section::with(|_| unsafe { | 74 | critical_section::with(|_| unsafe { |
| 75 | $( | 75 | $( |
| @@ -81,8 +81,8 @@ macro_rules! config_pins { | |||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | pub struct Dcmi<'d, T: Instance, Dma: FrameDma<T>> { | 83 | pub struct Dcmi<'d, T: Instance, Dma: FrameDma<T>> { |
| 84 | inner: Unborrowed<'d, T>, | 84 | inner: PeripheralRef<'d, T>, |
| 85 | dma: Unborrowed<'d, Dma>, | 85 | dma: PeripheralRef<'d, Dma>, |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | impl<'d, T, Dma> Dcmi<'d, T, Dma> | 88 | impl<'d, T, Dma> Dcmi<'d, T, Dma> |
| @@ -91,23 +91,23 @@ where | |||
| 91 | Dma: FrameDma<T>, | 91 | Dma: FrameDma<T>, |
| 92 | { | 92 | { |
| 93 | pub fn new_8bit( | 93 | pub fn new_8bit( |
| 94 | peri: impl Unborrow<Target = T> + 'd, | 94 | peri: impl Peripheral<P = T> + 'd, |
| 95 | dma: impl Unborrow<Target = Dma> + 'd, | 95 | dma: impl Peripheral<P = Dma> + 'd, |
| 96 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 96 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 97 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 97 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 98 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 98 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 99 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 99 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 100 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 100 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 101 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 101 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 102 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 102 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 103 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 103 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 104 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 104 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 105 | v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd, | 105 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, |
| 106 | h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd, | 106 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, |
| 107 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 107 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 108 | config: Config, | 108 | config: Config, |
| 109 | ) -> Self { | 109 | ) -> Self { |
| 110 | unborrow!(peri, dma, irq); | 110 | into_ref!(peri, dma, irq); |
| 111 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); | 111 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); |
| 112 | config_pins!(v_sync, h_sync, pixclk); | 112 | config_pins!(v_sync, h_sync, pixclk); |
| 113 | 113 | ||
| @@ -115,25 +115,25 @@ where | |||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | pub fn new_10bit( | 117 | pub fn new_10bit( |
| 118 | peri: impl Unborrow<Target = T> + 'd, | 118 | peri: impl Peripheral<P = T> + 'd, |
| 119 | dma: impl Unborrow<Target = Dma> + 'd, | 119 | dma: impl Peripheral<P = Dma> + 'd, |
| 120 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 120 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 121 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 121 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 122 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 122 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 123 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 123 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 124 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 124 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 125 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 125 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 126 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 126 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 127 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 127 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 128 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 128 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 129 | d8: impl Unborrow<Target = impl D8Pin<T>> + 'd, | 129 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, |
| 130 | d9: impl Unborrow<Target = impl D9Pin<T>> + 'd, | 130 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, |
| 131 | v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd, | 131 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, |
| 132 | h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd, | 132 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, |
| 133 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 133 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 134 | config: Config, | 134 | config: Config, |
| 135 | ) -> Self { | 135 | ) -> Self { |
| 136 | unborrow!(peri, dma, irq); | 136 | into_ref!(peri, dma, irq); |
| 137 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); | 137 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); |
| 138 | config_pins!(v_sync, h_sync, pixclk); | 138 | config_pins!(v_sync, h_sync, pixclk); |
| 139 | 139 | ||
| @@ -141,27 +141,27 @@ where | |||
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | pub fn new_12bit( | 143 | pub fn new_12bit( |
| 144 | peri: impl Unborrow<Target = T> + 'd, | 144 | peri: impl Peripheral<P = T> + 'd, |
| 145 | dma: impl Unborrow<Target = Dma> + 'd, | 145 | dma: impl Peripheral<P = Dma> + 'd, |
| 146 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 146 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 147 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 147 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 148 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 148 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 149 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 149 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 150 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 150 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 151 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 151 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 152 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 152 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 153 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 153 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 154 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 154 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 155 | d8: impl Unborrow<Target = impl D8Pin<T>> + 'd, | 155 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, |
| 156 | d9: impl Unborrow<Target = impl D9Pin<T>> + 'd, | 156 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, |
| 157 | d10: impl Unborrow<Target = impl D10Pin<T>> + 'd, | 157 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, |
| 158 | d11: impl Unborrow<Target = impl D11Pin<T>> + 'd, | 158 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, |
| 159 | v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd, | 159 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, |
| 160 | h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd, | 160 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, |
| 161 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 161 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 162 | config: Config, | 162 | config: Config, |
| 163 | ) -> Self { | 163 | ) -> Self { |
| 164 | unborrow!(peri, dma, irq); | 164 | into_ref!(peri, dma, irq); |
| 165 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); | 165 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); |
| 166 | config_pins!(v_sync, h_sync, pixclk); | 166 | config_pins!(v_sync, h_sync, pixclk); |
| 167 | 167 | ||
| @@ -169,29 +169,29 @@ where | |||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | pub fn new_14bit( | 171 | pub fn new_14bit( |
| 172 | peri: impl Unborrow<Target = T> + 'd, | 172 | peri: impl Peripheral<P = T> + 'd, |
| 173 | dma: impl Unborrow<Target = Dma> + 'd, | 173 | dma: impl Peripheral<P = Dma> + 'd, |
| 174 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 174 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 175 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 175 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 176 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 176 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 177 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 177 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 178 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 178 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 179 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 179 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 180 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 180 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 181 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 181 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 182 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 182 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 183 | d8: impl Unborrow<Target = impl D8Pin<T>> + 'd, | 183 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, |
| 184 | d9: impl Unborrow<Target = impl D9Pin<T>> + 'd, | 184 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, |
| 185 | d10: impl Unborrow<Target = impl D10Pin<T>> + 'd, | 185 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, |
| 186 | d11: impl Unborrow<Target = impl D11Pin<T>> + 'd, | 186 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, |
| 187 | d12: impl Unborrow<Target = impl D12Pin<T>> + 'd, | 187 | d12: impl Peripheral<P = impl D12Pin<T>> + 'd, |
| 188 | d13: impl Unborrow<Target = impl D13Pin<T>> + 'd, | 188 | d13: impl Peripheral<P = impl D13Pin<T>> + 'd, |
| 189 | v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd, | 189 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, |
| 190 | h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd, | 190 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, |
| 191 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 191 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 192 | config: Config, | 192 | config: Config, |
| 193 | ) -> Self { | 193 | ) -> Self { |
| 194 | unborrow!(peri, dma, irq); | 194 | into_ref!(peri, dma, irq); |
| 195 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); | 195 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); |
| 196 | config_pins!(v_sync, h_sync, pixclk); | 196 | config_pins!(v_sync, h_sync, pixclk); |
| 197 | 197 | ||
| @@ -199,21 +199,21 @@ where | |||
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | pub fn new_es_8bit( | 201 | pub fn new_es_8bit( |
| 202 | peri: impl Unborrow<Target = T> + 'd, | 202 | peri: impl Peripheral<P = T> + 'd, |
| 203 | dma: impl Unborrow<Target = Dma> + 'd, | 203 | dma: impl Peripheral<P = Dma> + 'd, |
| 204 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 204 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 205 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 205 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 206 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 206 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 207 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 207 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 208 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 208 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 209 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 209 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 210 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 210 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 211 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 211 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 212 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 212 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 213 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 213 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 214 | config: Config, | 214 | config: Config, |
| 215 | ) -> Self { | 215 | ) -> Self { |
| 216 | unborrow!(peri, dma, irq); | 216 | into_ref!(peri, dma, irq); |
| 217 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); | 217 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); |
| 218 | config_pins!(pixclk); | 218 | config_pins!(pixclk); |
| 219 | 219 | ||
| @@ -221,23 +221,23 @@ where | |||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | pub fn new_es_10bit( | 223 | pub fn new_es_10bit( |
| 224 | peri: impl Unborrow<Target = T> + 'd, | 224 | peri: impl Peripheral<P = T> + 'd, |
| 225 | dma: impl Unborrow<Target = Dma> + 'd, | 225 | dma: impl Peripheral<P = Dma> + 'd, |
| 226 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 226 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 227 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 227 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 228 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 228 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 229 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 229 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 230 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 230 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 231 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 231 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 232 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 232 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 233 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 233 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 234 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 234 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 235 | d8: impl Unborrow<Target = impl D8Pin<T>> + 'd, | 235 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, |
| 236 | d9: impl Unborrow<Target = impl D9Pin<T>> + 'd, | 236 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, |
| 237 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 237 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 238 | config: Config, | 238 | config: Config, |
| 239 | ) -> Self { | 239 | ) -> Self { |
| 240 | unborrow!(peri, dma, irq); | 240 | into_ref!(peri, dma, irq); |
| 241 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); | 241 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); |
| 242 | config_pins!(pixclk); | 242 | config_pins!(pixclk); |
| 243 | 243 | ||
| @@ -245,25 +245,25 @@ where | |||
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | pub fn new_es_12bit( | 247 | pub fn new_es_12bit( |
| 248 | peri: impl Unborrow<Target = T> + 'd, | 248 | peri: impl Peripheral<P = T> + 'd, |
| 249 | dma: impl Unborrow<Target = Dma> + 'd, | 249 | dma: impl Peripheral<P = Dma> + 'd, |
| 250 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 250 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 251 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 251 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 252 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 252 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 253 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 253 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 254 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 254 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 255 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 255 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 256 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 256 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 257 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 257 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 258 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 258 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 259 | d8: impl Unborrow<Target = impl D8Pin<T>> + 'd, | 259 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, |
| 260 | d9: impl Unborrow<Target = impl D9Pin<T>> + 'd, | 260 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, |
| 261 | d10: impl Unborrow<Target = impl D10Pin<T>> + 'd, | 261 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, |
| 262 | d11: impl Unborrow<Target = impl D11Pin<T>> + 'd, | 262 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, |
| 263 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 263 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 264 | config: Config, | 264 | config: Config, |
| 265 | ) -> Self { | 265 | ) -> Self { |
| 266 | unborrow!(peri, dma, irq); | 266 | into_ref!(peri, dma, irq); |
| 267 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); | 267 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); |
| 268 | config_pins!(pixclk); | 268 | config_pins!(pixclk); |
| 269 | 269 | ||
| @@ -271,27 +271,27 @@ where | |||
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | pub fn new_es_14bit( | 273 | pub fn new_es_14bit( |
| 274 | peri: impl Unborrow<Target = T> + 'd, | 274 | peri: impl Peripheral<P = T> + 'd, |
| 275 | dma: impl Unborrow<Target = Dma> + 'd, | 275 | dma: impl Peripheral<P = Dma> + 'd, |
| 276 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 276 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 277 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 277 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 278 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 278 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 279 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 279 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 280 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 280 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 281 | d4: impl Unborrow<Target = impl D4Pin<T>> + 'd, | 281 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, |
| 282 | d5: impl Unborrow<Target = impl D5Pin<T>> + 'd, | 282 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, |
| 283 | d6: impl Unborrow<Target = impl D6Pin<T>> + 'd, | 283 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, |
| 284 | d7: impl Unborrow<Target = impl D7Pin<T>> + 'd, | 284 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, |
| 285 | d8: impl Unborrow<Target = impl D8Pin<T>> + 'd, | 285 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, |
| 286 | d9: impl Unborrow<Target = impl D9Pin<T>> + 'd, | 286 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, |
| 287 | d10: impl Unborrow<Target = impl D10Pin<T>> + 'd, | 287 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, |
| 288 | d11: impl Unborrow<Target = impl D11Pin<T>> + 'd, | 288 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, |
| 289 | d12: impl Unborrow<Target = impl D12Pin<T>> + 'd, | 289 | d12: impl Peripheral<P = impl D12Pin<T>> + 'd, |
| 290 | d13: impl Unborrow<Target = impl D13Pin<T>> + 'd, | 290 | d13: impl Peripheral<P = impl D13Pin<T>> + 'd, |
| 291 | pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd, | 291 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, |
| 292 | config: Config, | 292 | config: Config, |
| 293 | ) -> Self { | 293 | ) -> Self { |
| 294 | unborrow!(peri, dma, irq); | 294 | into_ref!(peri, dma, irq); |
| 295 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); | 295 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); |
| 296 | config_pins!(pixclk); | 296 | config_pins!(pixclk); |
| 297 | 297 | ||
| @@ -299,9 +299,9 @@ where | |||
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | fn new_inner( | 301 | fn new_inner( |
| 302 | peri: Unborrowed<'d, T>, | 302 | peri: PeripheralRef<'d, T>, |
| 303 | dma: Unborrowed<'d, Dma>, | 303 | dma: PeripheralRef<'d, Dma>, |
| 304 | irq: Unborrowed<'d, T::Interrupt>, | 304 | irq: PeripheralRef<'d, T::Interrupt>, |
| 305 | config: Config, | 305 | config: Config, |
| 306 | use_embedded_synchronization: bool, | 306 | use_embedded_synchronization: bool, |
| 307 | edm: u8, | 307 | edm: u8, |
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index fe2bf900e..cc030a93e 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -12,11 +12,11 @@ use core::mem; | |||
| 12 | use core::pin::Pin; | 12 | use core::pin::Pin; |
| 13 | use core::task::{Context, Poll, Waker}; | 13 | use core::task::{Context, Poll, Waker}; |
| 14 | 14 | ||
| 15 | use embassy_hal_common::{impl_unborrow, unborrow}; | 15 | use embassy_hal_common::{impl_peripheral, into_ref}; |
| 16 | 16 | ||
| 17 | #[cfg(dmamux)] | 17 | #[cfg(dmamux)] |
| 18 | pub use self::dmamux::*; | 18 | pub use self::dmamux::*; |
| 19 | use crate::Unborrow; | 19 | use crate::Peripheral; |
| 20 | 20 | ||
| 21 | #[cfg(feature = "unstable-pac")] | 21 | #[cfg(feature = "unstable-pac")] |
| 22 | pub mod low_level { | 22 | pub mod low_level { |
| @@ -206,19 +206,19 @@ impl Default for TransferOptions { | |||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | mod transfers { | 208 | mod transfers { |
| 209 | use embassy_hal_common::Unborrowed; | 209 | use embassy_hal_common::PeripheralRef; |
| 210 | 210 | ||
| 211 | use super::*; | 211 | use super::*; |
| 212 | 212 | ||
| 213 | #[allow(unused)] | 213 | #[allow(unused)] |
| 214 | pub fn read<'a, W: Word>( | 214 | pub fn read<'a, W: Word>( |
| 215 | channel: impl Unborrow<Target = impl Channel> + 'a, | 215 | channel: impl Peripheral<P = impl Channel> + 'a, |
| 216 | request: Request, | 216 | request: Request, |
| 217 | reg_addr: *mut W, | 217 | reg_addr: *mut W, |
| 218 | buf: &'a mut [W], | 218 | buf: &'a mut [W], |
| 219 | ) -> impl Future<Output = ()> + 'a { | 219 | ) -> impl Future<Output = ()> + 'a { |
| 220 | assert!(buf.len() > 0 && buf.len() <= 0xFFFF); | 220 | assert!(buf.len() > 0 && buf.len() <= 0xFFFF); |
| 221 | unborrow!(channel); | 221 | into_ref!(channel); |
| 222 | 222 | ||
| 223 | unsafe { channel.start_read::<W>(request, reg_addr, buf, Default::default()) }; | 223 | unsafe { channel.start_read::<W>(request, reg_addr, buf, Default::default()) }; |
| 224 | 224 | ||
| @@ -227,13 +227,13 @@ mod transfers { | |||
| 227 | 227 | ||
| 228 | #[allow(unused)] | 228 | #[allow(unused)] |
| 229 | pub fn write<'a, W: Word>( | 229 | pub fn write<'a, W: Word>( |
| 230 | channel: impl Unborrow<Target = impl Channel> + 'a, | 230 | channel: impl Peripheral<P = impl Channel> + 'a, |
| 231 | request: Request, | 231 | request: Request, |
| 232 | buf: &'a [W], | 232 | buf: &'a [W], |
| 233 | reg_addr: *mut W, | 233 | reg_addr: *mut W, |
| 234 | ) -> impl Future<Output = ()> + 'a { | 234 | ) -> impl Future<Output = ()> + 'a { |
| 235 | assert!(buf.len() > 0 && buf.len() <= 0xFFFF); | 235 | assert!(buf.len() > 0 && buf.len() <= 0xFFFF); |
| 236 | unborrow!(channel); | 236 | into_ref!(channel); |
| 237 | 237 | ||
| 238 | unsafe { channel.start_write::<W>(request, buf, reg_addr, Default::default()) }; | 238 | unsafe { channel.start_write::<W>(request, buf, reg_addr, Default::default()) }; |
| 239 | 239 | ||
| @@ -242,13 +242,13 @@ mod transfers { | |||
| 242 | 242 | ||
| 243 | #[allow(unused)] | 243 | #[allow(unused)] |
| 244 | pub fn write_repeated<'a, W: Word>( | 244 | pub fn write_repeated<'a, W: Word>( |
| 245 | channel: impl Unborrow<Target = impl Channel> + 'a, | 245 | channel: impl Peripheral<P = impl Channel> + 'a, |
| 246 | request: Request, | 246 | request: Request, |
| 247 | repeated: W, | 247 | repeated: W, |
| 248 | count: usize, | 248 | count: usize, |
| 249 | reg_addr: *mut W, | 249 | reg_addr: *mut W, |
| 250 | ) -> impl Future<Output = ()> + 'a { | 250 | ) -> impl Future<Output = ()> + 'a { |
| 251 | unborrow!(channel); | 251 | into_ref!(channel); |
| 252 | 252 | ||
| 253 | unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr, Default::default()) }; | 253 | unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr, Default::default()) }; |
| 254 | 254 | ||
| @@ -256,12 +256,12 @@ mod transfers { | |||
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | pub(crate) struct Transfer<'a, C: Channel> { | 258 | pub(crate) struct Transfer<'a, C: Channel> { |
| 259 | channel: Unborrowed<'a, C>, | 259 | channel: PeripheralRef<'a, C>, |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | impl<'a, C: Channel> Transfer<'a, C> { | 262 | impl<'a, C: Channel> Transfer<'a, C> { |
| 263 | pub(crate) fn new(channel: impl Unborrow<Target = C> + 'a) -> Self { | 263 | pub(crate) fn new(channel: impl Peripheral<P = C> + 'a) -> Self { |
| 264 | unborrow!(channel); | 264 | into_ref!(channel); |
| 265 | Self { channel } | 265 | Self { channel } |
| 266 | } | 266 | } |
| 267 | } | 267 | } |
| @@ -287,11 +287,11 @@ mod transfers { | |||
| 287 | } | 287 | } |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | pub trait Channel: sealed::Channel + Unborrow<Target = Self> + 'static {} | 290 | pub trait Channel: sealed::Channel + Peripheral<P = Self> + 'static {} |
| 291 | 291 | ||
| 292 | pub struct NoDma; | 292 | pub struct NoDma; |
| 293 | 293 | ||
| 294 | impl_unborrow!(NoDma); | 294 | impl_peripheral!(NoDma); |
| 295 | 295 | ||
| 296 | // safety: must be called only once at startup | 296 | // safety: must be called only once at startup |
| 297 | pub(crate) unsafe fn init() { | 297 | pub(crate) unsafe fn init() { |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index f2cdd9098..5e31c32b5 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs | |||
| @@ -6,7 +6,7 @@ use core::task::Waker; | |||
| 6 | 6 | ||
| 7 | use embassy::waitqueue::AtomicWaker; | 7 | use embassy::waitqueue::AtomicWaker; |
| 8 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 8 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 9 | use embassy_hal_common::{unborrow, Unborrowed}; | 9 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 10 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 10 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 11 | 11 | ||
| 12 | use crate::gpio::sealed::{AFType, Pin as __GpioPin}; | 12 | use crate::gpio::sealed::{AFType, Pin as __GpioPin}; |
| @@ -16,7 +16,7 @@ use crate::pac::AFIO; | |||
| 16 | #[cfg(any(eth_v1b, eth_v1c))] | 16 | #[cfg(any(eth_v1b, eth_v1c))] |
| 17 | use crate::pac::SYSCFG; | 17 | use crate::pac::SYSCFG; |
| 18 | use crate::pac::{ETH, RCC}; | 18 | use crate::pac::{ETH, RCC}; |
| 19 | use crate::Unborrow; | 19 | use crate::Peripheral; |
| 20 | 20 | ||
| 21 | mod descriptors; | 21 | mod descriptors; |
| 22 | mod rx_desc; | 22 | mod rx_desc; |
| @@ -36,7 +36,7 @@ impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { | |||
| 36 | 36 | ||
| 37 | pub struct Ethernet<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> { | 37 | pub struct Ethernet<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> { |
| 38 | state: PeripheralMutex<'d, Inner<'d, T, TX, RX>>, | 38 | state: PeripheralMutex<'d, Inner<'d, T, TX, RX>>, |
| 39 | pins: [Unborrowed<'d, AnyPin>; 9], | 39 | pins: [PeripheralRef<'d, AnyPin>; 9], |
| 40 | _phy: P, | 40 | _phy: P, |
| 41 | clock_range: Cr, | 41 | clock_range: Cr, |
| 42 | phy_addr: u8, | 42 | phy_addr: u8, |
| @@ -86,22 +86,22 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, T, | |||
| 86 | /// safety: the returned instance is not leak-safe | 86 | /// safety: the returned instance is not leak-safe |
| 87 | pub unsafe fn new( | 87 | pub unsafe fn new( |
| 88 | state: &'d mut State<'d, T, TX, RX>, | 88 | state: &'d mut State<'d, T, TX, RX>, |
| 89 | peri: impl Unborrow<Target = T> + 'd, | 89 | peri: impl Peripheral<P = T> + 'd, |
| 90 | interrupt: impl Unborrow<Target = crate::interrupt::ETH> + 'd, | 90 | interrupt: impl Peripheral<P = crate::interrupt::ETH> + 'd, |
| 91 | ref_clk: impl Unborrow<Target = impl RefClkPin<T>> + 'd, | 91 | ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd, |
| 92 | mdio: impl Unborrow<Target = impl MDIOPin<T>> + 'd, | 92 | mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, |
| 93 | mdc: impl Unborrow<Target = impl MDCPin<T>> + 'd, | 93 | mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, |
| 94 | crs: impl Unborrow<Target = impl CRSPin<T>> + 'd, | 94 | crs: impl Peripheral<P = impl CRSPin<T>> + 'd, |
| 95 | rx_d0: impl Unborrow<Target = impl RXD0Pin<T>> + 'd, | 95 | rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, |
| 96 | rx_d1: impl Unborrow<Target = impl RXD1Pin<T>> + 'd, | 96 | rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, |
| 97 | tx_d0: impl Unborrow<Target = impl TXD0Pin<T>> + 'd, | 97 | tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, |
| 98 | tx_d1: impl Unborrow<Target = impl TXD1Pin<T>> + 'd, | 98 | tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, |
| 99 | tx_en: impl Unborrow<Target = impl TXEnPin<T>> + 'd, | 99 | tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, |
| 100 | phy: P, | 100 | phy: P, |
| 101 | mac_addr: [u8; 6], | 101 | mac_addr: [u8; 6], |
| 102 | phy_addr: u8, | 102 | phy_addr: u8, |
| 103 | ) -> Self { | 103 | ) -> Self { |
| 104 | unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | 104 | into_ref!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); |
| 105 | 105 | ||
| 106 | // Enable the necessary Clocks | 106 | // Enable the necessary Clocks |
| 107 | // NOTE(unsafe) We have exclusive access to the registers | 107 | // NOTE(unsafe) We have exclusive access to the registers |
| @@ -370,7 +370,7 @@ struct Inner<'d, T: Instance, const TX: usize, const RX: usize> { | |||
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | impl<'d, T: Instance, const TX: usize, const RX: usize> Inner<'d, T, TX, RX> { | 372 | impl<'d, T: Instance, const TX: usize, const RX: usize> Inner<'d, T, TX, RX> { |
| 373 | pub fn new(_peri: impl Unborrow<Target = T> + 'd) -> Self { | 373 | pub fn new(_peri: impl Peripheral<P = T> + 'd) -> Self { |
| 374 | Self { | 374 | Self { |
| 375 | _peri: PhantomData, | 375 | _peri: PhantomData, |
| 376 | desc_ring: DescriptorRing::new(), | 376 | desc_ring: DescriptorRing::new(), |
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index c67a03077..2b4a9367b 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -4,13 +4,13 @@ use core::task::Waker; | |||
| 4 | 4 | ||
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 6 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 7 | use embassy_hal_common::{unborrow, Unborrowed}; | 7 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 8 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 8 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 9 | 9 | ||
| 10 | use crate::gpio::sealed::{AFType, Pin as _}; | 10 | use crate::gpio::sealed::{AFType, Pin as _}; |
| 11 | use crate::gpio::{AnyPin, Speed}; | 11 | use crate::gpio::{AnyPin, Speed}; |
| 12 | use crate::pac::{ETH, RCC, SYSCFG}; | 12 | use crate::pac::{ETH, RCC, SYSCFG}; |
| 13 | use crate::Unborrow; | 13 | use crate::Peripheral; |
| 14 | 14 | ||
| 15 | mod descriptors; | 15 | mod descriptors; |
| 16 | use descriptors::DescriptorRing; | 16 | use descriptors::DescriptorRing; |
| @@ -25,7 +25,7 @@ impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { | |||
| 25 | } | 25 | } |
| 26 | pub struct Ethernet<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> { | 26 | pub struct Ethernet<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> { |
| 27 | state: PeripheralMutex<'d, Inner<'d, T, TX, RX>>, | 27 | state: PeripheralMutex<'d, Inner<'d, T, TX, RX>>, |
| 28 | pins: [Unborrowed<'d, AnyPin>; 9], | 28 | pins: [PeripheralRef<'d, AnyPin>; 9], |
| 29 | _phy: P, | 29 | _phy: P, |
| 30 | clock_range: u8, | 30 | clock_range: u8, |
| 31 | phy_addr: u8, | 31 | phy_addr: u8, |
| @@ -48,22 +48,22 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, T, | |||
| 48 | /// safety: the returned instance is not leak-safe | 48 | /// safety: the returned instance is not leak-safe |
| 49 | pub unsafe fn new( | 49 | pub unsafe fn new( |
| 50 | state: &'d mut State<'d, T, TX, RX>, | 50 | state: &'d mut State<'d, T, TX, RX>, |
| 51 | peri: impl Unborrow<Target = T> + 'd, | 51 | peri: impl Peripheral<P = T> + 'd, |
| 52 | interrupt: impl Unborrow<Target = crate::interrupt::ETH> + 'd, | 52 | interrupt: impl Peripheral<P = crate::interrupt::ETH> + 'd, |
| 53 | ref_clk: impl Unborrow<Target = impl RefClkPin<T>> + 'd, | 53 | ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd, |
| 54 | mdio: impl Unborrow<Target = impl MDIOPin<T>> + 'd, | 54 | mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, |
| 55 | mdc: impl Unborrow<Target = impl MDCPin<T>> + 'd, | 55 | mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, |
| 56 | crs: impl Unborrow<Target = impl CRSPin<T>> + 'd, | 56 | crs: impl Peripheral<P = impl CRSPin<T>> + 'd, |
| 57 | rx_d0: impl Unborrow<Target = impl RXD0Pin<T>> + 'd, | 57 | rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, |
| 58 | rx_d1: impl Unborrow<Target = impl RXD1Pin<T>> + 'd, | 58 | rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, |
| 59 | tx_d0: impl Unborrow<Target = impl TXD0Pin<T>> + 'd, | 59 | tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, |
| 60 | tx_d1: impl Unborrow<Target = impl TXD1Pin<T>> + 'd, | 60 | tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, |
| 61 | tx_en: impl Unborrow<Target = impl TXEnPin<T>> + 'd, | 61 | tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, |
| 62 | phy: P, | 62 | phy: P, |
| 63 | mac_addr: [u8; 6], | 63 | mac_addr: [u8; 6], |
| 64 | phy_addr: u8, | 64 | phy_addr: u8, |
| 65 | ) -> Self { | 65 | ) -> Self { |
| 66 | unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | 66 | into_ref!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); |
| 67 | 67 | ||
| 68 | // Enable the necessary Clocks | 68 | // Enable the necessary Clocks |
| 69 | // NOTE(unsafe) We have exclusive access to the registers | 69 | // NOTE(unsafe) We have exclusive access to the registers |
| @@ -316,7 +316,7 @@ struct Inner<'d, T: Instance, const TX: usize, const RX: usize> { | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | impl<'d, T: Instance, const TX: usize, const RX: usize> Inner<'d, T, TX, RX> { | 318 | impl<'d, T: Instance, const TX: usize, const RX: usize> Inner<'d, T, TX, RX> { |
| 319 | pub fn new(_peri: impl Unborrow<Target = T> + 'd) -> Self { | 319 | pub fn new(_peri: impl Peripheral<P = T> + 'd) -> Self { |
| 320 | Self { | 320 | Self { |
| 321 | _peri: PhantomData, | 321 | _peri: PhantomData, |
| 322 | desc_ring: DescriptorRing::new(), | 322 | desc_ring: DescriptorRing::new(), |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 5076de2e4..3b8d9390f 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -4,12 +4,12 @@ use core::pin::Pin; | |||
| 4 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 5 | 5 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::impl_unborrow; | 7 | use embassy_hal_common::impl_peripheral; |
| 8 | 8 | ||
| 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; | 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; |
| 10 | use crate::pac::exti::regs::Lines; | 10 | use crate::pac::exti::regs::Lines; |
| 11 | use crate::pac::EXTI; | 11 | use crate::pac::EXTI; |
| 12 | use crate::{interrupt, pac, peripherals, Unborrow}; | 12 | use crate::{interrupt, pac, peripherals, Peripheral}; |
| 13 | 13 | ||
| 14 | const EXTI_COUNT: usize = 16; | 14 | const EXTI_COUNT: usize = 16; |
| 15 | const NEW_AW: AtomicWaker = AtomicWaker::new(); | 15 | const NEW_AW: AtomicWaker = AtomicWaker::new(); |
| @@ -86,7 +86,7 @@ pub struct ExtiInput<'d, T: GpioPin> { | |||
| 86 | impl<'d, T: GpioPin> Unpin for ExtiInput<'d, T> {} | 86 | impl<'d, T: GpioPin> Unpin for ExtiInput<'d, T> {} |
| 87 | 87 | ||
| 88 | impl<'d, T: GpioPin> ExtiInput<'d, T> { | 88 | impl<'d, T: GpioPin> ExtiInput<'d, T> { |
| 89 | pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self { | 89 | pub fn new(pin: Input<'d, T>, _ch: impl Peripheral<P = T::ExtiChannel> + 'd) -> Self { |
| 90 | Self { pin } | 90 | Self { pin } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| @@ -320,7 +320,7 @@ pub trait Channel: sealed::Channel + Sized { | |||
| 320 | pub struct AnyChannel { | 320 | pub struct AnyChannel { |
| 321 | number: u8, | 321 | number: u8, |
| 322 | } | 322 | } |
| 323 | impl_unborrow!(AnyChannel); | 323 | impl_peripheral!(AnyChannel); |
| 324 | impl sealed::Channel for AnyChannel {} | 324 | impl sealed::Channel for AnyChannel {} |
| 325 | impl Channel for AnyChannel { | 325 | impl Channel for AnyChannel { |
| 326 | fn number(&self) -> usize { | 326 | fn number(&self) -> usize { |
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index bd64fdd76..5258c9b04 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use embassy_hal_common::{unborrow, Unborrowed}; | 1 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 2 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; | 2 | use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; |
| 3 | 3 | ||
| 4 | pub use crate::pac::{ERASE_SIZE, ERASE_VALUE, FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; | 4 | pub use crate::pac::{ERASE_SIZE, ERASE_VALUE, FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; |
| 5 | use crate::peripherals::FLASH; | 5 | use crate::peripherals::FLASH; |
| 6 | use crate::Unborrow; | 6 | use crate::Peripheral; |
| 7 | const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; | 7 | const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; |
| 8 | 8 | ||
| 9 | #[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] | 9 | #[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] |
| @@ -14,16 +14,16 @@ const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; | |||
| 14 | mod family; | 14 | mod family; |
| 15 | 15 | ||
| 16 | pub struct Flash<'d> { | 16 | pub struct Flash<'d> { |
| 17 | _inner: Unborrowed<'d, FLASH>, | 17 | _inner: PeripheralRef<'d, FLASH>, |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | impl<'d> Flash<'d> { | 20 | impl<'d> Flash<'d> { |
| 21 | pub fn new(p: impl Unborrow<Target = FLASH> + 'd) -> Self { | 21 | pub fn new(p: impl Peripheral<P = FLASH> + 'd) -> Self { |
| 22 | unborrow!(p); | 22 | into_ref!(p); |
| 23 | Self { _inner: p } | 23 | Self { _inner: p } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | pub fn unlock(p: impl Unborrow<Target = FLASH> + 'd) -> Self { | 26 | pub fn unlock(p: impl Peripheral<P = FLASH> + 'd) -> Self { |
| 27 | let flash = Self::new(p); | 27 | let flash = Self::new(p); |
| 28 | 28 | ||
| 29 | unsafe { family::unlock() }; | 29 | unsafe { family::unlock() }; |
diff --git a/embassy-stm32/src/fmc/mod.rs b/embassy-stm32/src/fmc/mod.rs index 4f8e467d0..856a4adca 100644 --- a/embassy-stm32/src/fmc/mod.rs +++ b/embassy-stm32/src/fmc/mod.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::into_ref; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
| 6 | use crate::gpio::{Pull, Speed}; | 6 | use crate::gpio::{Pull, Speed}; |
| 7 | use crate::Unborrow; | 7 | use crate::Peripheral; |
| 8 | 8 | ||
| 9 | mod pins; | 9 | mod pins; |
| 10 | pub use pins::*; | 10 | pub use pins::*; |
| @@ -39,7 +39,7 @@ where | |||
| 39 | 39 | ||
| 40 | macro_rules! config_pins { | 40 | macro_rules! config_pins { |
| 41 | ($($pin:ident),*) => { | 41 | ($($pin:ident),*) => { |
| 42 | unborrow!($($pin),*); | 42 | into_ref!($($pin),*); |
| 43 | $( | 43 | $( |
| 44 | $pin.set_as_af_pull($pin.af_num(), AFType::OutputPushPull, Pull::Up); | 44 | $pin.set_as_af_pull($pin.af_num(), AFType::OutputPushPull, Pull::Up); |
| 45 | $pin.set_speed(Speed::VeryHigh); | 45 | $pin.set_speed(Speed::VeryHigh); |
| @@ -57,12 +57,12 @@ macro_rules! fmc_sdram_constructor { | |||
| 57 | ctrl: [$(($ctrl_pin_name:ident: $ctrl_signal:ident)),*] | 57 | ctrl: [$(($ctrl_pin_name:ident: $ctrl_signal:ident)),*] |
| 58 | )) => { | 58 | )) => { |
| 59 | pub fn $name<CHIP: stm32_fmc::SdramChip>( | 59 | pub fn $name<CHIP: stm32_fmc::SdramChip>( |
| 60 | _instance: impl Unborrow<Target = T> + 'd, | 60 | _instance: impl Peripheral<P = T> + 'd, |
| 61 | $($addr_pin_name: impl Unborrow<Target = impl $addr_signal<T>> + 'd),*, | 61 | $($addr_pin_name: impl Peripheral<P = impl $addr_signal<T>> + 'd),*, |
| 62 | $($ba_pin_name: impl Unborrow<Target = impl $ba_signal<T>> + 'd),*, | 62 | $($ba_pin_name: impl Peripheral<P = impl $ba_signal<T>> + 'd),*, |
| 63 | $($d_pin_name: impl Unborrow<Target = impl $d_signal<T>> + 'd),*, | 63 | $($d_pin_name: impl Peripheral<P = impl $d_signal<T>> + 'd),*, |
| 64 | $($nbl_pin_name: impl Unborrow<Target = impl $nbl_signal<T>> + 'd),*, | 64 | $($nbl_pin_name: impl Peripheral<P = impl $nbl_signal<T>> + 'd),*, |
| 65 | $($ctrl_pin_name: impl Unborrow<Target = impl $ctrl_signal<T>> + 'd),*, | 65 | $($ctrl_pin_name: impl Peripheral<P = impl $ctrl_signal<T>> + 'd),*, |
| 66 | chip: CHIP | 66 | chip: CHIP |
| 67 | ) -> stm32_fmc::Sdram<Fmc<'d, T>, CHIP> { | 67 | ) -> stm32_fmc::Sdram<Fmc<'d, T>, CHIP> { |
| 68 | 68 | ||
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 92cd2bb27..bdb18187c 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | use core::convert::Infallible; | 2 | use core::convert::Infallible; |
| 3 | 3 | ||
| 4 | use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed}; | 4 | use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; |
| 5 | 5 | ||
| 6 | use crate::pac::gpio::{self, vals}; | 6 | use crate::pac::gpio::{self, vals}; |
| 7 | use crate::{pac, peripherals, Unborrow}; | 7 | use crate::{pac, peripherals, Peripheral}; |
| 8 | 8 | ||
| 9 | /// GPIO flexible pin. | 9 | /// GPIO flexible pin. |
| 10 | /// | 10 | /// |
| @@ -12,7 +12,7 @@ use crate::{pac, peripherals, Unborrow}; | |||
| 12 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output | 12 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output |
| 13 | /// mode. | 13 | /// mode. |
| 14 | pub struct Flex<'d, T: Pin> { | 14 | pub struct Flex<'d, T: Pin> { |
| 15 | pub(crate) pin: Unborrowed<'d, T>, | 15 | pub(crate) pin: PeripheralRef<'d, T>, |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | impl<'d, T: Pin> Flex<'d, T> { | 18 | impl<'d, T: Pin> Flex<'d, T> { |
| @@ -22,8 +22,8 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 22 | /// before the pin is put into output mode. | 22 | /// before the pin is put into output mode. |
| 23 | /// | 23 | /// |
| 24 | #[inline] | 24 | #[inline] |
| 25 | pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self { | 25 | pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self { |
| 26 | unborrow!(pin); | 26 | into_ref!(pin); |
| 27 | // Pin will be in disconnected state. | 27 | // Pin will be in disconnected state. |
| 28 | Self { pin } | 28 | Self { pin } |
| 29 | } | 29 | } |
| @@ -280,7 +280,7 @@ pub struct Input<'d, T: Pin> { | |||
| 280 | 280 | ||
| 281 | impl<'d, T: Pin> Input<'d, T> { | 281 | impl<'d, T: Pin> Input<'d, T> { |
| 282 | #[inline] | 282 | #[inline] |
| 283 | pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { | 283 | pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self { |
| 284 | let mut pin = Flex::new(pin); | 284 | let mut pin = Flex::new(pin); |
| 285 | pin.set_as_input(pull); | 285 | pin.set_as_input(pull); |
| 286 | Self { pin } | 286 | Self { pin } |
| @@ -335,7 +335,7 @@ pub struct Output<'d, T: Pin> { | |||
| 335 | 335 | ||
| 336 | impl<'d, T: Pin> Output<'d, T> { | 336 | impl<'d, T: Pin> Output<'d, T> { |
| 337 | #[inline] | 337 | #[inline] |
| 338 | pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, speed: Speed) -> Self { | 338 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed) -> Self { |
| 339 | let mut pin = Flex::new(pin); | 339 | let mut pin = Flex::new(pin); |
| 340 | match initial_output { | 340 | match initial_output { |
| 341 | Level::High => pin.set_high(), | 341 | Level::High => pin.set_high(), |
| @@ -395,7 +395,7 @@ pub struct OutputOpenDrain<'d, T: Pin> { | |||
| 395 | 395 | ||
| 396 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { | 396 | impl<'d, T: Pin> OutputOpenDrain<'d, T> { |
| 397 | #[inline] | 397 | #[inline] |
| 398 | pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { | 398 | pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { |
| 399 | let mut pin = Flex::new(pin); | 399 | let mut pin = Flex::new(pin); |
| 400 | 400 | ||
| 401 | match initial_output { | 401 | match initial_output { |
| @@ -668,7 +668,7 @@ impl AnyPin { | |||
| 668 | } | 668 | } |
| 669 | } | 669 | } |
| 670 | 670 | ||
| 671 | impl_unborrow!(AnyPin); | 671 | impl_peripheral!(AnyPin); |
| 672 | impl Pin for AnyPin { | 672 | impl Pin for AnyPin { |
| 673 | #[cfg(feature = "exti")] | 673 | #[cfg(feature = "exti")] |
| 674 | type ExtiChannel = crate::exti::AnyChannel; | 674 | type ExtiChannel = crate::exti::AnyChannel; |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 65c918780..613815a9c 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_embedded_hal::SetConfig; | 3 | use embassy_embedded_hal::SetConfig; |
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::into_ref; |
| 5 | 5 | ||
| 6 | use crate::gpio::sealed::AFType; | 6 | use crate::gpio::sealed::AFType; |
| 7 | use crate::i2c::{Error, Instance, SclPin, SdaPin}; | 7 | use crate::i2c::{Error, Instance, SclPin, SdaPin}; |
| 8 | use crate::pac::i2c; | 8 | use crate::pac::i2c; |
| 9 | use crate::time::Hertz; | 9 | use crate::time::Hertz; |
| 10 | use crate::Unborrow; | 10 | use crate::Peripheral; |
| 11 | 11 | ||
| 12 | pub struct State {} | 12 | pub struct State {} |
| 13 | 13 | ||
| @@ -23,12 +23,12 @@ pub struct I2c<'d, T: Instance> { | |||
| 23 | 23 | ||
| 24 | impl<'d, T: Instance> I2c<'d, T> { | 24 | impl<'d, T: Instance> I2c<'d, T> { |
| 25 | pub fn new( | 25 | pub fn new( |
| 26 | _peri: impl Unborrow<Target = T> + 'd, | 26 | _peri: impl Peripheral<P = T> + 'd, |
| 27 | scl: impl Unborrow<Target = impl SclPin<T>> + 'd, | 27 | scl: impl Peripheral<P = impl SclPin<T>> + 'd, |
| 28 | sda: impl Unborrow<Target = impl SdaPin<T>> + 'd, | 28 | sda: impl Peripheral<P = impl SdaPin<T>> + 'd, |
| 29 | freq: Hertz, | 29 | freq: Hertz, |
| 30 | ) -> Self { | 30 | ) -> Self { |
| 31 | unborrow!(scl, sda); | 31 | into_ref!(scl, sda); |
| 32 | 32 | ||
| 33 | T::enable(); | 33 | T::enable(); |
| 34 | T::reset(); | 34 | T::reset(); |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index ec7fec15e..dec92cc88 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -5,7 +5,7 @@ use atomic_polyfill::{AtomicUsize, Ordering}; | |||
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | use embassy_embedded_hal::SetConfig; | 6 | use embassy_embedded_hal::SetConfig; |
| 7 | use embassy_hal_common::drop::OnDrop; | 7 | use embassy_hal_common::drop::OnDrop; |
| 8 | use embassy_hal_common::{unborrow, Unborrowed}; | 8 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
| 11 | use crate::dma::NoDma; | 11 | use crate::dma::NoDma; |
| @@ -14,7 +14,7 @@ use crate::i2c::{Error, Instance, SclPin, SdaPin}; | |||
| 14 | use crate::interrupt::InterruptExt; | 14 | use crate::interrupt::InterruptExt; |
| 15 | use crate::pac::i2c; | 15 | use crate::pac::i2c; |
| 16 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 17 | use crate::Unborrow; | 17 | use crate::Peripheral; |
| 18 | 18 | ||
| 19 | pub struct State { | 19 | pub struct State { |
| 20 | waker: AtomicWaker, | 20 | waker: AtomicWaker, |
| @@ -31,23 +31,23 @@ impl State { | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> { | 33 | pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> { |
| 34 | _peri: Unborrowed<'d, T>, | 34 | _peri: PeripheralRef<'d, T>, |
| 35 | tx_dma: Unborrowed<'d, TXDMA>, | 35 | tx_dma: PeripheralRef<'d, TXDMA>, |
| 36 | #[allow(dead_code)] | 36 | #[allow(dead_code)] |
| 37 | rx_dma: Unborrowed<'d, RXDMA>, | 37 | rx_dma: PeripheralRef<'d, RXDMA>, |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | 40 | impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { |
| 41 | pub fn new( | 41 | pub fn new( |
| 42 | peri: impl Unborrow<Target = T> + 'd, | 42 | peri: impl Peripheral<P = T> + 'd, |
| 43 | scl: impl Unborrow<Target = impl SclPin<T>> + 'd, | 43 | scl: impl Peripheral<P = impl SclPin<T>> + 'd, |
| 44 | sda: impl Unborrow<Target = impl SdaPin<T>> + 'd, | 44 | sda: impl Peripheral<P = impl SdaPin<T>> + 'd, |
| 45 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 45 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 46 | tx_dma: impl Unborrow<Target = TXDMA> + 'd, | 46 | tx_dma: impl Peripheral<P = TXDMA> + 'd, |
| 47 | rx_dma: impl Unborrow<Target = RXDMA> + 'd, | 47 | rx_dma: impl Peripheral<P = RXDMA> + 'd, |
| 48 | freq: Hertz, | 48 | freq: Hertz, |
| 49 | ) -> Self { | 49 | ) -> Self { |
| 50 | unborrow!(peri, irq, scl, sda, tx_dma, rx_dma); | 50 | into_ref!(peri, irq, scl, sda, tx_dma, rx_dma); |
| 51 | 51 | ||
| 52 | T::enable(); | 52 | T::enable(); |
| 53 | T::reset(); | 53 | T::reset(); |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index f58ab2f96..78025f3db 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -75,7 +75,7 @@ pub(crate) mod _generated { | |||
| 75 | // Reexports | 75 | // Reexports |
| 76 | pub use _generated::{peripherals, Peripherals}; | 76 | pub use _generated::{peripherals, Peripherals}; |
| 77 | pub use embassy_cortex_m::executor; | 77 | pub use embassy_cortex_m::executor; |
| 78 | pub use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; | 78 | pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 79 | pub use embassy_macros::cortex_m_interrupt as interrupt; | 79 | pub use embassy_macros::cortex_m_interrupt as interrupt; |
| 80 | #[cfg(feature = "unstable-pac")] | 80 | #[cfg(feature = "unstable-pac")] |
| 81 | pub use stm32_metapac as pac; | 81 | pub use stm32_metapac as pac; |
diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs index 137d3145f..7b2cdbc01 100644 --- a/embassy-stm32/src/pwm/simple_pwm.rs +++ b/embassy-stm32/src/pwm/simple_pwm.rs | |||
| @@ -1,18 +1,18 @@ | |||
| 1 | use embassy_hal_common::{unborrow, Unborrowed}; | 1 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 2 | 2 | ||
| 3 | use super::*; | 3 | use super::*; |
| 4 | #[allow(unused_imports)] | 4 | #[allow(unused_imports)] |
| 5 | use crate::gpio::sealed::{AFType, Pin}; | 5 | use crate::gpio::sealed::{AFType, Pin}; |
| 6 | use crate::time::Hertz; | 6 | use crate::time::Hertz; |
| 7 | use crate::Unborrow; | 7 | use crate::Peripheral; |
| 8 | 8 | ||
| 9 | pub struct SimplePwm<'d, T> { | 9 | pub struct SimplePwm<'d, T> { |
| 10 | inner: Unborrowed<'d, T>, | 10 | inner: PeripheralRef<'d, T>, |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | macro_rules! config_pins { | 13 | macro_rules! config_pins { |
| 14 | ($($pin:ident),*) => { | 14 | ($($pin:ident),*) => { |
| 15 | unborrow!($($pin),*); | 15 | into_ref!($($pin),*); |
| 16 | // NOTE(unsafe) Exclusive access to the registers | 16 | // NOTE(unsafe) Exclusive access to the registers |
| 17 | critical_section::with(|_| unsafe { | 17 | critical_section::with(|_| unsafe { |
| 18 | $( | 18 | $( |
| @@ -27,8 +27,8 @@ macro_rules! config_pins { | |||
| 27 | 27 | ||
| 28 | impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | 28 | impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { |
| 29 | pub fn new_1ch( | 29 | pub fn new_1ch( |
| 30 | tim: impl Unborrow<Target = T> + 'd, | 30 | tim: impl Peripheral<P = T> + 'd, |
| 31 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, | 31 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| 32 | freq: Hertz, | 32 | freq: Hertz, |
| 33 | ) -> Self { | 33 | ) -> Self { |
| 34 | Self::new_inner(tim, freq, move || { | 34 | Self::new_inner(tim, freq, move || { |
| @@ -37,9 +37,9 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | |||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | pub fn new_2ch( | 39 | pub fn new_2ch( |
| 40 | tim: impl Unborrow<Target = T> + 'd, | 40 | tim: impl Peripheral<P = T> + 'd, |
| 41 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, | 41 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| 42 | ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, | 42 | ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd, |
| 43 | freq: Hertz, | 43 | freq: Hertz, |
| 44 | ) -> Self { | 44 | ) -> Self { |
| 45 | Self::new_inner(tim, freq, move || { | 45 | Self::new_inner(tim, freq, move || { |
| @@ -48,10 +48,10 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | pub fn new_3ch( | 50 | pub fn new_3ch( |
| 51 | tim: impl Unborrow<Target = T> + 'd, | 51 | tim: impl Peripheral<P = T> + 'd, |
| 52 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, | 52 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| 53 | ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, | 53 | ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd, |
| 54 | ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, | 54 | ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd, |
| 55 | freq: Hertz, | 55 | freq: Hertz, |
| 56 | ) -> Self { | 56 | ) -> Self { |
| 57 | Self::new_inner(tim, freq, move || { | 57 | Self::new_inner(tim, freq, move || { |
| @@ -60,11 +60,11 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | pub fn new_4ch( | 62 | pub fn new_4ch( |
| 63 | tim: impl Unborrow<Target = T> + 'd, | 63 | tim: impl Peripheral<P = T> + 'd, |
| 64 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, | 64 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| 65 | ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, | 65 | ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd, |
| 66 | ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, | 66 | ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd, |
| 67 | ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd, | 67 | ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd, |
| 68 | freq: Hertz, | 68 | freq: Hertz, |
| 69 | ) -> Self { | 69 | ) -> Self { |
| 70 | Self::new_inner(tim, freq, move || { | 70 | Self::new_inner(tim, freq, move || { |
| @@ -72,8 +72,8 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { | |||
| 72 | }) | 72 | }) |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | fn new_inner(tim: impl Unborrow<Target = T> + 'd, freq: Hertz, configure_pins: impl FnOnce()) -> Self { | 75 | fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, configure_pins: impl FnOnce()) -> Self { |
| 76 | unborrow!(tim); | 76 | into_ref!(tim); |
| 77 | 77 | ||
| 78 | T::enable(); | 78 | T::enable(); |
| 79 | <T as crate::rcc::sealed::RccPeripheral>::reset(); | 79 | <T as crate::rcc::sealed::RccPeripheral>::reset(); |
diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs index 6b1014312..0185f7ae8 100644 --- a/embassy-stm32/src/rcc/h7.rs +++ b/embassy-stm32/src/rcc/h7.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::into_ref; |
| 4 | pub use pll::PllConfig; | 4 | pub use pll::PllConfig; |
| 5 | use stm32_metapac::rcc::vals::{Mco1, Mco2}; | 5 | use stm32_metapac::rcc::vals::{Mco1, Mco2}; |
| 6 | 6 | ||
| @@ -10,7 +10,7 @@ use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw, T | |||
| 10 | use crate::pac::{PWR, RCC, SYSCFG}; | 10 | use crate::pac::{PWR, RCC, SYSCFG}; |
| 11 | use crate::rcc::{set_freqs, Clocks}; | 11 | use crate::rcc::{set_freqs, Clocks}; |
| 12 | use crate::time::Hertz; | 12 | use crate::time::Hertz; |
| 13 | use crate::{peripherals, Unborrow}; | 13 | use crate::{peripherals, Peripheral}; |
| 14 | 14 | ||
| 15 | /// HSI speed | 15 | /// HSI speed |
| 16 | pub const HSI_FREQ: Hertz = Hertz(64_000_000); | 16 | pub const HSI_FREQ: Hertz = Hertz(64_000_000); |
| @@ -385,12 +385,12 @@ pub struct Mco<'d, T: McoInstance> { | |||
| 385 | 385 | ||
| 386 | impl<'d, T: McoInstance> Mco<'d, T> { | 386 | impl<'d, T: McoInstance> Mco<'d, T> { |
| 387 | pub fn new( | 387 | pub fn new( |
| 388 | _peri: impl Unborrow<Target = T> + 'd, | 388 | _peri: impl Peripheral<P = T> + 'd, |
| 389 | pin: impl Unborrow<Target = impl McoPin<T>> + 'd, | 389 | pin: impl Peripheral<P = impl McoPin<T>> + 'd, |
| 390 | source: impl McoSource<Raw = T::Source>, | 390 | source: impl McoSource<Raw = T::Source>, |
| 391 | prescaler: McoClock, | 391 | prescaler: McoClock, |
| 392 | ) -> Self { | 392 | ) -> Self { |
| 393 | unborrow!(pin); | 393 | into_ref!(pin); |
| 394 | 394 | ||
| 395 | critical_section::with(|_| unsafe { | 395 | critical_section::with(|_| unsafe { |
| 396 | T::apply_clock_settings(source.into_raw(), prescaler.into_raw()); | 396 | T::apply_clock_settings(source.into_raw(), prescaler.into_raw()); |
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 967fa71fb..2b0ee7131 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs | |||
| @@ -3,11 +3,11 @@ | |||
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | use embassy_hal_common::{unborrow, Unborrowed}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 8 | use rand_core::{CryptoRng, RngCore}; | 8 | use rand_core::{CryptoRng, RngCore}; |
| 9 | 9 | ||
| 10 | use crate::{pac, peripherals, Unborrow}; | 10 | use crate::{pac, peripherals, Peripheral}; |
| 11 | 11 | ||
| 12 | pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); | 12 | pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); |
| 13 | 13 | ||
| @@ -18,14 +18,14 @@ pub enum Error { | |||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | pub struct Rng<'d, T: Instance> { | 20 | pub struct Rng<'d, T: Instance> { |
| 21 | _inner: Unborrowed<'d, T>, | 21 | _inner: PeripheralRef<'d, T>, |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | impl<'d, T: Instance> Rng<'d, T> { | 24 | impl<'d, T: Instance> Rng<'d, T> { |
| 25 | pub fn new(inner: impl Unborrow<Target = T> + 'd) -> Self { | 25 | pub fn new(inner: impl Peripheral<P = T> + 'd) -> Self { |
| 26 | T::enable(); | 26 | T::enable(); |
| 27 | T::reset(); | 27 | T::reset(); |
| 28 | unborrow!(inner); | 28 | into_ref!(inner); |
| 29 | let mut random = Self { _inner: inner }; | 29 | let mut random = Self { _inner: inner }; |
| 30 | random.reset(); | 30 | random.reset(); |
| 31 | random | 31 | random |
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index fbb48263d..b9dff8faf 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -5,7 +5,7 @@ use core::task::Poll; | |||
| 5 | 5 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::drop::OnDrop; | 7 | use embassy_hal_common::drop::OnDrop; |
| 8 | use embassy_hal_common::{unborrow, Unborrowed}; | 8 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; | 10 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; |
| 11 | 11 | ||
| @@ -16,7 +16,7 @@ use crate::interrupt::{Interrupt, InterruptExt}; | |||
| 16 | use crate::pac::sdmmc::Sdmmc as RegBlock; | 16 | use crate::pac::sdmmc::Sdmmc as RegBlock; |
| 17 | use crate::rcc::RccPeripheral; | 17 | use crate::rcc::RccPeripheral; |
| 18 | use crate::time::Hertz; | 18 | use crate::time::Hertz; |
| 19 | use crate::{peripherals, Unborrow}; | 19 | use crate::{peripherals, Peripheral}; |
| 20 | 20 | ||
| 21 | /// The signalling scheme used on the SDMMC bus | 21 | /// The signalling scheme used on the SDMMC bus |
| 22 | #[non_exhaustive] | 22 | #[non_exhaustive] |
| @@ -176,16 +176,16 @@ impl Default for Config { | |||
| 176 | 176 | ||
| 177 | /// Sdmmc device | 177 | /// Sdmmc device |
| 178 | pub struct Sdmmc<'d, T: Instance, Dma = NoDma> { | 178 | pub struct Sdmmc<'d, T: Instance, Dma = NoDma> { |
| 179 | _peri: Unborrowed<'d, T>, | 179 | _peri: PeripheralRef<'d, T>, |
| 180 | irq: Unborrowed<'d, T::Interrupt>, | 180 | irq: PeripheralRef<'d, T::Interrupt>, |
| 181 | dma: Unborrowed<'d, Dma>, | 181 | dma: PeripheralRef<'d, Dma>, |
| 182 | 182 | ||
| 183 | clk: Unborrowed<'d, AnyPin>, | 183 | clk: PeripheralRef<'d, AnyPin>, |
| 184 | cmd: Unborrowed<'d, AnyPin>, | 184 | cmd: PeripheralRef<'d, AnyPin>, |
| 185 | d0: Unborrowed<'d, AnyPin>, | 185 | d0: PeripheralRef<'d, AnyPin>, |
| 186 | d1: Option<Unborrowed<'d, AnyPin>>, | 186 | d1: Option<PeripheralRef<'d, AnyPin>>, |
| 187 | d2: Option<Unborrowed<'d, AnyPin>>, | 187 | d2: Option<PeripheralRef<'d, AnyPin>>, |
| 188 | d3: Option<Unborrowed<'d, AnyPin>>, | 188 | d3: Option<PeripheralRef<'d, AnyPin>>, |
| 189 | 189 | ||
| 190 | config: Config, | 190 | config: Config, |
| 191 | /// Current clock to card | 191 | /// Current clock to card |
| @@ -199,15 +199,15 @@ pub struct Sdmmc<'d, T: Instance, Dma = NoDma> { | |||
| 199 | #[cfg(sdmmc_v1)] | 199 | #[cfg(sdmmc_v1)] |
| 200 | impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> { | 200 | impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> { |
| 201 | pub fn new_1bit( | 201 | pub fn new_1bit( |
| 202 | sdmmc: impl Unborrow<Target = T> + 'd, | 202 | sdmmc: impl Peripheral<P = T> + 'd, |
| 203 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 203 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 204 | dma: impl Unborrow<Target = Dma> + 'd, | 204 | dma: impl Peripheral<P = Dma> + 'd, |
| 205 | clk: impl Unborrow<Target = impl CkPin<T>> + 'd, | 205 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, |
| 206 | cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd, | 206 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, |
| 207 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 207 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 208 | config: Config, | 208 | config: Config, |
| 209 | ) -> Self { | 209 | ) -> Self { |
| 210 | unborrow!(clk, cmd, d0); | 210 | into_ref!(clk, cmd, d0); |
| 211 | 211 | ||
| 212 | critical_section::with(|_| unsafe { | 212 | critical_section::with(|_| unsafe { |
| 213 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); | 213 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); |
| @@ -234,18 +234,18 @@ impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> { | |||
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | pub fn new_4bit( | 236 | pub fn new_4bit( |
| 237 | sdmmc: impl Unborrow<Target = T> + 'd, | 237 | sdmmc: impl Peripheral<P = T> + 'd, |
| 238 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 238 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 239 | dma: impl Unborrow<Target = Dma> + 'd, | 239 | dma: impl Peripheral<P = Dma> + 'd, |
| 240 | clk: impl Unborrow<Target = impl CkPin<T>> + 'd, | 240 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, |
| 241 | cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd, | 241 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, |
| 242 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 242 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 243 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 243 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 244 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 244 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 245 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 245 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 246 | config: Config, | 246 | config: Config, |
| 247 | ) -> Self { | 247 | ) -> Self { |
| 248 | unborrow!(clk, cmd, d0, d1, d2, d3); | 248 | into_ref!(clk, cmd, d0, d1, d2, d3); |
| 249 | 249 | ||
| 250 | critical_section::with(|_| unsafe { | 250 | critical_section::with(|_| unsafe { |
| 251 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); | 251 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); |
| @@ -278,18 +278,18 @@ impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> { | |||
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | fn new_inner( | 280 | fn new_inner( |
| 281 | sdmmc: impl Unborrow<Target = T> + 'd, | 281 | sdmmc: impl Peripheral<P = T> + 'd, |
| 282 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 282 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 283 | dma: impl Unborrow<Target = Dma> + 'd, | 283 | dma: impl Peripheral<P = Dma> + 'd, |
| 284 | clk: Unborrowed<'d, AnyPin>, | 284 | clk: PeripheralRef<'d, AnyPin>, |
| 285 | cmd: Unborrowed<'d, AnyPin>, | 285 | cmd: PeripheralRef<'d, AnyPin>, |
| 286 | d0: Unborrowed<'d, AnyPin>, | 286 | d0: PeripheralRef<'d, AnyPin>, |
| 287 | d1: Option<Unborrowed<'d, AnyPin>>, | 287 | d1: Option<PeripheralRef<'d, AnyPin>>, |
| 288 | d2: Option<Unborrowed<'d, AnyPin>>, | 288 | d2: Option<PeripheralRef<'d, AnyPin>>, |
| 289 | d3: Option<Unborrowed<'d, AnyPin>>, | 289 | d3: Option<PeripheralRef<'d, AnyPin>>, |
| 290 | config: Config, | 290 | config: Config, |
| 291 | ) -> Self { | 291 | ) -> Self { |
| 292 | unborrow!(sdmmc, irq, dma); | 292 | into_ref!(sdmmc, irq, dma); |
| 293 | 293 | ||
| 294 | T::enable(); | 294 | T::enable(); |
| 295 | T::reset(); | 295 | T::reset(); |
| @@ -324,14 +324,14 @@ impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> { | |||
| 324 | #[cfg(sdmmc_v2)] | 324 | #[cfg(sdmmc_v2)] |
| 325 | impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { | 325 | impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { |
| 326 | pub fn new_1bit( | 326 | pub fn new_1bit( |
| 327 | sdmmc: impl Unborrow<Target = T> + 'd, | 327 | sdmmc: impl Peripheral<P = T> + 'd, |
| 328 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 328 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 329 | clk: impl Unborrow<Target = impl CkPin<T>> + 'd, | 329 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, |
| 330 | cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd, | 330 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, |
| 331 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 331 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 332 | config: Config, | 332 | config: Config, |
| 333 | ) -> Self { | 333 | ) -> Self { |
| 334 | unborrow!(clk, cmd, d0); | 334 | into_ref!(clk, cmd, d0); |
| 335 | 335 | ||
| 336 | critical_section::with(|_| unsafe { | 336 | critical_section::with(|_| unsafe { |
| 337 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); | 337 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); |
| @@ -357,17 +357,17 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { | |||
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | pub fn new_4bit( | 359 | pub fn new_4bit( |
| 360 | sdmmc: impl Unborrow<Target = T> + 'd, | 360 | sdmmc: impl Peripheral<P = T> + 'd, |
| 361 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 361 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 362 | clk: impl Unborrow<Target = impl CkPin<T>> + 'd, | 362 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, |
| 363 | cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd, | 363 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, |
| 364 | d0: impl Unborrow<Target = impl D0Pin<T>> + 'd, | 364 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, |
| 365 | d1: impl Unborrow<Target = impl D1Pin<T>> + 'd, | 365 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, |
| 366 | d2: impl Unborrow<Target = impl D2Pin<T>> + 'd, | 366 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, |
| 367 | d3: impl Unborrow<Target = impl D3Pin<T>> + 'd, | 367 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, |
| 368 | config: Config, | 368 | config: Config, |
| 369 | ) -> Self { | 369 | ) -> Self { |
| 370 | unborrow!(clk, cmd, d0, d1, d2, d3); | 370 | into_ref!(clk, cmd, d0, d1, d2, d3); |
| 371 | 371 | ||
| 372 | critical_section::with(|_| unsafe { | 372 | critical_section::with(|_| unsafe { |
| 373 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); | 373 | clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None); |
| @@ -399,17 +399,17 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { | |||
| 399 | } | 399 | } |
| 400 | 400 | ||
| 401 | fn new_inner( | 401 | fn new_inner( |
| 402 | sdmmc: impl Unborrow<Target = T> + 'd, | 402 | sdmmc: impl Peripheral<P = T> + 'd, |
| 403 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 403 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 404 | clk: Unborrowed<'d, AnyPin>, | 404 | clk: PeripheralRef<'d, AnyPin>, |
| 405 | cmd: Unborrowed<'d, AnyPin>, | 405 | cmd: PeripheralRef<'d, AnyPin>, |
| 406 | d0: Unborrowed<'d, AnyPin>, | 406 | d0: PeripheralRef<'d, AnyPin>, |
| 407 | d1: Option<Unborrowed<'d, AnyPin>>, | 407 | d1: Option<PeripheralRef<'d, AnyPin>>, |
| 408 | d2: Option<Unborrowed<'d, AnyPin>>, | 408 | d2: Option<PeripheralRef<'d, AnyPin>>, |
| 409 | d3: Option<Unborrowed<'d, AnyPin>>, | 409 | d3: Option<PeripheralRef<'d, AnyPin>>, |
| 410 | config: Config, | 410 | config: Config, |
| 411 | ) -> Self { | 411 | ) -> Self { |
| 412 | unborrow!(sdmmc, irq); | 412 | into_ref!(sdmmc, irq); |
| 413 | 413 | ||
| 414 | T::enable(); | 414 | T::enable(); |
| 415 | T::reset(); | 415 | T::reset(); |
| @@ -424,7 +424,7 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> { | |||
| 424 | Self { | 424 | Self { |
| 425 | _peri: sdmmc, | 425 | _peri: sdmmc, |
| 426 | irq, | 426 | irq, |
| 427 | dma: NoDma.unborrow(), | 427 | dma: NoDma.into_ref(), |
| 428 | 428 | ||
| 429 | clk, | 429 | clk, |
| 430 | cmd, | 430 | cmd, |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 595957b2e..26fb392ef 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use core::ptr; | 3 | use core::ptr; |
| 4 | 4 | ||
| 5 | use embassy_embedded_hal::SetConfig; | 5 | use embassy_embedded_hal::SetConfig; |
| 6 | use embassy_hal_common::{unborrow, Unborrowed}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 7 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 7 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 8 | use futures::future::join; | 8 | use futures::future::join; |
| 9 | 9 | ||
| @@ -14,7 +14,7 @@ use crate::gpio::AnyPin; | |||
| 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; | 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; |
| 15 | use crate::rcc::RccPeripheral; | 15 | use crate::rcc::RccPeripheral; |
| 16 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 17 | use crate::{peripherals, Unborrow}; | 17 | use crate::{peripherals, Peripheral}; |
| 18 | 18 | ||
| 19 | #[derive(Debug)] | 19 | #[derive(Debug)] |
| 20 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 20 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -72,27 +72,27 @@ impl Config { | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | pub struct Spi<'d, T: Instance, Tx, Rx> { | 74 | pub struct Spi<'d, T: Instance, Tx, Rx> { |
| 75 | _peri: Unborrowed<'d, T>, | 75 | _peri: PeripheralRef<'d, T>, |
| 76 | sck: Option<Unborrowed<'d, AnyPin>>, | 76 | sck: Option<PeripheralRef<'d, AnyPin>>, |
| 77 | mosi: Option<Unborrowed<'d, AnyPin>>, | 77 | mosi: Option<PeripheralRef<'d, AnyPin>>, |
| 78 | miso: Option<Unborrowed<'d, AnyPin>>, | 78 | miso: Option<PeripheralRef<'d, AnyPin>>, |
| 79 | txdma: Unborrowed<'d, Tx>, | 79 | txdma: PeripheralRef<'d, Tx>, |
| 80 | rxdma: Unborrowed<'d, Rx>, | 80 | rxdma: PeripheralRef<'d, Rx>, |
| 81 | current_word_size: WordSize, | 81 | current_word_size: WordSize, |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | 84 | impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { |
| 85 | pub fn new( | 85 | pub fn new( |
| 86 | peri: impl Unborrow<Target = T> + 'd, | 86 | peri: impl Peripheral<P = T> + 'd, |
| 87 | sck: impl Unborrow<Target = impl SckPin<T>> + 'd, | 87 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, |
| 88 | mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd, | 88 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, |
| 89 | miso: impl Unborrow<Target = impl MisoPin<T>> + 'd, | 89 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, |
| 90 | txdma: impl Unborrow<Target = Tx> + 'd, | 90 | txdma: impl Peripheral<P = Tx> + 'd, |
| 91 | rxdma: impl Unborrow<Target = Rx> + 'd, | 91 | rxdma: impl Peripheral<P = Rx> + 'd, |
| 92 | freq: Hertz, | 92 | freq: Hertz, |
| 93 | config: Config, | 93 | config: Config, |
| 94 | ) -> Self { | 94 | ) -> Self { |
| 95 | unborrow!(peri, sck, mosi, miso); | 95 | into_ref!(peri, sck, mosi, miso); |
| 96 | unsafe { | 96 | unsafe { |
| 97 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 97 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); |
| 98 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | 98 | #[cfg(any(spi_v2, spi_v3, spi_v4))] |
| @@ -118,15 +118,15 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | pub fn new_rxonly( | 120 | pub fn new_rxonly( |
| 121 | peri: impl Unborrow<Target = T> + 'd, | 121 | peri: impl Peripheral<P = T> + 'd, |
| 122 | sck: impl Unborrow<Target = impl SckPin<T>> + 'd, | 122 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, |
| 123 | miso: impl Unborrow<Target = impl MisoPin<T>> + 'd, | 123 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, |
| 124 | txdma: impl Unborrow<Target = Tx> + 'd, // TODO remove | 124 | txdma: impl Peripheral<P = Tx> + 'd, // TODO remove |
| 125 | rxdma: impl Unborrow<Target = Rx> + 'd, | 125 | rxdma: impl Peripheral<P = Rx> + 'd, |
| 126 | freq: Hertz, | 126 | freq: Hertz, |
| 127 | config: Config, | 127 | config: Config, |
| 128 | ) -> Self { | 128 | ) -> Self { |
| 129 | unborrow!(sck, miso); | 129 | into_ref!(sck, miso); |
| 130 | unsafe { | 130 | unsafe { |
| 131 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 131 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); |
| 132 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | 132 | #[cfg(any(spi_v2, spi_v3, spi_v4))] |
| @@ -149,15 +149,15 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | pub fn new_txonly( | 151 | pub fn new_txonly( |
| 152 | peri: impl Unborrow<Target = T> + 'd, | 152 | peri: impl Peripheral<P = T> + 'd, |
| 153 | sck: impl Unborrow<Target = impl SckPin<T>> + 'd, | 153 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, |
| 154 | mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd, | 154 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, |
| 155 | txdma: impl Unborrow<Target = Tx> + 'd, | 155 | txdma: impl Peripheral<P = Tx> + 'd, |
| 156 | rxdma: impl Unborrow<Target = Rx> + 'd, // TODO remove | 156 | rxdma: impl Peripheral<P = Rx> + 'd, // TODO remove |
| 157 | freq: Hertz, | 157 | freq: Hertz, |
| 158 | config: Config, | 158 | config: Config, |
| 159 | ) -> Self { | 159 | ) -> Self { |
| 160 | unborrow!(sck, mosi); | 160 | into_ref!(sck, mosi); |
| 161 | unsafe { | 161 | unsafe { |
| 162 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 162 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); |
| 163 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | 163 | #[cfg(any(spi_v2, spi_v3, spi_v4))] |
| @@ -180,16 +180,16 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | fn new_inner( | 182 | fn new_inner( |
| 183 | peri: impl Unborrow<Target = T> + 'd, | 183 | peri: impl Peripheral<P = T> + 'd, |
| 184 | sck: Option<Unborrowed<'d, AnyPin>>, | 184 | sck: Option<PeripheralRef<'d, AnyPin>>, |
| 185 | mosi: Option<Unborrowed<'d, AnyPin>>, | 185 | mosi: Option<PeripheralRef<'d, AnyPin>>, |
| 186 | miso: Option<Unborrowed<'d, AnyPin>>, | 186 | miso: Option<PeripheralRef<'d, AnyPin>>, |
| 187 | txdma: impl Unborrow<Target = Tx> + 'd, | 187 | txdma: impl Peripheral<P = Tx> + 'd, |
| 188 | rxdma: impl Unborrow<Target = Rx> + 'd, | 188 | rxdma: impl Peripheral<P = Rx> + 'd, |
| 189 | freq: Hertz, | 189 | freq: Hertz, |
| 190 | config: Config, | 190 | config: Config, |
| 191 | ) -> Self { | 191 | ) -> Self { |
| 192 | unborrow!(peri, txdma, rxdma); | 192 | into_ref!(peri, txdma, rxdma); |
| 193 | 193 | ||
| 194 | let pclk = T::frequency(); | 194 | let pclk = T::frequency(); |
| 195 | let br = compute_baud_rate(pclk, freq.into()); | 195 | let br = compute_baud_rate(pclk, freq.into()); |
| @@ -994,7 +994,7 @@ pub trait Word: Copy + 'static + sealed::Word + Default + crate::dma::Word {} | |||
| 994 | impl Word for u8 {} | 994 | impl Word for u8 {} |
| 995 | impl Word for u16 {} | 995 | impl Word for u16 {} |
| 996 | 996 | ||
| 997 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + RccPeripheral {} | 997 | pub trait Instance: Peripheral<P = Self> + sealed::Instance + RccPeripheral {} |
| 998 | pin_trait!(SckPin, Instance); | 998 | pin_trait!(SckPin, Instance); |
| 999 | pin_trait!(MosiPin, Instance); | 999 | pin_trait!(MosiPin, Instance); |
| 1000 | pin_trait!(MisoPin, Instance); | 1000 | pin_trait!(MisoPin, Instance); |
diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index ce513ec63..f02fc140f 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs | |||
| @@ -83,7 +83,7 @@ use crate::peripherals::SUBGHZSPI; | |||
| 83 | use crate::rcc::sealed::RccPeripheral; | 83 | use crate::rcc::sealed::RccPeripheral; |
| 84 | use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}; | 84 | use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}; |
| 85 | use crate::time::Hertz; | 85 | use crate::time::Hertz; |
| 86 | use crate::{pac, Unborrow}; | 86 | use crate::{pac, Peripheral}; |
| 87 | 87 | ||
| 88 | /// Passthrough for SPI errors (for now) | 88 | /// Passthrough for SPI errors (for now) |
| 89 | pub type Error = crate::spi::Error; | 89 | pub type Error = crate::spi::Error; |
| @@ -211,12 +211,12 @@ impl<'d, Tx, Rx> SubGhz<'d, Tx, Rx> { | |||
| 211 | /// This will reset the radio and the SPI bus, and enable the peripheral | 211 | /// This will reset the radio and the SPI bus, and enable the peripheral |
| 212 | /// clock. | 212 | /// clock. |
| 213 | pub fn new( | 213 | pub fn new( |
| 214 | peri: impl Unborrow<Target = SUBGHZSPI> + 'd, | 214 | peri: impl Peripheral<P = SUBGHZSPI> + 'd, |
| 215 | sck: impl Unborrow<Target = impl SckPin<SUBGHZSPI>> + 'd, | 215 | sck: impl Peripheral<P = impl SckPin<SUBGHZSPI>> + 'd, |
| 216 | mosi: impl Unborrow<Target = impl MosiPin<SUBGHZSPI>> + 'd, | 216 | mosi: impl Peripheral<P = impl MosiPin<SUBGHZSPI>> + 'd, |
| 217 | miso: impl Unborrow<Target = impl MisoPin<SUBGHZSPI>> + 'd, | 217 | miso: impl Peripheral<P = impl MisoPin<SUBGHZSPI>> + 'd, |
| 218 | txdma: impl Unborrow<Target = Tx> + 'd, | 218 | txdma: impl Peripheral<P = Tx> + 'd, |
| 219 | rxdma: impl Unborrow<Target = Rx> + 'd, | 219 | rxdma: impl Peripheral<P = Rx> + 'd, |
| 220 | ) -> Self { | 220 | ) -> Self { |
| 221 | Self::pulse_radio_reset(); | 221 | Self::pulse_radio_reset(); |
| 222 | 222 | ||
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index c4703cff2..4e47ef73d 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -39,11 +39,11 @@ impl<'d, T: Instance> BufferedUart<'d, T> { | |||
| 39 | pub fn new( | 39 | pub fn new( |
| 40 | state: &'d mut State<'d, T>, | 40 | state: &'d mut State<'d, T>, |
| 41 | _uart: Uart<'d, T, NoDma, NoDma>, | 41 | _uart: Uart<'d, T, NoDma, NoDma>, |
| 42 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 42 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 43 | tx_buffer: &'d mut [u8], | 43 | tx_buffer: &'d mut [u8], |
| 44 | rx_buffer: &'d mut [u8], | 44 | rx_buffer: &'d mut [u8], |
| 45 | ) -> BufferedUart<'d, T> { | 45 | ) -> BufferedUart<'d, T> { |
| 46 | unborrow!(irq); | 46 | into_ref!(irq); |
| 47 | 47 | ||
| 48 | let r = T::regs(); | 48 | let r = T::regs(); |
| 49 | unsafe { | 49 | unsafe { |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 6b12378da..ca75bab41 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -2,14 +2,14 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_common::{unborrow, Unborrowed}; | 5 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 6 | 6 | ||
| 7 | use crate::dma::NoDma; | 7 | use crate::dma::NoDma; |
| 8 | use crate::gpio::sealed::AFType; | 8 | use crate::gpio::sealed::AFType; |
| 9 | use crate::interrupt::Interrupt; | 9 | use crate::interrupt::Interrupt; |
| 10 | use crate::pac::usart::{regs, vals}; | 10 | use crate::pac::usart::{regs, vals}; |
| 11 | use crate::rcc::RccPeripheral; | 11 | use crate::rcc::RccPeripheral; |
| 12 | use crate::{peripherals, Unborrow}; | 12 | use crate::{peripherals, Peripheral}; |
| 13 | 13 | ||
| 14 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | 14 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 15 | pub enum DataBits { | 15 | pub enum DataBits { |
| @@ -78,16 +78,16 @@ pub struct Uart<'d, T: Instance, TxDma = NoDma, RxDma = NoDma> { | |||
| 78 | 78 | ||
| 79 | pub struct UartTx<'d, T: Instance, TxDma = NoDma> { | 79 | pub struct UartTx<'d, T: Instance, TxDma = NoDma> { |
| 80 | phantom: PhantomData<&'d mut T>, | 80 | phantom: PhantomData<&'d mut T>, |
| 81 | tx_dma: Unborrowed<'d, TxDma>, | 81 | tx_dma: PeripheralRef<'d, TxDma>, |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | pub struct UartRx<'d, T: Instance, RxDma = NoDma> { | 84 | pub struct UartRx<'d, T: Instance, RxDma = NoDma> { |
| 85 | phantom: PhantomData<&'d mut T>, | 85 | phantom: PhantomData<&'d mut T>, |
| 86 | rx_dma: Unborrowed<'d, RxDma>, | 86 | rx_dma: PeripheralRef<'d, RxDma>, |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> { | 89 | impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> { |
| 90 | fn new(tx_dma: Unborrowed<'d, TxDma>) -> Self { | 90 | fn new(tx_dma: PeripheralRef<'d, TxDma>) -> Self { |
| 91 | Self { | 91 | Self { |
| 92 | tx_dma, | 92 | tx_dma, |
| 93 | phantom: PhantomData, | 93 | phantom: PhantomData, |
| @@ -133,7 +133,7 @@ impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> { | |||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> { | 135 | impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> { |
| 136 | fn new(rx_dma: Unborrowed<'d, RxDma>) -> Self { | 136 | fn new(rx_dma: PeripheralRef<'d, RxDma>) -> Self { |
| 137 | Self { | 137 | Self { |
| 138 | rx_dma, | 138 | rx_dma, |
| 139 | phantom: PhantomData, | 139 | phantom: PhantomData, |
| @@ -189,14 +189,14 @@ impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> { | |||
| 189 | 189 | ||
| 190 | impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | 190 | impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { |
| 191 | pub fn new( | 191 | pub fn new( |
| 192 | _inner: impl Unborrow<Target = T> + 'd, | 192 | _inner: impl Peripheral<P = T> + 'd, |
| 193 | rx: impl Unborrow<Target = impl RxPin<T>> + 'd, | 193 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, |
| 194 | tx: impl Unborrow<Target = impl TxPin<T>> + 'd, | 194 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, |
| 195 | tx_dma: impl Unborrow<Target = TxDma> + 'd, | 195 | tx_dma: impl Peripheral<P = TxDma> + 'd, |
| 196 | rx_dma: impl Unborrow<Target = RxDma> + 'd, | 196 | rx_dma: impl Peripheral<P = RxDma> + 'd, |
| 197 | config: Config, | 197 | config: Config, |
| 198 | ) -> Self { | 198 | ) -> Self { |
| 199 | unborrow!(_inner, rx, tx, tx_dma, rx_dma); | 199 | into_ref!(_inner, rx, tx, tx_dma, rx_dma); |
| 200 | 200 | ||
| 201 | T::enable(); | 201 | T::enable(); |
| 202 | T::reset(); | 202 | T::reset(); |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 4633ff00c..11ef75954 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -7,7 +7,7 @@ use core::task::Poll; | |||
| 7 | use atomic_polyfill::{AtomicBool, AtomicU8}; | 7 | use atomic_polyfill::{AtomicBool, AtomicU8}; |
| 8 | use embassy::time::{block_for, Duration}; | 8 | use embassy::time::{block_for, Duration}; |
| 9 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::into_ref; |
| 11 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; | 11 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; |
| 12 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; | 12 | use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; |
| 13 | use futures::future::poll_fn; | 13 | use futures::future::poll_fn; |
| @@ -20,7 +20,7 @@ use crate::gpio::sealed::AFType; | |||
| 20 | use crate::interrupt::InterruptExt; | 20 | use crate::interrupt::InterruptExt; |
| 21 | use crate::pac::usb::regs; | 21 | use crate::pac::usb::regs; |
| 22 | use crate::rcc::sealed::RccPeripheral; | 22 | use crate::rcc::sealed::RccPeripheral; |
| 23 | use crate::{pac, Unborrow}; | 23 | use crate::{pac, Peripheral}; |
| 24 | 24 | ||
| 25 | const EP_COUNT: usize = 8; | 25 | const EP_COUNT: usize = 8; |
| 26 | 26 | ||
| @@ -125,12 +125,12 @@ pub struct Driver<'d, T: Instance> { | |||
| 125 | 125 | ||
| 126 | impl<'d, T: Instance> Driver<'d, T> { | 126 | impl<'d, T: Instance> Driver<'d, T> { |
| 127 | pub fn new( | 127 | pub fn new( |
| 128 | _usb: impl Unborrow<Target = T> + 'd, | 128 | _usb: impl Peripheral<P = T> + 'd, |
| 129 | irq: impl Unborrow<Target = T::Interrupt> + 'd, | 129 | irq: impl Peripheral<P = T::Interrupt> + 'd, |
| 130 | dp: impl Unborrow<Target = impl DpPin<T>> + 'd, | 130 | dp: impl Peripheral<P = impl DpPin<T>> + 'd, |
| 131 | dm: impl Unborrow<Target = impl DmPin<T>> + 'd, | 131 | dm: impl Peripheral<P = impl DmPin<T>> + 'd, |
| 132 | ) -> Self { | 132 | ) -> Self { |
| 133 | unborrow!(irq, dp, dm); | 133 | into_ref!(irq, dp, dm); |
| 134 | irq.set_handler(Self::on_interrupt); | 134 | irq.set_handler(Self::on_interrupt); |
| 135 | irq.unpend(); | 135 | irq.unpend(); |
| 136 | irq.enable(); | 136 | irq.enable(); |
diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs index 581754135..f7faf12a8 100644 --- a/embassy-stm32/src/usb_otg.rs +++ b/embassy-stm32/src/usb_otg.rs | |||
| @@ -1,14 +1,14 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::into_ref; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
| 6 | use crate::rcc::RccPeripheral; | 6 | use crate::rcc::RccPeripheral; |
| 7 | use crate::{peripherals, Unborrow}; | 7 | use crate::{peripherals, Peripheral}; |
| 8 | 8 | ||
| 9 | macro_rules! config_ulpi_pins { | 9 | macro_rules! config_ulpi_pins { |
| 10 | ($($pin:ident),*) => { | 10 | ($($pin:ident),*) => { |
| 11 | unborrow!($($pin),*); | 11 | into_ref!($($pin),*); |
| 12 | // NOTE(unsafe) Exclusive access to the registers | 12 | // NOTE(unsafe) Exclusive access to the registers |
| 13 | critical_section::with(|_| unsafe { | 13 | critical_section::with(|_| unsafe { |
| 14 | $( | 14 | $( |
| @@ -43,11 +43,11 @@ pub struct UsbOtg<'d, T: Instance> { | |||
| 43 | impl<'d, T: Instance> UsbOtg<'d, T> { | 43 | impl<'d, T: Instance> UsbOtg<'d, T> { |
| 44 | /// Initializes USB OTG peripheral with internal Full-Speed PHY | 44 | /// Initializes USB OTG peripheral with internal Full-Speed PHY |
| 45 | pub fn new_fs( | 45 | pub fn new_fs( |
| 46 | _peri: impl Unborrow<Target = T> + 'd, | 46 | _peri: impl Peripheral<P = T> + 'd, |
| 47 | dp: impl Unborrow<Target = impl DpPin<T>> + 'd, | 47 | dp: impl Peripheral<P = impl DpPin<T>> + 'd, |
| 48 | dm: impl Unborrow<Target = impl DmPin<T>> + 'd, | 48 | dm: impl Peripheral<P = impl DmPin<T>> + 'd, |
| 49 | ) -> Self { | 49 | ) -> Self { |
| 50 | unborrow!(dp, dm); | 50 | into_ref!(dp, dm); |
| 51 | 51 | ||
| 52 | unsafe { | 52 | unsafe { |
| 53 | dp.set_as_af(dp.af_num(), AFType::OutputPushPull); | 53 | dp.set_as_af(dp.af_num(), AFType::OutputPushPull); |
| @@ -62,19 +62,19 @@ impl<'d, T: Instance> UsbOtg<'d, T> { | |||
| 62 | 62 | ||
| 63 | /// Initializes USB OTG peripheral with external High-Speed PHY | 63 | /// Initializes USB OTG peripheral with external High-Speed PHY |
| 64 | pub fn new_hs_ulpi( | 64 | pub fn new_hs_ulpi( |
| 65 | _peri: impl Unborrow<Target = T> + 'd, | 65 | _peri: impl Peripheral<P = T> + 'd, |
| 66 | ulpi_clk: impl Unborrow<Target = impl UlpiClkPin<T>> + 'd, | 66 | ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd, |
| 67 | ulpi_dir: impl Unborrow<Target = impl UlpiDirPin<T>> + 'd, | 67 | ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd, |
| 68 | ulpi_nxt: impl Unborrow<Target = impl UlpiNxtPin<T>> + 'd, | 68 | ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd, |
| 69 | ulpi_stp: impl Unborrow<Target = impl UlpiStpPin<T>> + 'd, | 69 | ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd, |
| 70 | ulpi_d0: impl Unborrow<Target = impl UlpiD0Pin<T>> + 'd, | 70 | ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd, |
| 71 | ulpi_d1: impl Unborrow<Target = impl UlpiD1Pin<T>> + 'd, | 71 | ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd, |
| 72 | ulpi_d2: impl Unborrow<Target = impl UlpiD2Pin<T>> + 'd, | 72 | ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd, |
| 73 | ulpi_d3: impl Unborrow<Target = impl UlpiD3Pin<T>> + 'd, | 73 | ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd, |
| 74 | ulpi_d4: impl Unborrow<Target = impl UlpiD4Pin<T>> + 'd, | 74 | ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd, |
| 75 | ulpi_d5: impl Unborrow<Target = impl UlpiD5Pin<T>> + 'd, | 75 | ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd, |
| 76 | ulpi_d6: impl Unborrow<Target = impl UlpiD6Pin<T>> + 'd, | 76 | ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd, |
| 77 | ulpi_d7: impl Unborrow<Target = impl UlpiD7Pin<T>> + 'd, | 77 | ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd, |
| 78 | ) -> Self { | 78 | ) -> Self { |
| 79 | config_ulpi_pins!( | 79 | config_ulpi_pins!( |
| 80 | ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6, | 80 | ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6, |
diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs index c4b2609b1..85176eefc 100644 --- a/embassy-stm32/src/wdg/mod.rs +++ b/embassy-stm32/src/wdg/mod.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_common::{unborrow, Unborrow}; | 3 | use embassy_hal_common::{into_ref, Peripheral}; |
| 4 | use stm32_metapac::iwdg::vals::{Key, Pr}; | 4 | use stm32_metapac::iwdg::vals::{Key, Pr}; |
| 5 | 5 | ||
| 6 | use crate::rcc::LSI_FREQ; | 6 | use crate::rcc::LSI_FREQ; |
| @@ -27,8 +27,8 @@ impl<'d, T: Instance> IndependentWatchdog<'d, T> { | |||
| 27 | /// | 27 | /// |
| 28 | /// [Self] has to be started with [Self::unleash()]. | 28 | /// [Self] has to be started with [Self::unleash()]. |
| 29 | /// Once timer expires, MCU will be reset. To prevent this, timer must be reloaded by repeatedly calling [Self::pet()] within timeout interval. | 29 | /// Once timer expires, MCU will be reset. To prevent this, timer must be reloaded by repeatedly calling [Self::pet()] within timeout interval. |
| 30 | pub fn new(_instance: impl Unborrow<Target = T> + 'd, timeout_us: u32) -> Self { | 30 | pub fn new(_instance: impl Peripheral<P = T> + 'd, timeout_us: u32) -> Self { |
| 31 | unborrow!(_instance); | 31 | into_ref!(_instance); |
| 32 | 32 | ||
| 33 | // Find lowest prescaler value, which makes watchdog period longer or equal to timeout. | 33 | // Find lowest prescaler value, which makes watchdog period longer or equal to timeout. |
| 34 | // This iterates from 4 (2^2) to 256 (2^8). | 34 | // This iterates from 4 (2^2) to 256 (2^8). |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index e54f1bb67..d7c6da5bd 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -9,7 +9,7 @@ use embassy_stm32::gpio::low_level::AFType; | |||
| 9 | use embassy_stm32::gpio::Speed; | 9 | use embassy_stm32::gpio::Speed; |
| 10 | use embassy_stm32::pwm::*; | 10 | use embassy_stm32::pwm::*; |
| 11 | use embassy_stm32::time::{khz, mhz, Hertz}; | 11 | use embassy_stm32::time::{khz, mhz, Hertz}; |
| 12 | use embassy_stm32::{unborrow, Config, Peripherals, Unborrow, Unborrowed}; | 12 | use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef, Peripherals}; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | pub fn config() -> Config { | 15 | pub fn config() -> Config { |
| @@ -47,19 +47,19 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| 49 | pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> { | 49 | pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> { |
| 50 | inner: Unborrowed<'d, T>, | 50 | inner: PeripheralRef<'d, T>, |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | 53 | impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { |
| 54 | pub fn new( | 54 | pub fn new( |
| 55 | tim: impl Unborrow<Target = T> + 'd, | 55 | tim: impl Peripheral<P = T> + 'd, |
| 56 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, | 56 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| 57 | ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, | 57 | ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd, |
| 58 | ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, | 58 | ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd, |
| 59 | ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd, | 59 | ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd, |
| 60 | freq: Hertz, | 60 | freq: Hertz, |
| 61 | ) -> Self { | 61 | ) -> Self { |
| 62 | unborrow!(tim, ch1, ch2, ch3, ch4); | 62 | into_ref!(tim, ch1, ch2, ch3, ch4); |
| 63 | 63 | ||
| 64 | T::enable(); | 64 | T::enable(); |
| 65 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); | 65 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); |
