diff options
Diffstat (limited to 'quantum/matrix.c')
| -rw-r--r-- | quantum/matrix.c | 68 |
1 files changed, 6 insertions, 62 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index 907492a0f..62a86fba6 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -17,30 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 17 | #include <stdint.h> | 17 | #include <stdint.h> |
| 18 | #include <stdbool.h> | 18 | #include <stdbool.h> |
| 19 | #include "wait.h" | 19 | #include "wait.h" |
| 20 | #include "print.h" | ||
| 21 | #include "debug.h" | ||
| 22 | #include "util.h" | 20 | #include "util.h" |
| 23 | #include "matrix.h" | 21 | #include "matrix.h" |
| 24 | #include "debounce.h" | 22 | #include "debounce.h" |
| 25 | #include "quantum.h" | 23 | #include "quantum.h" |
| 26 | 24 | ||
| 27 | #if (MATRIX_COLS <= 8) | ||
| 28 | # define print_matrix_header() print("\nr/c 01234567\n") | ||
| 29 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) | ||
| 30 | # define matrix_bitpop(i) bitpop(matrix[i]) | ||
| 31 | # define ROW_SHIFTER ((uint8_t)1) | ||
| 32 | #elif (MATRIX_COLS <= 16) | ||
| 33 | # define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") | ||
| 34 | # define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) | ||
| 35 | # define matrix_bitpop(i) bitpop16(matrix[i]) | ||
| 36 | # define ROW_SHIFTER ((uint16_t)1) | ||
| 37 | #elif (MATRIX_COLS <= 32) | ||
| 38 | # define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") | ||
| 39 | # define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) | ||
| 40 | # define matrix_bitpop(i) bitpop32(matrix[i]) | ||
| 41 | # define ROW_SHIFTER ((uint32_t)1) | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifdef MATRIX_MASKED | 25 | #ifdef MATRIX_MASKED |
| 45 | extern const matrix_row_t matrix_mask[]; | 26 | extern const matrix_row_t matrix_mask[]; |
| 46 | #endif | 27 | #endif |
| @@ -56,27 +37,7 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | |||
| 56 | static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | 37 | static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values |
| 57 | static matrix_row_t matrix[MATRIX_ROWS]; // debounced values | 38 | static matrix_row_t matrix[MATRIX_ROWS]; // debounced values |
| 58 | 39 | ||
| 59 | __attribute__((weak)) void matrix_init_quantum(void) { matrix_init_kb(); } | 40 | // helper functions |
| 60 | |||
| 61 | __attribute__((weak)) void matrix_scan_quantum(void) { matrix_scan_kb(); } | ||
| 62 | |||
| 63 | __attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } | ||
| 64 | |||
| 65 | __attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } | ||
| 66 | |||
| 67 | __attribute__((weak)) void matrix_init_user(void) {} | ||
| 68 | |||
| 69 | __attribute__((weak)) void matrix_scan_user(void) {} | ||
| 70 | |||
| 71 | inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } | ||
| 72 | |||
| 73 | inline uint8_t matrix_cols(void) { return MATRIX_COLS; } | ||
| 74 | |||
| 75 | // Deprecated. | ||
| 76 | bool matrix_is_modified(void) { | ||
| 77 | if (debounce_active()) return false; | ||
| 78 | return true; | ||
| 79 | } | ||
| 80 | 41 | ||
| 81 | inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } | 42 | inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } |
| 82 | 43 | ||
| @@ -90,24 +51,7 @@ inline matrix_row_t matrix_get_row(uint8_t row) { | |||
| 90 | #endif | 51 | #endif |
| 91 | } | 52 | } |
| 92 | 53 | ||
| 93 | void matrix_print(void) { | 54 | // matrix code |
| 94 | print_matrix_header(); | ||
| 95 | |||
| 96 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 97 | phex(row); | ||
| 98 | print(": "); | ||
| 99 | print_matrix_row(row); | ||
| 100 | print("\n"); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | uint8_t matrix_key_count(void) { | ||
| 105 | uint8_t count = 0; | ||
| 106 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 107 | count += matrix_bitpop(i); | ||
| 108 | } | ||
| 109 | return count; | ||
| 110 | } | ||
| 111 | 55 | ||
| 112 | #ifdef DIRECT_PINS | 56 | #ifdef DIRECT_PINS |
| 113 | 57 | ||
| @@ -129,7 +73,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
| 129 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 73 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
| 130 | pin_t pin = direct_pins[current_row][col_index]; | 74 | pin_t pin = direct_pins[current_row][col_index]; |
| 131 | if (pin != NO_PIN) { | 75 | if (pin != NO_PIN) { |
| 132 | current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index); | 76 | current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
| 133 | } | 77 | } |
| 134 | } | 78 | } |
| 135 | 79 | ||
| @@ -175,7 +119,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
| 175 | uint8_t pin_state = readPin(col_pins[col_index]); | 119 | uint8_t pin_state = readPin(col_pins[col_index]); |
| 176 | 120 | ||
| 177 | // Populate the matrix row with the state of the col pin | 121 | // Populate the matrix row with the state of the col pin |
| 178 | current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); | 122 | current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
| 179 | } | 123 | } |
| 180 | 124 | ||
| 181 | // Unselect row | 125 | // Unselect row |
| @@ -221,10 +165,10 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
| 221 | // Check row pin state | 165 | // Check row pin state |
| 222 | if (readPin(row_pins[row_index]) == 0) { | 166 | if (readPin(row_pins[row_index]) == 0) { |
| 223 | // Pin LO, set col bit | 167 | // Pin LO, set col bit |
| 224 | current_matrix[row_index] |= (ROW_SHIFTER << current_col); | 168 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); |
| 225 | } else { | 169 | } else { |
| 226 | // Pin HI, clear col bit | 170 | // Pin HI, clear col bit |
| 227 | current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); | 171 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); |
| 228 | } | 172 | } |
| 229 | 173 | ||
| 230 | // Determine if the matrix changed state | 174 | // Determine if the matrix changed state |
