Re-adds embassy macros for stm32
* Hook RCC config into chip config and use chip-specific RCC init function * RTC/clock setup is ignored for now
This commit is contained in:
parent
4b98361967
commit
1c10e746b6
@ -15,5 +15,6 @@ proc-macro = true
|
||||
|
||||
[features]
|
||||
nrf = []
|
||||
stm32 = []
|
||||
rp = []
|
||||
std = []
|
||||
|
26
embassy-macros/src/chip/stm32.rs
Normal file
26
embassy-macros/src/chip/stm32.rs
Normal file
@ -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 { <peripherals::TIM2 as #embassy_path::util::Steal>::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);
|
||||
*/
|
||||
)
|
||||
}
|
@ -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<syn::LitStr>,
|
||||
}
|
||||
|
||||
#[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);
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -527,3 +527,7 @@ impl<'d> Rcc<'d> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn init(config: Config) {
|
||||
// TODO
|
||||
}
|
||||
|
@ -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) {}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user