aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Henrik Tjäder <henrik@tjaders.com> 2020-05-19 09:55:50 +0000
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2020-09-25 14:29:34 +0000
commitc718413cb56f9c25d79c71e607079561923b1a05 (patch)
tree447200567c6efee118167c57dcc6b00b4174c5fe
parent148ad4045e36f3c1d11d2708494c7628b3838df7 (diff)
downloadrtic-c718413cb56f9c25d79c71e607079561923b1a05.tar.gz
rtic-c718413cb56f9c25d79c71e607079561923b1a05.tar.zst
rtic-c718413cb56f9c25d79c71e607079561923b1a05.zip
Generate mod instead of const, handle import of idle and init
-rw-r--r--macros/src/codegen.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index fe4d59a6..83e5ce8b 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -26,6 +26,7 @@ mod util;
// TODO document the syntax here or in `rtic-syntax`
pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let mut const_app = vec![];
+ let mut const_app_imports = vec![];
let mut mains = vec![];
let mut root = vec![];
let mut user = vec![];
@@ -41,6 +42,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let (const_app_idle, root_idle, user_idle, call_idle) = idle::codegen(app, analysis, extra);
+ if user_init.is_some() {
+ const_app_imports.push(quote!(
+ use super::init;
+ ))
+ }
+ if user_idle.is_some() {
+ const_app_imports.push(quote!(
+ use super::idle;
+ ))
+ }
+
user.push(quote!(
#user_init
@@ -111,10 +123,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
#(#root_software_tasks)*
/// Implementation details
- // The user can't access the items within this `const` item
- const #name: () = {
+ // the user can't access the items within this `const` item
+ mod #name {
/// Always include the device crate which contains the vector table
use #device as _;
+ #(#const_app_imports)*
#(#const_app)*
@@ -133,6 +146,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
#(#const_app_schedule)*
#(#mains)*
- };
+ }
)
}