mirror of
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials.git
synced 2024-11-15 18:14:02 +00:00
125 lines
3.4 KiB
Rust
125 lines
3.4 KiB
Rust
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
//
|
||
|
// Copyright (c) 2018-2022 Andre Richter <andre.o.richter@gmail.com>
|
||
|
|
||
|
//! Printing.
|
||
|
|
||
|
use crate::console;
|
||
|
use core::fmt;
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Public Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
|
#[doc(hidden)]
|
||
|
pub fn _print(args: fmt::Arguments) {
|
||
|
console::console().write_fmt(args).unwrap();
|
||
|
}
|
||
|
|
||
|
/// 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.
|
||
|
///
|
||
|
/// Carbon copy from <https://doc.rust-lang.org/src/std/macros.rs.html>
|
||
|
#[macro_export]
|
||
|
macro_rules! println {
|
||
|
() => ($crate::print!("\n"));
|
||
|
($($arg:tt)*) => ({
|
||
|
$crate::print::_print(format_args_nl!($($arg)*));
|
||
|
})
|
||
|
}
|
||
|
|
||
|
/// Prints an info, with a newline.
|
||
|
#[macro_export]
|
||
|
macro_rules! info {
|
||
|
($string:expr) => ({
|
||
|
use $crate::time::interface::TimeManager;
|
||
|
|
||
|
let timestamp = $crate::time::time_manager().uptime();
|
||
|
|
||
|
$crate::print::_print(format_args_nl!(
|
||
|
concat!("[ {:>3}.{:06}] ", $string),
|
||
|
timestamp.as_secs(),
|
||
|
timestamp.subsec_micros(),
|
||
|
));
|
||
|
});
|
||
|
($format_string:expr, $($arg:tt)*) => ({
|
||
|
use $crate::time::interface::TimeManager;
|
||
|
|
||
|
let timestamp = $crate::time::time_manager().uptime();
|
||
|
|
||
|
$crate::print::_print(format_args_nl!(
|
||
|
concat!("[ {:>3}.{:06}] ", $format_string),
|
||
|
timestamp.as_secs(),
|
||
|
timestamp.subsec_micros(),
|
||
|
$($arg)*
|
||
|
));
|
||
|
})
|
||
|
}
|
||
|
|
||
|
/// Prints a warning, with a newline.
|
||
|
#[macro_export]
|
||
|
macro_rules! warn {
|
||
|
($string:expr) => ({
|
||
|
use $crate::time::interface::TimeManager;
|
||
|
|
||
|
let timestamp = $crate::time::time_manager().uptime();
|
||
|
|
||
|
$crate::print::_print(format_args_nl!(
|
||
|
concat!("[W {:>3}.{:06}] ", $string),
|
||
|
timestamp.as_secs(),
|
||
|
timestamp.subsec_micros(),
|
||
|
));
|
||
|
});
|
||
|
($format_string:expr, $($arg:tt)*) => ({
|
||
|
use $crate::time::interface::TimeManager;
|
||
|
|
||
|
let timestamp = $crate::time::time_manager().uptime();
|
||
|
|
||
|
$crate::print::_print(format_args_nl!(
|
||
|
concat!("[W {:>3}.{:06}] ", $format_string),
|
||
|
timestamp.as_secs(),
|
||
|
timestamp.subsec_micros(),
|
||
|
$($arg)*
|
||
|
));
|
||
|
})
|
||
|
}
|
||
|
|
||
|
/// Debug print, with a newline.
|
||
|
#[macro_export]
|
||
|
macro_rules! debug {
|
||
|
($string:expr) => ({
|
||
|
if cfg!(feature = "debug_prints") {
|
||
|
use $crate::time::interface::TimeManager;
|
||
|
|
||
|
let timestamp = $crate::time::time_manager().uptime();
|
||
|
|
||
|
$crate::print::_print(format_args_nl!(
|
||
|
concat!("<[>D {:>3}.{:06}> ", $string),
|
||
|
timestamp.as_secs(),
|
||
|
timestamp.subsec_micros(),
|
||
|
));
|
||
|
}
|
||
|
});
|
||
|
($format_string:expr, $($arg:tt)*) => ({
|
||
|
if cfg!(feature = "debug_prints") {
|
||
|
use $crate::time::interface::TimeManager;
|
||
|
|
||
|
let timestamp = $crate::time::time_manager().uptime();
|
||
|
|
||
|
$crate::print::_print(format_args_nl!(
|
||
|
concat!("<D {:>3}.{:06}> ", $format_string),
|
||
|
timestamp.as_secs(),
|
||
|
timestamp.subsec_micros(),
|
||
|
$($arg)*
|
||
|
));
|
||
|
}
|
||
|
})
|
||
|
}
|