diff options
-rw-r--r-- | keyboards/xd84/custom_matrix_helper.c | 71 | ||||
-rw-r--r-- | keyboards/xd84/matrix.c | 4 | ||||
-rw-r--r-- | keyboards/xd84/rules.mk | 2 | ||||
-rw-r--r-- | keyboards/xd96/custom_matrix_helper.c | 71 | ||||
-rw-r--r-- | keyboards/xd96/matrix.c | 4 | ||||
-rw-r--r-- | keyboards/xd96/rules.mk | 2 | ||||
-rw-r--r-- | quantum/matrix.c | 22 | ||||
-rw-r--r-- | quantum/matrix_common.c | 48 | ||||
-rw-r--r-- | quantum/split_common/matrix.c | 10 |
9 files changed, 58 insertions, 176 deletions
diff --git a/keyboards/xd84/custom_matrix_helper.c b/keyboards/xd84/custom_matrix_helper.c deleted file mode 100644 index e4e256381..000000000 --- a/keyboards/xd84/custom_matrix_helper.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* Copyright 2019 | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #include <stdint.h> | ||
17 | #include <stdbool.h> | ||
18 | #include "wait.h" | ||
19 | #include "print.h" | ||
20 | #include "debug.h" | ||
21 | #include "util.h" | ||
22 | #include "matrix.h" | ||
23 | #include "debounce.h" | ||
24 | #include "quantum.h" | ||
25 | |||
26 | //_____COULD BE COMMON_________________________________________________________ | ||
27 | /* matrix state(1:on, 0:off) */ | ||
28 | /*static*/ matrix_row_t raw_matrix[MATRIX_ROWS]; | ||
29 | /*static*/ matrix_row_t matrix[MATRIX_ROWS]; | ||
30 | |||
31 | __attribute__ ((weak)) | ||
32 | matrix_row_t matrix_get_row(uint8_t row) { | ||
33 | return matrix[row]; | ||
34 | } | ||
35 | |||
36 | //_____CUSTOM MATRIX 'LITE'____________________________________________________ | ||
37 | __attribute__ ((weak)) | ||
38 | void custom_matrix_init(void) { | ||
39 | } | ||
40 | |||
41 | __attribute__ ((weak)) | ||
42 | bool custom_matrix_scan(matrix_row_t current_matrix[]) { | ||
43 | bool changed = true; | ||
44 | return changed; | ||
45 | } | ||
46 | |||
47 | __attribute__ ((weak)) | ||
48 | void matrix_init(void) { | ||
49 | |||
50 | custom_matrix_init(); | ||
51 | |||
52 | // initialize matrix state: all keys off | ||
53 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
54 | raw_matrix[i] = 0; | ||
55 | matrix[i] = 0; | ||
56 | } | ||
57 | |||
58 | debounce_init(MATRIX_ROWS); | ||
59 | |||
60 | matrix_init_quantum(); | ||
61 | } | ||
62 | |||
63 | __attribute__ ((weak)) | ||
64 | uint8_t matrix_scan(void) { | ||
65 | bool changed = custom_matrix_scan(raw_matrix); | ||
66 | |||
67 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); | ||
68 | |||
69 | matrix_scan_quantum(); | ||
70 | return 1; | ||
71 | } | ||
diff --git a/keyboards/xd84/matrix.c b/keyboards/xd84/matrix.c index a4ddbee9a..92b8ff854 100644 --- a/keyboards/xd84/matrix.c +++ b/keyboards/xd84/matrix.c | |||
@@ -82,14 +82,14 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
82 | 82 | ||
83 | //_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ | 83 | //_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ |
84 | 84 | ||
85 | void custom_matrix_init(void) { | 85 | void matrix_init_custom(void) { |
86 | pca9555_init(IC1); | 86 | pca9555_init(IC1); |
87 | pca9555_init(IC2); | 87 | pca9555_init(IC2); |
88 | 88 | ||
89 | init_pins(); | 89 | init_pins(); |
90 | } | 90 | } |
91 | 91 | ||
92 | bool custom_matrix_scan(matrix_row_t current_matrix[]) { | 92 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { |
93 | bool changed = false; | 93 | bool changed = false; |
94 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | 94 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { |
95 | changed |= read_cols_on_row(current_matrix, current_row); | 95 | changed |= read_cols_on_row(current_matrix, current_row); |
diff --git a/keyboards/xd84/rules.mk b/keyboards/xd84/rules.mk index 4a460d91f..13e1b4ba3 100644 --- a/keyboards/xd84/rules.mk +++ b/keyboards/xd84/rules.mk | |||
@@ -37,7 +37,7 @@ LINK_TIME_OPTIMIZATION_ENABLE = yes | |||
37 | CUSTOM_MATRIX = lite | 37 | CUSTOM_MATRIX = lite |
38 | 38 | ||
39 | VPATH += drivers/gpio | 39 | VPATH += drivers/gpio |
40 | SRC += custom_matrix_helper.c pca9555.c matrix.c | 40 | SRC += pca9555.c matrix.c |
41 | QUANTUM_LIB_SRC += i2c_master.c | 41 | QUANTUM_LIB_SRC += i2c_master.c |
42 | 42 | ||
43 | LAYOUTS = 75_ansi 75_iso | 43 | LAYOUTS = 75_ansi 75_iso |
diff --git a/keyboards/xd96/custom_matrix_helper.c b/keyboards/xd96/custom_matrix_helper.c deleted file mode 100644 index e4e256381..000000000 --- a/keyboards/xd96/custom_matrix_helper.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* Copyright 2019 | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #include <stdint.h> | ||
17 | #include <stdbool.h> | ||
18 | #include "wait.h" | ||
19 | #include "print.h" | ||
20 | #include "debug.h" | ||
21 | #include "util.h" | ||
22 | #include "matrix.h" | ||
23 | #include "debounce.h" | ||
24 | #include "quantum.h" | ||
25 | |||
26 | //_____COULD BE COMMON_________________________________________________________ | ||
27 | /* matrix state(1:on, 0:off) */ | ||
28 | /*static*/ matrix_row_t raw_matrix[MATRIX_ROWS]; | ||
29 | /*static*/ matrix_row_t matrix[MATRIX_ROWS]; | ||
30 | |||
31 | __attribute__ ((weak)) | ||
32 | matrix_row_t matrix_get_row(uint8_t row) { | ||
33 | return matrix[row]; | ||
34 | } | ||
35 | |||
36 | //_____CUSTOM MATRIX 'LITE'____________________________________________________ | ||
37 | __attribute__ ((weak)) | ||
38 | void custom_matrix_init(void) { | ||
39 | } | ||
40 | |||
41 | __attribute__ ((weak)) | ||
42 | bool custom_matrix_scan(matrix_row_t current_matrix[]) { | ||
43 | bool changed = true; | ||
44 | return changed; | ||
45 | } | ||
46 | |||
47 | __attribute__ ((weak)) | ||
48 | void matrix_init(void) { | ||
49 | |||
50 | custom_matrix_init(); | ||
51 | |||
52 | // initialize matrix state: all keys off | ||
53 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
54 | raw_matrix[i] = 0; | ||
55 | matrix[i] = 0; | ||
56 | } | ||
57 | |||
58 | debounce_init(MATRIX_ROWS); | ||
59 | |||
60 | matrix_init_quantum(); | ||
61 | } | ||
62 | |||
63 | __attribute__ ((weak)) | ||
64 | uint8_t matrix_scan(void) { | ||
65 | bool changed = custom_matrix_scan(raw_matrix); | ||
66 | |||
67 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); | ||
68 | |||
69 | matrix_scan_quantum(); | ||
70 | return 1; | ||
71 | } | ||
diff --git a/keyboards/xd96/matrix.c b/keyboards/xd96/matrix.c index e8fd850ed..8cecc79c2 100644 --- a/keyboards/xd96/matrix.c +++ b/keyboards/xd96/matrix.c | |||
@@ -80,14 +80,14 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
80 | 80 | ||
81 | //_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ | 81 | //_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ |
82 | 82 | ||
83 | void custom_matrix_init(void) { | 83 | void matrix_init_custom(void) { |
84 | pca9555_init(IC1); | 84 | pca9555_init(IC1); |
85 | pca9555_init(IC2); | 85 | pca9555_init(IC2); |
86 | 86 | ||
87 | init_pins(); | 87 | init_pins(); |
88 | } | 88 | } |
89 | 89 | ||
90 | bool custom_matrix_scan(matrix_row_t current_matrix[]) { | 90 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { |
91 | bool changed = false; | 91 | bool changed = false; |
92 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | 92 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { |
93 | changed |= read_cols_on_row(current_matrix, current_row); | 93 | changed |= read_cols_on_row(current_matrix, current_row); |
diff --git a/keyboards/xd96/rules.mk b/keyboards/xd96/rules.mk index d5ac5df36..9afd4eec4 100644 --- a/keyboards/xd96/rules.mk +++ b/keyboards/xd96/rules.mk | |||
@@ -37,5 +37,5 @@ LINK_TIME_OPTIMIZATION_ENABLE = yes | |||
37 | CUSTOM_MATRIX = lite | 37 | CUSTOM_MATRIX = lite |
38 | 38 | ||
39 | VPATH += drivers/gpio | 39 | VPATH += drivers/gpio |
40 | SRC += custom_matrix_helper.c pca9555.c matrix.c | 40 | SRC += pca9555.c matrix.c |
41 | QUANTUM_LIB_SRC += i2c_master.c | 41 | QUANTUM_LIB_SRC += i2c_master.c |
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 |