This removes the need to duplicate the configuration for each individual chip, but will instead pass on the configuration specified in the config attribute. Update nrf, stm32, rp macros with passing the config to a per-chip configure function which assumes the appropriate configuration to be passed to it. To demonstrate this feature, the stm32l0xx clock setup and RTC is added which exposes clock configuration different from stm32f4xx (and has a different set of timers and HAL APIs).
29 lines
954 B
Rust
29 lines
954 B
Rust
use crate::path::ModulePrefix;
|
|
use proc_macro2::TokenStream;
|
|
use quote::quote;
|
|
|
|
pub fn generate(embassy_prefix: &ModulePrefix, config: syn::Expr) -> TokenStream {
|
|
let embassy_path = embassy_prefix.append("embassy").path();
|
|
let embassy_stm32_path = embassy_prefix.append("embassy_stm32").path();
|
|
|
|
quote!(
|
|
use #embassy_stm32_path::{rtc, interrupt, Peripherals, pac, hal::rcc::RccExt, hal::time::U32Ext};
|
|
|
|
unsafe { #embassy_stm32_path::system::configure(#config) };
|
|
|
|
let (dp, clocks) = Peripherals::take().unwrap();
|
|
|
|
let mut rtc = rtc::RTC::new(dp.TIM2, interrupt::take!(TIM2), clocks);
|
|
let rtc = unsafe { make_static(&mut rtc) };
|
|
rtc.start();
|
|
let mut alarm = rtc.alarm1();
|
|
|
|
unsafe { #embassy_path::time::set_clock(rtc) };
|
|
|
|
let alarm = unsafe { make_static(&mut alarm) };
|
|
executor.set_alarm(alarm);
|
|
|
|
unsafe { Peripherals::set_peripherals(clocks) };
|
|
)
|
|
}
|