11#![ no_main]
22#![ no_std]
33
4- use panic_rtt_target as _;
5-
64use stm32g4xx_hal:: {
75 //delay::{DelayExt, SYSTDelayExt},
86 gpio:: { gpioc, ExtiPin , GpioExt , Input , PullDown , SignalEdge } ,
@@ -18,24 +16,27 @@ use cortex_m::{asm::wfi, interrupt::Mutex};
1816use cortex_m_rt:: entry;
1917use embedded_hal:: digital:: v2:: OutputPin ;
2018
21- use rtt_target:: { rprintln, rtt_init_print} ;
22-
2319type ButtonPin = gpioc:: PC13 < Input < PullDown > > ;
2420
2521// Make LED pin globally available
2622static G_BUTTON : Mutex < RefCell < Option < ButtonPin > > > = Mutex :: new ( RefCell :: new ( None ) ) ;
2723static G_LED_ON : AtomicBool = AtomicBool :: new ( true ) ;
2824
25+ #[ macro_use]
26+ mod utils;
27+
28+ use utils:: logger:: println;
29+
2930// Define an interupt handler, i.e. function to call when interrupt occurs.
3031// This specific interrupt will "trip" when the button is pressed
3132#[ interrupt]
3233fn EXTI15_10 ( ) {
3334 static mut BUTTON : Option < ButtonPin > = None ;
3435
35- rprintln ! ( "Got IRQ!" ) ;
36+ println ! ( "Got IRQ!" ) ;
3637
3738 let button = BUTTON . get_or_insert_with ( || {
38- rprintln ! ( "Transfer Button into EXTI interrupt" ) ;
39+ println ! ( "Transfer Button into EXTI interrupt" ) ;
3940 cortex_m:: interrupt:: free ( |cs| {
4041 // Move LED pin here, leaving a None in its place
4142 G_BUTTON . borrow ( cs) . replace ( None ) . unwrap ( )
@@ -49,45 +50,43 @@ fn EXTI15_10() {
4950
5051#[ entry]
5152fn main ( ) -> ! {
52- rtt_init_print ! ( ) ;
53-
5453 let mut dp = stm32:: Peripherals :: take ( ) . expect ( "cannot take peripherals" ) ;
5554 let mut rcc = dp. RCC . constrain ( ) ;
5655 let mut syscfg = dp. SYSCFG . constrain ( ) ;
5756
58- rprintln ! ( "Led Init" ) ;
57+ println ! ( "Led Init" ) ;
5958 // Configure PA5 pin to blink LED
6059 let gpioa = dp. GPIOA . split ( & mut rcc) ;
6160 let mut led = gpioa. pa5 . into_push_pull_output ( ) ;
6261
63- rprintln ! ( "Button Init" ) ;
62+ println ! ( "Button Init" ) ;
6463 let gpioc = dp. GPIOC . split ( & mut rcc) ;
6564 let mut button = gpioc. pc13 . into_pull_down_input ( ) ;
6665 button. make_interrupt_source ( & mut syscfg) ;
6766 button. trigger_on_edge ( & mut dp. EXTI , SignalEdge :: Rising ) ;
6867 button. enable_interrupt ( & mut dp. EXTI ) ;
6968
70- rprintln ! ( "Set Button into Global Mutex" ) ;
69+ println ! ( "Set Button into Global Mutex" ) ;
7170 // Move the pin into our global storage
7271 cortex_m:: interrupt:: free ( |cs| * G_BUTTON . borrow ( cs) . borrow_mut ( ) = Some ( button) ) ;
7372
74- rprintln ! ( "Enable EXTI Interrupt" ) ;
73+ println ! ( "Enable EXTI Interrupt" ) ;
7574 unsafe {
7675 cortex_m:: peripheral:: NVIC :: unmask ( Interrupt :: EXTI15_10 ) ;
7776 }
7877
7978 //let mut delay = cp.SYST.delay(&rcc.clocks);
8079
81- rprintln ! ( "Start Loop" ) ;
80+ println ! ( "Start Loop" ) ;
8281 loop {
8382 wfi ( ) ;
84- rprintln ! ( "Check" ) ;
83+ println ! ( "Check" ) ;
8584
8685 if G_LED_ON . load ( Ordering :: Relaxed ) {
87- rprintln ! ( "Turn Led On!" ) ;
86+ println ! ( "Turn Led On!" ) ;
8887 led. set_high ( ) . unwrap ( ) ;
8988 } else {
90- rprintln ! ( "Turn Led Off!" ) ;
89+ println ! ( "Turn Led Off!" ) ;
9190 led. set_low ( ) . unwrap ( ) ;
9291 }
9392 }
0 commit comments