From 5bb7ef0012378cd800bff74680b08c587e6338e4 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 13 Sep 2015 22:10:01 -0400 Subject: [PATCH] rows to col option, maybe --- keyboard/planck/config.h | 3 ++ keyboard/planck/config_definitions.h | 3 +- keyboard/planck/matrix.c | 65 +++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/keyboard/planck/config.h b/keyboard/planck/config.h index 47cf39a9..e9701277 100644 --- a/keyboard/planck/config.h +++ b/keyboard/planck/config.h @@ -36,6 +36,9 @@ along with this program. If not, see . #define COLS (int []){ F1, F0, B0, C7, F4, F5, F6, F7, D4, D6, B4, D7 } #define ROWS (int []){ D0, D5, B5, B6 } +/* COL2ROW or ROW2COL */ +#define DIODE_DIRECTION COL2ROW + /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/planck/config_definitions.h b/keyboard/planck/config_definitions.h index fd138b88..2ac31126 100644 --- a/keyboard/planck/config_definitions.h +++ b/keyboard/planck/config_definitions.h @@ -42,7 +42,8 @@ #define F6 0x66 #define F7 0x67 - +#define COL2ROW 0x0 +#define ROW2COL 0x1 diff --git a/keyboard/planck/matrix.c b/keyboard/planck/matrix.c index 98ef55ed..8a021719 100644 --- a/keyboard/planck/matrix.c +++ b/keyboard/planck/matrix.c @@ -37,6 +37,11 @@ static uint8_t debouncing = DEBOUNCE; static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +#if DIODE_DIRECTION == ROW2COL +static matrix_row_t matrix_reversed[MATRIX_COLS]; +static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS]; +#endif + static matrix_row_t read_cols(void); static void init_cols(void); static void unselect_rows(void); @@ -80,6 +85,7 @@ void matrix_init(void) uint8_t matrix_scan(void) { +#if DIODE_DIRECTION == COL2ROW for (uint8_t i = 0; i < MATRIX_ROWS; i++) { select_row(i); _delay_us(30); // without this wait read unstable value. @@ -103,6 +109,38 @@ uint8_t matrix_scan(void) } } } +#else + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + select_row(i); + _delay_us(30); // without this wait read unstable value. + matrix_row_t rows = read_cols(); + if (matrix_reversed_debouncing[i] != rows) { + matrix_reversed_debouncing[i] = rows; + if (debouncing) { + debug("bounce!: "); debug_hex(debouncing); debug("\n"); + } + debouncing = DEBOUNCE; + } + unselect_rows(); + } + + if (debouncing) { + if (--debouncing) { + _delay_ms(1); + } else { + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + matrix_reversed[i] = matrix_reversed_debouncing[i]; + } + } + } + for (uint8_t y = 0; y < MATRIX_ROWS; y++) { + matrix_row_t row = 0; + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + row |= ((matrix_reversed[x] & (1<> y) << x; + } + matrix[y] = row; + } +#endif return 1; } @@ -147,8 +185,14 @@ uint8_t matrix_key_count(void) static void init_cols(void) { int B = 0, C = 0, D = 0, E = 0, F = 0; - for(int x = 0; x < MATRIX_COLS; x++) { + +#if DIODE_DIRECTION == COL2ROW + for(int x = 0; x < MATRIX_COLS; x++) { int col = COLS[x]; +#else + for(int x = 0; x < MATRIX_ROWS; x++) { + int col = ROWS[x]; +#endif if ((col & 0xF0) == 0x20) { B |= (1<<(col & 0x0F)); } else if ((col & 0xF0) == 0x30) { @@ -171,8 +215,15 @@ static void init_cols(void) static matrix_row_t read_cols(void) { matrix_row_t result = 0; + +#if DIODE_DIRECTION == COL2ROW for(int x = 0; x < MATRIX_COLS; x++) { int col = COLS[x]; +#else + for(int x = 0; x < MATRIX_ROWS; x++) { + int col = ROWS[x]; +#endif + if ((col & 0xF0) == 0x20) { result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<