X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=keyboard%2Fgh60%2Fmatrix.c;h=451e541a4f3e1480652268ba400828c71d0612c5;hb=bb955a819af89e74843743e268aa7b4ceb06cc4e;hp=a61215152c94deec55e494ee7e389174d7ea9386;hpb=f3132adb33fd38e8d9d49845809ad5cb89f9c9c1;p=max%2Ftmk_keyboard.git
diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c
index a6121515..451e541a 100644
--- a/keyboard/gh60/matrix.c
+++ b/keyboard/gh60/matrix.c
@@ -25,13 +25,16 @@ along with this program. If not, see .
#include "print.h"
#include "debug.h"
#include "util.h"
+#include "timer.h"
#include "matrix.h"
#ifndef DEBOUNCE
# define DEBOUNCE 5
#endif
-static uint8_t debouncing = DEBOUNCE;
+static bool debouncing = false;
+static uint16_t debouncing_time = 0;
+
/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];
@@ -43,18 +46,6 @@ static void unselect_rows(void);
static void select_row(uint8_t row);
-inline
-uint8_t matrix_rows(void)
-{
- return MATRIX_ROWS;
-}
-
-inline
-uint8_t matrix_cols(void)
-{
- return MATRIX_COLS;
-}
-
void matrix_init(void)
{
// initialize row and col
@@ -72,68 +63,35 @@ uint8_t matrix_scan(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
select_row(i);
- _delay_us(30); // without this wait read unstable value.
+ _delay_us(1); // delay for settling
matrix_row_t cols = read_cols();
if (matrix_debouncing[i] != cols) {
- matrix_debouncing[i] = cols;
if (debouncing) {
- debug("bounce!: "); debug_hex(debouncing); debug("\n");
+ dprintf("bounce: %d %d@%02X\n", timer_elapsed(debouncing_time), i, matrix_debouncing[i]^cols);
}
- debouncing = DEBOUNCE;
+ matrix_debouncing[i] = cols;
+ debouncing = true;
+ debouncing_time = timer_read();
}
unselect_rows();
}
- if (debouncing) {
- if (--debouncing) {
- _delay_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- matrix[i] = matrix_debouncing[i];
- }
+ if (debouncing && timer_elapsed(debouncing_time) >= DEBOUNCE) {
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ matrix[i] = matrix_debouncing[i];
}
+ debouncing = false;
}
return 1;
}
-bool matrix_is_modified(void)
-{
- if (debouncing) return false;
- return true;
-}
-
-inline
-bool matrix_is_on(uint8_t row, uint8_t col)
-{
- return (matrix[row] & ((matrix_row_t)1<