Rename PeripheralBorrow to Unborrow
This commit is contained in:
		| @@ -16,7 +16,7 @@ macro_rules! peripherals { | ||||
|                 } | ||||
|  | ||||
|                 $(#[$cfg])? | ||||
|                 impl embassy::util::PeripheralBorrow for $name { | ||||
|                 impl embassy::util::Unborrow for $name { | ||||
|                     type Target = $name; | ||||
|                     #[inline] | ||||
|                     unsafe fn unborrow(self) -> $name { | ||||
| @@ -25,7 +25,7 @@ macro_rules! peripherals { | ||||
|                 } | ||||
|  | ||||
|                 $(#[$cfg])? | ||||
|                 impl embassy::util::PeripheralBorrow for &mut $name { | ||||
|                 impl embassy::util::Unborrow for &mut $name { | ||||
|                     type Target = $name; | ||||
|                     #[inline] | ||||
|                     unsafe fn unborrow(self) -> $name { | ||||
| @@ -89,7 +89,7 @@ macro_rules! unborrow { | ||||
| #[macro_export] | ||||
| macro_rules! impl_unborrow { | ||||
|     ($type:ident) => { | ||||
|         impl ::embassy::util::PeripheralBorrow for $type { | ||||
|         impl ::embassy::util::Unborrow for $type { | ||||
|             type Target = $type; | ||||
|             #[inline] | ||||
|             unsafe fn unborrow(self) -> Self::Target { | ||||
| @@ -97,7 +97,7 @@ macro_rules! impl_unborrow { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         impl<'a> ::embassy::util::PeripheralBorrow for &'a mut $type { | ||||
|         impl<'a> ::embassy::util::Unborrow for &'a mut $type { | ||||
|             type Target = $type; | ||||
|             #[inline] | ||||
|             unsafe fn unborrow(self) -> Self::Target { | ||||
|   | ||||
| @@ -147,14 +147,14 @@ pub fn interrupt_declare(item: TokenStream) -> TokenStream { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         impl ::embassy::util::PeripheralBorrow for #name_interrupt { | ||||
|         impl ::embassy::util::Unborrow for #name_interrupt { | ||||
|             type Target = #name_interrupt; | ||||
|             unsafe fn unborrow(self) -> #name_interrupt { | ||||
|                 self | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         impl ::embassy::util::PeripheralBorrow for &mut #name_interrupt { | ||||
|         impl ::embassy::util::Unborrow for &mut #name_interrupt { | ||||
|             type Target = #name_interrupt; | ||||
|             unsafe fn unborrow(self) -> #name_interrupt { | ||||
|                 ::core::ptr::read(self) | ||||
|   | ||||
| @@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | ||||
| use core::task::{Context, Poll}; | ||||
| use embassy::interrupt::InterruptExt; | ||||
| use embassy::io::{AsyncBufRead, AsyncWrite, Result}; | ||||
| use embassy::util::{PeripheralBorrow, WakerRegistration}; | ||||
| use embassy::util::{Unborrow, WakerRegistration}; | ||||
| use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; | ||||
| use embassy_extras::ring_buffer::RingBuffer; | ||||
| use embassy_extras::{low_power_wait_until, unborrow}; | ||||
| @@ -63,15 +63,15 @@ pub struct BufferedUarte<'d, U: UarteInstance, T: TimerInstance> { | ||||
| impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { | ||||
|     /// unsafe: may not leak self or futures | ||||
|     pub unsafe fn new( | ||||
|         uarte: impl PeripheralBorrow<Target = U> + 'd, | ||||
|         timer: impl PeripheralBorrow<Target = T> + 'd, | ||||
|         ppi_ch1: impl PeripheralBorrow<Target = impl ConfigurableChannel> + 'd, | ||||
|         ppi_ch2: impl PeripheralBorrow<Target = impl ConfigurableChannel> + 'd, | ||||
|         irq: impl PeripheralBorrow<Target = U::Interrupt> + 'd, | ||||
|         rxd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         txd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         cts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         rts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         uarte: impl Unborrow<Target = U> + 'd, | ||||
|         timer: impl Unborrow<Target = T> + 'd, | ||||
|         ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel> + 'd, | ||||
|         ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel> + 'd, | ||||
|         irq: impl Unborrow<Target = U::Interrupt> + 'd, | ||||
|         rxd: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         txd: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         cts: impl Unborrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         rts: impl Unborrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         config: Config, | ||||
|         rx_buffer: &'d mut [u8], | ||||
|         tx_buffer: &'d mut [u8], | ||||
|   | ||||
| @@ -2,7 +2,7 @@ use core::convert::Infallible; | ||||
| use core::hint::unreachable_unchecked; | ||||
| use core::marker::PhantomData; | ||||
|  | ||||
| use embassy::util::PeripheralBorrow; | ||||
| use embassy::util::Unborrow; | ||||
| use embassy_extras::{impl_unborrow, unborrow}; | ||||
| use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; | ||||
| use gpio::pin_cnf::DRIVE_A; | ||||
| @@ -38,7 +38,7 @@ pub struct Input<'d, T: Pin> { | ||||
| } | ||||
|  | ||||
| impl<'d, T: Pin> Input<'d, T> { | ||||
|     pub fn new(pin: impl PeripheralBorrow<Target = T> + 'd, pull: Pull) -> Self { | ||||
|     pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { | ||||
|         unborrow!(pin); | ||||
|  | ||||
|         pin.conf().write(|w| { | ||||
| @@ -123,7 +123,7 @@ pub struct Output<'d, T: Pin> { | ||||
|  | ||||
| impl<'d, T: Pin> Output<'d, T> { | ||||
|     pub fn new( | ||||
|         pin: impl PeripheralBorrow<Target = T> + 'd, | ||||
|         pin: impl Unborrow<Target = T> + 'd, | ||||
|         initial_output: Level, | ||||
|         drive: OutputDrive, | ||||
|     ) -> Self { | ||||
|   | ||||
| @@ -11,7 +11,7 @@ | ||||
|  | ||||
| use core::marker::PhantomData; | ||||
| use core::ptr::NonNull; | ||||
| use embassy::util::PeripheralBorrow; | ||||
| use embassy::util::Unborrow; | ||||
| use embassy_extras::{impl_unborrow, unborrow}; | ||||
|  | ||||
| use crate::{pac, peripherals}; | ||||
| @@ -25,7 +25,7 @@ pub struct Ppi<'d, C: Channel> { | ||||
| } | ||||
|  | ||||
| impl<'d, C: Channel> Ppi<'d, C> { | ||||
|     pub fn new(ch: impl PeripheralBorrow<Target = C> + 'd) -> Self { | ||||
|     pub fn new(ch: impl Unborrow<Target = C> + 'd) -> Self { | ||||
|         unborrow!(ch); | ||||
|         let mut this = Self { | ||||
|             ch, | ||||
|   | ||||
| @@ -3,7 +3,7 @@ use core::marker::PhantomData; | ||||
| use core::task::Poll; | ||||
| use embassy::interrupt::{Interrupt, InterruptExt}; | ||||
| use embassy::traits::flash::{Error, Flash}; | ||||
| use embassy::util::{AtomicWaker, DropBomb, PeripheralBorrow}; | ||||
| use embassy::util::{AtomicWaker, DropBomb, Unborrow}; | ||||
| use embassy_extras::unborrow; | ||||
| use futures::future::poll_fn; | ||||
|  | ||||
| @@ -61,14 +61,14 @@ pub struct Qspi<'d, T: Instance> { | ||||
|  | ||||
| impl<'d, T: Instance> Qspi<'d, T> { | ||||
|     pub fn new( | ||||
|         qspi: impl PeripheralBorrow<Target = T> + 'd, | ||||
|         irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, | ||||
|         sck: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         csn: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         io0: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         io1: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         io2: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         io3: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         qspi: impl Unborrow<Target = T> + 'd, | ||||
|         irq: impl Unborrow<Target = T::Interrupt> + 'd, | ||||
|         sck: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         csn: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         io0: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         io1: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         io2: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         io3: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         config: Config, | ||||
|     ) -> Self { | ||||
|         unborrow!(qspi, irq, sck, csn, io0, io1, io2, io3); | ||||
|   | ||||
| @@ -3,15 +3,12 @@ use core::marker::PhantomData; | ||||
| use core::pin::Pin; | ||||
| use core::sync::atomic::{compiler_fence, Ordering}; | ||||
| use core::task::Poll; | ||||
| use embassy::traits; | ||||
| use embassy::util::{wake_on_interrupt, PeripheralBorrow}; | ||||
| use embassy::util::{wake_on_interrupt, Unborrow}; | ||||
| use embassy_extras::unborrow; | ||||
| use futures::future::poll_fn; | ||||
| use traits::spi::FullDuplex; | ||||
|  | ||||
| use crate::gpio::Pin as GpioPin; | ||||
| use crate::interrupt::{self, Interrupt}; | ||||
| use crate::{pac, peripherals, slice_in_ram_or}; | ||||
| use crate::interrupt; | ||||
| use crate::{pac, peripherals}; | ||||
|  | ||||
| #[cfg(feature = "9160")] | ||||
| use pac::{saadc_ns as saadc, SAADC_NS as SAADC}; | ||||
| @@ -74,9 +71,9 @@ impl Default for Config { | ||||
|  | ||||
| impl<'d, T: PositivePin> OneShot<'d, T> { | ||||
|     pub fn new( | ||||
|         saadc: impl PeripheralBorrow<Target = peripherals::SAADC> + 'd, | ||||
|         irq: impl PeripheralBorrow<Target = interrupt::SAADC> + 'd, | ||||
|         positive_pin: impl PeripheralBorrow<Target = T> + 'd, | ||||
|         saadc: impl Unborrow<Target = peripherals::SAADC> + 'd, | ||||
|         irq: impl Unborrow<Target = interrupt::SAADC> + 'd, | ||||
|         positive_pin: impl Unborrow<Target = T> + 'd, | ||||
|         config: Config, | ||||
|     ) -> Self { | ||||
|         unborrow!(saadc, irq, positive_pin); | ||||
|   | ||||
| @@ -4,7 +4,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | ||||
| use core::task::Poll; | ||||
| use embassy::interrupt::InterruptExt; | ||||
| use embassy::traits; | ||||
| use embassy::util::{AtomicWaker, PeripheralBorrow}; | ||||
| use embassy::util::{AtomicWaker, Unborrow}; | ||||
| use embassy_extras::unborrow; | ||||
| use futures::future::poll_fn; | ||||
| use traits::spi::FullDuplex; | ||||
| @@ -41,11 +41,11 @@ pub struct Config { | ||||
|  | ||||
| impl<'d, T: Instance> Spim<'d, T> { | ||||
|     pub fn new( | ||||
|         spim: impl PeripheralBorrow<Target = T> + 'd, | ||||
|         irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, | ||||
|         sck: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         miso: impl PeripheralBorrow<Target = impl OptionalPin> + 'd, | ||||
|         mosi: impl PeripheralBorrow<Target = impl OptionalPin> + 'd, | ||||
|         spim: impl Unborrow<Target = T> + 'd, | ||||
|         irq: impl Unborrow<Target = T::Interrupt> + 'd, | ||||
|         sck: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         miso: impl Unborrow<Target = impl OptionalPin> + 'd, | ||||
|         mosi: impl Unborrow<Target = impl OptionalPin> + 'd, | ||||
|         config: Config, | ||||
|     ) -> Self { | ||||
|         unborrow!(spim, irq, sck, miso, mosi); | ||||
|   | ||||
| @@ -6,7 +6,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; | ||||
| use core::task::Poll; | ||||
| use embassy::interrupt::InterruptExt; | ||||
| use embassy::traits::uart::{Error, Read, Write}; | ||||
| use embassy::util::{AtomicWaker, OnDrop, PeripheralBorrow}; | ||||
| use embassy::util::{AtomicWaker, OnDrop, Unborrow}; | ||||
| use embassy_extras::unborrow; | ||||
| use futures::future::poll_fn; | ||||
|  | ||||
| @@ -54,12 +54,12 @@ impl<'d, T: Instance> Uarte<'d, T> { | ||||
|     /// or [`receive`](Uarte::receive). | ||||
|     #[allow(unused_unsafe)] | ||||
|     pub unsafe fn new( | ||||
|         uarte: impl PeripheralBorrow<Target = T> + 'd, | ||||
|         irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, | ||||
|         rxd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         txd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, | ||||
|         cts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         rts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         uarte: impl Unborrow<Target = T> + 'd, | ||||
|         irq: impl Unborrow<Target = T::Interrupt> + 'd, | ||||
|         rxd: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         txd: impl Unborrow<Target = impl GpioPin> + 'd, | ||||
|         cts: impl Unborrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         rts: impl Unborrow<Target = impl GpioOptionalPin> + 'd, | ||||
|         config: Config, | ||||
|     ) -> Self { | ||||
|         unborrow!(uarte, irq, rxd, txd, cts, rts); | ||||
|   | ||||
| @@ -5,7 +5,7 @@ use crate::pac::generic::{Reg, RW}; | ||||
| use crate::pac::SIO; | ||||
| use crate::peripherals; | ||||
|  | ||||
| use embassy::util::PeripheralBorrow; | ||||
| use embassy::util::Unborrow; | ||||
| use embassy_extras::{impl_unborrow, unborrow}; | ||||
| use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; | ||||
|  | ||||
| @@ -37,7 +37,7 @@ pub struct Input<'d, T: Pin> { | ||||
| } | ||||
|  | ||||
| impl<'d, T: Pin> Input<'d, T> { | ||||
|     pub fn new(pin: impl PeripheralBorrow<Target = T> + 'd, pull: Pull) -> Self { | ||||
|     pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self { | ||||
|         unborrow!(pin); | ||||
|  | ||||
|         unsafe { | ||||
| @@ -91,7 +91,7 @@ pub struct Output<'d, T: Pin> { | ||||
|  | ||||
| impl<'d, T: Pin> Output<'d, T> { | ||||
|     // TODO opendrain | ||||
|     pub fn new(pin: impl PeripheralBorrow<Target = T> + 'd, initial_output: Level) -> Self { | ||||
|     pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self { | ||||
|         unborrow!(pin); | ||||
|  | ||||
|         unsafe { | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| use core::marker::PhantomData; | ||||
|  | ||||
| use embassy::util::PeripheralBorrow; | ||||
| use embassy::util::Unborrow; | ||||
| use embassy_extras::unborrow; | ||||
| use gpio::Pin; | ||||
|  | ||||
| @@ -30,11 +30,11 @@ pub struct Uart<'d, T: Instance> { | ||||
|  | ||||
| impl<'d, T: Instance> Uart<'d, T> { | ||||
|     pub fn new( | ||||
|         inner: impl PeripheralBorrow<Target = T>, | ||||
|         tx: impl PeripheralBorrow<Target = impl TxPin<T>>, | ||||
|         rx: impl PeripheralBorrow<Target = impl RxPin<T>>, | ||||
|         cts: impl PeripheralBorrow<Target = impl CtsPin<T>>, | ||||
|         rts: impl PeripheralBorrow<Target = impl RtsPin<T>>, | ||||
|         inner: impl Unborrow<Target = T>, | ||||
|         tx: impl Unborrow<Target = impl TxPin<T>>, | ||||
|         rx: impl Unborrow<Target = impl RxPin<T>>, | ||||
|         cts: impl Unborrow<Target = impl CtsPin<T>>, | ||||
|         rts: impl Unborrow<Target = impl RtsPin<T>>, | ||||
|         config: Config, | ||||
|     ) -> Self { | ||||
|         unborrow!(inner, tx, rx, cts, rts); | ||||
|   | ||||
| @@ -1,15 +1,16 @@ | ||||
| //! Async utilities | ||||
| mod critical_section; | ||||
| mod drop_bomb; | ||||
| mod forever; | ||||
| mod mutex; | ||||
| mod on_drop; | ||||
| mod portal; | ||||
| mod signal; | ||||
| mod critical_section; | ||||
|  | ||||
| #[cfg_attr(feature = "executor-agnostic", path = "waker_agnostic.rs")] | ||||
| mod waker; | ||||
|  | ||||
| pub use critical_section::*; | ||||
| pub use drop_bomb::*; | ||||
| pub use forever::*; | ||||
| pub use mutex::*; | ||||
| @@ -17,9 +18,8 @@ pub use on_drop::*; | ||||
| pub use portal::*; | ||||
| pub use signal::*; | ||||
| pub use waker::*; | ||||
| pub use critical_section::*; | ||||
|  | ||||
| pub trait PeripheralBorrow { | ||||
| pub trait Unborrow { | ||||
|     type Target; | ||||
|     unsafe fn unborrow(self) -> Self::Target; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user