mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
make the init::Resources argument optional
This commit is contained in:
parent
b7e43c1dbc
commit
8485a24d36
1 changed files with 40 additions and 23 deletions
|
@ -30,9 +30,15 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
let device = &app.device;
|
let device = &app.device;
|
||||||
let krate = krate();
|
let krate = krate();
|
||||||
|
|
||||||
|
let mut tys = vec![quote!(init::Peripherals)];
|
||||||
|
let mut exprs = vec![quote!(init::Peripherals::all())];
|
||||||
|
let mut mod_items = vec![];
|
||||||
|
|
||||||
|
if !app.resources.is_empty() {
|
||||||
let mut fields = vec![];
|
let mut fields = vec![];
|
||||||
let mut exprs = vec![];
|
|
||||||
let mut lifetime = None;
|
let mut lifetime = None;
|
||||||
|
let mut rexprs = vec![];
|
||||||
|
|
||||||
for (name, resource) in &app.resources {
|
for (name, resource) in &app.resources {
|
||||||
lifetime = Some(quote!('a));
|
lifetime = Some(quote!('a));
|
||||||
|
|
||||||
|
@ -42,7 +48,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
pub #name: &'a mut #krate::Static<#ty>,
|
pub #name: &'a mut #krate::Static<#ty>,
|
||||||
});
|
});
|
||||||
|
|
||||||
exprs.push(quote! {
|
rexprs.push(quote! {
|
||||||
#name: ::#krate::Static::ref_mut(&mut *super::#name.get()),
|
#name: ::#krate::Static::ref_mut(&mut *super::#name.get()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -53,18 +59,29 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
pub struct _initResources<#lifetime> {
|
pub struct _initResources<#lifetime> {
|
||||||
#(#fields)*
|
#(#fields)*
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mod init {
|
mod_items.push(quote! {
|
||||||
pub use ::#device::Peripherals;
|
|
||||||
pub use ::_initResources as Resources;
|
pub use ::_initResources as Resources;
|
||||||
|
|
||||||
impl<#lifetime> Resources<#lifetime> {
|
impl<#lifetime> Resources<#lifetime> {
|
||||||
pub unsafe fn new() -> Self {
|
pub unsafe fn new() -> Self {
|
||||||
Resources {
|
Resources {
|
||||||
#(#exprs)*
|
#(#rexprs)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tys.push(quote!(init::Resources));
|
||||||
|
exprs.push(quote!(init::Resources::new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
root.push(quote! {
|
||||||
|
mod init {
|
||||||
|
pub use ::#device::Peripherals;
|
||||||
|
|
||||||
|
#(#mod_items)*
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -116,10 +133,10 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
let init = &app.init.path;
|
let init = &app.init.path;
|
||||||
main.push(quote! {
|
main.push(quote! {
|
||||||
// type check
|
// type check
|
||||||
let init: fn(init::Peripherals, init::Resources) = #init;
|
let init: fn(#(#tys,)*) = #init;
|
||||||
|
|
||||||
#krate::atomic(|_cs| unsafe {
|
#krate::atomic(|_cs| unsafe {
|
||||||
init(init::Peripherals::all(), init::Resources::new());
|
init(#(#exprs,)*);
|
||||||
|
|
||||||
#(#exceptions)*
|
#(#exceptions)*
|
||||||
#(#interrupts)*
|
#(#interrupts)*
|
||||||
|
|
Loading…
Reference in a new issue