Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user