rust-raspberrypi-OS-tutorials/05_drivers_gpio_uart/src/print.rs

39 lines
1.0 KiB
Rust
Raw Normal View History

2019-11-25 18:54:05 +00:00
// SPDX-License-Identifier: MIT OR Apache-2.0
2019-10-08 19:50:48 +00:00
//
2021-01-01 10:28:32 +00:00
// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
2019-10-08 19:50:48 +00:00
//! Printing.
2019-10-08 19:50:48 +00:00
2020-03-28 12:26:48 +00:00
use crate::{bsp, console};
2019-10-08 19:50:48 +00:00
use core::fmt;
2020-03-28 12:26:48 +00:00
//--------------------------------------------------------------------------------------------------
2020-09-29 19:43:31 +00:00
// Public Code
2020-03-28 12:26:48 +00:00
//--------------------------------------------------------------------------------------------------
2019-12-17 12:42:20 +00:00
#[doc(hidden)]
pub fn _print(args: fmt::Arguments) {
2020-03-28 12:26:48 +00:00
use console::interface::Write;
2020-03-28 12:26:48 +00:00
bsp::console::console().write_fmt(args).unwrap();
}
2019-10-08 19:50:48 +00:00
/// Prints without a newline.
///
2021-01-29 21:30:02 +00:00
/// Carbon copy from <https://doc.rust-lang.org/src/std/macros.rs.html>
2019-10-08 19:50:48 +00:00
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::print::_print(format_args!($($arg)*)));
}
/// Prints with a newline.
///
2021-01-29 21:30:02 +00:00
/// Carbon copy from <https://doc.rust-lang.org/src/std/macros.rs.html>
2019-10-08 19:50:48 +00:00
#[macro_export]
macro_rules! println {
() => ($crate::print!("\n"));
($($arg:tt)*) => ({
$crate::print::_print(format_args_nl!($($arg)*));
})
}