#![no_std]
/// Macro for sending a formatted string through an ITM channel 0,
/// Interleaved with other output to ITM channel 0
#[macro_export]
macro_rules! ip {
    ($s:expr) => {
		{
	    	extern crate cortex_m;
	        #[allow(unsafe_code)]
	        cortex_m::itm::write_str(
	            unsafe { &(&*cortex_m::peripheral::ITM.get()).stim[0] },
	            $s
	        );
	    }
    };
    ($($arg:tt)*) => {
		{
			extern crate cortex_m;
	        #[allow(unsafe_code)]
	        cortex_m::itm::write_fmt(
	            unsafe { &(&*cortex_m::peripheral::ITM.get()).stim[0] },
	            format_args!($($arg)*)
	        );
		}
    }
}

/// Macro for sending a formatted string through an ITM channel 0, with a newline.
/// Interleaved with other output to ITM channel 0
#[macro_export]
macro_rules! ipln {
    () => {
        ip!("\n");
    };
    ($fmt:expr) => {
        ip!(concat!($fmt, "\n"));
    };
    ($fmt:expr, $($arg:tt)*) => {
        ip!(concat!($fmt, "\n"), $($arg)*);
    };
}

/// Macro for sending a formatted string overes semihosting, with a newline.
#[macro_export]
macro_rules! sprintln {
    ($($e:tt)*) => {
        {
            extern crate cortex_m_semihosting;
            use core::fmt::Write;
            writeln!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap();
        }
    }
}

/// Macro for sending a formatted string overes semihosting.
#[macro_export]
macro_rules! sprint {
    ($($e:tt)*) => {
        {
            extern crate cortex_m_semihosting;
            use core::fmt::Write;
            write!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap();
        }
    }
}