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)
37 void matrix_init(void)
42 // initialize matrix state: all keys off
43 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
48 // convert E0-escaped codes into unused area
49 static uint8_t move_e0code(uint8_t code) {
51 // Original IBM XT keyboard doesn't use E0-codes probably
52 // Some XT compatilble keyobards need these keys?
53 // http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf
54 // https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc
55 case 0x37: return 0x54; // Print Screen
56 case 0x46: return 0x55; // Ctrl + Pause
57 case 0x1C: return 0x6F; // Keypad Enter
58 case 0x35: return 0x7F; // Keypad /
59 case 0x5B: return 0x5A; // Left GUI
60 case 0x5C: return 0x5B; // Right GUI
61 case 0x5D: return 0x5C; // Application
62 case 0x5E: return 0x5D; // Power(not used)
63 case 0x5F: return 0x5E; // Sleep(not used)
64 case 0x63: return 0x5F; // Wake (not used)
65 case 0x48: return 0x60; // Up
66 case 0x4B: return 0x61; // Left
67 case 0x50: return 0x62; // Down
68 case 0x4D: return 0x63; // Right
69 case 0x52: return 0x71; // Insert
70 case 0x53: return 0x72; // Delete
71 case 0x47: return 0x74; // Home
72 case 0x4F: return 0x75; // End
73 case 0x49: return 0x77; // Home
74 case 0x51: return 0x78; // End
75 case 0x1D: return 0x7A; // Right Ctrl
76 case 0x38: return 0x7C; // Right Alt
81 uint8_t matrix_scan(void)
86 // Pause: E1 1D 45, E1 9D C5
92 uint8_t code = xt_host_recv();
94 dprintf("%02X ", code);
108 matrix_break(code & 0x7F);
123 matrix_make(move_e0code(code));
125 matrix_break(move_e0code(code & 0x7F));
170 uint8_t matrix_get_row(uint8_t row)
176 static void matrix_make(uint8_t code)
178 if (!matrix_is_on(ROW(code), COL(code))) {
179 matrix[ROW(code)] |= 1<<COL(code);
184 static void matrix_break(uint8_t code)
186 if (matrix_is_on(ROW(code), COL(code))) {
187 matrix[ROW(code)] &= ~(1<<COL(code));
191 void matrix_clear(void)
193 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
199 - http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf
200 - https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc
202 01-53: Normal codes used in original XT keyboard
203 54-7F: Not used in original XT keyboard
205 0 1 2 3 4 5 6 7 8 9 A B C D E F
206 50 - - - - * * x x x x * * * o o o
207 60 * * * * x x x x x x x x x x x *
208 70 x * * x * * x * * x * x * x x *
210 -: codes existed in original XT keyboard
211 *: E0-escaped codes converted into unused code area(internal use in TMK)
212 x: Non-espcaped codes(not used in real keyboards probably, for CodeSet2-CodeSet1 translation purpose)
217 00 (reserved) DO NOT USE