Move DAC, I2C, SPI and RNG to macro-tables.

This commit is contained in:
Bob McWhirter
2021-06-03 11:09:29 -04:00
parent d4d914ea50
commit 6958091b50
6 changed files with 162 additions and 62 deletions

View File

@ -4,6 +4,7 @@
#[cfg_attr(spi_v2, path = "v2.rs")]
#[cfg_attr(spi_v3, path = "v3.rs")]
mod _version;
use crate::peripherals;
pub use _version::*;
use crate::gpio::Pin;
@ -71,26 +72,46 @@ pub trait MosiPin<T: Instance>: sealed::MosiPin<T> + 'static {}
pub trait MisoPin<T: Instance>: sealed::MisoPin<T> + 'static {}
macro_rules! impl_spi {
($inst:ident, $clk:ident) => {
impl crate::spi::sealed::Instance for peripherals::$inst {
crate::pac::peripherals!(
(spi, $inst:ident) => {
impl sealed::Instance for peripherals::$inst {
fn regs() -> &'static crate::pac::spi::Spi {
&crate::pac::$inst
}
}
impl crate::spi::Instance for peripherals::$inst {}
impl Instance for peripherals::$inst {}
};
}
);
macro_rules! impl_spi_pin {
($inst:ident, $pin_func:ident, $pin:ident, $af:expr) => {
impl crate::spi::$pin_func<peripherals::$inst> for peripherals::$pin {}
crate::pac::peripheral_pins!(
($inst:ident, spi, SPI, $pin:ident, SCK, $af:expr) => {
impl SckPin<peripherals::$inst> for peripherals::$pin {}
impl crate::spi::sealed::$pin_func<peripherals::$inst> for peripherals::$pin {
impl sealed::SckPin<peripherals::$inst> for peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
}
($inst:ident, spi, SPI, $pin:ident, MOSI, $af:expr) => {
impl MosiPin<peripherals::$inst> for peripherals::$pin {}
impl sealed::MosiPin<peripherals::$inst> for peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
($inst:ident, spi, SPI, $pin:ident, MISO, $af:expr) => {
impl MisoPin<peripherals::$inst> for peripherals::$pin {}
impl sealed::MisoPin<peripherals::$inst> for peripherals::$pin {
fn af_num(&self) -> u8 {
$af
}
}
};
);