Skip to content
Snippets Groups Projects
Select Git revision
  • 98c8c8d8b4f13bceb3077f5d9b1635dafe40e17f
  • master default protected
2 results

led.rs

Blame
  • lib.rs 1.69 KiB
    #![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)]
    	        let itm = unsafe { &mut *cortex_m::peripheral::ITM::ptr() };
                
    	        cortex_m::itm::write_str(
    	            &mut itm.stim[0],
    	            $s
    	        );
    	    }
        };
        ($($arg:tt)*) => {
    		{
    			extern crate cortex_m;   
                #[allow(unsafe_code)]
    	        let itm = unsafe { &mut *cortex_m::peripheral::ITM::ptr() };
    
    	        cortex_m::itm::write_fmt(
    	            &mut itm.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 over semihosting.
    #[macro_export]
    macro_rules! sp {
        ($($e:tt)*) => {
            {
                extern crate cortex_m_semihosting;
                use core::fmt::Write;
                write!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap();
            }
        }
    }
    
    /// Macro for sending a formatted string over semihosting, with a newline.
    #[macro_export]
    macro_rules! spln {
        ($($e:tt)*) => {
            {
                extern crate cortex_m_semihosting;
                use core::fmt::Write;
                writeln!(cortex_m_semihosting::hio::hstdout().unwrap(), $($e)*).unwrap();
            }
        }
    }