diff --git a/keyboards/massdrop/alt/matrix.c b/keyboards/massdrop/alt/matrix.c index 05369a9a8774..5c31868532c9 100644 --- a/keyboards/massdrop/alt/matrix.c +++ b/keyboards/massdrop/alt/matrix.c @@ -83,15 +83,15 @@ void matrix_init(void) } uint64_t mdebouncing = 0; +bool debouncing = false; + uint8_t matrix_scan(void) { - uint8_t mchanged; + uint64_t timer; uint8_t row; uint8_t col; uint32_t scans[MCU_PORTS_USED]; //Array size must match number of unique MCU ports used for reads (PA, PB, PC, etc) - if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer for (col = 0; col < MATRIX_COLS; col++) @@ -115,25 +115,26 @@ uint8_t matrix_scan(void) } } - mchanged = 0; //Default to no matrix change since last + timer = timer_read64(); for (row = 0; row < MATRIX_ROWS; row++) { - if (mlast[row] != mlatest[row]) - mchanged = 1; + if (mlast[row] != mlatest[row]) { + debouncing = true; + mdebouncing = timer + DEBOUNCE; + } + mlast[row] = mlatest[row]; } - if (!mchanged) + if (debouncing && timer >= mdebouncing) { - for (row = 0; row < MATRIX_ROWS; row++) + for (row = 0; row < MATRIX_ROWS; row++) { mdebounced[row] = mlatest[row]; + } + mdebouncing = 0; - } - else - { - //Begin or extend debounce on change - mdebouncing = timer_read64() + DEBOUNCE; + debouncing = false; } matrix_scan_quantum(); diff --git a/keyboards/massdrop/ctrl/matrix.c b/keyboards/massdrop/ctrl/matrix.c index f167ab5a35fb..b53c1693df9b 100644 --- a/keyboards/massdrop/ctrl/matrix.c +++ b/keyboards/massdrop/ctrl/matrix.c @@ -83,15 +83,15 @@ void matrix_init(void) } uint64_t mdebouncing = 0; +bool debouncing = false; + uint8_t matrix_scan(void) { - uint8_t mchanged; + uint64_t timer; uint8_t row; uint8_t col; uint32_t scans[MCU_PORTS_USED]; //Array size must match number of unique MCU ports used for reads (PA, PB, PC, etc) - if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer for (col = 0; col < MATRIX_COLS; col++) @@ -115,25 +115,26 @@ uint8_t matrix_scan(void) } } - mchanged = 0; //Default to no matrix change since last + timer = timer_read64(); for (row = 0; row < MATRIX_ROWS; row++) { - if (mlast[row] != mlatest[row]) - mchanged = 1; + if (mlast[row] != mlatest[row]) { + debouncing = true; + mdebouncing = timer + DEBOUNCE; + } + mlast[row] = mlatest[row]; } - if (!mchanged) + if (debouncing && timer >= mdebouncing) { - for (row = 0; row < MATRIX_ROWS; row++) + for (row = 0; row < MATRIX_ROWS; row++) { mdebounced[row] = mlatest[row]; + } + mdebouncing = 0; - } - else - { - //Begin or extend debounce on change - mdebouncing = timer_read64() + DEBOUNCE; + debouncing = false; } matrix_scan_quantum(); diff --git a/keyboards/massdrop/rocketeer/config.h b/keyboards/massdrop/rocketeer/config.h index 08ab67c999fb..3caa0fdf7a3f 100644 --- a/keyboards/massdrop/rocketeer/config.h +++ b/keyboards/massdrop/rocketeer/config.h @@ -93,7 +93,7 @@ along with this program. If not, see . #define DEBUG_BOOT_TRACING_PIN 23 /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ -#define DEBOUNCING_DELAY 5 +#define DEBOUNCE 5 /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ //#define LOCKING_SUPPORT_ENABLE diff --git a/keyboards/massdrop/rocketeer/matrix.c b/keyboards/massdrop/rocketeer/matrix.c index 8667c1b2b601..ef45711c332f 100644 --- a/keyboards/massdrop/rocketeer/matrix.c +++ b/keyboards/massdrop/rocketeer/matrix.c @@ -83,15 +83,15 @@ void matrix_init(void) } uint64_t mdebouncing = 0; +bool debouncing = false; + uint8_t matrix_scan(void) { - uint8_t mchanged; + uint64_t timer; uint8_t row; uint8_t col; uint32_t scans[MCU_PORTS_USED]; //Array size must match number of unique MCU ports used for reads (PA, PB, PC, etc) - if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer for (col = 0; col < MATRIX_COLS; col++) @@ -115,25 +115,26 @@ uint8_t matrix_scan(void) } } - mchanged = 0; //Default to no matrix change since last + timer = timer_read64(); for (row = 0; row < MATRIX_ROWS; row++) { - if (mlast[row] != mlatest[row]) - mchanged = 1; + if (mlast[row] != mlatest[row]) { + debouncing = true; + mdebouncing = timer + DEBOUNCE; + } + mlast[row] = mlatest[row]; } - if (!mchanged) + if (debouncing && timer >= mdebouncing) { - for (row = 0; row < MATRIX_ROWS; row++) + for (row = 0; row < MATRIX_ROWS; row++) { mdebounced[row] = mlatest[row]; + } + mdebouncing = 0; - } - else - { - //Begin or extend debounce on change - mdebouncing = timer_read64() + DEBOUNCING_DELAY; + debouncing = false; } matrix_scan_quantum(); diff --git a/keyboards/massdrop/shift/config.h b/keyboards/massdrop/shift/config.h index 38922cc7daa4..d5a9bb6406ec 100644 --- a/keyboards/massdrop/shift/config.h +++ b/keyboards/massdrop/shift/config.h @@ -123,7 +123,7 @@ along with this program. If not, see . #define DEBUG_BOOT_TRACING_PIN 23 /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ -#define DEBOUNCING_DELAY 5 +#define DEBOUNCE 5 /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ //#define LOCKING_SUPPORT_ENABLE diff --git a/keyboards/massdrop/shift/matrix.c b/keyboards/massdrop/shift/matrix.c index f83c52fd4c64..a2cc30ded0e0 100644 --- a/keyboards/massdrop/shift/matrix.c +++ b/keyboards/massdrop/shift/matrix.c @@ -95,15 +95,15 @@ void matrix_init(void) } uint64_t mdebouncing = 0; +bool debouncing = false; + uint8_t matrix_scan(void) { - uint8_t mchanged; + uint64_t timer; uint8_t row; uint8_t col; uint32_t scans[MCU_PORTS_USED]; //Array size must match number of unique MCU ports used for reads (PA, PB, PC, etc) - if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer for (col = 0; col < MATRIX_COLS; col++) @@ -144,25 +144,26 @@ uint8_t matrix_scan(void) } } - mchanged = 0; //Default to no matrix change since last + timer = timer_read64(); for (row = 0; row < MATRIX_ROWS; row++) { - if (mlast[row] != mlatest[row]) - mchanged = 1; + if (mlast[row] != mlatest[row]) { + debouncing = true; + mdebouncing = timer + DEBOUNCE; + } + mlast[row] = mlatest[row]; } - if (!mchanged) + if (debouncing && timer >= mdebouncing) { - for (row = 0; row < MATRIX_ROWS; row++) + for (row = 0; row < MATRIX_ROWS; row++) { mdebounced[row] = mlatest[row]; + } + mdebouncing = 0; - } - else - { - //Begin or extend debounce on change - mdebouncing = timer_read64() + DEBOUNCING_DELAY; + debouncing = false; } matrix_scan_quantum();