1
0

Change debounce methodology to shift debounce window until row is settled (#5)

This commit is contained in:
just-another-jxliu
2019-08-02 16:44:19 -07:00
committed by GitHub
parent 9b80ceca52
commit 3cb242b47d
6 changed files with 58 additions and 54 deletions

View File

@@ -83,15 +83,15 @@ void matrix_init(void)
} }
uint64_t mdebouncing = 0; uint64_t mdebouncing = 0;
bool debouncing = false;
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
uint8_t mchanged; uint64_t timer;
uint8_t row; uint8_t row;
uint8_t col; 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) 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 memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer
for (col = 0; col < MATRIX_COLS; col++) 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++) for (row = 0; row < MATRIX_ROWS; row++)
{ {
if (mlast[row] != mlatest[row]) if (mlast[row] != mlatest[row]) {
mchanged = 1; debouncing = true;
mdebouncing = timer + DEBOUNCE;
}
mlast[row] = mlatest[row]; 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]; mdebounced[row] = mlatest[row];
}
mdebouncing = 0; mdebouncing = 0;
} debouncing = false;
else
{
//Begin or extend debounce on change
mdebouncing = timer_read64() + DEBOUNCE;
} }
matrix_scan_quantum(); matrix_scan_quantum();

View File

@@ -83,15 +83,15 @@ void matrix_init(void)
} }
uint64_t mdebouncing = 0; uint64_t mdebouncing = 0;
bool debouncing = false;
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
uint8_t mchanged; uint64_t timer;
uint8_t row; uint8_t row;
uint8_t col; 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) 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 memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer
for (col = 0; col < MATRIX_COLS; col++) 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++) for (row = 0; row < MATRIX_ROWS; row++)
{ {
if (mlast[row] != mlatest[row]) if (mlast[row] != mlatest[row]) {
mchanged = 1; debouncing = true;
mdebouncing = timer + DEBOUNCE;
}
mlast[row] = mlatest[row]; 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]; mdebounced[row] = mlatest[row];
}
mdebouncing = 0; mdebouncing = 0;
} debouncing = false;
else
{
//Begin or extend debounce on change
mdebouncing = timer_read64() + DEBOUNCE;
} }
matrix_scan_quantum(); matrix_scan_quantum();

View File

@@ -93,7 +93,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEBUG_BOOT_TRACING_PIN 23 #define DEBUG_BOOT_TRACING_PIN 23
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ /* 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 */ /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
//#define LOCKING_SUPPORT_ENABLE //#define LOCKING_SUPPORT_ENABLE

View File

@@ -83,15 +83,15 @@ void matrix_init(void)
} }
uint64_t mdebouncing = 0; uint64_t mdebouncing = 0;
bool debouncing = false;
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
uint8_t mchanged; uint64_t timer;
uint8_t row; uint8_t row;
uint8_t col; 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) 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 memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer
for (col = 0; col < MATRIX_COLS; col++) 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++) for (row = 0; row < MATRIX_ROWS; row++)
{ {
if (mlast[row] != mlatest[row]) if (mlast[row] != mlatest[row]) {
mchanged = 1; debouncing = true;
mdebouncing = timer + DEBOUNCE;
}
mlast[row] = mlatest[row]; 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]; mdebounced[row] = mlatest[row];
}
mdebouncing = 0; mdebouncing = 0;
} debouncing = false;
else
{
//Begin or extend debounce on change
mdebouncing = timer_read64() + DEBOUNCING_DELAY;
} }
matrix_scan_quantum(); matrix_scan_quantum();

View File

@@ -123,7 +123,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEBUG_BOOT_TRACING_PIN 23 #define DEBUG_BOOT_TRACING_PIN 23
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ /* 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 */ /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
//#define LOCKING_SUPPORT_ENABLE //#define LOCKING_SUPPORT_ENABLE

View File

@@ -95,15 +95,15 @@ void matrix_init(void)
} }
uint64_t mdebouncing = 0; uint64_t mdebouncing = 0;
bool debouncing = false;
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
uint8_t mchanged; uint64_t timer;
uint8_t row; uint8_t row;
uint8_t col; 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) 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 memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer
for (col = 0; col < MATRIX_COLS; col++) 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++) for (row = 0; row < MATRIX_ROWS; row++)
{ {
if (mlast[row] != mlatest[row]) if (mlast[row] != mlatest[row]) {
mchanged = 1; debouncing = true;
mdebouncing = timer + DEBOUNCE;
}
mlast[row] = mlatest[row]; 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]; mdebounced[row] = mlatest[row];
}
mdebouncing = 0; mdebouncing = 0;
} debouncing = false;
else
{
//Begin or extend debounce on change
mdebouncing = timer_read64() + DEBOUNCING_DELAY;
} }
matrix_scan_quantum(); matrix_scan_quantum();