aboutsummaryrefslogtreecommitdiff
path: root/keyboards/chidori/matrix.c
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2020-02-08 13:50:42 +1100
committerGitHub <noreply@github.com>2020-02-07 18:50:42 -0800
commit3b1f29a5d6d171c7c659eb0d76fff806a52ac1cf (patch)
treebe578e91697a3b0962cd35e58ee95afcec0ebd73 /keyboards/chidori/matrix.c
parent707c04b4ab588967c803114d7d88ef3fdd934967 (diff)
downloadqmk_firmware-3b1f29a5d6d171c7c659eb0d76fff806a52ac1cf.tar.gz
qmk_firmware-3b1f29a5d6d171c7c659eb0d76fff806a52ac1cf.zip
[Keyboard] Misc tidyups for Chidori (#8091)
Diffstat (limited to 'keyboards/chidori/matrix.c')
-rw-r--r--keyboards/chidori/matrix.c89
1 files changed, 6 insertions, 83 deletions
diff --git a/keyboards/chidori/matrix.c b/keyboards/chidori/matrix.c
index 204f236a6..6228125d9 100644
--- a/keyboards/chidori/matrix.c
+++ b/keyboards/chidori/matrix.c
@@ -14,100 +14,23 @@ GNU General Public License for more details.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <stdint.h> 17
18#include <stdbool.h>
19#include "wait.h"
20#include "print.h"
21#include "debug.h"
22#include "util.h"
23#include "matrix.h"
24#include "debounce.h"
25#include "quantum.h" 18#include "quantum.h"
19#include "matrix.h"
26#include "board.h" 20#include "board.h"
27 21
28#if (MATRIX_COLS <= 8) 22void matrix_init_custom(void) {
29# define print_matrix_header() print("\nr/c 01234567\n")
30# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
31# define matrix_bitpop(i) bitpop(matrix[i])
32# define ROW_SHIFTER ((uint8_t)1)
33#elif (MATRIX_COLS <= 16)
34# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
35# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
36# define matrix_bitpop(i) bitpop16(matrix[i])
37# define ROW_SHIFTER ((uint16_t)1)
38#elif (MATRIX_COLS <= 32)
39# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
40# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
41# define matrix_bitpop(i) bitpop32(matrix[i])
42# define ROW_SHIFTER ((uint32_t)1)
43#endif
44
45#ifdef MATRIX_MASKED
46extern const matrix_row_t matrix_mask[];
47#endif
48
49/* matrix state(1:on, 0:off) */
50static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
51static matrix_row_t matrix[MATRIX_ROWS]; // debounced values
52
53__attribute__((weak)) void matrix_init_quantum(void) { matrix_init_kb(); }
54
55__attribute__((weak)) void matrix_scan_quantum(void) { matrix_scan_kb(); }
56
57__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
58
59__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
60
61__attribute__((weak)) void matrix_init_user(void) {}
62
63__attribute__((weak)) void matrix_scan_user(void) {}
64
65inline matrix_row_t matrix_get_row(uint8_t row) {
66 // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
67 // switch blocker installed and the switch is always pressed.
68#ifdef MATRIX_MASKED
69 return matrix[row] & matrix_mask[row];
70#else
71 return matrix[row];
72#endif
73}
74
75void matrix_print(void) {
76 print_matrix_header();
77
78 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
79 phex(row);
80 print(": ");
81 print_matrix_row(row);
82 print("\n");
83 }
84}
85
86void matrix_init(void) {
87 // initialize key pins 23 // initialize key pins
88 board_init(); 24 board_init();
89
90 // initialize matrix state: all keys off
91 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
92 raw_matrix[i] = 0;
93 matrix[i] = 0;
94 }
95
96 debounce_init(MATRIX_ROWS);
97
98 matrix_init_quantum();
99} 25}
100 26
101uint8_t matrix_scan(void) { 27bool matrix_scan_custom(matrix_row_t current_matrix[]) {
102 bool changed = false; 28 bool changed = false;
103 29
104 // Set row, read cols 30 // Set row, read cols
105 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { 31 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
106 changed |= board_read_cols_on_row(raw_matrix, current_row); 32 changed |= board_read_cols_on_row(current_matrix, current_row);
107 } 33 }
108 34
109 debounce(raw_matrix, matrix, MATRIX_ROWS, changed); 35 return changed;
110
111 matrix_scan_quantum();
112 return 1;
113} 36}