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.
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.
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/>.
26 //_____COMMON__________________________________________________________________
27 // user-defined overridable functions
28 __attribute__((weak
)) void matrix_init_kb(void) { matrix_init_user(); }
29 __attribute__((weak
)) void matrix_scan_kb(void) { matrix_scan_user(); }
30 __attribute__((weak
)) void matrix_init_user(void) {}
31 __attribute__((weak
)) void matrix_scan_user(void) {}
34 //_____COULD BE COMMON_________________________________________________________
35 /* matrix state(1:on, 0:off) */
36 /*static*/ matrix_row_t raw_matrix
[MATRIX_ROWS
];
37 /*static*/ matrix_row_t matrix
[MATRIX_ROWS
];
39 #if (MATRIX_COLS <= 8)
40 # define print_matrix_header() print("\nr/c 01234567\n")
41 # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
42 # define matrix_bitpop(i) bitpop(matrix[i])
43 # define ROW_SHIFTER ((uint8_t)1)
44 #elif (MATRIX_COLS <= 16)
45 # define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
46 # define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
47 # define matrix_bitpop(i) bitpop16(matrix[i])
48 # define ROW_SHIFTER ((uint16_t)1)
49 #elif (MATRIX_COLS <= 32)
50 # define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
51 # define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
52 # define matrix_bitpop(i) bitpop32(matrix[i])
53 # define ROW_SHIFTER ((uint32_t)1)
56 __attribute__ ((weak
))
57 uint8_t matrix_rows(void) {
61 __attribute__ ((weak
))
62 uint8_t matrix_cols(void) {
66 __attribute__ ((weak
))
67 matrix_row_t
matrix_get_row(uint8_t row
) {
71 __attribute__ ((weak
))
72 uint8_t matrix_key_count(void) {
74 for (uint8_t i
= 0; i
< MATRIX_ROWS
; i
++) {
75 count
+= matrix_bitpop(i
);
80 __attribute__ ((weak
))
81 void matrix_print(void) {
82 print_matrix_header();
84 for (uint8_t row
= 0; row
< MATRIX_ROWS
; row
++) {
85 phex(row
); print(": ");
86 print_matrix_row(row
);
92 //_____CUSTOM MATRIX 'LITE'____________________________________________________
93 __attribute__ ((weak
))
94 void custom_matrix_init(void) {
97 __attribute__ ((weak
))
98 bool custom_matrix_scan(matrix_row_t current_matrix
[]) {
103 __attribute__ ((weak
))
104 void matrix_init(void) {
106 custom_matrix_init();
108 // initialize matrix state: all keys off
109 for (uint8_t i
=0; i
< MATRIX_ROWS
; i
++) {
114 debounce_init(MATRIX_ROWS
);
116 matrix_init_quantum();
119 __attribute__ ((weak
))
120 uint8_t matrix_scan(void) {
121 bool changed
= custom_matrix_scan(raw_matrix
);
123 debounce(raw_matrix
, matrix
, MATRIX_ROWS
, changed
);
125 matrix_scan_quantum();