From 894e393c672dbe72fabb9ab555f415dc0977d889 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 21 Aug 2017 23:23:34 +0900 Subject: [PATCH] pana_m8: Add debouncing --- converter/pana_m8/config.h | 3 +++ converter/pana_m8/pana_m8.c | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/converter/pana_m8/config.h b/converter/pana_m8/config.h index 6d626d99..4580b834 100644 --- a/converter/pana_m8/config.h +++ b/converter/pana_m8/config.h @@ -14,6 +14,9 @@ #define MATRIX_ROWS 8 #define MATRIX_COLS 8 +/* matrix debounce time in ms */ +#define DEBOUNCE 10 + /* key combination for command */ #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) diff --git a/converter/pana_m8/pana_m8.c b/converter/pana_m8/pana_m8.c index 19f88487..b4556751 100644 --- a/converter/pana_m8/pana_m8.c +++ b/converter/pana_m8/pana_m8.c @@ -3,16 +3,19 @@ #include "matrix.h" #include "led.h" #include "wait.h" +#include "timer.h" #include "debug.h" #define CLK_HI() (PORTD |= (1<<0)) #define CLK_LO() (PORTD &= ~(1<<0)) -#define STATE() (PIND & (1<<1)) +#define STATE() (!!(PIND & (1<<1))) #define RST_HI() (PORTD |= (1<<3)) #define RST_LO() (PORTD &= ~(1<<3)) #define SENSE() (PIND & (1<<2)) static matrix_row_t matrix[8] = {}; +static matrix_row_t matrix_debouncing[8] = {}; +static uint16_t debouncing_time = 0; void matrix_init(void) @@ -48,10 +51,10 @@ uint8_t matrix_scan(void) CLK_HI(); wait_us(10); - if (STATE()) { - matrix[row] |= (1< DEBOUNCE) { + for (int row = 0; row < MATRIX_ROWS; row++) { + matrix[row] = matrix_debouncing[row]; + } + debouncing_time = 0; + } return 1; } -- 2.46.2