|
@@ -89,7 +89,7 @@ fn main() -> ! {
|
|
// Configure fault LED output on PC15
|
|
// 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);
|
|
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| {
|
|
free(|cs| {
|
|
FAULT_LED.borrow(cs).replace(Some(fault_led));
|
|
FAULT_LED.borrow(cs).replace(Some(fault_led));
|
|
});
|
|
});
|
|
@@ -206,10 +206,10 @@ fn main() -> ! {
|
|
hv_enable.set_high().unwrap();
|
|
hv_enable.set_high().unwrap();
|
|
|
|
|
|
// Cycle through all tubes on powerup
|
|
// 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 {
|
|
loop {
|
|
// Delay before cycling digits to prevent cathode poisoning
|
|
// Delay before cycling digits to prevent cathode poisoning
|
|
@@ -217,25 +217,12 @@ fn main() -> ! {
|
|
|
|
|
|
// Choose a random tube to cycle
|
|
// Choose a random tube to cycle
|
|
let tube = (rng.get_random_data() % 4) as usize;
|
|
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
|
|
// Trigger the start of a new cycle sequence
|
|
-fn trigger_cycle(tube: usize) {
|
|
|
|
|
|
+fn start_cycle(tube: usize) {
|
|
free(|cs| {
|
|
free(|cs| {
|
|
let mut cycle_timer_ref = CYCLE_TIMER.borrow(cs).borrow_mut();
|
|
let mut cycle_timer_ref = CYCLE_TIMER.borrow(cs).borrow_mut();
|
|
let mut clock_ref = CLOCK.borrow(cs).borrow_mut();
|
|
let mut clock_ref = CLOCK.borrow(cs).borrow_mut();
|
|
@@ -260,24 +247,22 @@ fn EXTI9_5() {
|
|
if let Some(ref mut rtc_int) = rtc_int_ref.deref_mut() {
|
|
if let Some(ref mut rtc_int) = rtc_int_ref.deref_mut() {
|
|
if let Some(ref mut i2c) = i2c_int_ref.deref_mut() {
|
|
if let Some(ref mut i2c) = i2c_int_ref.deref_mut() {
|
|
if let Some(ref mut refresh_timer) = refresh_timer_ref.deref_mut() {
|
|
if let Some(ref mut refresh_timer) = refresh_timer_ref.deref_mut() {
|
|
- if rtc_int.check_interrupt() {
|
|
|
|
- // Read new time from DS3231
|
|
|
|
- let (second, minute, hour) = ds3231::get_time(DS3231_ADDR, i2c);
|
|
|
|
- let (weekday, day, month, _, _) = ds3231::get_date(DS3231_ADDR, i2c);
|
|
|
|
-
|
|
|
|
- // Calculate new values and account for DST
|
|
|
|
- let hour = if ds3231::in_dst(weekday, day, month, hour) { (hour + 1) % 12 } else { hour % 12 };
|
|
|
|
- let hour = if hour == 0 { 12 } else { hour };
|
|
|
|
-
|
|
|
|
- // Trigger the processing of a new time value
|
|
|
|
- clock_ref.deref_mut().rtc_tick(second, minute, hour);
|
|
|
|
-
|
|
|
|
- // Start the refresh timer to update the display
|
|
|
|
- refresh_timer.listen(Event::TimeOut);
|
|
|
|
-
|
|
|
|
- // Clear the interrupt flag for the timer
|
|
|
|
- rtc_int.clear_interrupt_pending_bit();
|
|
|
|
- }
|
|
|
|
|
|
+ // Read new time from DS3231
|
|
|
|
+ let (second, minute, hour) = ds3231::get_time(DS3231_ADDR, i2c);
|
|
|
|
+ let (weekday, day, month, _, _) = ds3231::get_date(DS3231_ADDR, i2c);
|
|
|
|
+
|
|
|
|
+ // Calculate new values and account for DST
|
|
|
|
+ let hour = if ds3231::in_dst(weekday, day, month, hour) { (hour + 1) % 12 } else { hour % 12 };
|
|
|
|
+ let hour = if hour == 0 { 12 } else { hour };
|
|
|
|
+
|
|
|
|
+ // Trigger the processing of a new time value
|
|
|
|
+ clock_ref.deref_mut().rtc_tick(second, minute, hour);
|
|
|
|
+
|
|
|
|
+ // Start the refresh timer to update the display
|
|
|
|
+ refresh_timer.listen(Event::TimeOut);
|
|
|
|
+
|
|
|
|
+ // Clear the interrupt flag for the timer
|
|
|
|
+ rtc_int.clear_interrupt_pending_bit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -307,11 +292,8 @@ fn TIM2() {
|
|
let mut clock_ref = CLOCK.borrow(cs).borrow_mut();
|
|
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 i2c) = i2c_int_ref.deref_mut() {
|
|
if let Some(ref mut refresh_timer) = refresh_timer_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
|
|
// 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);
|
|
clock_ref.deref_mut().write_i2c(i2c);
|
|
refresh_timer.clear_interrupt(Event::TimeOut);
|
|
refresh_timer.clear_interrupt(Event::TimeOut);
|
|
} else {
|
|
} else {
|
|
@@ -345,6 +327,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
|
|
// Custom panic handler
|
|
#[panic_handler]
|
|
#[panic_handler]
|
|
#[cfg(not(test))]
|
|
#[cfg(not(test))]
|