Make debounce times configurable on the fly

This commit is contained in:
Eric Tang
2018-07-05 14:41:19 -07:00
parent 2ef5c49090
commit d722b3d173
3 changed files with 8 additions and 3 deletions

View File

@@ -350,12 +350,12 @@ static void updateActiveUsbReports(void)
key_action_t *action = &CurrentKeymap[activeLayer][slotId][keyId]; key_action_t *action = &CurrentKeymap[activeLayer][slotId][keyId];
if (keyState->debouncing) { 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; keyState->debouncing = false;
} else { } else {
keyState->current = keyState->previous; keyState->current = keyState->previous;
} }
} else if (!keyState->previous && keyState->current) { } else if (keyState->previous != keyState->current) {
keyState->timestamp = Timer_GetCurrentTime(); keyState->timestamp = Timer_GetCurrentTime();
keyState->debouncing = true; keyState->debouncing = true;
} }

View File

@@ -1,6 +1,8 @@
#include "fsl_gpio.h" #include "fsl_gpio.h"
#include "key_matrix.h" #include "key_matrix.h"
uint8_t DebounceTimePress = 100, DebounceTimeRelease = 0;
void KeyMatrix_Init(key_matrix_t *keyMatrix) void KeyMatrix_Init(key_matrix_t *keyMatrix)
{ {
for (key_matrix_pin_t *row = keyMatrix->rows; row < keyMatrix->rows + keyMatrix->rowNum; row++) { for (key_matrix_pin_t *row = keyMatrix->rows; row < keyMatrix->rows + keyMatrix->rowNum; row++) {

View File

@@ -9,7 +9,6 @@
// Macros: // Macros:
#define MAX_KEYS_IN_MATRIX 100 #define MAX_KEYS_IN_MATRIX 100
#define KEY_BOUNCE_TIME_MSEC 100
// Typedefs: // Typedefs:
@@ -29,6 +28,10 @@
uint8_t keyStates[MAX_KEYS_IN_MATRIX]; uint8_t keyStates[MAX_KEYS_IN_MATRIX];
} key_matrix_t; } key_matrix_t;
// Variables:
extern uint8_t DebounceTimePress, DebounceTimeRelease;
// Functions: // Functions:
void KeyMatrix_Init(key_matrix_t *keyMatrix); void KeyMatrix_Init(key_matrix_t *keyMatrix);