Pass config directly to chip specific configure function
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).
This commit is contained in:
@ -1,57 +1,19 @@
|
||||
use crate::path::ModulePrefix;
|
||||
use darling::FromMeta;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::spanned::Spanned;
|
||||
use quote::quote;
|
||||
|
||||
#[derive(Debug, FromMeta, Default)]
|
||||
pub struct Args {
|
||||
#[darling(default)]
|
||||
pub embassy_prefix: ModulePrefix,
|
||||
#[darling(default)]
|
||||
pub use_hse: Option<u32>,
|
||||
#[darling(default)]
|
||||
pub sysclk: Option<u32>,
|
||||
#[darling(default)]
|
||||
pub pclk1: Option<u32>,
|
||||
#[darling(default)]
|
||||
pub require_pll48clk: bool,
|
||||
}
|
||||
|
||||
pub fn generate(args: &Args) -> TokenStream {
|
||||
let embassy_path = args.embassy_prefix.append("embassy").path();
|
||||
let embassy_stm32_path = args.embassy_prefix.append("embassy_stm32").path();
|
||||
|
||||
let mut clock_cfg_args = quote! {};
|
||||
if args.use_hse.is_some() {
|
||||
let mhz = args.use_hse.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.use_hse(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if args.sysclk.is_some() {
|
||||
let mhz = args.sysclk.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.sysclk(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if args.pclk1.is_some() {
|
||||
let mhz = args.pclk1.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.pclk1(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if args.require_pll48clk {
|
||||
clock_cfg_args = quote! { #clock_cfg_args.require_pll48clk() };
|
||||
}
|
||||
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};
|
||||
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let rcc = dp.RCC.constrain();
|
||||
let clocks = rcc.cfgr#clock_cfg_args.freeze();
|
||||
unsafe { #embassy_stm32_path::system::configure(#config) };
|
||||
|
||||
unsafe { Peripherals::set_peripherals(clocks) };
|
||||
let (dp, clocks) = Peripherals::take().unwrap();
|
||||
|
||||
let mut rtc = rtc::RTC::new(dp.TIM3, interrupt::take!(TIM3), clocks);
|
||||
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();
|
||||
@ -60,5 +22,7 @@ pub fn generate(args: &Args) -> TokenStream {
|
||||
|
||||
let alarm = unsafe { make_static(&mut alarm) };
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
unsafe { Peripherals::set_peripherals(clocks) };
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user