From a0afdcf476ff9157c29b3e2fcd9594cac329e1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Tue, 14 Nov 2017 22:54:53 +0100 Subject: [PATCH] Implement key debouncer. --- right/src/init_peripherals.c | 2 ++ right/src/key_debouncer.c | 32 ++++++++++++++++++++++++++++++++ right/src/key_debouncer.h | 18 ++++++++++++++++++ right/src/key_scanner.h | 2 +- right/src/key_states.h | 1 + right/src/peripherals/pit.h | 26 +++++++++++++++++--------- right/src/usb_report_updater.c | 8 ++++++++ 7 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 right/src/key_debouncer.c create mode 100644 right/src/key_debouncer.h diff --git a/right/src/init_peripherals.c b/right/src/init_peripherals.c index bd84feb..53e1d16 100644 --- a/right/src/init_peripherals.c +++ b/right/src/init_peripherals.c @@ -14,6 +14,7 @@ #include "eeprom.h" #include "microseconds/microseconds_pit.c" #include "timer.h" +#include "key_debouncer.h" void InitInterruptPriorities(void) { @@ -122,6 +123,7 @@ void InitPeripherals(void) #ifdef I2C_WATCHDOG InitI2cWatchdog(); #endif + InitKeyDebouncer(); EEPROM_Init(); //microseconds_init(); } diff --git a/right/src/key_debouncer.c b/right/src/key_debouncer.c new file mode 100644 index 0000000..8a85eb3 --- /dev/null +++ b/right/src/key_debouncer.c @@ -0,0 +1,32 @@ +#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) +{ + TEST_LED_TOGGLE(); + for (uint8_t slotId=0; slotIddebounceCounter < KEY_DEBOUNCER_TIMEOUT_MSEC) { + keyState->current = keyState->previous; + } else if (!keyState->previous && keyState->current) { + keyState->debounceCounter = 0; + } + if (keyState->current) { if (suppressKeys) { keyState->suppressed = true;