Remove PeripheralRef::into_inner()

This commit is contained in:
Dario Nieuwenhuis
2022-07-23 14:27:45 +02:00
parent a158295782
commit f02ba35482
11 changed files with 156 additions and 105 deletions

View File

@ -647,7 +647,7 @@ pub(crate) mod sealed {
}
}
pub trait Pin: Peripheral<P = Self> + sealed::Pin {
pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static {
/// Degrade to a generic pin struct
fn degrade(self) -> AnyPin {
AnyPin {
@ -660,22 +660,6 @@ pub struct AnyPin {
pin_bank: u8,
}
impl AnyPin {
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! into_degraded_ref {
($($name:ident),*) => {
$(
let $name = $crate::gpio::AnyPin::into_degraded_ref($name);
)*
};
}
impl_peripheral!(AnyPin);
impl Pin for AnyPin {}
@ -695,6 +679,12 @@ macro_rules! impl_pin {
($bank as u8) * 32 + $pin_num
}
}
impl From<peripherals::$name> for crate::gpio::AnyPin {
fn from(val: peripherals::$name) -> Self {
crate::gpio::Pin::degrade(val)
}
}
};
}

View File

@ -65,8 +65,15 @@ impl<'d, T: Instance> Spi<'d, T> {
miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd,
config: Config,
) -> Self {
into_degraded_ref!(clk, mosi, miso);
Self::new_inner(inner, Some(clk), Some(mosi), Some(miso), None, config)
into_ref!(clk, mosi, miso);
Self::new_inner(
inner,
Some(clk.map_into()),
Some(mosi.map_into()),
Some(miso.map_into()),
None,
config,
)
}
pub fn new_txonly(
@ -75,8 +82,8 @@ impl<'d, T: Instance> Spi<'d, T> {
mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd,
config: Config,
) -> Self {
into_degraded_ref!(clk, mosi);
Self::new_inner(inner, Some(clk), Some(mosi), None, None, config)
into_ref!(clk, mosi);
Self::new_inner(inner, Some(clk.map_into()), Some(mosi.map_into()), None, None, config)
}
pub fn new_rxonly(
@ -85,8 +92,8 @@ impl<'d, T: Instance> Spi<'d, T> {
miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd,
config: Config,
) -> Self {
into_degraded_ref!(clk, miso);
Self::new_inner(inner, Some(clk), None, Some(miso), None, config)
into_ref!(clk, miso);
Self::new_inner(inner, Some(clk.map_into()), None, Some(miso.map_into()), None, config)
}
fn new_inner(