aboutsummaryrefslogtreecommitdiff
path: root/src/print.rs
blob: 56fd6c5b295bc997ce8344a7547e883838bf8984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! # Printing to UART
//!
//! This module contains the macros to print formatted strings to UART.
use crate::console::interface::Write;
use crate::uart::UART_WRITER;
use core::fmt;

#[doc(hidden)]
pub fn _serial_print(args: fmt::Arguments) {
    UART_WRITER.write_fmt(args).unwrap();
}

/// # Print without newline
///
/// Print formatted arguments without a newline
#[macro_export]
macro_rules! serial_print {
	($($arg:tt)*) => ($crate::print::_serial_print(format_args!($($arg)*)));
}

/// # Print with newline
///
/// Print formatted arguments with a newline
#[macro_export]
macro_rules! serial_println {
	() => ($crate::print!("\n"));
	($($arg:tt)*) => ({
		$crate::print::_serial_print(format_args_nl!($($arg)*));
	})
}

/// # Debug print without newline
///
/// Print formatted arguments without a newline but only with `verbose` feature
#[macro_export]
macro_rules! serial_vprint {
	($($arg:tt)*) => ({
		#[cfg(feature="verbose")]
		$crate::print::_serial_print(format_args!($($arg)*))
	});
}

/// # Debug print with newline
///
/// Print formatted arguments with a newline but only with `verbose` feature
#[macro_export]
macro_rules! serial_vprintln {
	() => ({
		#[cfg(feature="verbose")]
		$crate::print!("\n")
	});
	($($arg:tt)*) => ({
		#[cfg(feature="verbose")]
		$crate::print::_serial_print(format_args_nl!($($arg)*));
	})
}