use core::fmt::Write;
#[cfg(feature = "debug")]
use core::arch::asm;
#[cfg(feature = "debug")]
fn print(s: &str) {
let p = s.as_bytes().as_ptr();
for i in 0..s.len() {
let m = unsafe { p.add(i) };
unsafe {
asm!(
"svc #0xab",
in("r1") m,
inout("r0") 3 => _,
);
}
}
}
#[cfg(not(feature = "debug"))]
pub fn print(_s: &str) {}
pub struct DBG;
#[cfg(feature = "debug")]
impl Write for DBG {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
print(s);
Ok(())
}
}
#[cfg(not(feature = "debug"))]
impl Write for DBG {
fn write_str(&mut self, _s: &str) -> core::fmt::Result {
Ok(()) }
}
#[cfg(feature = "debug")]
#[macro_export]
macro_rules! log {
($lvl:expr, $fmt:literal $($arg:tt)*) => ({
use core::fmt::Write;
let _ = core::write!($crate::log::DBG, concat!("[{}] {}:{}: ", $fmt, "\r\n"), $lvl, core::file!(), core::line!() $($arg)*);
});
}
#[cfg(not(feature = "debug"))]
#[macro_export]
macro_rules! log {
($lvl:expr, $fmt:literal $($arg:tt)*) => {
if false {
let _ = $lvl;
let _ = ::core::format_args!($fmt $($arg)*);
}
};
}
#[cfg(feature = "log_error")]
#[macro_export]
macro_rules! error {
($fmt:literal $($arg:tt)*) => ({$crate::log!("ERROR", $fmt $($arg)*)})
}
#[cfg(not(feature = "log_error"))]
#[macro_export]
macro_rules! error {
($fmt:literal $($arg:tt)*) => {
if false { let _ = ::core::format_args!($fmt $($arg)*); }
};
}
#[cfg(feature = "log_warn")]
#[macro_export]
macro_rules! warn {
($fmt:literal $($arg:tt)*) => ({$crate::log!("WARN", $fmt $($arg)*)})
}
#[cfg(not(feature = "log_warn"))]
#[macro_export]
macro_rules! warn {
($fmt:literal $($arg:tt)*) => {
if false { let _ = ::core::format_args!($fmt $($arg)*); }
};
}
#[cfg(feature = "log_info")]
#[macro_export]
macro_rules! info {
($fmt:literal $($arg:tt)*) => ({$crate::log!("INFO", $fmt $($arg)*)})
}
#[cfg(not(feature = "log_info"))]
#[macro_export]
macro_rules! info {
($fmt:literal $($arg:tt)*) => {
if false { let _ = ::core::format_args!($fmt $($arg)*); }
};
}
#[cfg(feature = "log_debug")]
#[macro_export]
macro_rules! debug {
($fmt:literal $($arg:tt)*) => ({$crate::log!("DEBUG", $fmt $($arg)*)})
}
#[cfg(not(feature = "log_debug"))]
#[macro_export]
macro_rules! debug {
($fmt:literal $($arg:tt)*) => {
if false { let _ = ::core::format_args!($fmt $($arg)*); }
};
}
#[cfg(feature = "log_trace")]
#[macro_export]
macro_rules! trace {
($fmt:literal $($arg:tt)*) => ({$crate::log!("TRACE", $fmt $($arg)*)})
}
#[cfg(not(feature = "log_trace"))]
#[macro_export]
macro_rules! trace {
($fmt:literal $($arg:tt)*) => {
if false { let _ = ::core::format_args!($fmt $($arg)*); }
};
}
pub use crate::{debug, error, info, log, trace, warn};