Skip to content

Commit d30209f

Browse files
committed
initialize singletons at runtime
1 parent c921d43 commit d30209f

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ version = "0.4.2"
1313
aligned = "0.1.1"
1414
bare-metal = "0.1.0"
1515
volatile-register = "0.2.0"
16+
untagged-option = "0.1.1"
1617

1718
[features]
18-
cm7-r0p1 = []
19+
cm7-r0p1 = []

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
extern crate aligned;
1717
extern crate bare_metal;
18+
extern crate untagged_option;
1819
extern crate volatile_register;
1920

2021
#[macro_use]
@@ -31,3 +32,4 @@ pub mod peripheral;
3132
pub mod register;
3233

3334
pub use peripheral::Peripherals;
35+
pub use untagged_option::UntaggedOption;

src/macros.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ macro_rules! singleton {
5454
(: $ty:ty = $expr:expr) => {
5555
$crate::interrupt::free(|_| unsafe {
5656
static mut USED: bool = false;
57-
static mut VAR: $ty = $expr;
57+
static mut VAR: $crate::UntaggedOption<$ty> = $crate::UntaggedOption { none: () };
5858

5959
if USED {
6060
None
6161
} else {
6262
USED = true;
63-
let var: &'static mut _ = &mut VAR;
63+
VAR.some = $expr;
64+
let var: &'static mut _ = &mut VAR.some;
6465
Some(var)
6566
}
6667
})

0 commit comments

Comments
 (0)