The main loop in the count-debounce example looks like the following:
let mut cur_count = 0;
loop {
// "wait for interrupt": CPU goes to sleep until an interrupt.
asm::wfi();
let count = COUNTER.load(Acquire);
if count > cur_count {
rprintln!("ouch {}", count);
cur_count = count;
}
}
There is no explanation for the role of the cur_count. When I try to remove it, it seems that the timer is not enough to "synchronize" the main loop with the interrupt handler: pressing the Button A gives 2 prints of the counter sometimes. If I try to increase the debounce timer interval, it's still 2 prints but with the same counter value. And wrapping rprintln! into the GPIOTE peripheral mutex lock doesn't help either. I'm curious about what's happening there and if we can improve the explanation.
The main loop in the
count-debounceexample looks like the following:There is no explanation for the role of the
cur_count. When I try to remove it, it seems that the timer is not enough to "synchronize" the main loop with the interrupt handler: pressing the Button A gives 2 prints of the counter sometimes. If I try to increase the debounce timer interval, it's still 2 prints but with the same counter value. And wrappingrprintln!into the GPIOTE peripheral mutex lock doesn't help either. I'm curious about what's happening there and if we can improve the explanation.