2019-11-25 18:54:05 +00:00
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
2019-11-04 21:59:31 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018-2019 Andre Richter <andre.o.richter@gmail.com>
|
|
|
|
|
|
|
|
//! Printing facilities.
|
|
|
|
|
|
|
|
use crate::{bsp, interface};
|
|
|
|
use core::fmt;
|
|
|
|
|
2019-11-06 21:45:29 +00:00
|
|
|
pub fn _print(args: fmt::Arguments) {
|
|
|
|
use interface::console::Write;
|
|
|
|
|
|
|
|
bsp::console().write_fmt(args).unwrap();
|
|
|
|
}
|
|
|
|
|
2019-11-04 21:59:31 +00:00
|
|
|
/// Prints without a newline.
|
|
|
|
///
|
|
|
|
/// Carbon copy from https://doc.rust-lang.org/src/std/macros.rs.html
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! print {
|
|
|
|
($($arg:tt)*) => ($crate::print::_print(format_args!($($arg)*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prints with a newline.
|
2019-11-13 08:11:05 +00:00
|
|
|
///
|
|
|
|
/// Carbon copy from https://doc.rust-lang.org/src/std/macros.rs.html
|
2019-11-04 21:59:31 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! println {
|
|
|
|
() => ($crate::print!("\n"));
|
2019-11-13 08:11:05 +00:00
|
|
|
($($arg:tt)*) => ({
|
|
|
|
$crate::print::_print(format_args_nl!($($arg)*));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prints am info, with newline.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! info {
|
2019-11-04 21:59:31 +00:00
|
|
|
($string:expr) => ({
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use crate::interface::time::Timer;
|
|
|
|
|
|
|
|
let timestamp = $crate::arch::timer().uptime();
|
|
|
|
let timestamp_subsec_us = timestamp.subsec_micros();
|
|
|
|
|
|
|
|
$crate::print::_print(format_args_nl!(
|
|
|
|
concat!("[ {:>3}.{:03}{:03}] ", $string),
|
|
|
|
timestamp.as_secs(),
|
|
|
|
timestamp_subsec_us / 1_000,
|
|
|
|
timestamp_subsec_us % 1_000
|
|
|
|
));
|
|
|
|
});
|
|
|
|
($format_string:expr, $($arg:tt)*) => ({
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use crate::interface::time::Timer;
|
|
|
|
|
|
|
|
let timestamp = $crate::arch::timer().uptime();
|
|
|
|
let timestamp_subsec_us = timestamp.subsec_micros();
|
|
|
|
|
|
|
|
$crate::print::_print(format_args_nl!(
|
|
|
|
concat!("[ {:>3}.{:03}{:03}] ", $format_string),
|
|
|
|
timestamp.as_secs(),
|
|
|
|
timestamp_subsec_us / 1_000,
|
|
|
|
timestamp_subsec_us % 1_000,
|
|
|
|
$($arg)*
|
|
|
|
));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prints a warning, with newline.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! warn {
|
|
|
|
($string:expr) => ({
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use crate::interface::time::Timer;
|
|
|
|
|
|
|
|
let timestamp = $crate::arch::timer().uptime();
|
|
|
|
let timestamp_subsec_us = timestamp.subsec_micros();
|
|
|
|
|
|
|
|
$crate::print::_print(format_args_nl!(
|
|
|
|
concat!("[W {:>3}.{:03}{:03}] ", $string),
|
|
|
|
timestamp.as_secs(),
|
|
|
|
timestamp_subsec_us / 1_000,
|
|
|
|
timestamp_subsec_us % 1_000
|
|
|
|
));
|
|
|
|
});
|
|
|
|
($format_string:expr, $($arg:tt)*) => ({
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use crate::interface::time::Timer;
|
|
|
|
|
|
|
|
let timestamp = $crate::arch::timer().uptime();
|
|
|
|
let timestamp_subsec_us = timestamp.subsec_micros();
|
|
|
|
|
|
|
|
$crate::print::_print(format_args_nl!(
|
|
|
|
concat!("[W {:>3}.{:03}{:03}] ", $format_string),
|
|
|
|
timestamp.as_secs(),
|
|
|
|
timestamp_subsec_us / 1_000,
|
|
|
|
timestamp_subsec_us % 1_000,
|
|
|
|
$($arg)*
|
|
|
|
));
|
|
|
|
})
|
|
|
|
}
|