]>
git.gir.st - tmk_keyboard.git/blob - converter/terminal_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/>.
21 #include <util/delay.h>
29 static void matrix_make(uint8_t code
);
30 static void matrix_break(uint8_t code
);
35 * 'Scan Code Set 3' is assigned into 17x8 cell matrix.
45 static uint8_t matrix
[MATRIX_ROWS
];
46 #define ROW(code) (code>>3)
47 #define COL(code) (code&0x07)
50 void matrix_init(void)
53 //debug_matrix = true;
54 //debug_keyboard = true;
55 //debug_mouse = false;
59 // initialize matrix state: all keys off
60 for (uint8_t i
=0; i
< MATRIX_ROWS
; i
++) matrix
[i
] = 0x00;
65 uint8_t matrix_scan(void)
68 // scan code reading states
80 if ((code
= ps2_host_recv())) {
81 debug("r"); debug_hex(code
); debug(" ");
87 if (ps2_host_send(0xFF) == 0xFA) {
88 debug("[ack]\nRESET_RESPONSE: ");
89 state
= RESET_RESPONSE
;
94 debug("[ok]\nKBD_ID: ");
97 debug("err\nRESET: ");
101 // after reset receive keyboad ID(2 bytes)
115 if (ps2_host_send(0xF8) == 0xFA) {
116 debug("[ack]\nREADY\n");
128 default: // normal key make
132 debug("unexpected scan code at READY: "); debug_hex(code
); debug("\n");
138 case F0
: // Break code
146 debug("unexpected scan code at F0: "); debug_hex(code
); debug("\n");
157 uint8_t matrix_get_row(uint8_t row
)
163 static void matrix_make(uint8_t code
)
165 if (!matrix_is_on(ROW(code
), COL(code
))) {
166 matrix
[ROW(code
)] |= 1<<COL(code
);
171 static void matrix_break(uint8_t code
)
173 if (matrix_is_on(ROW(code
), COL(code
))) {
174 matrix
[ROW(code
)] &= ~(1<<COL(code
));