Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral

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

View File

@ -5,11 +5,11 @@ use core::task::{Context, Poll};
use embassy::waitqueue::AtomicWaker;
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed};
use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef};
use crate::pac::common::{Reg, RW};
use crate::pac::SIO;
use crate::{interrupt, pac, peripherals, Unborrow};
use crate::{interrupt, pac, peripherals, Peripheral};
const PIN_COUNT: usize = 30;
const NEW_AW: AtomicWaker = AtomicWaker::new();
@ -61,7 +61,7 @@ pub struct Input<'d, T: Pin> {
impl<'d, T: Pin> Input<'d, T> {
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, pull: Pull) -> Self {
let mut pin = Flex::new(pin);
pin.set_as_input();
pin.set_pull(pull);
@ -177,13 +177,13 @@ unsafe fn IO_IRQ_BANK0() {
}
struct InputFuture<'a, T: Pin> {
pin: Unborrowed<'a, T>,
pin: PeripheralRef<'a, T>,
level: InterruptTrigger,
}
impl<'d, T: Pin> InputFuture<'d, T> {
pub fn new(pin: impl Unborrow<Target = T> + 'd, level: InterruptTrigger) -> Self {
unborrow!(pin);
pub fn new(pin: impl Peripheral<P = T> + 'd, level: InterruptTrigger) -> Self {
into_ref!(pin);
unsafe {
let irq = interrupt::IO_IRQ_BANK0::steal();
irq.disable();
@ -290,7 +290,7 @@ pub struct Output<'d, T: Pin> {
impl<'d, T: Pin> Output<'d, T> {
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level) -> Self {
let mut pin = Flex::new(pin);
match initial_output {
Level::High => pin.set_high(),
@ -351,7 +351,7 @@ pub struct OutputOpenDrain<'d, T: Pin> {
impl<'d, T: Pin> OutputOpenDrain<'d, T> {
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd, initial_output: Level) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level) -> Self {
let mut pin = Flex::new(pin);
pin.set_low();
match initial_output {
@ -415,13 +415,13 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
/// mode.
pub struct Flex<'d, T: Pin> {
pin: Unborrowed<'d, T>,
pin: PeripheralRef<'d, T>,
}
impl<'d, T: Pin> Flex<'d, T> {
#[inline]
pub fn new(pin: impl Unborrow<Target = T> + 'd) -> Self {
unborrow!(pin);
pub fn new(pin: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(pin);
unsafe {
pin.pad_ctrl().write(|w| {
@ -647,7 +647,7 @@ pub(crate) mod sealed {
}
}
pub trait Pin: Unborrow<Target = Self> + sealed::Pin {
pub trait Pin: Peripheral<P = Self> + sealed::Pin {
/// Degrade to a generic pin struct
fn degrade(self) -> AnyPin {
AnyPin {
@ -661,22 +661,22 @@ pub struct AnyPin {
}
impl AnyPin {
pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
Unborrowed::new(AnyPin {
pin_bank: pin.unborrow().pin_bank(),
pub(crate) fn into_degraded_ref<'a>(pin: impl Peripheral<P = impl Pin + 'a> + 'a) -> PeripheralRef<'a, Self> {
PeripheralRef::new(AnyPin {
pin_bank: pin.into_ref().pin_bank(),
})
}
}
macro_rules! unborrow_and_degrade {
macro_rules! into_degraded_ref {
($($name:ident),*) => {
$(
let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name);
let $name = $crate::gpio::AnyPin::into_degraded_ref($name);
)*
};
}
impl_unborrow!(AnyPin);
impl_peripheral!(AnyPin);
impl Pin for AnyPin {}
impl sealed::Pin for AnyPin {

View File

@ -17,7 +17,7 @@ mod reset;
// Reexports
pub use embassy_cortex_m::executor;
pub use embassy_hal_common::{unborrow, Unborrow, Unborrowed};
pub use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
pub use embassy_macros::cortex_m_interrupt as interrupt;
#[cfg(feature = "unstable-pac")]
pub use rp2040_pac2 as pac;

View File

@ -1,10 +1,10 @@
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
pub use embedded_hal_02::spi::{Phase, Polarity};
use crate::gpio::sealed::Pin as _;
use crate::gpio::{AnyPin, Pin as GpioPin};
use crate::{pac, peripherals, Unborrow};
use crate::{pac, peripherals, Peripheral};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -31,7 +31,7 @@ impl Default for Config {
}
pub struct Spi<'d, T: Instance> {
inner: Unborrowed<'d, T>,
inner: PeripheralRef<'d, T>,
}
fn div_roundup(a: u32, b: u32) -> u32 {
@ -59,45 +59,45 @@ fn calc_prescs(freq: u32) -> (u8, u8) {
impl<'d, T: Instance> Spi<'d, T> {
pub fn new(
inner: impl Unborrow<Target = T> + 'd,
clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd,
miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd,
inner: impl Peripheral<P = T> + 'd,
clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd,
mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd,
miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(clk, mosi, miso);
into_degraded_ref!(clk, mosi, miso);
Self::new_inner(inner, Some(clk), Some(mosi), Some(miso), None, config)
}
pub fn new_txonly(
inner: impl Unborrow<Target = T> + 'd,
clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd,
inner: impl Peripheral<P = T> + 'd,
clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd,
mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(clk, mosi);
into_degraded_ref!(clk, mosi);
Self::new_inner(inner, Some(clk), Some(mosi), None, None, config)
}
pub fn new_rxonly(
inner: impl Unborrow<Target = T> + 'd,
clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd,
inner: impl Peripheral<P = T> + 'd,
clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd,
miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd,
config: Config,
) -> Self {
unborrow_and_degrade!(clk, miso);
into_degraded_ref!(clk, miso);
Self::new_inner(inner, Some(clk), None, Some(miso), None, config)
}
fn new_inner(
inner: impl Unborrow<Target = T> + 'd,
clk: Option<Unborrowed<'d, AnyPin>>,
mosi: Option<Unborrowed<'d, AnyPin>>,
miso: Option<Unborrowed<'d, AnyPin>>,
cs: Option<Unborrowed<'d, AnyPin>>,
inner: impl Peripheral<P = T> + 'd,
clk: Option<PeripheralRef<'d, AnyPin>>,
mosi: Option<PeripheralRef<'d, AnyPin>>,
miso: Option<PeripheralRef<'d, AnyPin>>,
cs: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(inner);
into_ref!(inner);
unsafe {
let p = inner.regs();

View File

@ -1,7 +1,7 @@
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use gpio::Pin;
use crate::{gpio, pac, peripherals, Unborrow};
use crate::{gpio, pac, peripherals, Peripheral};
#[non_exhaustive]
pub struct Config {
@ -21,19 +21,19 @@ impl Default for Config {
}
pub struct Uart<'d, T: Instance> {
inner: Unborrowed<'d, T>,
inner: PeripheralRef<'d, T>,
}
impl<'d, T: Instance> Uart<'d, T> {
pub fn new(
inner: impl Unborrow<Target = T> + 'd,
tx: impl Unborrow<Target = impl TxPin<T>> + 'd,
rx: impl Unborrow<Target = impl RxPin<T>> + 'd,
cts: impl Unborrow<Target = impl CtsPin<T>> + 'd,
rts: impl Unborrow<Target = impl RtsPin<T>> + 'd,
inner: impl Peripheral<P = T> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(inner, tx, rx, cts, rts);
into_ref!(inner, tx, rx, cts, rts);
unsafe {
let p = inner.regs();