aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2021-04-07 11:06:57 +0200
committerGravatar Emil Fresk <emil.fresk@gmail.com> 2021-04-08 09:15:38 +0200
commit2068eae9280881e34b5cc2d76b0b1a61402223e7 (patch)
tree21b4fa3bb6f5bac8f9430758a39140b40d6bcdfd /macros/src
parent6c8257bb73de0f68072467447692a1f7dff555f9 (diff)
downloadrtic-2068eae9280881e34b5cc2d76b0b1a61402223e7.tar.gz
rtic-2068eae9280881e34b5cc2d76b0b1a61402223e7.tar.zst
rtic-2068eae9280881e34b5cc2d76b0b1a61402223e7.zip
Type aliases now work in the app module
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/codegen.rs16
-rw-r--r--macros/src/codegen/hardware_tasks.rs4
-rw-r--r--macros/src/codegen/module.rs21
3 files changed, 29 insertions, 12 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index c5d95687..cf728a7d 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -112,8 +112,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let user_imports = &app.user_imports;
quote! {
- pub use rtic::Monotonic as _;
-
#[doc = #doc]
#[allow(non_snake_case)]
pub mod #name {
@@ -143,6 +141,18 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
})
.collect();
+ let monotonics = if !monotonic_parts.is_empty() {
+ quote!(
+ pub use rtic::Monotonic as _;
+
+ /// Holds static methods for each monotonic.
+ pub mod monotonics {
+ #(#monotonic_parts)*
+ }
+ )
+ } else {
+ quote!()
+ };
let rt_err = util::rt_err_ident();
quote!(
@@ -151,7 +161,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
/// Always include the device crate which contains the vector table
use #device as #rt_err;
- #(#monotonic_parts)*
+ #monotonics
#(#user_imports)*
diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs
index 4a1d7492..540b95e5 100644
--- a/macros/src/codegen/hardware_tasks.rs
+++ b/macros/src/codegen/hardware_tasks.rs
@@ -37,12 +37,16 @@ pub fn codegen(
let symbol = task.args.binds.clone();
let priority = task.args.priority;
+ let cfgs = &task.cfgs;
+ let attrs = &task.attrs;
let app_name = &app.name;
let app_path = quote! {crate::#app_name};
mod_app.push(quote!(
#[allow(non_snake_case)]
#[no_mangle]
+ #(#attrs)*
+ #(#cfgs)*
unsafe fn #symbol() {
const PRIORITY: u8 = #priority;
diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs
index e15aab1c..ac69a803 100644
--- a/macros/src/codegen/module.rs
+++ b/macros/src/codegen/module.rs
@@ -21,7 +21,7 @@ pub fn codegen(
let app_name = &app.name;
let app_path = quote! {crate::#app_name};
- let all_task_names: Vec<_> = app
+ let all_task_imports: Vec<_> = app
.software_tasks
.iter()
.map(|(name, st)| {
@@ -46,6 +46,13 @@ pub fn codegen(
quote!()
}
}))
+ .chain(app.user_types.iter().map(|ty| {
+ let t = &ty.ident;
+ quote! {
+ #[allow(unused_imports)]
+ use super::#t;
+ }
+ }))
.collect();
let mut lt = None;
@@ -230,7 +237,7 @@ pub fn codegen(
// Spawn caller
items.push(quote!(
- #(#all_task_names)*
+ #(#all_task_imports)*
#(#cfgs)*
/// Spawns the task directly
@@ -268,7 +275,7 @@ pub fn codegen(
let tq = util::mark_internal_ident(&tq);
let t = util::schedule_t_ident();
let m = &monotonic.ident;
- let mono_type = &monotonic.ty;
+ let mono_type = &monotonic.ident;
let m_ident = util::monotonic_ident(&monotonic_name);
let m_ident = util::mark_internal_ident(&m_ident);
let m_isr = &monotonic.args.binds;
@@ -300,10 +307,6 @@ pub fn codegen(
items.push(quote!(
/// Holds methods related to this monotonic
pub mod #m {
- // #(
- // #[allow(unused_imports)]
- // use #app_path::#all_task_names as #all_task_names;
- // )*
use super::*;
#[allow(unused_imports)]
use #app_path::#tq_marker;
@@ -341,7 +344,7 @@ pub fn codegen(
where D: rtic::time::duration::Duration + rtic::time::fixed_point::FixedPoint,
D::T: Into<<#app_path::#mono_type as rtic::time::Clock>::T>,
{
- self.reschedule_at(#app_path::#m::now() + duration)
+ self.reschedule_at(#app_path::monotonics::#m::now() + duration)
}
pub fn reschedule_at(self, instant: rtic::time::Instant<#app_path::#mono_type>) -> Result<Self, ()>
@@ -373,7 +376,7 @@ pub fn codegen(
let instant = if rtic::export::interrupt::free(|_| unsafe { #app_path::#m_ident.is_none() }) {
rtic::time::Instant::new(0)
} else {
- #app_path::#m::now()
+ #app_path::monotonics::#m::now()
};
spawn_at(instant + duration #(,#untupled)*)