Skip to content

Commit

Permalink
feat: define our own assign_resources macro
Browse files Browse the repository at this point in the history
We need our own peripheral-extraction macro compatible with
`OptionalPeripherals`.
  • Loading branch information
ROMemories authored and kaspar030 committed Jan 8, 2024
1 parent 6c8b9ea commit 1829b61
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/riot-rs-embassy/src/assign_resources.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Based on https://github.com/adamgreig/assign-resources/tree/94ad10e2729afdf0fd5a77cd12e68409a982f58a
// under MIT license
#[macro_export]
macro_rules! assign_resources {
{
$resources: ident,
$(
$(#[$outer:meta])*
$group_name:ident : $group_struct:ident {
$(
$(#[$inner:meta])*
$resource_name:ident : $resource_field:ident $(=$resource_alias:ident)?),*
$(,)?
}
$(,)?
)+
} => {
#[allow(dead_code,non_snake_case,missing_docs)]
pub struct $resources {
$(pub $group_name : $group_struct),*
}
$(
#[allow(dead_code,non_snake_case)]
$(#[$outer])*
pub struct $group_struct {
$(
$(#[$inner])*
pub $resource_name: peripherals::$resource_field
),*
}
)+


$($($(
#[allow(missing_docs)]
pub type $resource_alias = peripherals::$resource_field;
)?)*)*

#[macro_export]
/// `split_resources!` macro
macro_rules! split_resources (
($p:ident) => {
$resources {
$($group_name: $group_struct {
$($resource_name: $p.$resource_field.take().ok_or(1)?),*
}),*
}
}
);
}
}
2 changes: 2 additions & 0 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![feature(type_alias_impl_trait)]
#![feature(used_with_arg)]

pub mod assign_resources;

use linkme::distributed_slice;

use embassy_executor::{InterruptExecutor, Spawner};
Expand Down
2 changes: 1 addition & 1 deletion src/riot-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

pub use riot_rs_buildinfo as buildinfo;
pub use riot_rs_core::thread;
pub use riot_rs_embassy as embassy;
pub use riot_rs_embassy::{self as embassy, assign_resources};
pub use riot_rs_rt as rt;

// ensure this gets linked
Expand Down

0 comments on commit 1829b61

Please sign in to comment.