From 27d12ea31fcf4d26bb6f0449625fc4679e95646d Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Thu, 5 Jul 2018 12:33:55 -0700 Subject: [PATCH] Remove the debouncing interrupt --- right/src/init_peripherals.c | 3 --- right/src/key_debouncer.c | 32 -------------------------------- right/src/key_debouncer.h | 18 ------------------ right/src/key_states.h | 3 ++- right/src/peripherals/pit.h | 4 ---- right/src/usb_report_updater.c | 12 ++++++++---- shared/key_matrix.h | 1 + 7 files changed, 11 insertions(+), 62 deletions(-) delete mode 100644 right/src/key_debouncer.c delete mode 100644 right/src/key_debouncer.h diff --git a/right/src/init_peripherals.c b/right/src/init_peripherals.c index 7efcb20..35f34e2 100644 --- a/right/src/init_peripherals.c +++ b/right/src/init_peripherals.c @@ -12,7 +12,6 @@ #include "init_peripherals.h" #include "eeprom.h" #include "timer.h" -#include "key_debouncer.h" #include "usb_api.h" #include "slave_scheduler.h" #include "bootloader/wormhole.h" @@ -67,7 +66,6 @@ static void initInterruptPriorities(void) NVIC_SetPriority(I2C_EEPROM_BUS_IRQ_ID, 0); NVIC_SetPriority(PIT_TIMER_IRQ_ID, 3); NVIC_SetPriority(PIT_KEY_SCANNER_IRQ_ID, 4); - NVIC_SetPriority(PIT_KEY_DEBOUNCER_IRQ_ID, 4); NVIC_SetPriority(I2C_MAIN_BUS_IRQ_ID, 4); NVIC_SetPriority(USB_IRQ_ID, 4); } @@ -159,6 +157,5 @@ void InitPeripherals(void) TestLed_Init(); LedPwm_Init(); InitI2cWatchdog(); - InitKeyDebouncer(); EEPROM_Init(); } diff --git a/right/src/key_debouncer.c b/right/src/key_debouncer.c deleted file mode 100644 index 0ec19e7..0000000 --- a/right/src/key_debouncer.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "key_debouncer.h" -#include "fsl_pit.h" -#include "slot.h" -#include "module.h" -#include "key_states.h" -#include "peripherals/test_led.h" - -void PIT_KEY_DEBOUNCER_HANDLER(void) -{ - TestLed_Toggle(); - for (uint8_t slotId=0; slotIddebounceCounter) { - keyState->current = keyState->previous; + if (keyState->debouncing) { + if ((uint8_t)(Timer_GetCurrentTime() - keyState->timestamp) > KEY_BOUNCE_TIME_MSEC) { + keyState->debouncing = false; + } else { + keyState->current = keyState->previous; + } } else if (!keyState->previous && keyState->current) { - keyState->debounceCounter = KEY_DEBOUNCER_TIMEOUT_MSEC + 1; + keyState->timestamp = Timer_GetCurrentTime(); + keyState->debouncing = true; } if (keyState->current) { diff --git a/shared/key_matrix.h b/shared/key_matrix.h index e58e12c..abe221b 100644 --- a/shared/key_matrix.h +++ b/shared/key_matrix.h @@ -9,6 +9,7 @@ // Macros: #define MAX_KEYS_IN_MATRIX 100 + #define KEY_BOUNCE_TIME_MSEC 100 // Typedefs: