Skip to content

Commit

Permalink
Change debounce methodology to shift debounce window until row is set…
Browse files Browse the repository at this point in the history
…tled (Massdrop#5)
  • Loading branch information
just-another-jxliu authored Aug 2, 2019
1 parent 9b80cec commit 3cb242b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 deletions.
27 changes: 14 additions & 13 deletions keyboards/massdrop/alt/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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();
Expand Down
27 changes: 14 additions & 13 deletions keyboards/massdrop/ctrl/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion keyboards/massdrop/rocketeer/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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
Expand Down
27 changes: 14 additions & 13 deletions keyboards/massdrop/rocketeer/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion keyboards/massdrop/shift/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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
Expand Down
27 changes: 14 additions & 13 deletions keyboards/massdrop/shift/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3cb242b

Please sign in to comment.