Skip to content

Commit da6daa8

Browse files
vittoriuseldruin
authored andcommitted
Add a comment on cur_count variable
1 parent 3c78abf commit da6daa8

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

mdbook/src/15-interrupts/examples/count-debounce.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ fn main() -> ! {
6767
unsafe { pac::NVIC::unmask(pac::Interrupt::GPIOTE) };
6868
pac::NVIC::unpend(pac::Interrupt::GPIOTE);
6969

70+
// Because we're not disabling GPIOTE interrupts even during the debounce timer countdown,
71+
// we can get extra button interrupts even during the debounce interval.
72+
// It would be reasonable to disable button interrupts when the debounce timer is started
73+
// and re-enable them when it expires, but this would require a debounce timer interrupt handler.
74+
// To make a simple "fix" for this that doesn't hurt the readability,
75+
// we introduce the cur_count "guard" variable.
7076
let mut cur_count = 0;
7177
loop {
7278
// "wait for interrupt": CPU goes to sleep until an interrupt.

0 commit comments

Comments
 (0)