aboutsummaryrefslogtreecommitdiff
path: root/rtic-macros/src/codegen
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-06-14 18:29:29 +0000
committerGitHub <noreply@github.com>2023-06-14 18:29:29 +0000
commit08c0065c02b1c027207c25a297b2c0aa92646786 (patch)
tree0537a5acb1dd6381585c6596bc59b7801d1358c0 /rtic-macros/src/codegen
parentbd67d2aaa5ddf2f4a0717fa0fd888c66189aa4e7 (diff)
parent7c9cbda6fccf3ad4634e081fe219331635f2dcd1 (diff)
Merge #767
767: allow #[init] and #[idle] to be externed r=korken89 a=wiktorwieclaw I updated `rtic-macros` to a allow init and idle to be externally defined. ## Design notes * Updated `extern_binds` example to include external #[init] and #[idle] functions. * Added docs to Local and Shared structs. The `extern_binds` example has a `#![deny(missing_docs)]` which caused some issues. ## Testing Apart from building the example, I also used this feature in one of my projects and ran it on a MCU [here](https://github.com/grupacosmo/cansat/blob/98ca7bd42e737adfb140a548da1ade01beb495da/crates/cansat-stm32f4/src/main.rs#L59-L74) ## Related issues * https://github.com/rtic-rs/rtic/issues/505 ## Related PRs * https://github.com/rtic-rs/rtic-syntax/pull/71 Co-authored-by: Vixu <lonevixu@gmail.com>
Diffstat (limited to 'rtic-macros/src/codegen')
-rw-r--r--rtic-macros/src/codegen/idle.rs24
-rw-r--r--rtic-macros/src/codegen/init.rs22
2 files changed, 28 insertions, 18 deletions
diff --git a/rtic-macros/src/codegen/idle.rs b/rtic-macros/src/codegen/idle.rs
index 0c833ef..9e608cb 100644
--- a/rtic-macros/src/codegen/idle.rs
+++ b/rtic-macros/src/codegen/idle.rs
@@ -34,16 +34,20 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
let attrs = &idle.attrs;
let context = &idle.context;
let stmts = &idle.stmts;
- let user_idle = Some(quote!(
- #(#attrs)*
- #[allow(non_snake_case)]
- fn #name(#context: #name::Context) -> ! {
- use rtic::Mutex as _;
- use rtic::mutex::prelude::*;
-
- #(#stmts)*
- }
- ));
+ let user_idle = if !idle.is_extern {
+ Some(quote!(
+ #(#attrs)*
+ #[allow(non_snake_case)]
+ fn #name(#context: #name::Context) -> ! {
+ use rtic::Mutex as _;
+ use rtic::mutex::prelude::*;
+
+ #(#stmts)*
+ }
+ ))
+ } else {
+ None
+ };
quote!(
#(#mod_app)*
diff --git a/rtic-macros/src/codegen/init.rs b/rtic-macros/src/codegen/init.rs
index b667ae0..f6bb43d 100644
--- a/rtic-macros/src/codegen/init.rs
+++ b/rtic-macros/src/codegen/init.rs
@@ -54,10 +54,12 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
.collect();
root_init.push(quote! {
+ #[doc = r"Shared resources"]
#shared_vis struct #shared {
#(#shared_resources)*
}
+ #[doc = r"Local resources"]
#local_vis struct #local {
#(#local_resources)*
}
@@ -67,14 +69,18 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
let user_init_return = quote! {#shared, #local};
- let user_init = quote!(
- #(#attrs)*
- #[inline(always)]
- #[allow(non_snake_case)]
- fn #name(#context: #name::Context) -> (#user_init_return) {
- #(#stmts)*
- }
- );
+ let user_init = if !init.is_extern {
+ Some(quote!(
+ #(#attrs)*
+ #[inline(always)]
+ #[allow(non_snake_case)]
+ fn #name(#context: #name::Context) -> (#user_init_return) {
+ #(#stmts)*
+ }
+ ))
+ } else {
+ None
+ };
let mut mod_app = None;