]>
git.gir.st - tmk_keyboard.git/blob - converter/usb_usb/matrix.c
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * HID keycode(1 byte):
30 * Higher 5 bits indicates ROW and lower 3 bits COL.
37 * Matrix space(32 * 8):
46 #define CODE(row, col) (((row) << 3) | (col))
47 #define ROW(code) (((code) & ROW_MASK) >> 3)
48 #define COL(code) ((code) & COL_MASK)
49 #define ROW_BITS(code) (1 << COL(code))
52 uint8_t matrix_rows(void) { return MATRIX_ROWS
; }
53 uint8_t matrix_cols(void) { return MATRIX_COLS
; }
54 void matrix_init(void) {}
55 bool matrix_has_ghost(void) { return false; }
57 static bool matrix_is_mod
=false;
59 uint8_t matrix_scan(void) {
60 static uint16_t last_time_stamp
= 0;
62 if (last_time_stamp
!= usb_hid_time_stamp
) {
63 last_time_stamp
= usb_hid_time_stamp
;
66 matrix_is_mod
= false;
71 bool matrix_is_modified(void) {
76 bool matrix_is_on(uint8_t row
, uint8_t col
) {
77 uint8_t code
= CODE(row
, col
);
80 if (usb_hid_keyboard_report
.mods
& ROW_BITS(code
)) {
84 for (uint8_t i
= 0; i
< REPORT_KEYS
; i
++) {
85 if (usb_hid_keyboard_report
.keys
[i
] == code
) {
92 uint8_t matrix_get_row(uint8_t row
) {
95 if (IS_MOD(CODE(row
, 0)) && usb_hid_keyboard_report
.mods
) {
96 row_bits
|= usb_hid_keyboard_report
.mods
;
99 for (uint8_t i
= 0; i
< REPORT_KEYS
; i
++) {
100 if (IS_ANY(usb_hid_keyboard_report
.keys
[i
])) {
101 if (row
== ROW(usb_hid_keyboard_report
.keys
[i
])) {
102 row_bits
|= ROW_BITS(usb_hid_keyboard_report
.keys
[i
]);
109 uint8_t matrix_key_count(void) {
112 count
+= bitpop(usb_hid_keyboard_report
.mods
);
113 for (uint8_t i
= 0; i
< REPORT_KEYS
; i
++) {
114 if (IS_ANY(usb_hid_keyboard_report
.keys
[i
])) {
121 void matrix_print(void) {
122 print("\nr/c 01234567\n");
123 for (uint8_t row
= 0; row
< matrix_rows(); row
++) {
124 phex(row
); print(": ");
125 pbin_reverse(matrix_get_row(row
));
126 #ifdef MATRIX_HAS_GHOST
127 if (matrix_has_ghost_in_row(row
)) {