#[macro_export]
macro_rules! iprint {
($channel:expr, $s:expr) => {
$crate::itm::write_str($channel, $s);
};
($channel:expr, $($arg:tt)*) => {
$crate::itm::write_fmt($channel, format_args!($($arg)*));
};
}
#[macro_export]
macro_rules! iprintln {
($channel:expr) => {
$crate::itm::write_str($channel, "\n");
};
($channel:expr, $fmt:expr) => {
$crate::itm::write_str($channel, concat!($fmt, "\n"));
};
($channel:expr, $fmt:expr, $($arg:tt)*) => {
$crate::itm::write_fmt($channel, format_args!(concat!($fmt, "\n"), $($arg)*));
};
}
#[macro_export]
macro_rules! singleton {
($name:ident: $ty:ty = $expr:expr) => {
$crate::interrupt::free(|_| {
static mut $name: (::core::mem::MaybeUninit<$ty>, bool) =
(::core::mem::MaybeUninit::uninit(), false);
#[allow(unsafe_code)]
let used = unsafe { $name.1 };
if used {
None
} else {
let expr = $expr;
#[allow(unsafe_code)]
unsafe {
$name.1 = true;
$name.0 = ::core::mem::MaybeUninit::new(expr);
Some(&mut *$name.0.as_mut_ptr())
}
}
})
};
(: $ty:ty = $expr:expr) => {
$crate::singleton!(VAR: $ty = $expr)
};
}
#[allow(dead_code)]
const CFAIL: () = ();
#[allow(dead_code)]
const CPASS: () = ();