From 684793360cdb08ac1e50a6d27e1796fadd527adb Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 9 May 2016 00:36:23 -0400 Subject: quantum accommodates more than 16 columns --- quantum/matrix.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 2dab6ae941..7d70f728d4 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -42,6 +42,13 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS]; #endif + +#if MATRIX_COLS > 16 + #define SHIFTER 1UL +#else + #define SHIFTER 1 +#endif + static matrix_row_t read_cols(void); static void init_cols(void); static void unselect_rows(void); @@ -235,15 +242,15 @@ static matrix_row_t read_cols(void) #endif if ((col & 0xF0) == 0x20) { - result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1< Date: Sun, 15 May 2016 00:27:32 -0400 Subject: Leader key implementation (#326) * implements leader key for planck experimental * allows override of leader timeout * adds ability to use the leader key in seq * fixes leader keycode * adds chording prototype * fixes keycode detection * moves music mode to quantum.c * disables chording by default * updates process_action functions to return bool --- quantum/matrix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 7d70f728d4..cab39e117a 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -55,12 +55,12 @@ static void unselect_rows(void); static void select_row(uint8_t row); __attribute__ ((weak)) -void matrix_init_kb(void) { +void matrix_init_quantum(void) { } __attribute__ ((weak)) -void matrix_scan_kb(void) { +void matrix_scan_quantum(void) { } @@ -93,7 +93,7 @@ void matrix_init(void) matrix_debouncing[i] = 0; } - matrix_init_kb(); + matrix_init_quantum(); } @@ -157,7 +157,7 @@ uint8_t matrix_scan(void) } #endif - matrix_scan_kb(); + matrix_scan_quantum(); return 1; } -- cgit v1.2.1 From aaa758f1d3f97dda39879f2b055ad2da9680adfe Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Mon, 23 May 2016 20:42:21 -0700 Subject: Optimize matrix scanning (#343) --- quantum/matrix.c | 369 +++++++++++++++++++++---------------------------------- 1 file changed, 140 insertions(+), 229 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index cab39e117a..22126aa7ae 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -1,6 +1,6 @@ /* -Copyright 2012 Jun Wako -Generated by planckkeyboard.com (2014 Jack Humbert) +Copyright 2012 Jun Wako +Copyright 2014 Jack Humbert This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,300 +15,211 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ - -/* - * scan matrix - */ #include #include #include -#include +#include "wait.h" #include "print.h" #include "debug.h" #include "util.h" #include "matrix.h" -#ifndef DEBOUNCE -# define DEBOUNCE 10 +#ifdef MATRIX_HAS_GHOST +# error "The universal matrix.c file cannot be used for this keyboard." #endif -static uint8_t debouncing = DEBOUNCE; -/* matrix state(1:on, 0:off) */ -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]; +#ifndef DEBOUNCING_DELAY +# define DEBOUNCING_DELAY 5 #endif - -#if MATRIX_COLS > 16 - #define SHIFTER 1UL +static const io_pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const io_pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +/* matrix state */ +#if DIODE_DIRECTION == COL2ROW +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t debouncing_matrix[MATRIX_ROWS]; #else - #define SHIFTER 1 +static matrix_col_t matrix[MATRIX_COLS]; +static matrix_col_t debouncing_matrix[MATRIX_COLS]; #endif +static int8_t debouncing_delay = -1; +#if DIODE_DIRECTION == COL2ROW +static void toggle_row(uint8_t row); static matrix_row_t read_cols(void); -static void init_cols(void); -static void unselect_rows(void); -static void select_row(uint8_t row); +#else +static void toggle_col(uint8_t col); +static matrix_col_t read_rows(void); +#endif __attribute__ ((weak)) void matrix_init_quantum(void) { - } __attribute__ ((weak)) void matrix_scan_quantum(void) { - } -inline -uint8_t matrix_rows(void) -{ +uint8_t matrix_rows(void) { return MATRIX_ROWS; } -inline -uint8_t matrix_cols(void) -{ +uint8_t matrix_cols(void) { return MATRIX_COLS; } -void matrix_init(void) -{ - // To use PORTF disable JTAG with writing JTD bit twice within four cycles. - MCUCR |= (1<= 0; --r) { + /* DDRxn */ + _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit); + toggle_row(r); } - + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + /* PORTxn */ + _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit); + } +#else + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + /* DDRxn */ + _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit); + toggle_col(c); + } + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + /* PORTxn */ + _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit); + } +#endif matrix_init_quantum(); } - -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. - matrix_row_t cols = read_cols(); - if (matrix_debouncing[i] != cols) { - matrix_debouncing[i] = cols; - if (debouncing) { - debug("bounce!: "); debug_hex(debouncing); debug("\n"); - } - debouncing = DEBOUNCE; +uint8_t matrix_scan(void) { + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + toggle_row(r); + matrix_row_t state = read_cols(); + if (debouncing_matrix[r] != state) { + debouncing_matrix[r] = state; + debouncing_delay = DEBOUNCING_DELAY; } - unselect_rows(); + toggle_row(r); } - - if (debouncing) { - if (--debouncing) { - _delay_ms(1); - } else { - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - matrix[i] = matrix_debouncing[i]; - } + if (debouncing_delay >= 0) { + dprintf("Debouncing delay remaining: %X\n", debouncing_delay); + --debouncing_delay; + if (debouncing_delay >= 0) { + wait_ms(1); } - } -#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"); + else { + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + matrix[r] = debouncing_matrix[r]; } - 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 - matrix_scan_quantum(); - return 1; } -bool matrix_is_modified(void) -{ - if (debouncing) return false; - return true; +static void toggle_row(uint8_t row) { + /* PINxn */ + _SFR_IO8(row_pins[row].input_addr) = _BV(row_pins[row].bit); } -inline -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & ((matrix_row_t)1= 0; --c) { + /* PINxn */ + if (!(_SFR_IO8(col_pins[c].input_addr) & _BV(col_pins[c].bit))) { + state |= (matrix_row_t)1 << c; + } + } + return state; } -inline -matrix_row_t matrix_get_row(uint8_t row) -{ +matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } -void matrix_print(void) -{ - print("\nr/c 0123456789ABCDEF\n"); - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - phex(row); print(": "); - pbin_reverse16(matrix_get_row(row)); - print("\n"); +#else +uint8_t matrix_scan(void) { + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + toggle_col(c); + matrix_col_t state = read_rows(); + if (debouncing_matrix[c] != state) { + debouncing_matrix[c] = state; + debouncing_delay = DEBOUNCING_DELAY; + } + toggle_col(c); } -} - -uint8_t matrix_key_count(void) -{ - uint8_t count = 0; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - count += bitpop16(matrix[i]); + if (debouncing_delay >= 0) { + dprintf("Debouncing delay remaining: %X\n", debouncing_delay); + --debouncing_delay; + if (debouncing_delay >= 0) { + wait_ms(1); + } + else { + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + matrix[c] = debouncing_matrix[c]; + } + } } - return count; + matrix_scan_quantum(); + return 1; } -static void init_cols(void) -{ - int B = 0, C = 0, D = 0, E = 0, F = 0; +static void toggle_col(uint8_t col) { + /* PINxn */ + _SFR_IO8(col_pins[col].input_addr) = _BV(col_pins[col].bit); +} -#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) { - C |= (1<<(col & 0x0F)); - } else if ((col & 0xF0) == 0x40) { - D |= (1<<(col & 0x0F)); - } else if ((col & 0xF0) == 0x50) { - E |= (1<<(col & 0x0F)); - } else if ((col & 0xF0) == 0x60) { - F |= (1<<(col & 0x0F)); - } +static matrix_col_t read_rows(void) { + matrix_col_t state = 0; + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + /* PINxn */ + if (!(_SFR_IO8(row_pins[r].input_addr) & _BV(row_pins[r].bit))) { + state |= (matrix_col_t)1 << r; + } } - DDRB &= ~(B); PORTB |= (B); - DDRC &= ~(C); PORTC |= (C); - DDRD &= ~(D); PORTD |= (D); - DDRE &= ~(E); PORTE |= (E); - DDRF &= ~(F); PORTF |= (F); + return state; } -static matrix_row_t read_cols(void) -{ - matrix_row_t result = 0; +matrix_row_t matrix_get_row(uint8_t row) { + matrix_row_t state = 0; + matrix_col_t mask = (matrix_col_t)1 << row; + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + if (matrix[c] & mask) { + state |= (matrix_row_t)1 << c; + } + } + return state; +} -#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 : (SHIFTER<= 0) return false; + return true; } -static void unselect_rows(void) -{ - int B = 0, C = 0, D = 0, E = 0, F = 0; +bool matrix_is_on(uint8_t row, uint8_t col) { + return matrix_get_row(row) & (matrix_row_t)1 << col; +} -#if DIODE_DIRECTION == COL2ROW - for(int x = 0; x < MATRIX_ROWS; x++) { - int row = ROWS[x]; -#else - for(int x = 0; x < MATRIX_COLS; x++) { - int row = COLS[x]; -#endif - if ((row & 0xF0) == 0x20) { - B |= (1<<(row & 0x0F)); - } else if ((row & 0xF0) == 0x30) { - C |= (1<<(row & 0x0F)); - } else if ((row & 0xF0) == 0x40) { - D |= (1<<(row & 0x0F)); - } else if ((row & 0xF0) == 0x50) { - E |= (1<<(row & 0x0F)); - } else if ((row & 0xF0) == 0x60) { - F |= (1<<(row & 0x0F)); - } +void matrix_print(void) { + dprintln("Human-readable matrix state:"); + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + dprintf("State of row %X: %016b\n", r, bitrev16(matrix_get_row(r))); } - DDRB &= ~(B); PORTB |= (B); - DDRC &= ~(C); PORTC |= (C); - DDRD &= ~(D); PORTD |= (D); - DDRE &= ~(E); PORTE |= (E); - DDRF &= ~(F); PORTF |= (F); } -static void select_row(uint8_t row) -{ - -#if DIODE_DIRECTION == COL2ROW - int row_pin = ROWS[row]; -#else - int row_pin = COLS[row]; -#endif - - if ((row_pin & 0xF0) == 0x20) { - DDRB |= (1<<(row_pin & 0x0F)); - PORTB &= ~(1<<(row_pin & 0x0F)); - } else if ((row_pin & 0xF0) == 0x30) { - DDRC |= (1<<(row_pin & 0x0F)); - PORTC &= ~(1<<(row_pin & 0x0F)); - } else if ((row_pin & 0xF0) == 0x40) { - DDRD |= (1<<(row_pin & 0x0F)); - PORTD &= ~(1<<(row_pin & 0x0F)); - } else if ((row_pin & 0xF0) == 0x50) { - DDRE |= (1<<(row_pin & 0x0F)); - PORTE &= ~(1<<(row_pin & 0x0F)); - } else if ((row_pin & 0xF0) == 0x60) { - DDRF |= (1<<(row_pin & 0x0F)); - PORTF &= ~(1<<(row_pin & 0x0F)); - } -} \ No newline at end of file +uint8_t matrix_key_count(void) { + uint8_t count = 0; + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + count += bitpop16(matrix_get_row(r)); + } + return count; +} -- cgit v1.2.1 From 1ae6011cef2230826a9e6db6c5b638677bc640b7 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Tue, 24 May 2016 08:44:40 -0700 Subject: Clean up #343's code (#348) --- quantum/matrix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 22126aa7ae..d5fd7def8a 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -37,10 +37,8 @@ static const io_pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; /* matrix state */ #if DIODE_DIRECTION == COL2ROW static matrix_row_t matrix[MATRIX_ROWS]; -static matrix_row_t debouncing_matrix[MATRIX_ROWS]; #else static matrix_col_t matrix[MATRIX_COLS]; -static matrix_col_t debouncing_matrix[MATRIX_COLS]; #endif static int8_t debouncing_delay = -1; @@ -99,6 +97,7 @@ void matrix_init(void) { #if DIODE_DIRECTION == COL2ROW uint8_t matrix_scan(void) { + static matrix_row_t debouncing_matrix[MATRIX_ROWS]; for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { toggle_row(r); matrix_row_t state = read_cols(); @@ -146,6 +145,7 @@ matrix_row_t matrix_get_row(uint8_t row) { #else uint8_t matrix_scan(void) { + static matrix_col_t debouncing_matrix[MATRIX_COLS]; for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { toggle_col(c); matrix_col_t state = read_rows(); -- cgit v1.2.1 From de57799530d3184722532f93d156364067d8fcd5 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 28 May 2016 11:56:06 -0400 Subject: brings alps64 up-to-date (needs testing) --- quantum/matrix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index d5fd7def8a..412662a794 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -68,8 +68,10 @@ uint8_t matrix_cols(void) { void matrix_init(void) { /* frees PORTF by setting the JTD bit twice within four cycles */ - MCUCR |= _BV(JTD); - MCUCR |= _BV(JTD); + #ifdef __AVR_ATmega32U4__ + MCUCR |= _BV(JTD); + MCUCR |= _BV(JTD); + #endif /* initializes the I/O pins */ #if DIODE_DIRECTION == COL2ROW for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { -- cgit v1.2.1 From 008c8d54a0a1a1e908d372d0fe9edb45a2d491e5 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 17 Jun 2016 22:09:59 -0400 Subject: adds power_up to quantum's matrix file --- quantum/matrix.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 412662a794..4f1564ac87 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -66,6 +66,30 @@ uint8_t matrix_cols(void) { return MATRIX_COLS; } +void matrix_power_up(void) { +#if DIODE_DIRECTION == COL2ROW + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + /* DDRxn */ + _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit); + toggle_row(r); + } + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + /* PORTxn */ + _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit); + } +#else + for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { + /* DDRxn */ + _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit); + toggle_col(c); + } + for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { + /* PORTxn */ + _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit); + } +#endif +} + void matrix_init(void) { /* frees PORTF by setting the JTD bit twice within four cycles */ #ifdef __AVR_ATmega32U4__ -- cgit v1.2.1 From 13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 23 Jun 2016 22:18:20 -0400 Subject: Backlight abstraction and other changes (#439) * redoes matrix pins, abstracts backlight code for B5,6,7 * slimming down keyboard stuff, backlight breathing implemented * don't call backlight init when no pin * cleans up user/kb/quantum calls, keyboard files * fix pvc atomic * replaces CHANNEL with correct var in breathing * removes .hexs, updates readmes, updates template * cleans-up clueboards, readmes to lowercase * updates readme --- quantum/matrix.c | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 4f1564ac87..6e9f92727f 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -32,8 +32,8 @@ along with this program. If not, see . # define DEBOUNCING_DELAY 5 #endif -static const io_pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; -static const io_pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; /* matrix state */ #if DIODE_DIRECTION == COL2ROW static matrix_row_t matrix[MATRIX_ROWS]; @@ -52,10 +52,30 @@ static matrix_col_t read_rows(void); __attribute__ ((weak)) void matrix_init_quantum(void) { + matrix_init_kb(); } __attribute__ ((weak)) void matrix_scan_quantum(void) { + matrix_scan_kb(); +} + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +__attribute__ ((weak)) +void matrix_init_user(void) { +} + +__attribute__ ((weak)) +void matrix_scan_user(void) { } uint8_t matrix_rows(void) { @@ -70,22 +90,22 @@ void matrix_power_up(void) { #if DIODE_DIRECTION == COL2ROW for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { /* DDRxn */ - _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit); + _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF); toggle_row(r); } for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { /* PORTxn */ - _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit); + _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF); } #else for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { /* DDRxn */ - _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit); + _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF); toggle_col(c); } for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { /* PORTxn */ - _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit); + _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF); } #endif } @@ -100,22 +120,22 @@ void matrix_init(void) { #if DIODE_DIRECTION == COL2ROW for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { /* DDRxn */ - _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit); + _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF); toggle_row(r); } for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { /* PORTxn */ - _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit); + _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF); } #else for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { /* DDRxn */ - _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit); + _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF); toggle_col(c); } for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { /* PORTxn */ - _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit); + _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF); } #endif matrix_init_quantum(); @@ -151,14 +171,14 @@ uint8_t matrix_scan(void) { static void toggle_row(uint8_t row) { /* PINxn */ - _SFR_IO8(row_pins[row].input_addr) = _BV(row_pins[row].bit); + _SFR_IO8((row_pins[row] >> 4)) = _BV(row_pins[row] & 0xF); } static matrix_row_t read_cols(void) { matrix_row_t state = 0; for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { /* PINxn */ - if (!(_SFR_IO8(col_pins[c].input_addr) & _BV(col_pins[c].bit))) { + if (!(_SFR_IO8((col_pins[c] >> 4)) & _BV(col_pins[c] & 0xF))) { state |= (matrix_row_t)1 << c; } } @@ -199,14 +219,14 @@ uint8_t matrix_scan(void) { static void toggle_col(uint8_t col) { /* PINxn */ - _SFR_IO8(col_pins[col].input_addr) = _BV(col_pins[col].bit); + _SFR_IO8((col_pins[col] >> 4)) = _BV(col_pins[col] & 0xF); } static matrix_col_t read_rows(void) { matrix_col_t state = 0; for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { /* PINxn */ - if (!(_SFR_IO8(row_pins[r].input_addr) & _BV(row_pins[r].bit))) { + if (!(_SFR_IO8((row_pins[r] >> 4)) & _BV(row_pins[r] & 0xF))) { state |= (matrix_col_t)1 << r; } } -- cgit v1.2.1 From 215c2119af5281072d5a6efb0308408793cadd08 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 29 Jun 2016 16:21:41 -0400 Subject: Implements subprojects and updates projects for this (#459) * non-working commit * working * subprojects implemented for planck * pass a subproject variable through to c * consolidates clueboard revisions * thanks for letting me know about conflicts.. * turn off audio for yang's * corrects starting paths for subprojects * messing around with travis * semicolon * travis script * travis script * script for travis * correct directory (probably), amend files to commit * remove origin before adding * git pull, correct syntax * git checkout * git pull origin branch * where are we? * where are we? * merging * force things to happen * adds commit message, adds add * rebase, no commit message * rebase branch * idk! * try just pull * fetch - merge * specify repo branch * checkout * goddammit * merge? idk * pls * after all * don't split up keyboards * syntax * adds quick for all-keyboards * trying out new script * script update * lowercase * all keyboards * stop replacing compiled.hex automatically * adds if statement * skip automated build branches * forces push to automated build branch * throw an add in there * upstream? * adds AUTOGEN * ignore all .hex files again * testing out new repo * global ident * generate script, keyboard_keymap.hex * skip generation for now, print pandoc info, submodule update * try trusty * and sudo * try generate * updates subprojects to keyboards * no idea * updates to keyboards * cleans up clueboard stuff * setup to use local readme * updates cluepad, planck experimental * remove extra led.c [ci skip] * disable power up for now * config files updates * makefile updates * .h file updates, config tuning * disable audio for yang --- quantum/matrix.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 6e9f92727f..f5744658cf 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -86,29 +86,29 @@ uint8_t matrix_cols(void) { return MATRIX_COLS; } -void matrix_power_up(void) { -#if DIODE_DIRECTION == COL2ROW - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - /* DDRxn */ - _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF); - toggle_row(r); - } - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - /* PORTxn */ - _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF); - } -#else - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - /* DDRxn */ - _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF); - toggle_col(c); - } - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - /* PORTxn */ - _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF); - } -#endif -} +// void matrix_power_up(void) { +// #if DIODE_DIRECTION == COL2ROW +// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { +// /* DDRxn */ +// _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF); +// toggle_row(r); +// } +// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { +// /* PORTxn */ +// _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF); +// } +// #else +// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { +// /* DDRxn */ +// _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF); +// toggle_col(c); +// } +// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { +// /* PORTxn */ +// _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF); +// } +// #endif +// } void matrix_init(void) { /* frees PORTF by setting the JTD bit twice within four cycles */ -- cgit v1.2.1 From 4d4f7684e684bec319f166121463a88cd4a62703 Mon Sep 17 00:00:00 2001 From: fredizzimo Date: Fri, 1 Jul 2016 17:04:53 +0300 Subject: Add ChibiOS support for QMK (#465) * Modularity and gcc warnings fixes. * Add ChibiOS support (USB stack + support files). * Make usb_main more USB_DRIVER #define independent. * Move chibios to tool. * Implement jump-to-bootloader. * Small updates. * Fix bootloader-jump compiling. * Move AVR specific sleep_led.c into avr. * Add basic sleep_led for chibios. * Update chibios README. * NKRO fixes. * Rename some Makefile defines. * Move STM32 bootloader address config to separate .h file. * Add ARM Teensies bootloader code. * Fix chibios/usb_main GET_REPORT handing. * Add missing #include to keymap.c. * Make bootmagic.c code portable (_delay_ms -> wait_ms). * Move declaration of keymap_config. Should really not declare variables in .h files - since it's included in different .c files, a proper linker then complains that the same variable is declared more than once (once for each .c file that the offending .h is included in). * Add eeprom support for chibios/kinetis. * Rename chibios example keyboard. * Move chibios/cortex selection to local Makefiles. * Chibios: use WFI in idle. WIP suspend stuff. * ChibiOS/kinetis: sending remote wakeup. * ChibiOS/STM32: send remote wakeup. * Fix report size of boot protocol. * Fix drop key stroke Keyboard report should be checked if its transfer finishs successfully. Otherwise key stroke can be missing when other key event occurs before the last report transfer is done. Boot protocol 10ms interval probably causes this problem in case it receives key events in a row within the period. NKRO protocol suffers less or nothing due to its interval 1ms. * Chibios/usb_main: rename a variable for clarity. * Add correct chibios/bootloader_jump for infinity KB. * ChibiOS: make reset request more CMSISy. * Chibios: Add breathing sleep LED on Kinetis MCUs. * ChibiOS: Update infinity bootloader code to match updated ChibiOS. * ChibiOS: prettify/document sleep_led code. * Chibios: Remove the wait in the main loop. * Add maple mini code. * Do timeout when writing to CONSOLE EP queue. Fixes TMK bug #266. * Chibios: add 'core/protocol' to the makefiles' search path. * Chibios: Update to new USB API. * Chibios: add more guards for transmitting (fix a deadlock bug). * Add update for chibios in README * Chibios: Fix a HardFault bug (wait after start). * Chibios: cleanup usb_main code. * Chibios: Revert common.mk change (fix AVR linking problem). * core: Fix chibios user compile options Compile options can be defined in project Makefile such as UDEFS, UADEFS, UINCDIR, ULIBDIR and ULIBS. * Sysv format for ChibiOS arm-none-eabi-size Some new patches to ChibiOS puts heap as it's own section. So the berkeley format is now useless, as the heap will be included in the BSS report. The sysv format displays the bss size correctly. * Fix hard-coded path of CHIBIOS * Add support for new version of ChibiOS and Contrib The Kinetis support has moved to a separate Contrib repository in the newest version of Chibios. There has also been some structure changes. So this adds support for those, while maintaining back- wards compability. * Update ChibiOS instructions * Chibios: implement sleep LED for STM32. * Chibios: Update the main chibios README. * Chibios: fix STM32_BOOTLOADER_ADDRESS name. * Chibios: make the default bootloader_jump redefinable (weak). * Chibios: disable LTO (link-time optimisation). With LTO enabled, sometimes things fail for mysterious reasons (e.g. bootloader jump on WF with LEDs enabled), just because the linker optimisation is too aggressive. * Chibios: add default location for chibios-contrib. * ChibiOS: update mk to match chibios/master. * ChibiOS: update instructions.md. * Add chibi_onekey example. * Add comments to chibi_onekey Makefile. * Rename some Makefile defines. * Move STM32 bootloader address config to separate .h file. * Rename chibios example keyboard. * Move chibios/cortex selection to local Makefiles. * Add Teensy LC onekey example. * Chibios: use WFI in idle. WIP suspend stuff. * Update chibi/teensy instructions. * Update chibios/Teensy instructions. * Add infinity_chibios * Add keymap_hasu.c * Infinity_chibios: select correct bootloader_jump. * Infinity_chibios: improve comments. * Add generic STM32F103C8T6 example. * Add maple mini code. * STM32F103x fixes. * Add maple mini pinout pic. * Chibios: updates for 3.0.4 git. * Chibios: rename example stm32_onekey -> stm32_f072_onekey. * Chibios: add makefiles for Teensy 3.x examples. * Chibios: update Teensy 3.x instructions. * Chibios: Tsy LC is cortex-m0plus. * Chibios: add more guards for transmitting (fix a deadlock bug). * Change README for chibios * Chibios: update examples to current chibios git. Match the changes in mainline chibios: - update chconf.h - update supplied ld scripts structure - update Teensy instructions (switch to official chibios and introduce contrib) * Add ChibiOS and ChibiOS-Contrib submodules Also fix the makefile path for them. * Moves chibios keyboards to keyboards folder * First version of ChibiOS compilation Only the stm32_f072_onkey keyboard is ported at the moment. It compiles, but still doesn't link. * More chibios fixes It now compiles without warnings and links * Move the teensy_lc_onekey to the keyboards folder * Clean up the make file rule structure * Remove keymap_fn_to_action * Update more ChibiOS keyboards to QMK Most of them does not compile at the moment though. * Use older version of Chibios libraries The newest ones have problems with compilation * Remove USB_UNCONFIGURED event It isn't present in the older version of ChibiOS * Fix the infinity_chibios compilation * Fix potentially uninitialized variable * Add missing include * Fix the ChibiOS makefile * Fix some Chibios keyboard compilation * Revert the rules.mk file back to master version * Combine the chibios and AVR makefiles With just the required overrides in the respective platform specific one. * Slight makefile restrucuring Platform specific compiler options * Move avr specific targets out of the main rules * Fix ChibiOS objcopy The ChibiOS objcopy needs different parameters, so the parameters are moved to the corresponding platform rule file * Fix the objcopy for real this time The comands were moved around, so chibios used avr and the ohter way around. Also change the objsize output format * Fix the thumb flags * Fix the infinity hasu keymap * Per platform cpp flags * Add gcc-arm-none-eabi package to travis * Add arm-none-eabi-newlib to travis * Fix the name of the libnewlib-arm-none-eabi lib * Fix the ChibiOS paths So that they are properly relative, and builds don't generate extra folders * Fix the board path of stm32_f103_onekey * Only consider folders with Makefiles as subproject --- quantum/matrix.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index f5744658cf..a38c13f15b 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -17,7 +17,9 @@ along with this program. If not, see . */ #include #include +#if defined(__AVR__) #include +#endif #include "wait.h" #include "print.h" #include "debug.h" -- cgit v1.2.1 From 8e88d55bfd7c88cb15845e0c6415e4e892532861 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 4 Jul 2016 11:45:58 -0400 Subject: reverts #343 for the most part (#474) --- quantum/matrix.c | 292 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 163 insertions(+), 129 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index a38c13f15b..0949170255 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -26,32 +26,46 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" -#ifdef MATRIX_HAS_GHOST -# error "The universal matrix.c file cannot be used for this keyboard." -#endif +/* Set 0 if debouncing isn't needed */ +/* + * This constant define not debouncing time in msecs, but amount of matrix + * scan loops which should be made to get stable debounced results. + * + * On Ergodox matrix scan rate is relatively low, because of slow I2C. + * Now it's only 317 scans/second, or about 3.15 msec/scan. + * According to Cherry specs, debouncing time is 5 msec. + * + * And so, there is no sense to have DEBOUNCE higher than 2. + */ #ifndef DEBOUNCING_DELAY # define DEBOUNCING_DELAY 5 #endif +static uint8_t debouncing = DEBOUNCING_DELAY; static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -/* matrix state */ -#if DIODE_DIRECTION == COL2ROW + +/* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; -#else -static matrix_col_t matrix[MATRIX_COLS]; +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 int8_t debouncing_delay = -1; -#if DIODE_DIRECTION == COL2ROW -static void toggle_row(uint8_t row); -static matrix_row_t read_cols(void); +#if MATRIX_COLS > 16 + #define SHIFTER 1UL #else -static void toggle_col(uint8_t col); -static matrix_col_t read_rows(void); + #define SHIFTER 1 #endif +static matrix_row_t read_cols(void); +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); + __attribute__ ((weak)) void matrix_init_quantum(void) { matrix_init_kb(); @@ -80,10 +94,12 @@ __attribute__ ((weak)) void matrix_scan_user(void) { } +inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } +inline uint8_t matrix_cols(void) { return MATRIX_COLS; } @@ -113,161 +129,179 @@ uint8_t matrix_cols(void) { // } void matrix_init(void) { - /* frees PORTF by setting the JTD bit twice within four cycles */ + // To use PORTF disable JTAG with writing JTD bit twice within four cycles. #ifdef __AVR_ATmega32U4__ MCUCR |= _BV(JTD); MCUCR |= _BV(JTD); #endif - /* initializes the I/O pins */ -#if DIODE_DIRECTION == COL2ROW - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - /* DDRxn */ - _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF); - toggle_row(r); - } - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - /* PORTxn */ - _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF); - } -#else - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - /* DDRxn */ - _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF); - toggle_col(c); - } - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - /* PORTxn */ - _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF); + + // initialize row and col + unselect_rows(); + init_cols(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; } -#endif + matrix_init_quantum(); } +uint8_t matrix_scan(void) +{ + #if DIODE_DIRECTION == COL2ROW -uint8_t matrix_scan(void) { - static matrix_row_t debouncing_matrix[MATRIX_ROWS]; - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - toggle_row(r); - matrix_row_t state = read_cols(); - if (debouncing_matrix[r] != state) { - debouncing_matrix[r] = state; - debouncing_delay = DEBOUNCING_DELAY; - } - toggle_row(r); - } - if (debouncing_delay >= 0) { - dprintf("Debouncing delay remaining: %X\n", debouncing_delay); - --debouncing_delay; - if (debouncing_delay >= 0) { - wait_ms(1); - } - else { - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - matrix[r] = debouncing_matrix[r]; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + select_row(i); + wait_us(30); // without this wait read unstable value. + matrix_row_t cols = read_cols(); + if (matrix_debouncing[i] != cols) { + matrix_debouncing[i] = cols; + if (debouncing) { + debug("bounce!: "); debug_hex(debouncing); debug("\n"); } + debouncing = DEBOUNCING_DELAY; } + unselect_rows(); } - matrix_scan_quantum(); - return 1; -} - -static void toggle_row(uint8_t row) { - /* PINxn */ - _SFR_IO8((row_pins[row] >> 4)) = _BV(row_pins[row] & 0xF); -} -static matrix_row_t read_cols(void) { - matrix_row_t state = 0; - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - /* PINxn */ - if (!(_SFR_IO8((col_pins[c] >> 4)) & _BV(col_pins[c] & 0xF))) { - state |= (matrix_row_t)1 << c; + if (debouncing) { + if (--debouncing) { + wait_us(1); + } else { + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + matrix[i] = matrix_debouncing[i]; + } } } - return state; -} - -matrix_row_t matrix_get_row(uint8_t row) { - return matrix[row]; -} - #else -uint8_t matrix_scan(void) { - static matrix_col_t debouncing_matrix[MATRIX_COLS]; - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - toggle_col(c); - matrix_col_t state = read_rows(); - if (debouncing_matrix[c] != state) { - debouncing_matrix[c] = state; - debouncing_delay = DEBOUNCING_DELAY; + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + select_row(i); + wait_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 = DEBOUNCING_DELAY; } - toggle_col(c); + unselect_rows(); } - if (debouncing_delay >= 0) { - dprintf("Debouncing delay remaining: %X\n", debouncing_delay); - --debouncing_delay; - if (debouncing_delay >= 0) { - wait_ms(1); - } - else { - for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { - matrix[c] = debouncing_matrix[c]; + + if (debouncing) { + if (--debouncing) { + wait_us(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 + matrix_scan_quantum(); + return 1; } -static void toggle_col(uint8_t col) { - /* PINxn */ - _SFR_IO8((col_pins[col] >> 4)) = _BV(col_pins[col] & 0xF); +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; } -static matrix_col_t read_rows(void) { - matrix_col_t state = 0; - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - /* PINxn */ - if (!(_SFR_IO8((row_pins[r] >> 4)) & _BV(row_pins[r] & 0xF))) { - state |= (matrix_col_t)1 << r; - } +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1= 0; --c) { - if (matrix[c] & mask) { - state |= (matrix_row_t)1 << c; - } +uint8_t matrix_key_count(void) +{ + uint8_t count = 0; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + count += bitpop16(matrix[i]); } - return state; + return count; } +static void init_cols(void) +{ +#if DIODE_DIRECTION == COL2ROW + for(int x = 0; x < MATRIX_COLS; x++) { + int pin = col_pins[x]; +#else + for(int x = 0; x < MATRIX_ROWS; x++) { + int pin = row_pins[x]; #endif - -bool matrix_is_modified(void) { - if (debouncing_delay >= 0) return false; - return true; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); + } } -bool matrix_is_on(uint8_t row, uint8_t col) { - return matrix_get_row(row) & (matrix_row_t)1 << col; -} +static matrix_row_t read_cols(void) +{ + matrix_row_t result = 0; -void matrix_print(void) { - dprintln("Human-readable matrix state:"); - for (uint8_t r = 0; r < MATRIX_ROWS; r++) { - dprintf("State of row %X: %016b\n", r, bitrev16(matrix_get_row(r))); +#if DIODE_DIRECTION == COL2ROW + for(int x = 0; x < MATRIX_COLS; x++) { + int pin = col_pins[x]; +#else + for(int x = 0; x < MATRIX_ROWS; x++) { + int pin = row_pins[x]; +#endif + result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (SHIFTER << x); } + return result; } -uint8_t matrix_key_count(void) { - uint8_t count = 0; - for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { - count += bitpop16(matrix_get_row(r)); +static void unselect_rows(void) +{ +#if DIODE_DIRECTION == COL2ROW + for(int x = 0; x < MATRIX_ROWS; x++) { + int pin = row_pins[x]; +#else + for(int x = 0; x < MATRIX_COLS; x++) { + int pin = col_pins[x]; +#endif + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); } - return count; +} + +static void select_row(uint8_t row) +{ + +#if DIODE_DIRECTION == COL2ROW + int pin = row_pins[row]; +#else + int pin = col_pins[row]; +#endif + _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); + _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); } -- cgit v1.2.1 From 3577e26fd9916ceab58779ec6323d43da54eb3b5 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 6 Jul 2016 00:24:31 -0400 Subject: fix/annotate wait_us lines --- quantum/matrix.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'quantum/matrix.c') diff --git a/quantum/matrix.c b/quantum/matrix.c index 0949170255..3174e07390 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -27,16 +27,6 @@ along with this program. If not, see . #include "matrix.h" /* Set 0 if debouncing isn't needed */ -/* - * This constant define not debouncing time in msecs, but amount of matrix - * scan loops which should be made to get stable debounced results. - * - * On Ergodox matrix scan rate is relatively low, because of slow I2C. - * Now it's only 317 scans/second, or about 3.15 msec/scan. - * According to Cherry specs, debouncing time is 5 msec. - * - * And so, there is no sense to have DEBOUNCE higher than 2. - */ #ifndef DEBOUNCING_DELAY # define DEBOUNCING_DELAY 5 @@ -168,7 +158,7 @@ uint8_t matrix_scan(void) if (debouncing) { if (--debouncing) { - wait_us(1); + wait_ms(1); } else { for (uint8_t i = 0; i < MATRIX_ROWS; i++) { matrix[i] = matrix_debouncing[i]; @@ -192,7 +182,7 @@ uint8_t matrix_scan(void) if (debouncing) { if (--debouncing) { - wait_us(1); + wait_ms(1); } else { for (uint8_t i = 0; i < MATRIX_COLS; i++) { matrix_reversed[i] = matrix_reversed_debouncing[i]; -- cgit v1.2.1