Proper debouncing and dechattering

Move debouncing and dechattering to the beginning of the interrupt
service routines to handle them properly.
This commit is contained in:
finga 2021-09-23 22:57:03 +02:00
parent 3aa458c4bc
commit c0f8cac065

View file

@ -691,6 +691,9 @@ static void update_state(const enum input event) {
ISR(PCINT0_vect) {
cli();
// Dechatter
_delay_ms(3);
switch (enc) {
case 0:
if (ENC_A && !ENC_B)
@ -724,9 +727,6 @@ ISR(PCINT0_vect) {
break;
}
// TODO: proper dechattering
_delay_ms(3);
sei();
}
@ -734,6 +734,9 @@ ISR(PCINT0_vect) {
ISR(PCINT1_vect) {
cli();
// Debounce
_delay_ms(2);
if (PINC & (1 << PC0)) { // Release
if (TCCR1B & (1 << CS10)) // If release before hold
update_state(click); // Switch to selected state
@ -745,9 +748,6 @@ ISR(PCINT1_vect) {
TCCR1B |= (1 << CS11) | (1 << CS10); // Enable Timer/Counter1
}
// TODO: Proper debouncing
_delay_ms(3);
sei();
}