2 Copyright 2014 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>
30 static void matrix_make(uint8_t code);
31 static void matrix_break(uint8_t code);
36 * IBM 4704 scan codes are assigned into 128(16x8)-cell matrix.
47 static uint8_t matrix[MATRIX_ROWS];
49 // scan code bits 7654 3210
50 // R:row/C:column -RRR RCCC
51 #define ROW(code) ((code>>3)&0x0f)
52 #define COL(code) (code&0x07)
55 static void enable_break(void)
57 print("Enable break: ");
58 while (ibm4704_send(0xFC)) { _delay_ms(10); }
59 // valid scancode: 00-79h
60 for (uint8_t code = 0; code < 0x7F; code++) {
61 while (ibm4704_send(0x80|code)) _delay_ms(10);
62 _delay_ms(5); // wait for response
63 // No response(FF) when ok, FD when out of bound
64 xprintf("s%02X:r%02X ", code, ibm4704_recv());
66 while (ibm4704_send(0xFF)) { _delay_ms(10); } // End
71 void matrix_setup(void)
76 void matrix_init(void)
80 print("IBM 4704 converter\n");
82 _delay_ms(2000); // wait for keyboard starting up
83 uint8_t keyboard_id = ibm4704_recv();
84 xprintf("Keyboard ID: %02X\n", keyboard_id);
91 uint8_t matrix_scan(void)
93 uint8_t code = ibm4704_recv();
97 } else if ((code&0x7F) >= 0x7C) {
98 // 0xFF-FC and 0x7F-7C is not scancode
99 xprintf("Error: %02X\n", code);
102 } else if (code&0x80) {
103 dprintf("%02X\n", code);
106 dprintf("%02X\n", code);
113 uint8_t matrix_get_row(uint8_t row)
119 static void matrix_make(uint8_t code)
121 matrix[ROW(code)] |= 1<<COL(code);
125 static void matrix_break(uint8_t code)
127 matrix[ROW(code)] &= ~(1<<COL(code));
130 void matrix_clear(void)
132 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;