aboutsummaryrefslogtreecommitdiffstats
path: root/sw/picardy/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sw/picardy/src/main.rs')
-rw-r--r--sw/picardy/src/main.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs
index 0d27f7a..04f8fa5 100644
--- a/sw/picardy/src/main.rs
+++ b/sw/picardy/src/main.rs
@@ -55,6 +55,9 @@ use state::*;
static mut TIMER1: MaybeUninit<CountDownTimer<pac::TIM1>> = MaybeUninit::uninit();
static mut DECISECONDS_COUNTER: MaybeUninit<usize> = MaybeUninit::uninit();
+fn time_now() -> usize {
+ cortex_m::interrupt::free(|_cs| unsafe { *DECISECONDS_COUNTER.as_ptr() })
+}
#[cortex_m_rt::entry]
fn main() -> ! {
@@ -78,10 +81,10 @@ fn main() -> ! {
// Buttons as analog inputs (multi-level)
let mic_sw1 = gpioa.pa3.into_analog(&mut gpioa.crl);
let mic_sw2 = gpioa.pa4.into_analog(&mut gpioa.crl);
- let pb0 = gpiob.pb0.into_analog(&mut gpiob.crl);
- let pb1 = gpiob.pb1.into_analog(&mut gpiob.crl);
- let pb12 = gpiob.pb12.into_pull_up_input(&mut gpiob.crh);
- let pb13 = gpiob.pb13.into_pull_up_input(&mut gpiob.crh);
+ let pb0 = gpiob.pb0.into_analog(&mut gpiob.crl); // BTN1 Buttons B D C
+ let pb1 = gpiob.pb1.into_analog(&mut gpiob.crl); // BTN0 Buttons A F
+ let pb12 = gpiob.pb12.into_pull_up_input(&mut gpiob.crh); // BTN2 Button E
+ let pb13 = gpiob.pb13.into_pull_up_input(&mut gpiob.crh); // BTN3 Button G
let pc15 = gpioc.pc15.into_pull_up_input(&mut gpioc.crh);
let adc1 = dp.ADC1;
let mut ui = ui::UI::new(mic_sw1, mic_sw2, pb0, pb1, adc1, &mut rcc.apb2, &clocks, pb12, pb13, pc15);
@@ -177,13 +180,17 @@ fn main() -> ! {
let mut last_encoder_count = qei.count();
- let deciseconds_counter = unsafe { &mut *DECISECONDS_COUNTER.as_mut_ptr() };
- *deciseconds_counter = 0;
+ {
+ let deciseconds_counter = unsafe { &mut *DECISECONDS_COUNTER.as_mut_ptr() };
+ *deciseconds_counter = 0;
+ }
- let timer1 = unsafe { &mut *TIMER1.as_mut_ptr() };
- *timer1 = Timer::tim1(dp.TIM1, &clocks, &mut rcc.apb2)
- .start_count_down(10.hz());
- timer1.listen(Event::Update);
+ {
+ let timer1 = unsafe { &mut *TIMER1.as_mut_ptr() };
+ *timer1 = Timer::tim1(dp.TIM1, &clocks, &mut rcc.apb2)
+ .start_count_down(10.hz());
+ timer1.listen(Event::Update);
+ }
unsafe { pac::NVIC::unmask(pac::Interrupt::TIM1_UP); }
@@ -257,7 +264,7 @@ fn main() -> ! {
}
};
- let t_now = unsafe { *DECISECONDS_COUNTER.as_ptr() };
+ let t_now = time_now();
if state.sequence_state != next_state &&
last_sequence_state_change + 1 <= t_now {
update_disp_required = true;