Fix debouncing on Phantom.
parent
f4760c822a
commit
3d503c8932
|
@ -24,10 +24,8 @@
|
||||||
static uint8_t debouncing = DEBOUNCE;
|
static uint8_t debouncing = DEBOUNCE;
|
||||||
|
|
||||||
// bit array of key state(1:on, 0:off)
|
// bit array of key state(1:on, 0:off)
|
||||||
static matrix_row_t *matrix;
|
static matrix_row_t matrix[MATRIX_ROWS];
|
||||||
static matrix_row_t *matrix_debounced;
|
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||||
static matrix_row_t matrix0[MATRIX_ROWS];
|
|
||||||
static matrix_row_t matrix1[MATRIX_ROWS];
|
|
||||||
|
|
||||||
|
|
||||||
#define _DDRA (uint8_t *const)&DDRA
|
#define _DDRA (uint8_t *const)&DDRA
|
||||||
|
@ -165,11 +163,9 @@ void matrix_init(void)
|
||||||
|
|
||||||
// initialize matrix state: all keys off
|
// initialize matrix state: all keys off
|
||||||
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||||
matrix0[i] = 0;
|
matrix[i] = 0;
|
||||||
matrix1[i] = 0;
|
matrix_debouncing[i] = 0;
|
||||||
}
|
}
|
||||||
matrix = matrix0;
|
|
||||||
matrix_debounced = matrix1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t matrix_scan(void)
|
uint8_t matrix_scan(void)
|
||||||
|
@ -178,10 +174,10 @@ uint8_t matrix_scan(void)
|
||||||
pull_column(col); // output hi on theline
|
pull_column(col); // output hi on theline
|
||||||
_delay_us(3); // without this wait it won't read stable value.
|
_delay_us(3); // without this wait it won't read stable value.
|
||||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5
|
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5
|
||||||
bool prev_bit = matrix[row] & ((matrix_row_t)1<<col);
|
bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
|
||||||
bool curr_bit = !(*row_pin[row] & row_bit[row]);
|
bool curr_bit = !(*row_pin[row] & row_bit[row]);
|
||||||
if (prev_bit != curr_bit) {
|
if (prev_bit != curr_bit) {
|
||||||
matrix[row] ^= ((matrix_row_t)1<<col);
|
matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
|
||||||
if (debouncing) {
|
if (debouncing) {
|
||||||
debug("bounce!: "); debug_hex(debouncing); print("\n");
|
debug("bounce!: "); debug_hex(debouncing); print("\n");
|
||||||
}
|
}
|
||||||
|
@ -195,9 +191,9 @@ uint8_t matrix_scan(void)
|
||||||
if (--debouncing) {
|
if (--debouncing) {
|
||||||
_delay_ms(1);
|
_delay_ms(1);
|
||||||
} else {
|
} else {
|
||||||
matrix_row_t *tmp = matrix_debounced;
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
matrix_debounced = matrix;
|
matrix[i] = matrix_debouncing[i];
|
||||||
matrix = tmp;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,13 +209,13 @@ bool matrix_is_modified(void)
|
||||||
inline
|
inline
|
||||||
bool matrix_is_on(uint8_t row, uint8_t col)
|
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||||
{
|
{
|
||||||
return (matrix_debounced[row] & ((matrix_row_t)1<<col));
|
return (matrix[row] & ((matrix_row_t)1<<col));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
matrix_row_t matrix_get_row(uint8_t row)
|
matrix_row_t matrix_get_row(uint8_t row)
|
||||||
{
|
{
|
||||||
return matrix_debounced[row];
|
return matrix[row];
|
||||||
}
|
}
|
||||||
|
|
||||||
void matrix_print(void)
|
void matrix_print(void)
|
||||||
|
|
Loading…
Reference in New Issue