diff options
| author | IBNobody <ibnobody@gmail.com> | 2016-10-23 23:00:43 -0500 |
|---|---|---|
| committer | IBNobody <ibnobody@gmail.com> | 2016-10-23 23:00:43 -0500 |
| commit | 17170ba76d3c94edcf1ab263520238fdb0384774 (patch) | |
| tree | 4b80ab5544e6f53464068210278f0405bd596c41 /quantum/matrix.c | |
| parent | 05ceef2350dbd72f696d70b8a2567d048fa147dc (diff) | |
| download | qmk_firmware-17170ba76d3c94edcf1ab263520238fdb0384774.tar.gz qmk_firmware-17170ba76d3c94edcf1ab263520238fdb0384774.zip | |
Fixed some large keyboard bugs
Fixed some bugs relating to keyboards with more than 16 columns. Also
added the ability to mask off keyboard matrix bits.
Diffstat (limited to 'quantum/matrix.c')
| -rw-r--r-- | quantum/matrix.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index 3174e0739..ac81794e5 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -26,6 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 26 | #include "util.h" | 26 | #include "util.h" |
| 27 | #include "matrix.h" | 27 | #include "matrix.h" |
| 28 | 28 | ||
| 29 | #ifdef MATRIX_MASKED | ||
| 30 | extern const matrix_row_t matrix_mask[]; | ||
| 31 | #endif | ||
| 32 | |||
| 29 | /* Set 0 if debouncing isn't needed */ | 33 | /* Set 0 if debouncing isn't needed */ |
| 30 | 34 | ||
| 31 | #ifndef DEBOUNCING_DELAY | 35 | #ifndef DEBOUNCING_DELAY |
| @@ -218,15 +222,34 @@ bool matrix_is_on(uint8_t row, uint8_t col) | |||
| 218 | inline | 222 | inline |
| 219 | matrix_row_t matrix_get_row(uint8_t row) | 223 | matrix_row_t matrix_get_row(uint8_t row) |
| 220 | { | 224 | { |
| 225 | // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a | ||
| 226 | // switch blocker installed and the switch is always pressed. | ||
| 227 | #ifdef MATRIX_MASKED | ||
| 228 | return matrix[row] & matrix_mask[row]; | ||
| 229 | #else | ||
| 221 | return matrix[row]; | 230 | return matrix[row]; |
| 231 | #endif | ||
| 222 | } | 232 | } |
| 223 | 233 | ||
| 224 | void matrix_print(void) | 234 | void matrix_print(void) |
| 225 | { | 235 | { |
| 236 | #if (MATRIX_COLS <= 8) | ||
| 237 | print("\nr/c 01234567\n"); | ||
| 238 | #elif (MATRIX_COLS <= 16) | ||
| 226 | print("\nr/c 0123456789ABCDEF\n"); | 239 | print("\nr/c 0123456789ABCDEF\n"); |
| 240 | #elif (MATRIX_COLS <= 32) | ||
| 241 | print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n"); | ||
| 242 | #endif | ||
| 243 | |||
| 227 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | 244 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { |
| 228 | phex(row); print(": "); | 245 | phex(row); print(": "); |
| 229 | pbin_reverse16(matrix_get_row(row)); | 246 | #if (MATRIX_COLS <= 8) |
| 247 | print_bin_reverse8(matrix_get_row(row)); | ||
| 248 | #elif (MATRIX_COLS <= 16) | ||
| 249 | print_bin_reverse16(matrix_get_row(row)); | ||
| 250 | #elif (MATRIX_COLS <= 32) | ||
| 251 | print_bin_reverse32(matrix_get_row(row)); | ||
| 252 | #endif | ||
| 230 | print("\n"); | 253 | print("\n"); |
| 231 | } | 254 | } |
| 232 | } | 255 | } |
| @@ -235,7 +258,13 @@ uint8_t matrix_key_count(void) | |||
| 235 | { | 258 | { |
| 236 | uint8_t count = 0; | 259 | uint8_t count = 0; |
| 237 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 260 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
| 261 | #if (MATRIX_COLS <= 8) | ||
| 262 | count += bitpop(matrix[i]); | ||
| 263 | #elif (MATRIX_COLS <= 16) | ||
| 238 | count += bitpop16(matrix[i]); | 264 | count += bitpop16(matrix[i]); |
| 265 | #elif (MATRIX_COLS <= 32) | ||
| 266 | count += bitpop32(matrix[i]); | ||
| 267 | #endif | ||
| 239 | } | 268 | } |
| 240 | return count; | 269 | return count; |
| 241 | } | 270 | } |
| @@ -259,7 +288,7 @@ static matrix_row_t read_cols(void) | |||
| 259 | matrix_row_t result = 0; | 288 | matrix_row_t result = 0; |
| 260 | 289 | ||
| 261 | #if DIODE_DIRECTION == COL2ROW | 290 | #if DIODE_DIRECTION == COL2ROW |
| 262 | for(int x = 0; x < MATRIX_COLS; x++) { | 291 | for(int x = 0; x < MATRIX_COLS; x++) { |
| 263 | int pin = col_pins[x]; | 292 | int pin = col_pins[x]; |
| 264 | #else | 293 | #else |
| 265 | for(int x = 0; x < MATRIX_ROWS; x++) { | 294 | for(int x = 0; x < MATRIX_ROWS; x++) { |
| @@ -273,10 +302,10 @@ static matrix_row_t read_cols(void) | |||
| 273 | static void unselect_rows(void) | 302 | static void unselect_rows(void) |
| 274 | { | 303 | { |
| 275 | #if DIODE_DIRECTION == COL2ROW | 304 | #if DIODE_DIRECTION == COL2ROW |
| 276 | for(int x = 0; x < MATRIX_ROWS; x++) { | 305 | for(int x = 0; x < MATRIX_ROWS; x++) { |
| 277 | int pin = row_pins[x]; | 306 | int pin = row_pins[x]; |
| 278 | #else | 307 | #else |
| 279 | for(int x = 0; x < MATRIX_COLS; x++) { | 308 | for(int x = 0; x < MATRIX_COLS; x++) { |
| 280 | int pin = col_pins[x]; | 309 | int pin = col_pins[x]; |
| 281 | #endif | 310 | #endif |
| 282 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); | 311 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); |
