diff options
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/matrix.c | 22 | ||||
| -rw-r--r-- | quantum/matrix_common.c | 48 | ||||
| -rw-r--r-- | quantum/split_common/matrix.c | 10 |
3 files changed, 52 insertions, 28 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index 62a86fba6..1675f2477 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -22,10 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 22 | #include "debounce.h" | 22 | #include "debounce.h" |
| 23 | #include "quantum.h" | 23 | #include "quantum.h" |
| 24 | 24 | ||
| 25 | #ifdef MATRIX_MASKED | ||
| 26 | extern const matrix_row_t matrix_mask[]; | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #ifdef DIRECT_PINS | 25 | #ifdef DIRECT_PINS |
| 30 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; | 26 | static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; |
| 31 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) | 27 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) |
| @@ -34,22 +30,8 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | |||
| 34 | #endif | 30 | #endif |
| 35 | 31 | ||
| 36 | /* matrix state(1:on, 0:off) */ | 32 | /* matrix state(1:on, 0:off) */ |
| 37 | static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | 33 | extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values |
| 38 | static matrix_row_t matrix[MATRIX_ROWS]; // debounced values | 34 | extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values |
| 39 | |||
| 40 | // helper functions | ||
| 41 | |||
| 42 | inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } | ||
| 43 | |||
| 44 | inline matrix_row_t matrix_get_row(uint8_t row) { | ||
| 45 | // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a | ||
| 46 | // switch blocker installed and the switch is always pressed. | ||
| 47 | #ifdef MATRIX_MASKED | ||
| 48 | return matrix[row] & matrix_mask[row]; | ||
| 49 | #else | ||
| 50 | return matrix[row]; | ||
| 51 | #endif | ||
| 52 | } | ||
| 53 | 35 | ||
| 54 | // matrix code | 36 | // matrix code |
| 55 | 37 | ||
diff --git a/quantum/matrix_common.c b/quantum/matrix_common.c index 22704e8ee..a8948a264 100644 --- a/quantum/matrix_common.c +++ b/quantum/matrix_common.c | |||
| @@ -3,6 +3,14 @@ | |||
| 3 | #include "print.h" | 3 | #include "print.h" |
| 4 | #include "debug.h" | 4 | #include "debug.h" |
| 5 | 5 | ||
| 6 | /* matrix state(1:on, 0:off) */ | ||
| 7 | matrix_row_t raw_matrix[MATRIX_ROWS]; | ||
| 8 | matrix_row_t matrix[MATRIX_ROWS]; | ||
| 9 | |||
| 10 | #ifdef MATRIX_MASKED | ||
| 11 | extern const matrix_row_t matrix_mask[]; | ||
| 12 | #endif | ||
| 13 | |||
| 6 | // user-defined overridable functions | 14 | // user-defined overridable functions |
| 7 | 15 | ||
| 8 | __attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } | 16 | __attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } |
| @@ -19,6 +27,18 @@ inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } | |||
| 19 | 27 | ||
| 20 | inline uint8_t matrix_cols(void) { return MATRIX_COLS; } | 28 | inline uint8_t matrix_cols(void) { return MATRIX_COLS; } |
| 21 | 29 | ||
| 30 | inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } | ||
| 31 | |||
| 32 | inline matrix_row_t matrix_get_row(uint8_t row) { | ||
| 33 | // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a | ||
| 34 | // switch blocker installed and the switch is always pressed. | ||
| 35 | #ifdef MATRIX_MASKED | ||
| 36 | return matrix[row] & matrix_mask[row]; | ||
| 37 | #else | ||
| 38 | return matrix[row]; | ||
| 39 | #endif | ||
| 40 | } | ||
| 41 | |||
| 22 | // Deprecated. | 42 | // Deprecated. |
| 23 | bool matrix_is_modified(void) { | 43 | bool matrix_is_modified(void) { |
| 24 | if (debounce_active()) return false; | 44 | if (debounce_active()) return false; |
| @@ -57,3 +77,31 @@ uint8_t matrix_key_count(void) { | |||
| 57 | } | 77 | } |
| 58 | return count; | 78 | return count; |
| 59 | } | 79 | } |
| 80 | |||
| 81 | // CUSTOM MATRIX 'LITE' | ||
| 82 | __attribute__((weak)) void matrix_init_custom(void) {} | ||
| 83 | |||
| 84 | __attribute__((weak)) bool matrix_scan_custom(matrix_row_t current_matrix[]) { return true; } | ||
| 85 | |||
| 86 | __attribute__((weak)) void matrix_init(void) { | ||
| 87 | matrix_init_custom(); | ||
| 88 | |||
| 89 | // initialize matrix state: all keys off | ||
| 90 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 91 | raw_matrix[i] = 0; | ||
| 92 | matrix[i] = 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | debounce_init(MATRIX_ROWS); | ||
| 96 | |||
| 97 | matrix_init_quantum(); | ||
| 98 | } | ||
| 99 | |||
| 100 | __attribute__((weak)) uint8_t matrix_scan(void) { | ||
| 101 | bool changed = matrix_scan_custom(raw_matrix); | ||
| 102 | |||
| 103 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); | ||
| 104 | |||
| 105 | matrix_scan_quantum(); | ||
| 106 | return 1; | ||
| 107 | } | ||
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 58602af85..ed1ff5acf 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
| @@ -41,8 +41,8 @@ static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | |||
| 41 | #endif | 41 | #endif |
| 42 | 42 | ||
| 43 | /* matrix state(1:on, 0:off) */ | 43 | /* matrix state(1:on, 0:off) */ |
| 44 | static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | 44 | extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values |
| 45 | static matrix_row_t matrix[MATRIX_ROWS]; // debounced values | 45 | extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values |
| 46 | 46 | ||
| 47 | // row offsets for each hand | 47 | // row offsets for each hand |
| 48 | uint8_t thisHand, thatHand; | 48 | uint8_t thisHand, thatHand; |
| @@ -50,12 +50,6 @@ uint8_t thisHand, thatHand; | |||
| 50 | // user-defined overridable functions | 50 | // user-defined overridable functions |
| 51 | __attribute__((weak)) void matrix_slave_scan_user(void) {} | 51 | __attribute__((weak)) void matrix_slave_scan_user(void) {} |
| 52 | 52 | ||
| 53 | // helper functions | ||
| 54 | |||
| 55 | inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } | ||
| 56 | |||
| 57 | inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } | ||
| 58 | |||
| 59 | // matrix code | 53 | // matrix code |
| 60 | 54 | ||
| 61 | #ifdef DIRECT_PINS | 55 | #ifdef DIRECT_PINS |
