From d722b3d1732a7ee7156b486aecb3c2b82eed3258 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Thu, 5 Jul 2018 14:41:19 -0700 Subject: [PATCH] Make debounce times configurable on the fly --- right/src/usb_report_updater.c | 4 ++-- shared/key_matrix.c | 2 ++ shared/key_matrix.h | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index d2f1c1d..5ebc64f 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -350,12 +350,12 @@ static void updateActiveUsbReports(void) key_action_t *action = &CurrentKeymap[activeLayer][slotId][keyId]; if (keyState->debouncing) { - if ((uint8_t)(Timer_GetCurrentTime() - keyState->timestamp) > KEY_BOUNCE_TIME_MSEC) { + if ((uint8_t)(Timer_GetCurrentTime() - keyState->timestamp) > (keyState->previous ? DebounceTimePress : DebounceTimeRelease)) { keyState->debouncing = false; } else { keyState->current = keyState->previous; } - } else if (!keyState->previous && keyState->current) { + } else if (keyState->previous != keyState->current) { keyState->timestamp = Timer_GetCurrentTime(); keyState->debouncing = true; } diff --git a/shared/key_matrix.c b/shared/key_matrix.c index e59673a..e8fb941 100644 --- a/shared/key_matrix.c +++ b/shared/key_matrix.c @@ -1,6 +1,8 @@ #include "fsl_gpio.h" #include "key_matrix.h" +uint8_t DebounceTimePress = 100, DebounceTimeRelease = 0; + void KeyMatrix_Init(key_matrix_t *keyMatrix) { for (key_matrix_pin_t *row = keyMatrix->rows; row < keyMatrix->rows + keyMatrix->rowNum; row++) { diff --git a/shared/key_matrix.h b/shared/key_matrix.h index abe221b..f4311d0 100644 --- a/shared/key_matrix.h +++ b/shared/key_matrix.h @@ -9,7 +9,6 @@ // Macros: #define MAX_KEYS_IN_MATRIX 100 - #define KEY_BOUNCE_TIME_MSEC 100 // Typedefs: @@ -29,6 +28,10 @@ uint8_t keyStates[MAX_KEYS_IN_MATRIX]; } key_matrix_t; +// Variables: + + extern uint8_t DebounceTimePress, DebounceTimeRelease; + // Functions: void KeyMatrix_Init(key_matrix_t *keyMatrix);