Rename PeripheralBorrow to Unborrow

This commit is contained in:
Dario Nieuwenhuis 2021-04-14 19:59:52 +02:00
parent bac53e3e55
commit 97ca54fa66
12 changed files with 61 additions and 64 deletions

View File

@ -16,7 +16,7 @@ macro_rules! peripherals {
} }
$(#[$cfg])? $(#[$cfg])?
impl embassy::util::PeripheralBorrow for $name { impl embassy::util::Unborrow for $name {
type Target = $name; type Target = $name;
#[inline] #[inline]
unsafe fn unborrow(self) -> $name { unsafe fn unborrow(self) -> $name {
@ -25,7 +25,7 @@ macro_rules! peripherals {
} }
$(#[$cfg])? $(#[$cfg])?
impl embassy::util::PeripheralBorrow for &mut $name { impl embassy::util::Unborrow for &mut $name {
type Target = $name; type Target = $name;
#[inline] #[inline]
unsafe fn unborrow(self) -> $name { unsafe fn unborrow(self) -> $name {
@ -89,7 +89,7 @@ macro_rules! unborrow {
#[macro_export] #[macro_export]
macro_rules! impl_unborrow { macro_rules! impl_unborrow {
($type:ident) => { ($type:ident) => {
impl ::embassy::util::PeripheralBorrow for $type { impl ::embassy::util::Unborrow for $type {
type Target = $type; type Target = $type;
#[inline] #[inline]
unsafe fn unborrow(self) -> Self::Target { 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; type Target = $type;
#[inline] #[inline]
unsafe fn unborrow(self) -> Self::Target { unsafe fn unborrow(self) -> Self::Target {

View File

@ -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; type Target = #name_interrupt;
unsafe fn unborrow(self) -> #name_interrupt { unsafe fn unborrow(self) -> #name_interrupt {
self self
} }
} }
impl ::embassy::util::PeripheralBorrow for &mut #name_interrupt { impl ::embassy::util::Unborrow for &mut #name_interrupt {
type Target = #name_interrupt; type Target = #name_interrupt;
unsafe fn unborrow(self) -> #name_interrupt { unsafe fn unborrow(self) -> #name_interrupt {
::core::ptr::read(self) ::core::ptr::read(self)

View File

@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
use core::task::{Context, Poll}; use core::task::{Context, Poll};
use embassy::interrupt::InterruptExt; use embassy::interrupt::InterruptExt;
use embassy::io::{AsyncBufRead, AsyncWrite, Result}; 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::peripheral::{PeripheralMutex, PeripheralState};
use embassy_extras::ring_buffer::RingBuffer; use embassy_extras::ring_buffer::RingBuffer;
use embassy_extras::{low_power_wait_until, unborrow}; 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> { impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
/// unsafe: may not leak self or futures /// unsafe: may not leak self or futures
pub unsafe fn new( pub unsafe fn new(
uarte: impl PeripheralBorrow<Target = U> + 'd, uarte: impl Unborrow<Target = U> + 'd,
timer: impl PeripheralBorrow<Target = T> + 'd, timer: impl Unborrow<Target = T> + 'd,
ppi_ch1: impl PeripheralBorrow<Target = impl ConfigurableChannel> + 'd, ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel> + 'd,
ppi_ch2: impl PeripheralBorrow<Target = impl ConfigurableChannel> + 'd, ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel> + 'd,
irq: impl PeripheralBorrow<Target = U::Interrupt> + 'd, irq: impl Unborrow<Target = U::Interrupt> + 'd,
rxd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, txd: impl Unborrow<Target = impl GpioPin> + 'd,
cts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, cts: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
rts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, rts: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
config: Config, config: Config,
rx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8],
tx_buffer: &'d mut [u8], tx_buffer: &'d mut [u8],

View File

@ -2,7 +2,7 @@ use core::convert::Infallible;
use core::hint::unreachable_unchecked; use core::hint::unreachable_unchecked;
use core::marker::PhantomData; use core::marker::PhantomData;
use embassy::util::PeripheralBorrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{impl_unborrow, unborrow};
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
use gpio::pin_cnf::DRIVE_A; use gpio::pin_cnf::DRIVE_A;
@ -38,7 +38,7 @@ pub struct Input<'d, T: Pin> {
} }
impl<'d, T: Pin> Input<'d, T> { 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); unborrow!(pin);
pin.conf().write(|w| { pin.conf().write(|w| {
@ -123,7 +123,7 @@ pub struct Output<'d, T: Pin> {
impl<'d, T: Pin> Output<'d, T> { impl<'d, T: Pin> Output<'d, T> {
pub fn new( pub fn new(
pin: impl PeripheralBorrow<Target = T> + 'd, pin: impl Unborrow<Target = T> + 'd,
initial_output: Level, initial_output: Level,
drive: OutputDrive, drive: OutputDrive,
) -> Self { ) -> Self {

View File

@ -11,7 +11,7 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use core::ptr::NonNull; use core::ptr::NonNull;
use embassy::util::PeripheralBorrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{impl_unborrow, unborrow};
use crate::{pac, peripherals}; use crate::{pac, peripherals};
@ -25,7 +25,7 @@ pub struct Ppi<'d, C: Channel> {
} }
impl<'d, C: Channel> Ppi<'d, C> { 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); unborrow!(ch);
let mut this = Self { let mut this = Self {
ch, ch,

View File

@ -3,7 +3,7 @@ use core::marker::PhantomData;
use core::task::Poll; use core::task::Poll;
use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::interrupt::{Interrupt, InterruptExt};
use embassy::traits::flash::{Error, Flash}; use embassy::traits::flash::{Error, Flash};
use embassy::util::{AtomicWaker, DropBomb, PeripheralBorrow}; use embassy::util::{AtomicWaker, DropBomb, Unborrow};
use embassy_extras::unborrow; use embassy_extras::unborrow;
use futures::future::poll_fn; use futures::future::poll_fn;
@ -61,14 +61,14 @@ pub struct Qspi<'d, T: Instance> {
impl<'d, T: Instance> Qspi<'d, T> { impl<'d, T: Instance> Qspi<'d, T> {
pub fn new( pub fn new(
qspi: impl PeripheralBorrow<Target = T> + 'd, qspi: impl Unborrow<Target = T> + 'd,
irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: impl PeripheralBorrow<Target = impl GpioPin> + 'd, sck: impl Unborrow<Target = impl GpioPin> + 'd,
csn: impl PeripheralBorrow<Target = impl GpioPin> + 'd, csn: impl Unborrow<Target = impl GpioPin> + 'd,
io0: impl PeripheralBorrow<Target = impl GpioPin> + 'd, io0: impl Unborrow<Target = impl GpioPin> + 'd,
io1: impl PeripheralBorrow<Target = impl GpioPin> + 'd, io1: impl Unborrow<Target = impl GpioPin> + 'd,
io2: impl PeripheralBorrow<Target = impl GpioPin> + 'd, io2: impl Unborrow<Target = impl GpioPin> + 'd,
io3: impl PeripheralBorrow<Target = impl GpioPin> + 'd, io3: impl Unborrow<Target = impl GpioPin> + 'd,
config: Config, config: Config,
) -> Self { ) -> Self {
unborrow!(qspi, irq, sck, csn, io0, io1, io2, io3); unborrow!(qspi, irq, sck, csn, io0, io1, io2, io3);

View File

@ -3,15 +3,12 @@ use core::marker::PhantomData;
use core::pin::Pin; use core::pin::Pin;
use core::sync::atomic::{compiler_fence, Ordering}; use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll; use core::task::Poll;
use embassy::traits; use embassy::util::{wake_on_interrupt, Unborrow};
use embassy::util::{wake_on_interrupt, PeripheralBorrow};
use embassy_extras::unborrow; use embassy_extras::unborrow;
use futures::future::poll_fn; use futures::future::poll_fn;
use traits::spi::FullDuplex;
use crate::gpio::Pin as GpioPin; use crate::interrupt;
use crate::interrupt::{self, Interrupt}; use crate::{pac, peripherals};
use crate::{pac, peripherals, slice_in_ram_or};
#[cfg(feature = "9160")] #[cfg(feature = "9160")]
use pac::{saadc_ns as saadc, SAADC_NS as SAADC}; 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> { impl<'d, T: PositivePin> OneShot<'d, T> {
pub fn new( pub fn new(
saadc: impl PeripheralBorrow<Target = peripherals::SAADC> + 'd, saadc: impl Unborrow<Target = peripherals::SAADC> + 'd,
irq: impl PeripheralBorrow<Target = interrupt::SAADC> + 'd, irq: impl Unborrow<Target = interrupt::SAADC> + 'd,
positive_pin: impl PeripheralBorrow<Target = T> + 'd, positive_pin: impl Unborrow<Target = T> + 'd,
config: Config, config: Config,
) -> Self { ) -> Self {
unborrow!(saadc, irq, positive_pin); unborrow!(saadc, irq, positive_pin);

View File

@ -4,7 +4,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll; use core::task::Poll;
use embassy::interrupt::InterruptExt; use embassy::interrupt::InterruptExt;
use embassy::traits; use embassy::traits;
use embassy::util::{AtomicWaker, PeripheralBorrow}; use embassy::util::{AtomicWaker, Unborrow};
use embassy_extras::unborrow; use embassy_extras::unborrow;
use futures::future::poll_fn; use futures::future::poll_fn;
use traits::spi::FullDuplex; use traits::spi::FullDuplex;
@ -41,11 +41,11 @@ pub struct Config {
impl<'d, T: Instance> Spim<'d, T> { impl<'d, T: Instance> Spim<'d, T> {
pub fn new( pub fn new(
spim: impl PeripheralBorrow<Target = T> + 'd, spim: impl Unborrow<Target = T> + 'd,
irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, irq: impl Unborrow<Target = T::Interrupt> + 'd,
sck: impl PeripheralBorrow<Target = impl GpioPin> + 'd, sck: impl Unborrow<Target = impl GpioPin> + 'd,
miso: impl PeripheralBorrow<Target = impl OptionalPin> + 'd, miso: impl Unborrow<Target = impl OptionalPin> + 'd,
mosi: impl PeripheralBorrow<Target = impl OptionalPin> + 'd, mosi: impl Unborrow<Target = impl OptionalPin> + 'd,
config: Config, config: Config,
) -> Self { ) -> Self {
unborrow!(spim, irq, sck, miso, mosi); unborrow!(spim, irq, sck, miso, mosi);

View File

@ -6,7 +6,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll; use core::task::Poll;
use embassy::interrupt::InterruptExt; use embassy::interrupt::InterruptExt;
use embassy::traits::uart::{Error, Read, Write}; use embassy::traits::uart::{Error, Read, Write};
use embassy::util::{AtomicWaker, OnDrop, PeripheralBorrow}; use embassy::util::{AtomicWaker, OnDrop, Unborrow};
use embassy_extras::unborrow; use embassy_extras::unborrow;
use futures::future::poll_fn; use futures::future::poll_fn;
@ -54,12 +54,12 @@ impl<'d, T: Instance> Uarte<'d, T> {
/// or [`receive`](Uarte::receive). /// or [`receive`](Uarte::receive).
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
pub unsafe fn new( pub unsafe fn new(
uarte: impl PeripheralBorrow<Target = T> + 'd, uarte: impl Unborrow<Target = T> + 'd,
irq: impl PeripheralBorrow<Target = T::Interrupt> + 'd, irq: impl Unborrow<Target = T::Interrupt> + 'd,
rxd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, rxd: impl Unborrow<Target = impl GpioPin> + 'd,
txd: impl PeripheralBorrow<Target = impl GpioPin> + 'd, txd: impl Unborrow<Target = impl GpioPin> + 'd,
cts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, cts: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
rts: impl PeripheralBorrow<Target = impl GpioOptionalPin> + 'd, rts: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
config: Config, config: Config,
) -> Self { ) -> Self {
unborrow!(uarte, irq, rxd, txd, cts, rts); unborrow!(uarte, irq, rxd, txd, cts, rts);

View File

@ -5,7 +5,7 @@ use crate::pac::generic::{Reg, RW};
use crate::pac::SIO; use crate::pac::SIO;
use crate::peripherals; use crate::peripherals;
use embassy::util::PeripheralBorrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{impl_unborrow, unborrow};
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; 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> { 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); unborrow!(pin);
unsafe { unsafe {
@ -91,7 +91,7 @@ pub struct Output<'d, T: Pin> {
impl<'d, T: Pin> Output<'d, T> { impl<'d, T: Pin> Output<'d, T> {
// TODO opendrain // 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); unborrow!(pin);
unsafe { unsafe {

View File

@ -1,6 +1,6 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use embassy::util::PeripheralBorrow; use embassy::util::Unborrow;
use embassy_extras::unborrow; use embassy_extras::unborrow;
use gpio::Pin; use gpio::Pin;
@ -30,11 +30,11 @@ pub struct Uart<'d, T: Instance> {
impl<'d, T: Instance> Uart<'d, T> { impl<'d, T: Instance> Uart<'d, T> {
pub fn new( pub fn new(
inner: impl PeripheralBorrow<Target = T>, inner: impl Unborrow<Target = T>,
tx: impl PeripheralBorrow<Target = impl TxPin<T>>, tx: impl Unborrow<Target = impl TxPin<T>>,
rx: impl PeripheralBorrow<Target = impl RxPin<T>>, rx: impl Unborrow<Target = impl RxPin<T>>,
cts: impl PeripheralBorrow<Target = impl CtsPin<T>>, cts: impl Unborrow<Target = impl CtsPin<T>>,
rts: impl PeripheralBorrow<Target = impl RtsPin<T>>, rts: impl Unborrow<Target = impl RtsPin<T>>,
config: Config, config: Config,
) -> Self { ) -> Self {
unborrow!(inner, tx, rx, cts, rts); unborrow!(inner, tx, rx, cts, rts);

View File

@ -1,15 +1,16 @@
//! Async utilities //! Async utilities
mod critical_section;
mod drop_bomb; mod drop_bomb;
mod forever; mod forever;
mod mutex; mod mutex;
mod on_drop; mod on_drop;
mod portal; mod portal;
mod signal; mod signal;
mod critical_section;
#[cfg_attr(feature = "executor-agnostic", path = "waker_agnostic.rs")] #[cfg_attr(feature = "executor-agnostic", path = "waker_agnostic.rs")]
mod waker; mod waker;
pub use critical_section::*;
pub use drop_bomb::*; pub use drop_bomb::*;
pub use forever::*; pub use forever::*;
pub use mutex::*; pub use mutex::*;
@ -17,9 +18,8 @@ pub use on_drop::*;
pub use portal::*; pub use portal::*;
pub use signal::*; pub use signal::*;
pub use waker::*; pub use waker::*;
pub use critical_section::*;
pub trait PeripheralBorrow { pub trait Unborrow {
type Target; type Target;
unsafe fn unborrow(self) -> Self::Target; unsafe fn unborrow(self) -> Self::Target;
} }