]>
git.gir.st - tmk_keyboard.git/blob - converter/xt_usb/matrix.c
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
3 Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 static void matrix_make(uint8_t code
);
30 static void matrix_break(uint8_t code
);
32 static uint8_t matrix
[MATRIX_ROWS
];
33 #define ROW(code) (code>>3)
34 #define COL(code) (code&0x07)
36 // matrix positions for exceptional keys
37 #define PRINT_SCREEN (0x7C)
41 void matrix_init(void)
46 // initialize matrix state: all keys off
47 for (uint8_t i
=0; i
< MATRIX_ROWS
; i
++) matrix
[i
] = 0x00;
52 static uint8_t move_codes(uint8_t code
) {
95 uint8_t matrix_scan(void)
98 // scan code reading states
117 // 'pseudo break code' hack
118 if (matrix_is_on(ROW(PAUSE
), COL(PAUSE
))) {
122 uint8_t code
= xt_host_recv();
132 default: // normal key make
133 if (code
< 0x80 && code
!= 0x00) {
134 xprintf("make: %X\r\n", code
);
136 } else if (code
> 0x80 && code
< 0xFF && code
!= 0x00) {
137 xprintf("break %X\r\n", code
);
138 matrix_break(code
- 0x80);
143 case E0
: // E0-Prefixed
144 switch (code
) { //move these codes to unused places on the matrix
152 if (code
< 0x80 && code
!= 0x00) {
153 matrix_make(move_codes(code
));
154 } else if (code
> 0x80 && code
< 0xFF && code
!= 0x00) {
155 matrix_break(move_codes(code
- 0x80));
168 matrix_make(PRINT_SCREEN
);
180 matrix_break(PRINT_SCREEN
);
204 state
= E1_1D_45_E1_9D
;
221 uint8_t matrix_get_row(uint8_t row
)
227 static void matrix_make(uint8_t code
)
229 if (!matrix_is_on(ROW(code
), COL(code
))) {
230 matrix
[ROW(code
)] |= 1<<COL(code
);
235 static void matrix_break(uint8_t code
)
237 if (matrix_is_on(ROW(code
), COL(code
))) {
238 matrix
[ROW(code
)] &= ~(1<<COL(code
));
242 void matrix_clear(void)
244 for (uint8_t i
=0; i
< MATRIX_ROWS
; i
++) matrix
[i
] = 0x00;