From 5bb7ef0012378cd800bff74680b08c587e6338e4 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 13 Sep 2015 22:10:01 -0400 Subject: rows to col option, maybe --- keyboard/planck/matrix.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'keyboard/planck/matrix.c') diff --git a/keyboard/planck/matrix.c b/keyboard/planck/matrix.c index 98ef55ed68..8a021719ce 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<