-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
INFO Flags::empty(): FLAG_0 | ||
INFO Flags::empty(): Flags(0x0) (fmt::Debug) | ||
INFO Flags::all(): FLAG_1 | FLAG_2 | FLAG_7 | FLAG_7_COPY | ||
INFO Flags::all(): Flags(FLAG_1 | FLAG_2 | FLAG_7) (fmt::Debug) | ||
INFO Flags::FLAG_1: FLAG_1 | ||
INFO Flags::FLAG_1: Flags(FLAG_1) (fmt::Debug) | ||
INFO Flags::FLAG_7: FLAG_7 | FLAG_7_COPY | ||
INFO Flags::FLAG_7: Flags(FLAG_7) (fmt::Debug) | ||
INFO LargeFlags::ALL: MSB | ALL | NON_LITERAL | ||
INFO LargeFlags::ALL: LargeFlags(MSB | ALL) (fmt::Debug) | ||
INFO LargeFlags::empty(): (empty) | ||
INFO LargeFlags::empty(): LargeFlags(0x0) (fmt::Debug) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#![no_std] | ||
#![no_main] | ||
#![allow(clippy::bad_bit_mask)] | ||
|
||
use cortex_m_rt::entry; | ||
use cortex_m_semihosting::debug; | ||
use defmt::{bitflagsv2, Debug2Format}; | ||
|
||
use defmt_semihosting as _; // global logger | ||
|
||
bitflagsv2! { | ||
#[derive(Debug)] | ||
struct Flags: u8 { | ||
#[cfg(not(never))] | ||
const FLAG_0 = 0b00; | ||
const FLAG_1 = 0b01; | ||
const FLAG_2 = 0b10; | ||
const FLAG_7 = 1 << 7; | ||
const FLAG_7_COPY = Self::FLAG_7.bits(); | ||
#[cfg(never)] | ||
const CFGD_OUT = 1; | ||
} | ||
} | ||
|
||
bitflagsv2! { | ||
#[derive(Debug)] | ||
struct LargeFlags: u128 { | ||
const MSB = 1 << 127; | ||
const ALL = !0; | ||
const NON_LITERAL = compute_flag_value(0x346934553632462); | ||
} | ||
} | ||
|
||
const fn compute_flag_value(x: u128) -> u128 { | ||
x ^ 0xdeadbeef | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
defmt::info!("Flags::empty(): {}", Flags::empty()); | ||
defmt::info!( | ||
"Flags::empty(): {} (fmt::Debug)", | ||
Debug2Format(&Flags::empty()) | ||
); | ||
defmt::info!("Flags::all(): {}", Flags::all()); | ||
defmt::info!("Flags::all(): {} (fmt::Debug)", Debug2Format(&Flags::all())); | ||
defmt::info!("Flags::FLAG_1: {}", Flags::FLAG_1); | ||
defmt::info!( | ||
"Flags::FLAG_1: {} (fmt::Debug)", | ||
Debug2Format(&Flags::FLAG_1) | ||
); | ||
defmt::info!("Flags::FLAG_7: {}", Flags::FLAG_7); | ||
defmt::info!( | ||
"Flags::FLAG_7: {} (fmt::Debug)", | ||
Debug2Format(&Flags::FLAG_7) | ||
); | ||
|
||
defmt::info!("LargeFlags::ALL: {}", LargeFlags::ALL); | ||
defmt::info!( | ||
"LargeFlags::ALL: {} (fmt::Debug)", | ||
Debug2Format(&LargeFlags::ALL) | ||
); | ||
defmt::info!("LargeFlags::empty(): {}", LargeFlags::empty()); | ||
defmt::info!( | ||
"LargeFlags::empty(): {} (fmt::Debug)", | ||
Debug2Format(&LargeFlags::empty()) | ||
); | ||
|
||
loop { | ||
debug::exit(debug::EXIT_SUCCESS) | ||
} | ||
} | ||
|
||
// like `panic-semihosting` but doesn't print to stdout (that would corrupt the defmt stream) | ||
#[cfg(target_os = "none")] | ||
#[panic_handler] | ||
fn panic(_: &core::panic::PanicInfo) -> ! { | ||
loop { | ||
debug::exit(debug::EXIT_FAILURE) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters