Auto generate SPI v2 clock enable

Adds RccPeripheral trait for peripherals implementing clock enable and reset for a given peripheral.

Add macro table generting implementations of RccPeripheral for peripherals with clock set, currently restricted to SPI.
This commit is contained in:
Ulf Lilleengen
2021-06-02 16:34:37 +02:00
parent af0f8082f0
commit ee3b82b743
4 changed files with 65 additions and 7 deletions

View File

@ -1,3 +1,6 @@
#![macro_use]
use crate::peripherals;
use crate::time::Hertz;
use core::mem::MaybeUninit;
@ -44,3 +47,38 @@ cfg_if::cfg_if! {
}
}
}
pub(crate) mod sealed {
pub trait RccPeripheral {
fn reset();
fn enable();
fn disable();
}
}
pub trait RccPeripheral: sealed::RccPeripheral + 'static {}
crate::pac::peripheral_rcc!(
($inst:ident, $enable:ident, $reset:ident, $perien:ident, $perirst:ident) => {
impl sealed::RccPeripheral for peripherals::$inst {
fn enable() {
unsafe {
crate::pac::RCC.$enable().modify(|w| w.$perien(true));
}
}
fn disable() {
unsafe {
crate::pac::RCC.$enable().modify(|w| w.$perien(false));
}
}
fn reset() {
unsafe {
crate::pac::RCC.$reset().modify(|w| w.$perirst(true));
crate::pac::RCC.$reset().modify(|w| w.$perirst(false));
}
}
}
impl RccPeripheral for peripherals::$inst {}
};
);