mu_lib 0.2.2

XCENA mu Library
Documentation
//! Print module providing output functionality
//!
//! This module provides macros and functions for UART, host, and general output.
//! All output functions use null-terminated strings.

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

pub use crate::bindings::root::{
    hostPrintfSingleStringRB, printf_SingleStringRB, uartPrintfSingleStringRB,
};

/// Macro for printing a single string to UART
///
/// # Examples
/// ```
/// uart_print!("Hello, World! Value: {}\n", 42);
/// ```
#[macro_export]
macro_rules! uart_print {
    ($($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push('\0');
        unsafe { $crate::print::uartPrintfSingleStringRB(output.as_ptr() as *const u8) }
    }};
}

/// Macro for printing a single string to UART followed by a newline
///
/// # Examples
/// ```
/// uart_println!("Hello, World! Count: {}", 5);
/// ```
#[macro_export]
macro_rules! uart_println {
    ($($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push_str("\n\0");
        unsafe { $crate::print::uartPrintfSingleStringRB(output.as_ptr() as *const u8) }
    }};
}

/// Macro for printing a single string to the host
///
/// # Examples
/// ```
/// host_print!("Hello, Host! Status: {}\n", "OK");
/// ```
#[macro_export]
macro_rules! host_print {
    ($($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push('\0');
        unsafe { $crate::print::hostPrintfSingleStringRB(output.as_ptr() as *const u8) }
    }};
}

/// Macro for printing a single string to the host followed by a newline
///
/// # Examples
/// ```
/// host_println!("Hello, Host! Error code: {}", 404);
/// ```
#[macro_export]
macro_rules! host_println {
    ($($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push_str("\n\0");
        unsafe { $crate::print::hostPrintfSingleStringRB(output.as_ptr() as *const u8) }
    }};
}

#[doc(hidden)]
#[macro_export]
macro_rules! printf{
    ($($arg:tt)*) => {{
        let mut output = alloc::format!($($arg)*);
        output.push('\0');
        unsafe { $crate::print::sprintf_SingleStringRB(output.as_ptr() as *const u8) }
    }};
}