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

@ -1,12 +1,12 @@
use core::marker::PhantomData;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use crate::adc::{AdcPin, Instance};
use crate::rcc::get_freqs;
use crate::time::Hertz;
use crate::Unborrow;
use crate::Peripheral;
pub const VDDA_CALIB_MV: u32 = 3300;
pub const ADC_MAX: u32 = (1 << 12) - 1;
@ -91,8 +91,8 @@ pub struct Adc<'d, T: Instance> {
}
impl<'d, T: Instance> Adc<'d, T> {
pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
unborrow!(_peri);
pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
into_ref!(_peri);
T::enable();
T::reset();
unsafe {

View File

@ -1,11 +1,11 @@
use core::marker::PhantomData;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use crate::adc::{AdcPin, Instance};
use crate::time::Hertz;
use crate::Unborrow;
use crate::Peripheral;
pub const VDDA_CALIB_MV: u32 = 3000;
@ -159,8 +159,8 @@ impl<'d, T> Adc<'d, T>
where
T: Instance,
{
pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
unborrow!(_peri);
pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
into_ref!(_peri);
enable();
let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) };

View File

@ -1,10 +1,10 @@
use core::marker::PhantomData;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use crate::adc::{AdcPin, Instance};
use crate::Unborrow;
use crate::Peripheral;
pub const VDDA_CALIB_MV: u32 = 3000;
@ -208,8 +208,8 @@ pub struct Adc<'d, T: Instance> {
}
impl<'d, T: Instance> Adc<'d, T> {
pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
unborrow!(_peri);
pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
into_ref!(_peri);
enable();
unsafe {
T::regs().cr().modify(|reg| {

View File

@ -7,7 +7,7 @@ use pac::adccommon::vals::Presc;
use super::{AdcPin, Instance};
use crate::time::Hertz;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
pub enum Resolution {
SixteenBit,
@ -322,8 +322,8 @@ pub struct Adc<'d, T: Instance> {
}
impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u16>) -> Self {
embassy_hal_common::unborrow!(_peri);
pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u16>) -> Self {
embassy_hal_common::into_ref!(_peri);
T::enable();
T::reset();

View File

@ -1,11 +1,11 @@
use core::ops::{Deref, DerefMut};
pub use bxcan;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use crate::gpio::sealed::AFType;
use crate::rcc::RccPeripheral;
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
pub struct Can<'d, T: Instance> {
can: bxcan::Can<BxcanInstance<'d, T>>,
@ -13,11 +13,11 @@ pub struct Can<'d, T: Instance> {
impl<'d, T: Instance> Can<'d, T> {
pub fn new(
peri: impl Unborrow<Target = T> + 'd,
rx: impl Unborrow<Target = impl RxPin<T>> + 'd,
tx: impl Unborrow<Target = impl TxPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
) -> Self {
unborrow!(peri, rx, tx);
into_ref!(peri, rx, tx);
unsafe {
rx.set_as_af(rx.af_num(), AFType::Input);
@ -66,7 +66,7 @@ pub(crate) mod sealed {
pub trait Instance: sealed::Instance + RccPeripheral {}
pub struct BxcanInstance<'a, T>(Unborrowed<'a, T>);
pub struct BxcanInstance<'a, T>(PeripheralRef<'a, T>);
unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> {
const REGISTERS: *mut bxcan::RegisterBlock = T::REGISTERS;

View File

@ -1,25 +1,25 @@
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use crate::pac::CRC as PAC_CRC;
use crate::peripherals::CRC;
use crate::rcc::sealed::RccPeripheral;
use crate::Unborrow;
use crate::Peripheral;
pub struct Crc<'d> {
_peri: Unborrowed<'d, CRC>,
_peri: PeripheralRef<'d, CRC>,
}
impl<'d> Crc<'d> {
/// Instantiates the CRC32 peripheral and initializes it to default values.
pub fn new(peripheral: impl Unborrow<Target = CRC> + 'd) -> Self {
unborrow!(peripheral);
pub fn new(peripheral: impl Peripheral<P = CRC> + 'd) -> Self {
into_ref!(peripheral);
// Note: enable and reset come from RccPeripheral.
// enable CRC clock in RCC.
CRC::enable();
// Reset CRC to default values.
CRC::reset();
// Unborrow the peripheral
// Peripheral the peripheral
let mut instance = Self { _peri: peripheral };
instance.reset();
instance

View File

@ -1,13 +1,13 @@
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use crate::pac::crc::vals;
use crate::pac::CRC as PAC_CRC;
use crate::peripherals::CRC;
use crate::rcc::sealed::RccPeripheral;
use crate::Unborrow;
use crate::Peripheral;
pub struct Crc<'d> {
_peripheral: Unborrowed<'d, CRC>,
_peripheral: PeripheralRef<'d, CRC>,
_config: Config,
}
@ -67,13 +67,13 @@ pub enum PolySize {
impl<'d> Crc<'d> {
/// Instantiates the CRC32 peripheral and initializes it to default values.
pub fn new(peripheral: impl Unborrow<Target = CRC> + 'd, config: Config) -> Self {
pub fn new(peripheral: impl Peripheral<P = CRC> + 'd, config: Config) -> Self {
// Note: enable and reset come from RccPeripheral.
// enable CRC clock in RCC.
CRC::enable();
// Reset CRC to default values.
CRC::reset();
unborrow!(peripheral);
into_ref!(peripheral);
let mut instance = Self {
_peripheral: peripheral,
_config: config,

View File

@ -1,8 +1,8 @@
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use crate::dac::{DacPin, Instance};
use crate::pac::dac;
use crate::Unborrow;
use crate::Peripheral;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -88,7 +88,7 @@ pub enum Value {
pub struct Dac<'d, T: Instance> {
channels: u8,
_peri: Unborrowed<'d, T>,
_peri: PeripheralRef<'d, T>,
}
macro_rules! enable {
@ -100,21 +100,21 @@ macro_rules! enable {
}
impl<'d, T: Instance> Dac<'d, T> {
pub fn new_1ch(peri: impl Unborrow<Target = T> + 'd, _ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd) -> Self {
unborrow!(peri);
pub fn new_1ch(peri: impl Peripheral<P = T> + 'd, _ch1: impl Peripheral<P = impl DacPin<T, 1>> + 'd) -> Self {
into_ref!(peri);
Self::new_inner(peri, 1)
}
pub fn new_2ch(
peri: impl Unborrow<Target = T> + 'd,
_ch1: impl Unborrow<Target = impl DacPin<T, 1>> + 'd,
_ch2: impl Unborrow<Target = impl DacPin<T, 2>> + 'd,
peri: impl Peripheral<P = T> + 'd,
_ch1: impl Peripheral<P = impl DacPin<T, 1>> + 'd,
_ch2: impl Peripheral<P = impl DacPin<T, 2>> + 'd,
) -> Self {
unborrow!(peri);
into_ref!(peri);
Self::new_inner(peri, 2)
}
fn new_inner(peri: Unborrowed<'d, T>, channels: u8) -> Self {
fn new_inner(peri: PeripheralRef<'d, T>, channels: u8) -> Self {
unsafe {
// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent DAC clock
// configuration.

View File

@ -1,13 +1,13 @@
use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use crate::gpio::sealed::AFType;
use crate::gpio::Speed;
use crate::interrupt::{Interrupt, InterruptExt};
use crate::Unborrow;
use crate::Peripheral;
/// The level on the VSync pin when the data is not valid on the parallel interface.
#[derive(Clone, Copy, PartialEq)]
@ -69,7 +69,7 @@ impl Default for Config {
macro_rules! config_pins {
($($pin:ident),*) => {
unborrow!($($pin),*);
into_ref!($($pin),*);
// NOTE(unsafe) Exclusive access to the registers
critical_section::with(|_| unsafe {
$(
@ -81,8 +81,8 @@ macro_rules! config_pins {
}
pub struct Dcmi<'d, T: Instance, Dma: FrameDma<T>> {
inner: Unborrowed<'d, T>,
dma: Unborrowed<'d, Dma>,
inner: PeripheralRef<'d, T>,
dma: PeripheralRef<'d, Dma>,
}
impl<'d, T, Dma> Dcmi<'d, T, Dma>
@ -91,23 +91,23 @@ where
Dma: FrameDma<T>,
{
pub fn new_8bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd,
h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd,
h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7);
config_pins!(v_sync, h_sync, pixclk);
@ -115,25 +115,25 @@ where
}
pub fn new_10bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
d8: impl Unborrow<Target = impl D8Pin<T>> + 'd,
d9: impl Unborrow<Target = impl D9Pin<T>> + 'd,
v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd,
h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
d8: impl Peripheral<P = impl D8Pin<T>> + 'd,
d9: impl Peripheral<P = impl D9Pin<T>> + 'd,
v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd,
h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9);
config_pins!(v_sync, h_sync, pixclk);
@ -141,27 +141,27 @@ where
}
pub fn new_12bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
d8: impl Unborrow<Target = impl D8Pin<T>> + 'd,
d9: impl Unborrow<Target = impl D9Pin<T>> + 'd,
d10: impl Unborrow<Target = impl D10Pin<T>> + 'd,
d11: impl Unborrow<Target = impl D11Pin<T>> + 'd,
v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd,
h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
d8: impl Peripheral<P = impl D8Pin<T>> + 'd,
d9: impl Peripheral<P = impl D9Pin<T>> + 'd,
d10: impl Peripheral<P = impl D10Pin<T>> + 'd,
d11: impl Peripheral<P = impl D11Pin<T>> + 'd,
v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd,
h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11);
config_pins!(v_sync, h_sync, pixclk);
@ -169,29 +169,29 @@ where
}
pub fn new_14bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
d8: impl Unborrow<Target = impl D8Pin<T>> + 'd,
d9: impl Unborrow<Target = impl D9Pin<T>> + 'd,
d10: impl Unborrow<Target = impl D10Pin<T>> + 'd,
d11: impl Unborrow<Target = impl D11Pin<T>> + 'd,
d12: impl Unborrow<Target = impl D12Pin<T>> + 'd,
d13: impl Unborrow<Target = impl D13Pin<T>> + 'd,
v_sync: impl Unborrow<Target = impl VSyncPin<T>> + 'd,
h_sync: impl Unborrow<Target = impl HSyncPin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
d8: impl Peripheral<P = impl D8Pin<T>> + 'd,
d9: impl Peripheral<P = impl D9Pin<T>> + 'd,
d10: impl Peripheral<P = impl D10Pin<T>> + 'd,
d11: impl Peripheral<P = impl D11Pin<T>> + 'd,
d12: impl Peripheral<P = impl D12Pin<T>> + 'd,
d13: impl Peripheral<P = impl D13Pin<T>> + 'd,
v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd,
h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13);
config_pins!(v_sync, h_sync, pixclk);
@ -199,21 +199,21 @@ where
}
pub fn new_es_8bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7);
config_pins!(pixclk);
@ -221,23 +221,23 @@ where
}
pub fn new_es_10bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
d8: impl Unborrow<Target = impl D8Pin<T>> + 'd,
d9: impl Unborrow<Target = impl D9Pin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
d8: impl Peripheral<P = impl D8Pin<T>> + 'd,
d9: impl Peripheral<P = impl D9Pin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9);
config_pins!(pixclk);
@ -245,25 +245,25 @@ where
}
pub fn new_es_12bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
d8: impl Unborrow<Target = impl D8Pin<T>> + 'd,
d9: impl Unborrow<Target = impl D9Pin<T>> + 'd,
d10: impl Unborrow<Target = impl D10Pin<T>> + 'd,
d11: impl Unborrow<Target = impl D11Pin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
d8: impl Peripheral<P = impl D8Pin<T>> + 'd,
d9: impl Peripheral<P = impl D9Pin<T>> + 'd,
d10: impl Peripheral<P = impl D10Pin<T>> + 'd,
d11: impl Peripheral<P = impl D11Pin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11);
config_pins!(pixclk);
@ -271,27 +271,27 @@ where
}
pub fn new_es_14bit(
peri: impl Unborrow<Target = T> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
d4: impl Unborrow<Target = impl D4Pin<T>> + 'd,
d5: impl Unborrow<Target = impl D5Pin<T>> + 'd,
d6: impl Unborrow<Target = impl D6Pin<T>> + 'd,
d7: impl Unborrow<Target = impl D7Pin<T>> + 'd,
d8: impl Unborrow<Target = impl D8Pin<T>> + 'd,
d9: impl Unborrow<Target = impl D9Pin<T>> + 'd,
d10: impl Unborrow<Target = impl D10Pin<T>> + 'd,
d11: impl Unborrow<Target = impl D11Pin<T>> + 'd,
d12: impl Unborrow<Target = impl D12Pin<T>> + 'd,
d13: impl Unborrow<Target = impl D13Pin<T>> + 'd,
pixclk: impl Unborrow<Target = impl PixClkPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
d4: impl Peripheral<P = impl D4Pin<T>> + 'd,
d5: impl Peripheral<P = impl D5Pin<T>> + 'd,
d6: impl Peripheral<P = impl D6Pin<T>> + 'd,
d7: impl Peripheral<P = impl D7Pin<T>> + 'd,
d8: impl Peripheral<P = impl D8Pin<T>> + 'd,
d9: impl Peripheral<P = impl D9Pin<T>> + 'd,
d10: impl Peripheral<P = impl D10Pin<T>> + 'd,
d11: impl Peripheral<P = impl D11Pin<T>> + 'd,
d12: impl Peripheral<P = impl D12Pin<T>> + 'd,
d13: impl Peripheral<P = impl D13Pin<T>> + 'd,
pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(peri, dma, irq);
into_ref!(peri, dma, irq);
config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13);
config_pins!(pixclk);
@ -299,9 +299,9 @@ where
}
fn new_inner(
peri: Unborrowed<'d, T>,
dma: Unborrowed<'d, Dma>,
irq: Unborrowed<'d, T::Interrupt>,
peri: PeripheralRef<'d, T>,
dma: PeripheralRef<'d, Dma>,
irq: PeripheralRef<'d, T::Interrupt>,
config: Config,
use_embedded_synchronization: bool,
edm: u8,

View File

@ -12,11 +12,11 @@ use core::mem;
use core::pin::Pin;
use core::task::{Context, Poll, Waker};
use embassy_hal_common::{impl_unborrow, unborrow};
use embassy_hal_common::{impl_peripheral, into_ref};
#[cfg(dmamux)]
pub use self::dmamux::*;
use crate::Unborrow;
use crate::Peripheral;
#[cfg(feature = "unstable-pac")]
pub mod low_level {
@ -206,19 +206,19 @@ impl Default for TransferOptions {
}
mod transfers {
use embassy_hal_common::Unborrowed;
use embassy_hal_common::PeripheralRef;
use super::*;
#[allow(unused)]
pub fn read<'a, W: Word>(
channel: impl Unborrow<Target = impl Channel> + 'a,
channel: impl Peripheral<P = impl Channel> + 'a,
request: Request,
reg_addr: *mut W,
buf: &'a mut [W],
) -> impl Future<Output = ()> + 'a {
assert!(buf.len() > 0 && buf.len() <= 0xFFFF);
unborrow!(channel);
into_ref!(channel);
unsafe { channel.start_read::<W>(request, reg_addr, buf, Default::default()) };
@ -227,13 +227,13 @@ mod transfers {
#[allow(unused)]
pub fn write<'a, W: Word>(
channel: impl Unborrow<Target = impl Channel> + 'a,
channel: impl Peripheral<P = impl Channel> + 'a,
request: Request,
buf: &'a [W],
reg_addr: *mut W,
) -> impl Future<Output = ()> + 'a {
assert!(buf.len() > 0 && buf.len() <= 0xFFFF);
unborrow!(channel);
into_ref!(channel);
unsafe { channel.start_write::<W>(request, buf, reg_addr, Default::default()) };
@ -242,13 +242,13 @@ mod transfers {
#[allow(unused)]
pub fn write_repeated<'a, W: Word>(
channel: impl Unborrow<Target = impl Channel> + 'a,
channel: impl Peripheral<P = impl Channel> + 'a,
request: Request,
repeated: W,
count: usize,
reg_addr: *mut W,
) -> impl Future<Output = ()> + 'a {
unborrow!(channel);
into_ref!(channel);
unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr, Default::default()) };
@ -256,12 +256,12 @@ mod transfers {
}
pub(crate) struct Transfer<'a, C: Channel> {
channel: Unborrowed<'a, C>,
channel: PeripheralRef<'a, C>,
}
impl<'a, C: Channel> Transfer<'a, C> {
pub(crate) fn new(channel: impl Unborrow<Target = C> + 'a) -> Self {
unborrow!(channel);
pub(crate) fn new(channel: impl Peripheral<P = C> + 'a) -> Self {
into_ref!(channel);
Self { channel }
}
}
@ -287,11 +287,11 @@ mod transfers {
}
}
pub trait Channel: sealed::Channel + Unborrow<Target = Self> + 'static {}
pub trait Channel: sealed::Channel + Peripheral<P = Self> + 'static {}
pub struct NoDma;
impl_unborrow!(NoDma);
impl_peripheral!(NoDma);
// safety: must be called only once at startup
pub(crate) unsafe fn init() {

View File

@ -6,7 +6,7 @@ use core::task::Waker;
use embassy::waitqueue::AtomicWaker;
use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU};
use crate::gpio::sealed::{AFType, Pin as __GpioPin};
@ -16,7 +16,7 @@ use crate::pac::AFIO;
#[cfg(any(eth_v1b, eth_v1c))]
use crate::pac::SYSCFG;
use crate::pac::{ETH, RCC};
use crate::Unborrow;
use crate::Peripheral;
mod descriptors;
mod rx_desc;
@ -36,7 +36,7 @@ impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> {
pub struct Ethernet<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> {
state: PeripheralMutex<'d, Inner<'d, T, TX, RX>>,
pins: [Unborrowed<'d, AnyPin>; 9],
pins: [PeripheralRef<'d, AnyPin>; 9],
_phy: P,
clock_range: Cr,
phy_addr: u8,
@ -86,22 +86,22 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, T,
/// safety: the returned instance is not leak-safe
pub unsafe fn new(
state: &'d mut State<'d, T, TX, RX>,
peri: impl Unborrow<Target = T> + 'd,
interrupt: impl Unborrow<Target = crate::interrupt::ETH> + 'd,
ref_clk: impl Unborrow<Target = impl RefClkPin<T>> + 'd,
mdio: impl Unborrow<Target = impl MDIOPin<T>> + 'd,
mdc: impl Unborrow<Target = impl MDCPin<T>> + 'd,
crs: impl Unborrow<Target = impl CRSPin<T>> + 'd,
rx_d0: impl Unborrow<Target = impl RXD0Pin<T>> + 'd,
rx_d1: impl Unborrow<Target = impl RXD1Pin<T>> + 'd,
tx_d0: impl Unborrow<Target = impl TXD0Pin<T>> + 'd,
tx_d1: impl Unborrow<Target = impl TXD1Pin<T>> + 'd,
tx_en: impl Unborrow<Target = impl TXEnPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
interrupt: impl Peripheral<P = crate::interrupt::ETH> + 'd,
ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd,
mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd,
mdc: impl Peripheral<P = impl MDCPin<T>> + 'd,
crs: impl Peripheral<P = impl CRSPin<T>> + 'd,
rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd,
rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd,
tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd,
tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd,
tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd,
phy: P,
mac_addr: [u8; 6],
phy_addr: u8,
) -> Self {
unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
into_ref!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
// Enable the necessary Clocks
// NOTE(unsafe) We have exclusive access to the registers
@ -370,7 +370,7 @@ struct Inner<'d, T: Instance, const TX: usize, const RX: usize> {
}
impl<'d, T: Instance, const TX: usize, const RX: usize> Inner<'d, T, TX, RX> {
pub fn new(_peri: impl Unborrow<Target = T> + 'd) -> Self {
pub fn new(_peri: impl Peripheral<P = T> + 'd) -> Self {
Self {
_peri: PhantomData,
desc_ring: DescriptorRing::new(),

View File

@ -4,13 +4,13 @@ use core::task::Waker;
use embassy::waitqueue::AtomicWaker;
use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU};
use crate::gpio::sealed::{AFType, Pin as _};
use crate::gpio::{AnyPin, Speed};
use crate::pac::{ETH, RCC, SYSCFG};
use crate::Unborrow;
use crate::Peripheral;
mod descriptors;
use descriptors::DescriptorRing;
@ -25,7 +25,7 @@ impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> {
}
pub struct Ethernet<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> {
state: PeripheralMutex<'d, Inner<'d, T, TX, RX>>,
pins: [Unborrowed<'d, AnyPin>; 9],
pins: [PeripheralRef<'d, AnyPin>; 9],
_phy: P,
clock_range: u8,
phy_addr: u8,
@ -48,22 +48,22 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, T,
/// safety: the returned instance is not leak-safe
pub unsafe fn new(
state: &'d mut State<'d, T, TX, RX>,
peri: impl Unborrow<Target = T> + 'd,
interrupt: impl Unborrow<Target = crate::interrupt::ETH> + 'd,
ref_clk: impl Unborrow<Target = impl RefClkPin<T>> + 'd,
mdio: impl Unborrow<Target = impl MDIOPin<T>> + 'd,
mdc: impl Unborrow<Target = impl MDCPin<T>> + 'd,
crs: impl Unborrow<Target = impl CRSPin<T>> + 'd,
rx_d0: impl Unborrow<Target = impl RXD0Pin<T>> + 'd,
rx_d1: impl Unborrow<Target = impl RXD1Pin<T>> + 'd,
tx_d0: impl Unborrow<Target = impl TXD0Pin<T>> + 'd,
tx_d1: impl Unborrow<Target = impl TXD1Pin<T>> + 'd,
tx_en: impl Unborrow<Target = impl TXEnPin<T>> + 'd,
peri: impl Peripheral<P = T> + 'd,
interrupt: impl Peripheral<P = crate::interrupt::ETH> + 'd,
ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd,
mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd,
mdc: impl Peripheral<P = impl MDCPin<T>> + 'd,
crs: impl Peripheral<P = impl CRSPin<T>> + 'd,
rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd,
rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd,
tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd,
tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd,
tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd,
phy: P,
mac_addr: [u8; 6],
phy_addr: u8,
) -> Self {
unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
into_ref!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
// Enable the necessary Clocks
// NOTE(unsafe) We have exclusive access to the registers
@ -316,7 +316,7 @@ struct Inner<'d, T: Instance, const TX: usize, const RX: usize> {
}
impl<'d, T: Instance, const TX: usize, const RX: usize> Inner<'d, T, TX, RX> {
pub fn new(_peri: impl Unborrow<Target = T> + 'd) -> Self {
pub fn new(_peri: impl Peripheral<P = T> + 'd) -> Self {
Self {
_peri: PhantomData,
desc_ring: DescriptorRing::new(),

View File

@ -4,12 +4,12 @@ use core::pin::Pin;
use core::task::{Context, Poll};
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::impl_unborrow;
use embassy_hal_common::impl_peripheral;
use crate::gpio::{AnyPin, Input, Pin as GpioPin};
use crate::pac::exti::regs::Lines;
use crate::pac::EXTI;
use crate::{interrupt, pac, peripherals, Unborrow};
use crate::{interrupt, pac, peripherals, Peripheral};
const EXTI_COUNT: usize = 16;
const NEW_AW: AtomicWaker = AtomicWaker::new();
@ -86,7 +86,7 @@ pub struct ExtiInput<'d, T: GpioPin> {
impl<'d, T: GpioPin> Unpin for ExtiInput<'d, T> {}
impl<'d, T: GpioPin> ExtiInput<'d, T> {
pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self {
pub fn new(pin: Input<'d, T>, _ch: impl Peripheral<P = T::ExtiChannel> + 'd) -> Self {
Self { pin }
}
@ -320,7 +320,7 @@ pub trait Channel: sealed::Channel + Sized {
pub struct AnyChannel {
number: u8,
}
impl_unborrow!(AnyChannel);
impl_peripheral!(AnyChannel);
impl sealed::Channel for AnyChannel {}
impl Channel for AnyChannel {
fn number(&self) -> usize {

View File

@ -1,9 +1,9 @@
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash};
pub use crate::pac::{ERASE_SIZE, ERASE_VALUE, FLASH_BASE, FLASH_SIZE, WRITE_SIZE};
use crate::peripherals::FLASH;
use crate::Unborrow;
use crate::Peripheral;
const FLASH_END: usize = FLASH_BASE + FLASH_SIZE;
#[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;
mod family;
pub struct Flash<'d> {
_inner: Unborrowed<'d, FLASH>,
_inner: PeripheralRef<'d, FLASH>,
}
impl<'d> Flash<'d> {
pub fn new(p: impl Unborrow<Target = FLASH> + 'd) -> Self {
unborrow!(p);
pub fn new(p: impl Peripheral<P = FLASH> + 'd) -> Self {
into_ref!(p);
Self { _inner: p }
}
pub fn unlock(p: impl Unborrow<Target = FLASH> + 'd) -> Self {
pub fn unlock(p: impl Peripheral<P = FLASH> + 'd) -> Self {
let flash = Self::new(p);
unsafe { family::unlock() };

View File

@ -1,10 +1,10 @@
use core::marker::PhantomData;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use crate::gpio::sealed::AFType;
use crate::gpio::{Pull, Speed};
use crate::Unborrow;
use crate::Peripheral;
mod pins;
pub use pins::*;
@ -39,7 +39,7 @@ where
macro_rules! config_pins {
($($pin:ident),*) => {
unborrow!($($pin),*);
into_ref!($($pin),*);
$(
$pin.set_as_af_pull($pin.af_num(), AFType::OutputPushPull, Pull::Up);
$pin.set_speed(Speed::VeryHigh);
@ -57,12 +57,12 @@ macro_rules! fmc_sdram_constructor {
ctrl: [$(($ctrl_pin_name:ident: $ctrl_signal:ident)),*]
)) => {
pub fn $name<CHIP: stm32_fmc::SdramChip>(
_instance: impl Unborrow<Target = T> + 'd,
$($addr_pin_name: impl Unborrow<Target = impl $addr_signal<T>> + 'd),*,
$($ba_pin_name: impl Unborrow<Target = impl $ba_signal<T>> + 'd),*,
$($d_pin_name: impl Unborrow<Target = impl $d_signal<T>> + 'd),*,
$($nbl_pin_name: impl Unborrow<Target = impl $nbl_signal<T>> + 'd),*,
$($ctrl_pin_name: impl Unborrow<Target = impl $ctrl_signal<T>> + 'd),*,
_instance: impl Peripheral<P = T> + 'd,
$($addr_pin_name: impl Peripheral<P = impl $addr_signal<T>> + 'd),*,
$($ba_pin_name: impl Peripheral<P = impl $ba_signal<T>> + 'd),*,
$($d_pin_name: impl Peripheral<P = impl $d_signal<T>> + 'd),*,
$($nbl_pin_name: impl Peripheral<P = impl $nbl_signal<T>> + 'd),*,
$($ctrl_pin_name: impl Peripheral<P = impl $ctrl_signal<T>> + 'd),*,
chip: CHIP
) -> stm32_fmc::Sdram<Fmc<'d, T>, CHIP> {

View File

@ -1,10 +1,10 @@
#![macro_use]
use core::convert::Infallible;
use embassy_hal_common::{impl_unborrow, unborrow, Unborrowed};
use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef};
use crate::pac::gpio::{self, vals};
use crate::{pac, peripherals, Unborrow};
use crate::{pac, peripherals, Peripheral};
/// GPIO flexible pin.
///
@ -12,7 +12,7 @@ use crate::{pac, peripherals, Unborrow};
/// 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> {
pub(crate) pin: Unborrowed<'d, T>,
pub(crate) pin: PeripheralRef<'d, T>,
}
impl<'d, T: Pin> Flex<'d, T> {
@ -22,8 +22,8 @@ impl<'d, T: Pin> Flex<'d, T> {
/// before the pin is put into output mode.
///
#[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);
// Pin will be in disconnected state.
Self { pin }
}
@ -280,7 +280,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(pull);
Self { pin }
@ -335,7 +335,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, speed: Speed) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed) -> Self {
let mut pin = Flex::new(pin);
match initial_output {
Level::High => pin.set_high(),
@ -395,7 +395,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, speed: Speed, pull: Pull) -> Self {
pub fn new(pin: impl Peripheral<P = T> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self {
let mut pin = Flex::new(pin);
match initial_output {
@ -668,7 +668,7 @@ impl AnyPin {
}
}
impl_unborrow!(AnyPin);
impl_peripheral!(AnyPin);
impl Pin for AnyPin {
#[cfg(feature = "exti")]
type ExtiChannel = crate::exti::AnyChannel;

View File

@ -1,13 +1,13 @@
use core::marker::PhantomData;
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use crate::gpio::sealed::AFType;
use crate::i2c::{Error, Instance, SclPin, SdaPin};
use crate::pac::i2c;
use crate::time::Hertz;
use crate::Unborrow;
use crate::Peripheral;
pub struct State {}
@ -23,12 +23,12 @@ pub struct I2c<'d, T: Instance> {
impl<'d, T: Instance> I2c<'d, T> {
pub fn new(
_peri: impl Unborrow<Target = T> + 'd,
scl: impl Unborrow<Target = impl SclPin<T>> + 'd,
sda: impl Unborrow<Target = impl SdaPin<T>> + 'd,
_peri: impl Peripheral<P = T> + 'd,
scl: impl Peripheral<P = impl SclPin<T>> + 'd,
sda: impl Peripheral<P = impl SdaPin<T>> + 'd,
freq: Hertz,
) -> Self {
unborrow!(scl, sda);
into_ref!(scl, sda);
T::enable();
T::reset();

View File

@ -5,7 +5,7 @@ use atomic_polyfill::{AtomicUsize, Ordering};
use embassy::waitqueue::AtomicWaker;
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use crate::dma::NoDma;
@ -14,7 +14,7 @@ use crate::i2c::{Error, Instance, SclPin, SdaPin};
use crate::interrupt::InterruptExt;
use crate::pac::i2c;
use crate::time::Hertz;
use crate::Unborrow;
use crate::Peripheral;
pub struct State {
waker: AtomicWaker,
@ -31,23 +31,23 @@ impl State {
}
pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> {
_peri: Unborrowed<'d, T>,
tx_dma: Unborrowed<'d, TXDMA>,
_peri: PeripheralRef<'d, T>,
tx_dma: PeripheralRef<'d, TXDMA>,
#[allow(dead_code)]
rx_dma: Unborrowed<'d, RXDMA>,
rx_dma: PeripheralRef<'d, RXDMA>,
}
impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
pub fn new(
peri: impl Unborrow<Target = T> + 'd,
scl: impl Unborrow<Target = impl SclPin<T>> + 'd,
sda: impl Unborrow<Target = impl SdaPin<T>> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
tx_dma: impl Unborrow<Target = TXDMA> + 'd,
rx_dma: impl Unborrow<Target = RXDMA> + 'd,
peri: impl Peripheral<P = T> + 'd,
scl: impl Peripheral<P = impl SclPin<T>> + 'd,
sda: impl Peripheral<P = impl SdaPin<T>> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
tx_dma: impl Peripheral<P = TXDMA> + 'd,
rx_dma: impl Peripheral<P = RXDMA> + 'd,
freq: Hertz,
) -> Self {
unborrow!(peri, irq, scl, sda, tx_dma, rx_dma);
into_ref!(peri, irq, scl, sda, tx_dma, rx_dma);
T::enable();
T::reset();

View File

@ -75,7 +75,7 @@ pub(crate) mod _generated {
// Reexports
pub use _generated::{peripherals, Peripherals};
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 stm32_metapac as pac;

View File

@ -1,18 +1,18 @@
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use super::*;
#[allow(unused_imports)]
use crate::gpio::sealed::{AFType, Pin};
use crate::time::Hertz;
use crate::Unborrow;
use crate::Peripheral;
pub struct SimplePwm<'d, T> {
inner: Unborrowed<'d, T>,
inner: PeripheralRef<'d, T>,
}
macro_rules! config_pins {
($($pin:ident),*) => {
unborrow!($($pin),*);
into_ref!($($pin),*);
// NOTE(unsafe) Exclusive access to the registers
critical_section::with(|_| unsafe {
$(
@ -27,8 +27,8 @@ macro_rules! config_pins {
impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
pub fn new_1ch(
tim: impl Unborrow<Target = T> + 'd,
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
tim: impl Peripheral<P = T> + 'd,
ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
freq: Hertz,
) -> Self {
Self::new_inner(tim, freq, move || {
@ -37,9 +37,9 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
}
pub fn new_2ch(
tim: impl Unborrow<Target = T> + 'd,
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
tim: impl Peripheral<P = T> + 'd,
ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd,
freq: Hertz,
) -> Self {
Self::new_inner(tim, freq, move || {
@ -48,10 +48,10 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
}
pub fn new_3ch(
tim: impl Unborrow<Target = T> + 'd,
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd,
tim: impl Peripheral<P = T> + 'd,
ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd,
ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd,
freq: Hertz,
) -> Self {
Self::new_inner(tim, freq, move || {
@ -60,11 +60,11 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
}
pub fn new_4ch(
tim: impl Unborrow<Target = T> + 'd,
ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd,
ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd,
ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd,
tim: impl Peripheral<P = T> + 'd,
ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd,
ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd,
ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd,
freq: Hertz,
) -> Self {
Self::new_inner(tim, freq, move || {
@ -72,8 +72,8 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
})
}
fn new_inner(tim: impl Unborrow<Target = T> + 'd, freq: Hertz, configure_pins: impl FnOnce()) -> Self {
unborrow!(tim);
fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, configure_pins: impl FnOnce()) -> Self {
into_ref!(tim);
T::enable();
<T as crate::rcc::sealed::RccPeripheral>::reset();

View File

@ -1,6 +1,6 @@
use core::marker::PhantomData;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
pub use pll::PllConfig;
use stm32_metapac::rcc::vals::{Mco1, Mco2};
@ -10,7 +10,7 @@ use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw, T
use crate::pac::{PWR, RCC, SYSCFG};
use crate::rcc::{set_freqs, Clocks};
use crate::time::Hertz;
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
/// HSI speed
pub const HSI_FREQ: Hertz = Hertz(64_000_000);
@ -385,12 +385,12 @@ pub struct Mco<'d, T: McoInstance> {
impl<'d, T: McoInstance> Mco<'d, T> {
pub fn new(
_peri: impl Unborrow<Target = T> + 'd,
pin: impl Unborrow<Target = impl McoPin<T>> + 'd,
_peri: impl Peripheral<P = T> + 'd,
pin: impl Peripheral<P = impl McoPin<T>> + 'd,
source: impl McoSource<Raw = T::Source>,
prescaler: McoClock,
) -> Self {
unborrow!(pin);
into_ref!(pin);
critical_section::with(|_| unsafe {
T::apply_clock_settings(source.into_raw(), prescaler.into_raw());

View File

@ -3,11 +3,11 @@
use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use rand_core::{CryptoRng, RngCore};
use crate::{pac, peripherals, Unborrow};
use crate::{pac, peripherals, Peripheral};
pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new();
@ -18,14 +18,14 @@ pub enum Error {
}
pub struct Rng<'d, T: Instance> {
_inner: Unborrowed<'d, T>,
_inner: PeripheralRef<'d, T>,
}
impl<'d, T: Instance> Rng<'d, T> {
pub fn new(inner: impl Unborrow<Target = T> + 'd) -> Self {
pub fn new(inner: impl Peripheral<P = T> + 'd) -> Self {
T::enable();
T::reset();
unborrow!(inner);
into_ref!(inner);
let mut random = Self { _inner: inner };
random.reset();
random

View File

@ -5,7 +5,7 @@ use core::task::Poll;
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use futures::future::poll_fn;
use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR};
@ -16,7 +16,7 @@ use crate::interrupt::{Interrupt, InterruptExt};
use crate::pac::sdmmc::Sdmmc as RegBlock;
use crate::rcc::RccPeripheral;
use crate::time::Hertz;
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
/// The signalling scheme used on the SDMMC bus
#[non_exhaustive]
@ -176,16 +176,16 @@ impl Default for Config {
/// Sdmmc device
pub struct Sdmmc<'d, T: Instance, Dma = NoDma> {
_peri: Unborrowed<'d, T>,
irq: Unborrowed<'d, T::Interrupt>,
dma: Unborrowed<'d, Dma>,
_peri: PeripheralRef<'d, T>,
irq: PeripheralRef<'d, T::Interrupt>,
dma: PeripheralRef<'d, Dma>,
clk: Unborrowed<'d, AnyPin>,
cmd: Unborrowed<'d, AnyPin>,
d0: Unborrowed<'d, AnyPin>,
d1: Option<Unborrowed<'d, AnyPin>>,
d2: Option<Unborrowed<'d, AnyPin>>,
d3: Option<Unborrowed<'d, AnyPin>>,
clk: PeripheralRef<'d, AnyPin>,
cmd: PeripheralRef<'d, AnyPin>,
d0: PeripheralRef<'d, AnyPin>,
d1: Option<PeripheralRef<'d, AnyPin>>,
d2: Option<PeripheralRef<'d, AnyPin>>,
d3: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
/// Current clock to card
@ -199,15 +199,15 @@ pub struct Sdmmc<'d, T: Instance, Dma = NoDma> {
#[cfg(sdmmc_v1)]
impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> {
pub fn new_1bit(
sdmmc: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
clk: impl Unborrow<Target = impl CkPin<T>> + 'd,
cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
sdmmc: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
clk: impl Peripheral<P = impl CkPin<T>> + 'd,
cmd: impl Peripheral<P = impl CmdPin<T>> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(clk, cmd, d0);
into_ref!(clk, cmd, d0);
critical_section::with(|_| unsafe {
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> {
}
pub fn new_4bit(
sdmmc: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
clk: impl Unborrow<Target = impl CkPin<T>> + 'd,
cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
sdmmc: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
clk: impl Peripheral<P = impl CkPin<T>> + 'd,
cmd: impl Peripheral<P = impl CmdPin<T>> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(clk, cmd, d0, d1, d2, d3);
into_ref!(clk, cmd, d0, d1, d2, d3);
critical_section::with(|_| unsafe {
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> {
}
fn new_inner(
sdmmc: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
dma: impl Unborrow<Target = Dma> + 'd,
clk: Unborrowed<'d, AnyPin>,
cmd: Unborrowed<'d, AnyPin>,
d0: Unborrowed<'d, AnyPin>,
d1: Option<Unborrowed<'d, AnyPin>>,
d2: Option<Unborrowed<'d, AnyPin>>,
d3: Option<Unborrowed<'d, AnyPin>>,
sdmmc: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
dma: impl Peripheral<P = Dma> + 'd,
clk: PeripheralRef<'d, AnyPin>,
cmd: PeripheralRef<'d, AnyPin>,
d0: PeripheralRef<'d, AnyPin>,
d1: Option<PeripheralRef<'d, AnyPin>>,
d2: Option<PeripheralRef<'d, AnyPin>>,
d3: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(sdmmc, irq, dma);
into_ref!(sdmmc, irq, dma);
T::enable();
T::reset();
@ -324,14 +324,14 @@ impl<'d, T: Instance, Dma: SdmmcDma<T>> Sdmmc<'d, T, Dma> {
#[cfg(sdmmc_v2)]
impl<'d, T: Instance> Sdmmc<'d, T, NoDma> {
pub fn new_1bit(
sdmmc: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
clk: impl Unborrow<Target = impl CkPin<T>> + 'd,
cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
sdmmc: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
clk: impl Peripheral<P = impl CkPin<T>> + 'd,
cmd: impl Peripheral<P = impl CmdPin<T>> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(clk, cmd, d0);
into_ref!(clk, cmd, d0);
critical_section::with(|_| unsafe {
clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None);
@ -357,17 +357,17 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> {
}
pub fn new_4bit(
sdmmc: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
clk: impl Unborrow<Target = impl CkPin<T>> + 'd,
cmd: impl Unborrow<Target = impl CmdPin<T>> + 'd,
d0: impl Unborrow<Target = impl D0Pin<T>> + 'd,
d1: impl Unborrow<Target = impl D1Pin<T>> + 'd,
d2: impl Unborrow<Target = impl D2Pin<T>> + 'd,
d3: impl Unborrow<Target = impl D3Pin<T>> + 'd,
sdmmc: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
clk: impl Peripheral<P = impl CkPin<T>> + 'd,
cmd: impl Peripheral<P = impl CmdPin<T>> + 'd,
d0: impl Peripheral<P = impl D0Pin<T>> + 'd,
d1: impl Peripheral<P = impl D1Pin<T>> + 'd,
d2: impl Peripheral<P = impl D2Pin<T>> + 'd,
d3: impl Peripheral<P = impl D3Pin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(clk, cmd, d0, d1, d2, d3);
into_ref!(clk, cmd, d0, d1, d2, d3);
critical_section::with(|_| unsafe {
clk.set_as_af_pull(clk.af_num(), AFType::OutputPushPull, Pull::None);
@ -399,17 +399,17 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> {
}
fn new_inner(
sdmmc: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
clk: Unborrowed<'d, AnyPin>,
cmd: Unborrowed<'d, AnyPin>,
d0: Unborrowed<'d, AnyPin>,
d1: Option<Unborrowed<'d, AnyPin>>,
d2: Option<Unborrowed<'d, AnyPin>>,
d3: Option<Unborrowed<'d, AnyPin>>,
sdmmc: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
clk: PeripheralRef<'d, AnyPin>,
cmd: PeripheralRef<'d, AnyPin>,
d0: PeripheralRef<'d, AnyPin>,
d1: Option<PeripheralRef<'d, AnyPin>>,
d2: Option<PeripheralRef<'d, AnyPin>>,
d3: Option<PeripheralRef<'d, AnyPin>>,
config: Config,
) -> Self {
unborrow!(sdmmc, irq);
into_ref!(sdmmc, irq);
T::enable();
T::reset();
@ -424,7 +424,7 @@ impl<'d, T: Instance> Sdmmc<'d, T, NoDma> {
Self {
_peri: sdmmc,
irq,
dma: NoDma.unborrow(),
dma: NoDma.into_ref(),
clk,
cmd,

View File

@ -3,7 +3,7 @@
use core::ptr;
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
use futures::future::join;
@ -14,7 +14,7 @@ use crate::gpio::AnyPin;
use crate::pac::spi::{regs, vals, Spi as Regs};
use crate::rcc::RccPeripheral;
use crate::time::Hertz;
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -72,27 +72,27 @@ impl Config {
}
pub struct Spi<'d, T: Instance, Tx, Rx> {
_peri: Unborrowed<'d, T>,
sck: Option<Unborrowed<'d, AnyPin>>,
mosi: Option<Unborrowed<'d, AnyPin>>,
miso: Option<Unborrowed<'d, AnyPin>>,
txdma: Unborrowed<'d, Tx>,
rxdma: Unborrowed<'d, Rx>,
_peri: PeripheralRef<'d, T>,
sck: Option<PeripheralRef<'d, AnyPin>>,
mosi: Option<PeripheralRef<'d, AnyPin>>,
miso: Option<PeripheralRef<'d, AnyPin>>,
txdma: PeripheralRef<'d, Tx>,
rxdma: PeripheralRef<'d, Rx>,
current_word_size: WordSize,
}
impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
pub fn new(
peri: impl Unborrow<Target = T> + 'd,
sck: impl Unborrow<Target = impl SckPin<T>> + 'd,
mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
txdma: impl Unborrow<Target = Tx> + 'd,
rxdma: impl Unborrow<Target = Rx> + 'd,
peri: impl Peripheral<P = T> + 'd,
sck: impl Peripheral<P = impl SckPin<T>> + 'd,
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
txdma: impl Peripheral<P = Tx> + 'd,
rxdma: impl Peripheral<P = Rx> + 'd,
freq: Hertz,
config: Config,
) -> Self {
unborrow!(peri, sck, mosi, miso);
into_ref!(peri, sck, mosi, miso);
unsafe {
sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
#[cfg(any(spi_v2, spi_v3, spi_v4))]
@ -118,15 +118,15 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
}
pub fn new_rxonly(
peri: impl Unborrow<Target = T> + 'd,
sck: impl Unborrow<Target = impl SckPin<T>> + 'd,
miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
txdma: impl Unborrow<Target = Tx> + 'd, // TODO remove
rxdma: impl Unborrow<Target = Rx> + 'd,
peri: impl Peripheral<P = T> + 'd,
sck: impl Peripheral<P = impl SckPin<T>> + 'd,
miso: impl Peripheral<P = impl MisoPin<T>> + 'd,
txdma: impl Peripheral<P = Tx> + 'd, // TODO remove
rxdma: impl Peripheral<P = Rx> + 'd,
freq: Hertz,
config: Config,
) -> Self {
unborrow!(sck, miso);
into_ref!(sck, miso);
unsafe {
sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
#[cfg(any(spi_v2, spi_v3, spi_v4))]
@ -149,15 +149,15 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
}
pub fn new_txonly(
peri: impl Unborrow<Target = T> + 'd,
sck: impl Unborrow<Target = impl SckPin<T>> + 'd,
mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
txdma: impl Unborrow<Target = Tx> + 'd,
rxdma: impl Unborrow<Target = Rx> + 'd, // TODO remove
peri: impl Peripheral<P = T> + 'd,
sck: impl Peripheral<P = impl SckPin<T>> + 'd,
mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
txdma: impl Peripheral<P = Tx> + 'd,
rxdma: impl Peripheral<P = Rx> + 'd, // TODO remove
freq: Hertz,
config: Config,
) -> Self {
unborrow!(sck, mosi);
into_ref!(sck, mosi);
unsafe {
sck.set_as_af(sck.af_num(), AFType::OutputPushPull);
#[cfg(any(spi_v2, spi_v3, spi_v4))]
@ -180,16 +180,16 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
}
fn new_inner(
peri: impl Unborrow<Target = T> + 'd,
sck: Option<Unborrowed<'d, AnyPin>>,
mosi: Option<Unborrowed<'d, AnyPin>>,
miso: Option<Unborrowed<'d, AnyPin>>,
txdma: impl Unborrow<Target = Tx> + 'd,
rxdma: impl Unborrow<Target = Rx> + 'd,
peri: impl Peripheral<P = T> + 'd,
sck: Option<PeripheralRef<'d, AnyPin>>,
mosi: Option<PeripheralRef<'d, AnyPin>>,
miso: Option<PeripheralRef<'d, AnyPin>>,
txdma: impl Peripheral<P = Tx> + 'd,
rxdma: impl Peripheral<P = Rx> + 'd,
freq: Hertz,
config: Config,
) -> Self {
unborrow!(peri, txdma, rxdma);
into_ref!(peri, txdma, rxdma);
let pclk = T::frequency();
let br = compute_baud_rate(pclk, freq.into());
@ -994,7 +994,7 @@ pub trait Word: Copy + 'static + sealed::Word + Default + crate::dma::Word {}
impl Word for u8 {}
impl Word for u16 {}
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + RccPeripheral {}
pub trait Instance: Peripheral<P = Self> + sealed::Instance + RccPeripheral {}
pin_trait!(SckPin, Instance);
pin_trait!(MosiPin, Instance);
pin_trait!(MisoPin, Instance);

View File

@ -83,7 +83,7 @@ use crate::peripherals::SUBGHZSPI;
use crate::rcc::sealed::RccPeripheral;
use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0};
use crate::time::Hertz;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
/// Passthrough for SPI errors (for now)
pub type Error = crate::spi::Error;
@ -211,12 +211,12 @@ impl<'d, Tx, Rx> SubGhz<'d, Tx, Rx> {
/// This will reset the radio and the SPI bus, and enable the peripheral
/// clock.
pub fn new(
peri: impl Unborrow<Target = SUBGHZSPI> + 'd,
sck: impl Unborrow<Target = impl SckPin<SUBGHZSPI>> + 'd,
mosi: impl Unborrow<Target = impl MosiPin<SUBGHZSPI>> + 'd,
miso: impl Unborrow<Target = impl MisoPin<SUBGHZSPI>> + 'd,
txdma: impl Unborrow<Target = Tx> + 'd,
rxdma: impl Unborrow<Target = Rx> + 'd,
peri: impl Peripheral<P = SUBGHZSPI> + 'd,
sck: impl Peripheral<P = impl SckPin<SUBGHZSPI>> + 'd,
mosi: impl Peripheral<P = impl MosiPin<SUBGHZSPI>> + 'd,
miso: impl Peripheral<P = impl MisoPin<SUBGHZSPI>> + 'd,
txdma: impl Peripheral<P = Tx> + 'd,
rxdma: impl Peripheral<P = Rx> + 'd,
) -> Self {
Self::pulse_radio_reset();

View File

@ -39,11 +39,11 @@ impl<'d, T: Instance> BufferedUart<'d, T> {
pub fn new(
state: &'d mut State<'d, T>,
_uart: Uart<'d, T, NoDma, NoDma>,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
tx_buffer: &'d mut [u8],
rx_buffer: &'d mut [u8],
) -> BufferedUart<'d, T> {
unborrow!(irq);
into_ref!(irq);
let r = T::regs();
unsafe {

View File

@ -2,14 +2,14 @@
use core::marker::PhantomData;
use embassy_hal_common::{unborrow, Unborrowed};
use embassy_hal_common::{into_ref, PeripheralRef};
use crate::dma::NoDma;
use crate::gpio::sealed::AFType;
use crate::interrupt::Interrupt;
use crate::pac::usart::{regs, vals};
use crate::rcc::RccPeripheral;
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DataBits {
@ -78,16 +78,16 @@ pub struct Uart<'d, T: Instance, TxDma = NoDma, RxDma = NoDma> {
pub struct UartTx<'d, T: Instance, TxDma = NoDma> {
phantom: PhantomData<&'d mut T>,
tx_dma: Unborrowed<'d, TxDma>,
tx_dma: PeripheralRef<'d, TxDma>,
}
pub struct UartRx<'d, T: Instance, RxDma = NoDma> {
phantom: PhantomData<&'d mut T>,
rx_dma: Unborrowed<'d, RxDma>,
rx_dma: PeripheralRef<'d, RxDma>,
}
impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> {
fn new(tx_dma: Unborrowed<'d, TxDma>) -> Self {
fn new(tx_dma: PeripheralRef<'d, TxDma>) -> Self {
Self {
tx_dma,
phantom: PhantomData,
@ -133,7 +133,7 @@ impl<'d, T: Instance, TxDma> UartTx<'d, T, TxDma> {
}
impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> {
fn new(rx_dma: Unborrowed<'d, RxDma>) -> Self {
fn new(rx_dma: PeripheralRef<'d, RxDma>) -> Self {
Self {
rx_dma,
phantom: PhantomData,
@ -189,14 +189,14 @@ impl<'d, T: Instance, RxDma> UartRx<'d, T, RxDma> {
impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
pub fn new(
_inner: impl Unborrow<Target = T> + 'd,
rx: impl Unborrow<Target = impl RxPin<T>> + 'd,
tx: impl Unborrow<Target = impl TxPin<T>> + 'd,
tx_dma: impl Unborrow<Target = TxDma> + 'd,
rx_dma: impl Unborrow<Target = RxDma> + 'd,
_inner: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
tx_dma: impl Peripheral<P = TxDma> + 'd,
rx_dma: impl Peripheral<P = RxDma> + 'd,
config: Config,
) -> Self {
unborrow!(_inner, rx, tx, tx_dma, rx_dma);
into_ref!(_inner, rx, tx, tx_dma, rx_dma);
T::enable();
T::reset();

View File

@ -7,7 +7,7 @@ use core::task::Poll;
use atomic_polyfill::{AtomicBool, AtomicU8};
use embassy::time::{block_for, Duration};
use embassy::waitqueue::AtomicWaker;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported};
use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection};
use futures::future::poll_fn;
@ -20,7 +20,7 @@ use crate::gpio::sealed::AFType;
use crate::interrupt::InterruptExt;
use crate::pac::usb::regs;
use crate::rcc::sealed::RccPeripheral;
use crate::{pac, Unborrow};
use crate::{pac, Peripheral};
const EP_COUNT: usize = 8;
@ -125,12 +125,12 @@ pub struct Driver<'d, T: Instance> {
impl<'d, T: Instance> Driver<'d, T> {
pub fn new(
_usb: impl Unborrow<Target = T> + 'd,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
dp: impl Unborrow<Target = impl DpPin<T>> + 'd,
dm: impl Unborrow<Target = impl DmPin<T>> + 'd,
_usb: impl Peripheral<P = T> + 'd,
irq: impl Peripheral<P = T::Interrupt> + 'd,
dp: impl Peripheral<P = impl DpPin<T>> + 'd,
dm: impl Peripheral<P = impl DmPin<T>> + 'd,
) -> Self {
unborrow!(irq, dp, dm);
into_ref!(irq, dp, dm);
irq.set_handler(Self::on_interrupt);
irq.unpend();
irq.enable();

View File

@ -1,14 +1,14 @@
use core::marker::PhantomData;
use embassy_hal_common::unborrow;
use embassy_hal_common::into_ref;
use crate::gpio::sealed::AFType;
use crate::rcc::RccPeripheral;
use crate::{peripherals, Unborrow};
use crate::{peripherals, Peripheral};
macro_rules! config_ulpi_pins {
($($pin:ident),*) => {
unborrow!($($pin),*);
into_ref!($($pin),*);
// NOTE(unsafe) Exclusive access to the registers
critical_section::with(|_| unsafe {
$(
@ -43,11 +43,11 @@ pub struct UsbOtg<'d, T: Instance> {
impl<'d, T: Instance> UsbOtg<'d, T> {
/// Initializes USB OTG peripheral with internal Full-Speed PHY
pub fn new_fs(
_peri: impl Unborrow<Target = T> + 'd,
dp: impl Unborrow<Target = impl DpPin<T>> + 'd,
dm: impl Unborrow<Target = impl DmPin<T>> + 'd,
_peri: impl Peripheral<P = T> + 'd,
dp: impl Peripheral<P = impl DpPin<T>> + 'd,
dm: impl Peripheral<P = impl DmPin<T>> + 'd,
) -> Self {
unborrow!(dp, dm);
into_ref!(dp, dm);
unsafe {
dp.set_as_af(dp.af_num(), AFType::OutputPushPull);
@ -62,19 +62,19 @@ impl<'d, T: Instance> UsbOtg<'d, T> {
/// Initializes USB OTG peripheral with external High-Speed PHY
pub fn new_hs_ulpi(
_peri: impl Unborrow<Target = T> + 'd,
ulpi_clk: impl Unborrow<Target = impl UlpiClkPin<T>> + 'd,
ulpi_dir: impl Unborrow<Target = impl UlpiDirPin<T>> + 'd,
ulpi_nxt: impl Unborrow<Target = impl UlpiNxtPin<T>> + 'd,
ulpi_stp: impl Unborrow<Target = impl UlpiStpPin<T>> + 'd,
ulpi_d0: impl Unborrow<Target = impl UlpiD0Pin<T>> + 'd,
ulpi_d1: impl Unborrow<Target = impl UlpiD1Pin<T>> + 'd,
ulpi_d2: impl Unborrow<Target = impl UlpiD2Pin<T>> + 'd,
ulpi_d3: impl Unborrow<Target = impl UlpiD3Pin<T>> + 'd,
ulpi_d4: impl Unborrow<Target = impl UlpiD4Pin<T>> + 'd,
ulpi_d5: impl Unborrow<Target = impl UlpiD5Pin<T>> + 'd,
ulpi_d6: impl Unborrow<Target = impl UlpiD6Pin<T>> + 'd,
ulpi_d7: impl Unborrow<Target = impl UlpiD7Pin<T>> + 'd,
_peri: impl Peripheral<P = T> + 'd,
ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd,
ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd,
ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd,
ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd,
ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd,
ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd,
ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd,
ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd,
ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd,
ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd,
ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd,
ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd,
) -> Self {
config_ulpi_pins!(
ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6,

View File

@ -1,6 +1,6 @@
use core::marker::PhantomData;
use embassy_hal_common::{unborrow, Unborrow};
use embassy_hal_common::{into_ref, Peripheral};
use stm32_metapac::iwdg::vals::{Key, Pr};
use crate::rcc::LSI_FREQ;
@ -27,8 +27,8 @@ impl<'d, T: Instance> IndependentWatchdog<'d, T> {
///
/// [Self] has to be started with [Self::unleash()].
/// Once timer expires, MCU will be reset. To prevent this, timer must be reloaded by repeatedly calling [Self::pet()] within timeout interval.
pub fn new(_instance: impl Unborrow<Target = T> + 'd, timeout_us: u32) -> Self {
unborrow!(_instance);
pub fn new(_instance: impl Peripheral<P = T> + 'd, timeout_us: u32) -> Self {
into_ref!(_instance);
// Find lowest prescaler value, which makes watchdog period longer or equal to timeout.
// This iterates from 4 (2^2) to 256 (2^8).