Browse Source

Sync for easier diff

Kevin Lee 2 years ago
parent
commit
c27125d336
2 changed files with 37 additions and 43 deletions
  1. 21 24
      Nixie_Firmware_Rust/src/main.rs
  2. 16 19
      Nixie_Firmware_Rust/src/main_rtic.rs

+ 21 - 24
Nixie_Firmware_Rust/src/main.rs

@@ -89,7 +89,7 @@ fn main() -> ! {
     // Configure fault LED output on PC15
     let fault_led = gpioc.pc15.into_push_pull_output_with_state(&mut gpioc.moder, &mut gpioc.otyper, State::Low);
 
-    // Store fault LED in static singleton so that interrupt has access to it
+    // Store fault LED in static singleton so that it's accessible from anywhere
     free(|cs| {
         FAULT_LED.borrow(cs).replace(Some(fault_led));
     });
@@ -206,10 +206,10 @@ fn main() -> ! {
     hv_enable.set_high().unwrap();
 
     // Cycle through all tubes on powerup
-    trigger_cycle(0);
-    trigger_cycle(1);
-    trigger_cycle(2);
-    trigger_cycle(3);
+    start_cycle(0);
+    start_cycle(1);
+    start_cycle(2);
+    start_cycle(3);
 
     loop {
         // Delay before cycling digits to prevent cathode poisoning
@@ -217,25 +217,12 @@ fn main() -> ! {
 
         // Choose a random tube to cycle
         let tube = (rng.get_random_data() % 4) as usize;
-        trigger_cycle(tube);
+        start_cycle(tube);
     }
 }
 
-// Helper function to set onboard LED state
-fn set_fault_led(state: State) {
-    free(|cs| {
-        let mut led_ref = FAULT_LED.borrow(cs).borrow_mut();
-        if let Some(ref mut led) = led_ref.deref_mut() {
-            match state {
-                State::High => led.set_high().unwrap(),
-                State::Low => led.set_low().unwrap(),
-            };
-        }
-    });
-}
-
 // Trigger the start of a new cycle sequence
-fn trigger_cycle(tube: usize) {
+fn start_cycle(tube: usize) {
     free(|cs| {
         let mut cycle_timer_ref = CYCLE_TIMER.borrow(cs).borrow_mut();
         let mut clock_ref = CLOCK.borrow(cs).borrow_mut();
@@ -307,11 +294,8 @@ fn TIM2() {
         let mut clock_ref = CLOCK.borrow(cs).borrow_mut();
         if let Some(ref mut i2c) = i2c_int_ref.deref_mut() {
             if let Some(ref mut refresh_timer) = refresh_timer_ref.deref_mut() {
-                // Compute updates for non-static digits
-                let updated = clock_ref.deref_mut().fps_tick();
-
                 // Write new values if values have changed, otherwise disable the refresh timer
-                if updated {
+                if clock_ref.deref_mut().fps_tick() {
                     clock_ref.deref_mut().write_i2c(i2c);
                     refresh_timer.clear_interrupt(Event::TimeOut);
                 } else {
@@ -345,6 +329,19 @@ fn TIM7() {
     });
 }
 
+// Helper function to set onboard LED state
+fn set_fault_led(state: State) {
+    free(|cs| {
+        let mut led_ref = FAULT_LED.borrow(cs).borrow_mut();
+        if let Some(ref mut led) = led_ref.deref_mut() {
+            match state {
+                State::High => led.set_high().unwrap(),
+                State::Low => led.set_low().unwrap(),
+            };
+        }
+    });
+}
+
 // Custom panic handler
 #[panic_handler]
 #[cfg(not(test))]

+ 16 - 19
Nixie_Firmware_Rust/src/main_rtic.rs

@@ -191,6 +191,21 @@ const APP: () = {
         }
     }
 
+    // Trigger the start of a new cycle sequence
+    #[task(resources = [clock, cycle_timer], priority = 2, capacity = 4)]
+    fn start_cycle(ctx: start_cycle::Context, tube: usize) {
+        let start_cycle::Resources {mut clock, cycle_timer} = ctx.resources;
+
+        // Lower priority task requires a critical section to access shared data
+        clock.lock(|clock| {
+            // Trigger the start of a cycling sequence
+            clock.cycle_start(tube);
+        });
+
+        // Start the timer to cycle through individual digits
+        cycle_timer.listen(Event::TimeOut);
+    }
+
     // Interrupt handler for 1HZ signal from offchip RTC (DS3231)
     #[task(binds = EXTI9_5, priority = 1, resources = [clock, rtc_int, i2c, refresh_timer])]
     fn rtc_interrupt(ctx: rtc_interrupt::Context) {
@@ -243,11 +258,8 @@ const APP: () = {
     fn refresh_interrupt(ctx: refresh_interrupt::Context) {
         let refresh_interrupt::Resources {clock, refresh_timer, i2c} = ctx.resources;
 
-        // Compute updates for non-static digits
-        let updated = clock.fps_tick();
-
         // Write new values if values have changed, otherwise disable the refresh timer
-        if updated {
+        if clock.fps_tick() {
             clock.write_i2c(i2c);
             refresh_timer.clear_interrupt(Event::TimeOut);
         } else {
@@ -280,21 +292,6 @@ const APP: () = {
         });
     }
 
-    // Trigger the start of a new cycle sequence
-    #[task(resources = [clock, cycle_timer], priority = 2, capacity = 4)]
-    fn start_cycle(ctx: start_cycle::Context, tube: usize) {
-        let start_cycle::Resources {mut clock, cycle_timer} = ctx.resources;
-
-        // Lower priority task requires a critical section to access shared data
-        clock.lock(|clock| {
-            // Trigger the start of a cycling sequence
-            clock.cycle_start(tube);
-        });
-
-        // Start the timer to cycle through individual digits
-        cycle_timer.listen(Event::TimeOut);
-    }
-
     // RTIC requires that unused interrupts are declared in an extern block when
     // using software tasks; these free interrupts will be used to dispatch the
     // software tasks.