diff --git a/embassy-macros/Cargo.toml b/embassy-macros/Cargo.toml index 265a0c083..06dc6f072 100644 --- a/embassy-macros/Cargo.toml +++ b/embassy-macros/Cargo.toml @@ -15,5 +15,6 @@ proc-macro = true [features] nrf = [] +stm32 = [] rp = [] std = [] diff --git a/embassy-macros/src/chip/stm32.rs b/embassy-macros/src/chip/stm32.rs new file mode 100644 index 000000000..a1ceadd55 --- /dev/null +++ b/embassy-macros/src/chip/stm32.rs @@ -0,0 +1,26 @@ +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::{clock::Clock}; + + let p = #embassy_stm32_path::init(#config); + + /* + let mut rtc = #embass::RTC::new(unsafe { ::steal() }, interrupt::take!(TIM2)); + let rtc = unsafe { make_static(&mut rtc) }; + rtc.start(); + let mut alarm = rtc.alarm0(); + + unsafe { #embassy_path::time::set_clock(rtc) }; + + let alarm = unsafe { make_static(&mut alarm) }; + executor.set_alarm(alarm); + */ + ) +} diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index d23526aa2..3dc295fc1 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -256,6 +256,10 @@ pub fn interrupt_take(item: TokenStream) -> TokenStream { result.into() } +#[cfg(feature = "stm32")] +#[path = "chip/stm32.rs"] +mod chip; + #[cfg(feature = "nrf")] #[path = "chip/nrf.rs"] mod chip; @@ -273,7 +277,7 @@ struct MainArgs { config: Option, } -#[cfg(any(feature = "nrf", feature = "rp"))] +#[cfg(any(feature = "nrf", feature = "rp", feature = "stm32"))] #[proc_macro_attribute] pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { let macro_args = syn::parse_macro_input!(args as syn::AttributeArgs); diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 43d5250e5..6d234f65f 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] embassy = { version = "0.1.0", path = "../embassy" } -embassy-macros = { version = "0.1.0", path = "../embassy-macros" } +embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } embassy-extras = {version = "0.1.0", path = "../embassy-extras" } embassy-traits = {version = "0.1.0", path = "../embassy-traits" } @@ -23,6 +23,8 @@ critical-section = "0.2.1" bare-metal = "1.0.0" atomic-polyfill = "0.1.2" +cfg-if = "1.0.0" + [build-dependencies] regex = "1.4.6" diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 0ab998a87..250281f88 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -42,22 +42,25 @@ pub(crate) use pac::regs::generic; #[non_exhaustive] pub struct Config { - _private: (), + rcc: rcc::Config, } impl Default for Config { fn default() -> Self { - Self { _private: () } + Self { + rcc: Default::default(), + } } } /// Initialize embassy. -pub fn init(_config: Config) -> Peripherals { +pub fn init(config: Config) -> Peripherals { let p = Peripherals::take(); unsafe { dma::init(); pac::init_exti(); + rcc::init(config.rcc); } p diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs index d8d231bae..85e1cd00f 100644 --- a/embassy-stm32/src/rcc/h7/mod.rs +++ b/embassy-stm32/src/rcc/h7/mod.rs @@ -527,3 +527,7 @@ impl<'d> Rcc<'d> { } } } + +pub unsafe fn init(config: Config) { + // TODO +} diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 0bf62ef7c..59938e7bf 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -1,4 +1,13 @@ -#[cfg(feature = "_stm32h7")] -mod h7; -#[cfg(feature = "_stm32h7")] -pub use h7::*; +cfg_if::cfg_if! { + if #[cfg(feature = "_stm32h7")] { + mod h7; + pub use h7::*; + } else if #[cfg(feature = "_stm32l0")] { + mod l0; + pub use l0::*; + } else { + #[derive(Default)] + pub struct Config {} + pub fn init(_config: Config) {} + } +}