Merge pull request #204 from lulf/enable-stm32-macro

Enable stm32 macro
This commit is contained in:
Dario Nieuwenhuis 2021-05-25 15:12:45 +02:00 committed by GitHub
commit a126e17fb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 9 deletions

View file

@ -15,5 +15,6 @@ proc-macro = true
[features]
nrf = []
stm32 = []
rp = []
std = []

View 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);
*/
)
}

View file

@ -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);

View file

@ -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"

View file

@ -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

View file

@ -527,3 +527,7 @@ impl<'d> Rcc<'d> {
}
}
}
pub unsafe fn init(config: Config) {
// TODO
}

View file

@ -0,0 +1,20 @@
use crate::pac;
use embassy::util::Steal;
use pac::rcc::{self, vals};
#[derive(Default)]
pub struct Config {}
pub unsafe fn init(config: Config) {
let rcc = pac::RCC;
let enabled = vals::Iophen::ENABLED;
rcc.iopenr().write(|w| {
w.set_iopaen(enabled);
w.set_iopben(enabled);
w.set_iopcen(enabled);
w.set_iopden(enabled);
w.set_iopeen(enabled);
w.set_iophen(enabled);
});
}

View file

@ -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) {}
}
}