diff options
| -rw-r--r-- | embassy-macros/Cargo.toml | 1 | ||||
| -rw-r--r-- | embassy-macros/src/chip/stm32.rs | 26 | ||||
| -rw-r--r-- | embassy-macros/src/lib.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 9 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h7/mod.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 17 |
7 files changed, 58 insertions, 9 deletions
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 | |||
| 15 | 15 | ||
| 16 | [features] | 16 | [features] |
| 17 | nrf = [] | 17 | nrf = [] |
| 18 | stm32 = [] | ||
| 18 | rp = [] | 19 | rp = [] |
| 19 | std = [] | 20 | 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 @@ | |||
| 1 | use crate::path::ModulePrefix; | ||
| 2 | use proc_macro2::TokenStream; | ||
| 3 | use quote::quote; | ||
| 4 | |||
| 5 | pub fn generate(embassy_prefix: &ModulePrefix, config: syn::Expr) -> TokenStream { | ||
| 6 | let embassy_path = embassy_prefix.append("embassy").path(); | ||
| 7 | let embassy_stm32_path = embassy_prefix.append("embassy_stm32").path(); | ||
| 8 | |||
| 9 | quote!( | ||
| 10 | use #embassy_stm32_path::{clock::Clock}; | ||
| 11 | |||
| 12 | let p = #embassy_stm32_path::init(#config); | ||
| 13 | |||
| 14 | /* | ||
| 15 | let mut rtc = #embass::RTC::new(unsafe { <peripherals::TIM2 as #embassy_path::util::Steal>::steal() }, interrupt::take!(TIM2)); | ||
| 16 | let rtc = unsafe { make_static(&mut rtc) }; | ||
| 17 | rtc.start(); | ||
| 18 | let mut alarm = rtc.alarm0(); | ||
| 19 | |||
| 20 | unsafe { #embassy_path::time::set_clock(rtc) }; | ||
| 21 | |||
| 22 | let alarm = unsafe { make_static(&mut alarm) }; | ||
| 23 | executor.set_alarm(alarm); | ||
| 24 | */ | ||
| 25 | ) | ||
| 26 | } | ||
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 { | |||
| 256 | result.into() | 256 | result.into() |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | #[cfg(feature = "stm32")] | ||
| 260 | #[path = "chip/stm32.rs"] | ||
| 261 | mod chip; | ||
| 262 | |||
| 259 | #[cfg(feature = "nrf")] | 263 | #[cfg(feature = "nrf")] |
| 260 | #[path = "chip/nrf.rs"] | 264 | #[path = "chip/nrf.rs"] |
| 261 | mod chip; | 265 | mod chip; |
| @@ -273,7 +277,7 @@ struct MainArgs { | |||
| 273 | config: Option<syn::LitStr>, | 277 | config: Option<syn::LitStr>, |
| 274 | } | 278 | } |
| 275 | 279 | ||
| 276 | #[cfg(any(feature = "nrf", feature = "rp"))] | 280 | #[cfg(any(feature = "nrf", feature = "rp", feature = "stm32"))] |
| 277 | #[proc_macro_attribute] | 281 | #[proc_macro_attribute] |
| 278 | pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { | 282 | pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { |
| 279 | let macro_args = syn::parse_macro_input!(args as syn::AttributeArgs); | 283 | 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" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy = { version = "0.1.0", path = "../embassy" } | 8 | embassy = { version = "0.1.0", path = "../embassy" } |
| 9 | embassy-macros = { version = "0.1.0", path = "../embassy-macros" } | 9 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } |
| 10 | embassy-extras = {version = "0.1.0", path = "../embassy-extras" } | 10 | embassy-extras = {version = "0.1.0", path = "../embassy-extras" } |
| 11 | embassy-traits = {version = "0.1.0", path = "../embassy-traits" } | 11 | embassy-traits = {version = "0.1.0", path = "../embassy-traits" } |
| 12 | 12 | ||
| @@ -23,6 +23,8 @@ critical-section = "0.2.1" | |||
| 23 | bare-metal = "1.0.0" | 23 | bare-metal = "1.0.0" |
| 24 | atomic-polyfill = "0.1.2" | 24 | atomic-polyfill = "0.1.2" |
| 25 | 25 | ||
| 26 | cfg-if = "1.0.0" | ||
| 27 | |||
| 26 | [build-dependencies] | 28 | [build-dependencies] |
| 27 | regex = "1.4.6" | 29 | regex = "1.4.6" |
| 28 | 30 | ||
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; | |||
| 42 | 42 | ||
| 43 | #[non_exhaustive] | 43 | #[non_exhaustive] |
| 44 | pub struct Config { | 44 | pub struct Config { |
| 45 | _private: (), | 45 | rcc: rcc::Config, |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | impl Default for Config { | 48 | impl Default for Config { |
| 49 | fn default() -> Self { | 49 | fn default() -> Self { |
| 50 | Self { _private: () } | 50 | Self { |
| 51 | rcc: Default::default(), | ||
| 52 | } | ||
| 51 | } | 53 | } |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | /// Initialize embassy. | 56 | /// Initialize embassy. |
| 55 | pub fn init(_config: Config) -> Peripherals { | 57 | pub fn init(config: Config) -> Peripherals { |
| 56 | let p = Peripherals::take(); | 58 | let p = Peripherals::take(); |
| 57 | 59 | ||
| 58 | unsafe { | 60 | unsafe { |
| 59 | dma::init(); | 61 | dma::init(); |
| 60 | pac::init_exti(); | 62 | pac::init_exti(); |
| 63 | rcc::init(config.rcc); | ||
| 61 | } | 64 | } |
| 62 | 65 | ||
| 63 | p | 66 | 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> { | |||
| 527 | } | 527 | } |
| 528 | } | 528 | } |
| 529 | } | 529 | } |
| 530 | |||
| 531 | pub unsafe fn init(config: Config) { | ||
| 532 | // TODO | ||
| 533 | } | ||
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 @@ | |||
| 1 | #[cfg(feature = "_stm32h7")] | 1 | cfg_if::cfg_if! { |
| 2 | mod h7; | 2 | if #[cfg(feature = "_stm32h7")] { |
| 3 | #[cfg(feature = "_stm32h7")] | 3 | mod h7; |
| 4 | pub use h7::*; | 4 | pub use h7::*; |
| 5 | } else if #[cfg(feature = "_stm32l0")] { | ||
| 6 | mod l0; | ||
| 7 | pub use l0::*; | ||
| 8 | } else { | ||
| 9 | #[derive(Default)] | ||
| 10 | pub struct Config {} | ||
| 11 | pub fn init(_config: Config) {} | ||
| 12 | } | ||
| 13 | } | ||
