diff options
author | Joel Challis <git@zvecr.com> | 2020-01-15 01:58:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-15 01:58:32 +0000 |
commit | 48cac9e3c8710ae3e27c66fbd7043f38e7c6535e (patch) | |
tree | a34180fc73b535f3d2b8508f7267b872f0ddcb32 /quantum/matrix_common.c | |
parent | 537b8713e5bc9690dca3c1ad8733132892d48ea2 (diff) | |
download | qmk_firmware-48cac9e3c8710ae3e27c66fbd7043f38e7c6535e.tar.gz qmk_firmware-48cac9e3c8710ae3e27c66fbd7043f38e7c6535e.zip |
Migrate more custom matrix 'lite' code to core (#7863)
* Migrate more custom matrix lite code to core
* Align function names
* fix up MATRIX_MASKED
Diffstat (limited to 'quantum/matrix_common.c')
-rw-r--r-- | quantum/matrix_common.c | 48 |
1 files changed, 48 insertions, 0 deletions
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 | } | ||