diff options
| author | Alex Ong <the.onga@gmail.com> | 2019-01-04 19:43:45 +1100 |
|---|---|---|
| committer | Alex Ong <the.onga@gmail.com> | 2019-01-04 19:43:45 +1100 |
| commit | 2bb2977c133646c4e056960e72029270d77cc1eb (patch) | |
| tree | 235d491f992121ac1716c5bf2fafb80983748576 /quantum/matrix.c | |
| parent | a55c838961c89097ab849ed6cb1f261791e6b9b4 (diff) | |
| parent | 47c91fc7f75ae0a477e55b687aa0fc30da0a283c (diff) | |
| download | qmk_firmware-2bb2977c133646c4e056960e72029270d77cc1eb.tar.gz qmk_firmware-2bb2977c133646c4e056960e72029270d77cc1eb.zip | |
Merge branch 'master' into debounce_refactor
# Conflicts:
# tmk_core/common/keyboard.c
Diffstat (limited to 'quantum/matrix.c')
| -rw-r--r-- | quantum/matrix.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index bc7eb6b58..292171490 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Copyright 2012-2017 Jun Wako, Jack Humbert | 2 | Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
| @@ -16,15 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 16 | */ | 16 | */ |
| 17 | #include <stdint.h> | 17 | #include <stdint.h> |
| 18 | #include <stdbool.h> | 18 | #include <stdbool.h> |
| 19 | #if defined(__AVR__) | ||
| 20 | #include <avr/io.h> | ||
| 21 | #endif | ||
| 22 | #include "wait.h" | 19 | #include "wait.h" |
| 23 | #include "print.h" | 20 | #include "print.h" |
| 24 | #include "debug.h" | 21 | #include "debug.h" |
| 25 | #include "util.h" | 22 | #include "util.h" |
| 26 | #include "matrix.h" | 23 | #include "matrix.h" |
| 27 | #include "timer.h" | 24 | #include "timer.h" |
| 25 | #include "quantum.h" | ||
| 28 | 26 | ||
| 29 | 27 | ||
| 30 | #if (MATRIX_COLS <= 8) | 28 | #if (MATRIX_COLS <= 8) |
| @@ -49,8 +47,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 49 | #endif | 47 | #endif |
| 50 | 48 | ||
| 51 | #if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) | 49 | #if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) |
| 52 | static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | 50 | static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; |
| 53 | static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | 51 | static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; |
| 54 | #endif | 52 | #endif |
| 55 | 53 | ||
| 56 | /* matrix state(1:on, 0:off) */ | 54 | /* matrix state(1:on, 0:off) */ |
| @@ -198,9 +196,7 @@ uint8_t matrix_key_count(void) | |||
| 198 | static void init_cols(void) | 196 | static void init_cols(void) |
| 199 | { | 197 | { |
| 200 | for(uint8_t x = 0; x < MATRIX_COLS; x++) { | 198 | for(uint8_t x = 0; x < MATRIX_COLS; x++) { |
| 201 | uint8_t pin = col_pins[x]; | 199 | setPinInputHigh(col_pins[x]); |
| 202 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 203 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 204 | } | 200 | } |
| 205 | } | 201 | } |
| 206 | 202 | ||
| @@ -220,8 +216,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
| 220 | for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 216 | for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
| 221 | 217 | ||
| 222 | // Select the col pin to read (active low) | 218 | // Select the col pin to read (active low) |
| 223 | uint8_t pin = col_pins[col_index]; | 219 | uint8_t pin_state = readPin(col_pins[col_index]); |
| 224 | uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); | ||
| 225 | 220 | ||
| 226 | // Populate the matrix row with the state of the col pin | 221 | // Populate the matrix row with the state of the col pin |
| 227 | current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); | 222 | current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); |
| @@ -235,24 +230,19 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
| 235 | 230 | ||
| 236 | static void select_row(uint8_t row) | 231 | static void select_row(uint8_t row) |
| 237 | { | 232 | { |
| 238 | uint8_t pin = row_pins[row]; | 233 | setPinOutput(row_pins[row]); |
| 239 | _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT | 234 | writePinLow(row_pins[row]); |
| 240 | _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW | ||
| 241 | } | 235 | } |
| 242 | 236 | ||
| 243 | static void unselect_row(uint8_t row) | 237 | static void unselect_row(uint8_t row) |
| 244 | { | 238 | { |
| 245 | uint8_t pin = row_pins[row]; | 239 | setPinInputHigh(row_pins[row]); |
| 246 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 247 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 248 | } | 240 | } |
| 249 | 241 | ||
| 250 | static void unselect_rows(void) | 242 | static void unselect_rows(void) |
| 251 | { | 243 | { |
| 252 | for(uint8_t x = 0; x < MATRIX_ROWS; x++) { | 244 | for(uint8_t x = 0; x < MATRIX_ROWS; x++) { |
| 253 | uint8_t pin = row_pins[x]; | 245 | setPinInput(row_pins[x]); |
| 254 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 255 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 256 | } | 246 | } |
| 257 | } | 247 | } |
| 258 | 248 | ||
| @@ -261,9 +251,7 @@ static void unselect_rows(void) | |||
| 261 | static void init_rows(void) | 251 | static void init_rows(void) |
| 262 | { | 252 | { |
| 263 | for(uint8_t x = 0; x < MATRIX_ROWS; x++) { | 253 | for(uint8_t x = 0; x < MATRIX_ROWS; x++) { |
| 264 | uint8_t pin = row_pins[x]; | 254 | setPinInputHigh(row_pins[x]); |
| 265 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 266 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 267 | } | 255 | } |
| 268 | } | 256 | } |
| 269 | 257 | ||
| @@ -283,7 +271,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
| 283 | matrix_row_t last_row_value = current_matrix[row_index]; | 271 | matrix_row_t last_row_value = current_matrix[row_index]; |
| 284 | 272 | ||
| 285 | // Check row pin state | 273 | // Check row pin state |
| 286 | if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) | 274 | if (readPin(row_pins[row_index]) == 0) |
| 287 | { | 275 | { |
| 288 | // Pin LO, set col bit | 276 | // Pin LO, set col bit |
| 289 | current_matrix[row_index] |= (ROW_SHIFTER << current_col); | 277 | current_matrix[row_index] |= (ROW_SHIFTER << current_col); |
| @@ -309,24 +297,19 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
| 309 | 297 | ||
| 310 | static void select_col(uint8_t col) | 298 | static void select_col(uint8_t col) |
| 311 | { | 299 | { |
| 312 | uint8_t pin = col_pins[col]; | 300 | setPinOutput(col_pins[col]); |
| 313 | _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT | 301 | writePinLow(col_pins[col]); |
| 314 | _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW | ||
| 315 | } | 302 | } |
| 316 | 303 | ||
| 317 | static void unselect_col(uint8_t col) | 304 | static void unselect_col(uint8_t col) |
| 318 | { | 305 | { |
| 319 | uint8_t pin = col_pins[col]; | 306 | setPinInputHigh(col_pins[col]); |
| 320 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 321 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 322 | } | 307 | } |
| 323 | 308 | ||
| 324 | static void unselect_cols(void) | 309 | static void unselect_cols(void) |
| 325 | { | 310 | { |
| 326 | for(uint8_t x = 0; x < MATRIX_COLS; x++) { | 311 | for(uint8_t x = 0; x < MATRIX_COLS; x++) { |
| 327 | uint8_t pin = col_pins[x]; | 312 | setPinInputHigh(col_pins[x]); |
| 328 | _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN | ||
| 329 | _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI | ||
| 330 | } | 313 | } |
| 331 | } | 314 | } |
| 332 | 315 | ||
