aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/converter/xt_usb/README.md17
-rw-r--r--keyboards/converter/xt_usb/config.h78
-rw-r--r--keyboards/converter/xt_usb/keymaps/default/config.h1
-rw-r--r--keyboards/converter/xt_usb/keymaps/default/keymap.c55
-rw-r--r--keyboards/converter/xt_usb/led.c22
-rw-r--r--keyboards/converter/xt_usb/matrix.c309
-rw-r--r--keyboards/converter/xt_usb/rules.mk62
-rw-r--r--keyboards/converter/xt_usb/xt_usb.c1
-rw-r--r--keyboards/converter/xt_usb/xt_usb.h132
-rw-r--r--tmk_core/protocol.mk5
-rw-r--r--tmk_core/protocol/xt.h71
-rw-r--r--tmk_core/protocol/xt_interrupt.c173
12 files changed, 926 insertions, 0 deletions
diff --git a/keyboards/converter/xt_usb/README.md b/keyboards/converter/xt_usb/README.md
new file mode 100644
index 000000000..40b265a18
--- /dev/null
+++ b/keyboards/converter/xt_usb/README.md
@@ -0,0 +1,17 @@
1XT to USB keyboard converter
2==============================
3This is a port of TMK's converter/xt_usb to QMK.
4
5This firmware converts XT keyboard protocol to USB.(It supports Scan Code Set 1.)
6
7
8Connect Wires
9-------------
101. Connect **Vcc** and **GND**.
112. Connect **Clock** and **Data** line. **Clock** is on `PD1`, **Data** on `PD0` by default. And optionally you can use `PB7` for **Reset**.(Compatible to Soarer's converter) To change pin configuration edit `config.h`.
123. You need pull-up resistor. **1K-10K Ohm** will be OK.
13
14
15XT keyboard protocol resource
16------------------------------
17https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol
diff --git a/keyboards/converter/xt_usb/config.h b/keyboards/converter/xt_usb/config.h
new file mode 100644
index 000000000..963a3c639
--- /dev/null
+++ b/keyboards/converter/xt_usb/config.h
@@ -0,0 +1,78 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19
20#define VENDOR_ID 0xFEED
21#define PRODUCT_ID 0x6512
22#define DEVICE_VER 0x0001
23#define MANUFACTURER QMK
24#define PRODUCT XT keyboard converter
25#define DESCRIPTION convert XT keyboard to USB
26
27
28/* matrix size */
29#define MATRIX_ROWS 16 // keycode bit: 3-0
30#define MATRIX_COLS 8 // keycode bit: 6-4
31
32/* key combination for command */
33#define IS_COMMAND() ( \
34 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \
35 keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \
36)
37
38
39//#define NO_SUSPEND_POWER_DOWN
40
41/*
42 * XT Pin interrupt
43 */
44#define XT_CLOCK_PORT PORTD
45#define XT_CLOCK_PIN PIND
46#define XT_CLOCK_DDR DDRD
47#define XT_CLOCK_BIT 1
48#define XT_DATA_PORT PORTD
49#define XT_DATA_PIN PIND
50#define XT_DATA_DDR DDRD
51#define XT_DATA_BIT 0
52#define XT_RST_PORT PORTB
53#define XT_RST_PIN PINB
54#define XT_RST_DDR DDRB
55#define XT_RST_BIT 7
56
57/* hard reset: low pulse for 500ms and after that HiZ for safety */
58#define XT_RESET() do { \
59 XT_RST_PORT &= ~(1<<XT_RST_BIT); \
60 XT_RST_DDR |= (1<<XT_RST_BIT); \
61 _delay_ms(500); \
62 XT_RST_DDR &= ~(1<<XT_RST_BIT); \
63} while (0)
64
65/* INT1 for falling edge of clock line */
66#define XT_INT_INIT() do { \
67 EICRA |= ((1<<ISC11) | \
68 (0<<ISC10)); \
69} while (0)
70/* clears flag and enables interrupt */
71#define XT_INT_ON() do { \
72 EIFR |= (1<<INTF1); \
73 EIMSK |= (1<<INT1); \
74} while (0)
75#define XT_INT_OFF() do { \
76 EIMSK &= ~(1<<INT1); \
77} while (0)
78#define XT_INT_VECT INT1_vect
diff --git a/keyboards/converter/xt_usb/keymaps/default/config.h b/keyboards/converter/xt_usb/keymaps/default/config.h
new file mode 100644
index 000000000..6f70f09be
--- /dev/null
+++ b/keyboards/converter/xt_usb/keymaps/default/config.h
@@ -0,0 +1 @@
#pragma once
diff --git a/keyboards/converter/xt_usb/keymaps/default/keymap.c b/keyboards/converter/xt_usb/keymaps/default/keymap.c
new file mode 100644
index 000000000..3ef606070
--- /dev/null
+++ b/keyboards/converter/xt_usb/keymaps/default/keymap.c
@@ -0,0 +1,55 @@
1#include QMK_KEYBOARD_H
2
3
4const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
5 /* IBM XT keyboard layout
6 * ,-------. ,--------------------------------------------------------------------------.
7 * | F1| F2| |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| BS |NumLck |ScrLck |
8 * |-------| |--------------------------------------------------------------------------|
9 * | F3| F4| | Tab | Q| W| E| R| T| Y| U| I| O| P| [| ] | | 7| 8| 9| -|
10 * |-------| |------------------------------------------------------|Ent|---------------|
11 * | F5| F6| | Ctrl | A| S| D| F| G| H| J| K| L| ;| '| `| | 4| 5| 6| |
12 * |-------| |----------------------------------------------------------------------| |
13 * | F7| F8| |Shif| \| Z| X| C| V| B| N| M| ,| .| /|Shift|PrS| 1| 2| 3| +|
14 * |-------| |----------------------------------------------------------------------| |
15 * | F9|F10| | Alt | Space |CapsLck| 0 | . | |
16 * `-------' `--------------------------------------------------------------------------'
17 */
18 LAYOUT_xt( \
19 KC_F1, KC_F2, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_BSPC, KC_NLCK, KC_SLCK,
20 KC_F3, KC_F4, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC, KC_P7, KC_P8, KC_P9, KC_PMNS,
21 KC_F5, KC_F6, KC_LCTL,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_GRV, KC_ENT, KC_P4, KC_P5, KC_P6,
22 KC_F7, KC_F8, KC_LSFT,KC_BSLS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH,KC_RSFT,KC_PSCR,KC_P1, KC_P2, KC_P3, KC_PPLS,
23 KC_F9, KC_F10, KC_LALT, KC_SPC, KC_CAPS, KC_P0, KC_PDOT
24 ),
25
26 /* Extended keyboard layout
27 * ,-----------------------------------------------.
28 * |F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|
29 * ,---. |-----------------------------------------------| ,-----------. ,-----------.
30 * |Esc| |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12| |PrS|ScL|Pau| |VDn|VUp|Mut|
31 * `---' `-----------------------------------------------' `-----------' `-----------'
32 * ,-----------------------------------------------------------. ,-----------. ,---------------.
33 * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -|
34 * |-----------------------------------------------------------| |-----------| |---------------|
35 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|End|PgD| | 7| 8| 9| +|
36 * |-----------------------------------------------------------| `-----------' |---------------|
37 * |CapsL | A| S| D| F| G| H| J| K| L| ;| '| #|Entr| | 4| 5| 6|KP,|
38 * |-----------------------------------------------------------| ,---. |---------------|
39 * |Shft| <| Z| X| C| V| B| N| M| ,| .| /| RO|Shift | |Up | | 1| 2| 3|KP=|
40 * |-----------------------------------------------------------| ,-----------. |---------------|
41 * |Ctl|Gui|Alt|MHEN| Space |HENK|KANA|Alt|Gui|App|Ctl| |Lef|Dow|Rig| | 0| .|Ent|
42 * `-----------------------------------------------------------' `-----------' `---------------'
43 */
44 /* Try this if your keyboad has exotic keys.
45 LAYOUT(
46 KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, KC_F21, KC_F22, KC_F23, KC_F24,
47 KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR,KC_SLCK,KC_PAUS, KC_VOLD,KC_VOLU,KC_MUTE,
48 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_JYEN,KC_BSPC, KC_INS, KC_HOME,KC_PGUP, KC_NLCK,KC_PSLS,KC_PAST,KC_PMNS,
49 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, KC_P7, KC_P8, KC_P9, KC_PPLS,
50 KC_CAPS,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_NUHS,KC_ENT, KC_P4, KC_P5, KC_P6, KC_PCMM,
51 KC_LSFT,KC_NUBS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RO, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT,
52 KC_LCTL,KC_LGUI,KC_LALT,KC_MHEN, KC_SPC, KC_HENK,KC_KANA,KC_RALT,KC_RGUI,KC_APP, KC_RCTL, KC_LEFT,KC_DOWN,KC_RGHT, KC_P0, KC_PDOT,KC_PEQL
53 ),
54 */
55};
diff --git a/keyboards/converter/xt_usb/led.c b/keyboards/converter/xt_usb/led.c
new file mode 100644
index 000000000..6fa077032
--- /dev/null
+++ b/keyboards/converter/xt_usb/led.c
@@ -0,0 +1,22 @@
1/*
2Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "led.h"
19
20void led_set(uint8_t usb_led) {
21 //XT Keyboards do not have LEDs, nothing to do.
22}
diff --git a/keyboards/converter/xt_usb/matrix.c b/keyboards/converter/xt_usb/matrix.c
new file mode 100644
index 000000000..e2d7117b1
--- /dev/null
+++ b/keyboards/converter/xt_usb/matrix.c
@@ -0,0 +1,309 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <stdint.h>
20#include <stdbool.h>
21#include "action.h"
22#include "print.h"
23#include "util.h"
24#include "debug.h"
25#include "xt.h"
26#include "matrix.h"
27
28
29static void matrix_make(uint8_t code);
30static void matrix_break(uint8_t code);
31
32static uint8_t matrix[MATRIX_ROWS];
33#define ROW(code) (code>>3)
34#define COL(code) (code&0x07)
35
36__attribute__ ((weak))
37void matrix_init_kb(void) {
38 matrix_init_user();
39}
40
41__attribute__ ((weak))
42void matrix_scan_kb(void) {
43 matrix_scan_user();
44}
45
46__attribute__ ((weak))
47void matrix_init_user(void) {
48}
49
50__attribute__ ((weak))
51void matrix_scan_user(void) {
52}
53
54void matrix_init(void)
55{
56 debug_enable = true;
57 xt_host_init();
58
59 // initialize matrix state: all keys off
60 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
61
62 matrix_init_quantum();
63}
64
65// convert E0-escaped codes into unused area
66static uint8_t move_e0code(uint8_t code) {
67 switch(code) {
68 // Original IBM XT keyboard has these keys
69 case 0x37: return 0x54; // Print Screen
70 case 0x46: return 0x55; // Ctrl + Pause
71 case 0x1C: return 0x6F; // Keypad Enter
72 case 0x35: return 0x7F; // Keypad /
73
74 // Any XT keyobard with these keys?
75 // http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf
76 // https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc
77 case 0x5B: return 0x5A; // Left GUI
78 case 0x5C: return 0x5B; // Right GUI
79 case 0x5D: return 0x5C; // Application
80 case 0x5E: return 0x5D; // Power(not used)
81 case 0x5F: return 0x5E; // Sleep(not used)
82 case 0x63: return 0x5F; // Wake (not used)
83 case 0x48: return 0x60; // Up
84 case 0x4B: return 0x61; // Left
85 case 0x50: return 0x62; // Down
86 case 0x4D: return 0x63; // Right
87 case 0x52: return 0x71; // Insert
88 case 0x53: return 0x72; // Delete
89 case 0x47: return 0x74; // Home
90 case 0x4F: return 0x75; // End
91 case 0x49: return 0x77; // Home
92 case 0x51: return 0x78; // End
93 case 0x1D: return 0x7A; // Right Ctrl
94 case 0x38: return 0x7C; // Right Alt
95 }
96 return 0x00;
97}
98
99uint8_t matrix_scan(void)
100{
101 static enum {
102 INIT,
103 E0,
104 // Pause: E1 1D 45, E1 9D C5
105 E1,
106 E1_1D,
107 E1_9D,
108 } state = INIT;
109
110 uint8_t code = xt_host_recv();
111 if (!code) return 0;
112 xprintf("%02X ", code);
113 switch (state) {
114 case INIT:
115 switch (code) {
116 case 0xE0:
117 state = E0;
118 break;
119 case 0xE1:
120 state = E1;
121 break;
122 default:
123 if (code < 0x80)
124 matrix_make(code);
125 else
126 matrix_break(code & 0x7F);
127 break;
128 }
129 break;
130 case E0:
131 switch (code) {
132 case 0x2A:
133 case 0xAA:
134 case 0x36:
135 case 0xB6:
136 //ignore fake shift
137 state = INIT;
138 break;
139 default:
140 if (code < 0x80)
141 matrix_make(move_e0code(code));
142 else
143 matrix_break(move_e0code(code & 0x7F));
144 state = INIT;
145 break;
146 }
147 break;
148 case E1:
149 switch (code) {
150 case 0x1D:
151 state = E1_1D;
152 break;
153 case 0x9D:
154 state = E1_9D;
155 break;
156 default:
157 state = INIT;
158 break;
159 }
160 break;
161 case E1_1D:
162 switch (code) {
163 case 0x45:
164 matrix_make(0x55);
165 break;
166 default:
167 state = INIT;
168 break;
169 }
170 break;
171 case E1_9D:
172 switch (code) {
173 case 0x45:
174 matrix_break(0x55);
175 break;
176 default:
177 state = INIT;
178 break;
179 }
180 break;
181 default:
182 state = INIT;
183 }
184 matrix_scan_quantum();
185 return 1;
186}
187
188inline
189uint8_t matrix_get_row(uint8_t row)
190{
191 return matrix[row];
192}
193
194inline
195static void matrix_make(uint8_t code)
196{
197 if (!matrix_is_on(ROW(code), COL(code))) {
198 matrix[ROW(code)] |= 1<<COL(code);
199 }
200}
201
202inline
203static void matrix_break(uint8_t code)
204{
205 if (matrix_is_on(ROW(code), COL(code))) {
206 matrix[ROW(code)] &= ~(1<<COL(code));
207 }
208}
209
210void matrix_clear(void)
211{
212 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
213}
214
215bool matrix_is_on(uint8_t row, uint8_t col)
216{
217 return (matrix_get_row(row) & (1<<col));
218}
219
220#if (MATRIX_COLS <= 8)
221# define print_matrix_header() print("\nr/c 01234567\n")
222# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
223#elif (MATRIX_COLS <= 16)
224# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
225# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
226#elif (MATRIX_COLS <= 32)
227# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
228# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
229#endif
230
231void matrix_print(void)
232{
233 print_matrix_header();
234
235 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
236 phex(row); print(": ");
237 print_matrix_row(row);
238 print("\n");
239 }
240}
241
242/*
243XT Scancodes
244============
245- http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf
246- https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc
247
24801-53: Normal codes used in original XT keyboard
24954-7F: Not used in original XT keyboard
250
251 0 1 2 3 4 5 6 7 8 9 A B C D E F
252 50 - - - - * * x x x x * * * o o o
253 60 * * * * x x x x x x x x x x x *
254 70 x * * x * * x * * x * x * x x *
255
256-: codes existed in original XT keyboard
257*: E0-escaped codes converted into unused code area(internal use in TMK)
258x: Non-espcaped codes(not used in real keyboards probably, for CodeSet2-CodeSet1 translation purpose)
259o: reserved
260
261Usage in TMK:
262
263 00 (reserved) DO NOT USE
264 54 PrintScr*
265 55 Pause*
266 56 Euro2
267 57 F11
268 58 F12
269 59 Keypad =
270 5A LGUI*
271 5B RGUI*
272 5C APP*
273 5D (reserved)
274 5E (reserved)
275 5F (reserved)
276 60 cursor*
277 61 cursor*
278 62 cursor*
279 63 cursor*
280 64 F13
281 65 F14
282 66 F15
283 67 F16
284 68 F17
285 69 F18
286 6A F19
287 6B F20
288 6C F21
289 6D F22
290 6E F23
291 6F Keypad Enter*
292 70 KANA
293 71 nav*
294 72 nav*
295 73 RO
296 74 nav*
297 75 nav*
298 76 F24
299 77 nav*
300 78 nav*
301 79 HENKAN
302 7A RCTL*
303 7B MUHENKAN
304 7C RALT*
305 7D JPY
306 7E Keypad ,
307 7F Keypad / *
308
309*/
diff --git a/keyboards/converter/xt_usb/rules.mk b/keyboards/converter/xt_usb/rules.mk
new file mode 100644
index 000000000..0b8731f32
--- /dev/null
+++ b/keyboards/converter/xt_usb/rules.mk
@@ -0,0 +1,62 @@
1# MCU name
2MCU = atmega32u4
3
4# Processor frequency.
5# This will define a symbol, F_CPU, in all source code files equal to the
6# processor frequency in Hz. You can then use this symbol in your source code to
7# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
8# automatically to create a 32-bit value in your source code.
9#
10# This will be an integer division of F_USB below, as it is sourced by
11# F_USB after it has run through any CPU prescalers. Note that this value
12# does not *change* the processor frequency - it should merely be updated to
13# reflect the processor speed set externally so that the code can use accurate
14# software delays.
15F_CPU = 16000000
16
17
18#
19# LUFA specific
20#
21# Target architecture (see library "Board Types" documentation).
22ARCH = AVR8
23
24# Input clock frequency.
25# This will define a symbol, F_USB, in all source code files equal to the
26# input clock frequency (before any prescaling is performed) in Hz. This value may
27# differ from F_CPU if prescaling is used on the latter, and is required as the
28# raw input clock is fed directly to the PLL sections of the AVR for high speed
29# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
30# at the end, this will be done automatically to create a 32-bit value in your
31# source code.
32#
33# If no clock division is performed on the input clock inside the AVR (via the
34# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
35F_USB = $(F_CPU)
36
37# Interrupt driven control endpoint task(+60)
38OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
39
40# Bootloader
41# This indicates which bootloader is present on the board.
42# BOOTLOADER = caterina # Pro Micro
43BOOTLOADER = halfkay # Teensy
44
45
46# Build Options
47# comment out to disable the options.
48#
49BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
50MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
51EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
52CONSOLE_ENABLE = yes # Console for debug(+400)
53COMMAND_ENABLE = yes # Commands for debug and configuration
54NKRO_ENABLE = yes # USB Nkey Rollover
55XT_ENABLE = yes
56CUSTOM_MATRIX = yes
57
58
59# Optimize size but this may cause error "relocation truncated to fit"
60#EXTRALDFLAGS = -Wl,--relax
61
62SRC = matrix.c led.c
diff --git a/keyboards/converter/xt_usb/xt_usb.c b/keyboards/converter/xt_usb/xt_usb.c
new file mode 100644
index 000000000..88acee0b0
--- /dev/null
+++ b/keyboards/converter/xt_usb/xt_usb.c
@@ -0,0 +1 @@
#include "xt_usb.h"
diff --git a/keyboards/converter/xt_usb/xt_usb.h b/keyboards/converter/xt_usb/xt_usb.h
new file mode 100644
index 000000000..9785158b4
--- /dev/null
+++ b/keyboards/converter/xt_usb/xt_usb.h
@@ -0,0 +1,132 @@
1/*
2Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#pragma once
18
19#include "quantum.h"
20
21/* IBM XT keyboard layout
22 * ,-------. ,--------------------------------------------------------------------------.
23 * | F1| F2| |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| BS |NumLck |ScrLck |
24 * |-------| |--------------------------------------------------------------------------|
25 * | F3| F4| | Tab | Q| W| E| R| T| Y| U| I| O| P| [| ] | | 7| 8| 9| -|
26 * |-------| |------------------------------------------------------|Ent|---------------|
27 * | F5| F6| | Ctrl | A| S| D| F| G| H| J| K| L| ;| '| `| | 4| 5| 6| |
28 * |-------| |----------------------------------------------------------------------| |
29 * | F7| F8| |Shif| \| Z| X| C| V| B| N| M| ,| .| /|Shift|PrS| 1| 2| 3| +|
30 * |-------| |----------------------------------------------------------------------| |
31 * | F9|F10| | Alt | Space |CapsLck| 0 | . | |
32 * `-------' `--------------------------------------------------------------------------'
33 * Scan code set 1
34 * ,-------. ,--------------------------------------------------------------------------.
35 * | 3B| 3C| | 01| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 0E | 45 | 46 |
36 * |-------| |--------------------------------------------------------------------------|
37 * | 3D| 3E| | 0F | 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B | | 47| 48| 49| 4A|
38 * |-------| |------------------------------------------------------| 1C|---------------|
39 * | 3F| 40| | 1D | 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| | 4B| 4C| 4D| |
40 * |-------| |----------------------------------------------------------------------| |
41 * | 41| 42| | 2A | 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35| 36 |*37| 4F| 50| 51| 4E|
42 * |-------| |----------------------------------------------------------------------| |
43 * | 43| 44| | 38 | 39 | 3A | 52 | 53 | |
44 * `-------' `--------------------------------------------------------------------------'
45 */
46#define LAYOUT_xt( \
47 K3B,K3C, K01,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K0E, K45, K46, \
48 K3D,K3E, K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B, K47,K48,K49,K4A, \
49 K3F,K40, K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K1C,K4B,K4C,K4D, \
50 K41,K42, K2A,K2B,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35,K36,K54,K4F,K50,K51,K4E, \
51 K43,K44, K38, K39, K3A, K52, K53 \
52) { \
53 { KC_NO, K01, K02, K03, K04, K05, K06, K07 }, \
54 { K08, K09, K0A, K0B, K0C, K0D, K0E, K0F }, \
55 { K10, K11, K12, K13, K14, K15, K16, K17 }, \
56 { K18, K19, K1A, K1B, K1C, K1D, K1E, K1F }, \
57 { K20, K21, K22, K23, K24, K25, K26, K27 }, \
58 { K28, K29, K2A, K2B, K2C, K2D, K2E, K2F }, \
59 { K30, K31, K32, K33, K34, K35, K36, KC_NO }, \
60 { K38, K39, K3A, K3B, K3C, K3D, K3E, K3F }, \
61 { K40, K41, K42, K43, K44, K45, K46, K47 }, \
62 { K48, K49, K4A, K4B, K4C, K4D, K4E, K4F }, \
63 { K50, K51, K52, K53, K54, KC_NO, KC_NO, KC_NO }, \
64 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
65 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
66 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
67 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
68 { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \
69}
70
71/* Extended keyboard layout
72 * ,-----------------------------------------------.
73 * |F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|
74 * ,---. |-----------------------------------------------| ,-----------. ,-----------.
75 * |Esc| |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12| |PrS|ScL|Pau| |VDn|VUp|Mut|
76 * `---' `-----------------------------------------------' `-----------' `-----------'
77 * ,-----------------------------------------------------------. ,-----------. ,---------------.
78 * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -|
79 * |-----------------------------------------------------------| |-----------| |---------------|
80 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|End|PgD| | 7| 8| 9| +|
81 * |-----------------------------------------------------------| `-----------' |---------------|
82 * |CapsL | A| S| D| F| G| H| J| K| L| ;| '| #|Entr| | 4| 5| 6|KP,|
83 * |-----------------------------------------------------------| ,---. |---------------|
84 * |Shft| <| Z| X| C| V| B| N| M| ,| .| /| RO|Shift | |Up | | 1| 2| 3|Ent|
85 * |-----------------------------------------------------------| ,-----------. |---------------|
86 * |Ctl|Gui|Alt|MHEN| Space |HENK|KANA|Alt|Gui|App|Ctl| |Lef|Dow|Rig| | 0| .|KP=|
87 * `-----------------------------------------------------------' `-----------' `---------------'
88 * ,-----------------------------------------------.
89 * | 64| 65| 66| 67| 68| 69| 6A| 6B| 6C| 6D| 6E| 76|
90 * ,---. |-----------------------------------------------| ,-----------. ,-----------.
91 * | 01| | 3B| 3C| 3D| 3E| 3F| 40| 41| 42| 43| 44| 57| 58| |*37| 46|*45| |e5E|e5F|e63|
92 * `---' `-----------------------------------------------' `-----------' `-----------'
93 * ,-----------------------------------------------------------. ,-----------. ,---------------.
94 * | 29| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D| 7D| 0E| |e52|e47|e49| | 45|e35| 37| 4A|
95 * |-----------------------------------------------------------| |-----------| |---------------|
96 * | 0F | 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 2B | |e53|e4F|e51| | 47| 48| 49| 4E|
97 * |-----------------------------------------------------------| `-----------' |---------------|
98 * | 3A | 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 00| 1C | | 4B| 4C| 4D| 7E|
99 * |-----------------------------------------------------------| ,---. |---------------|
100 * | 2A | 56| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35| 73| 36 | |e48| | 4F| 50| 51|e1C|
101 * |-----------------------------------------------------------| ,-----------. |---------------|
102 * | 1D|e5B| 38| 7B | 39 | 79 | 70 |e38|e5C|e5D|e1D| |e4B|e50|e4D| | 52| 53| 59|
103 * `-----------------------------------------------------------' `-----------' `---------------'
104 * e: E0-escaped codes
105 * *: special handling codes
106 */
107#define LAYOUT( \
108 K64,K65,K66,K67,K68,K69,K6A,K6B,K6C,K6D,K6E,K76, \
109 K01, K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,K57,K58, K54,K46,K55, K5D,K5E,K5F, \
110 K29,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K7D,K0E, K71,K74,K77, K45,K7F,K37,K4A, \
111 K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B, K2B, K72,K75,K78, K47,K48,K49,K4E, \
112 K3A,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28, K00,K1C, K4B,K4C,K4D,K7E, \
113 K2A,K56,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35, K73,K36, K60, K4F,K50,K51,K6F, \
114 K1D,K5A,K38,K7B, K39, K79,K70,K7C,K5B,K5C,K7A, K61,K62,K63, K52,K53,K59 \
115) { \
116 { K00, K01, K02, K03, K04, K05, K06, K07 }, \
117 { K08, K09, K0A, K0B, K0C, K0D, K0E, K0F }, \
118 { K10, K11, K12, K13, K14, K15, K16, K17 }, \
119 { K18, K19, K1A, K1B, K1C, K1D, K1E, K1F }, \
120 { K20, K21, K22, K23, K24, K25, K26, K27 }, \
121 { K28, K29, K2A, K2B, K2C, K2D, K2E, K2F }, \
122 { K30, K31, K32, K33, K34, K35, K36, K37 }, \
123 { K38, K39, K3A, K3B, K3C, K3D, K3E, K3F }, \
124 { K40, K41, K42, K43, K44, K45, K46, K47 }, \
125 { K48, K49, K4A, K4B, K4C, K4D, K4E, K4F }, \
126 { K50, K51, K52, K53, K54, K55, K56, K57 }, \
127 { K58, K59, K5A, K5B, K5C, K5D, K5E, K5F }, \
128 { K60, K61, K62, K63, K64, K65, K66, K67 }, \
129 { K68, K69, K6A, K6B, K6C, K6D, K6E, K6F }, \
130 { K70, K71, K72, K73, K74, K75, K76, K77 }, \
131 { K78, K79, K7A, K7B, K7C, K7D, K7E, K7F } \
132}
diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk
index 54913329e..78b9deb29 100644
--- a/tmk_core/protocol.mk
+++ b/tmk_core/protocol.mk
@@ -50,5 +50,10 @@ ifdef ADB_MOUSE_ENABLE
50 OPT_DEFS += -DADB_MOUSE_ENABLE -DMOUSE_ENABLE 50 OPT_DEFS += -DADB_MOUSE_ENABLE -DMOUSE_ENABLE
51endif 51endif
52 52
53ifdef XT_ENABLE
54 SRC += $(PROTOCOL_DIR)/xt_interrupt.c
55 OPT_DEFS += -DXT_ENABLE
56endif
57
53# Search Path 58# Search Path
54VPATH += $(TMK_DIR)/protocol 59VPATH += $(TMK_DIR)/protocol
diff --git a/tmk_core/protocol/xt.h b/tmk_core/protocol/xt.h
new file mode 100644
index 000000000..93bc5daf8
--- /dev/null
+++ b/tmk_core/protocol/xt.h
@@ -0,0 +1,71 @@
1/*
2Copyright 2018 Jun WAKO <wakojun@gmail.com>
3Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
4
5This software is licensed with a Modified BSD License.
6All of this is supposed to be Free Software, Open Source, DFSG-free,
7GPL-compatible, and OK to use in both free and proprietary applications.
8Additions and corrections to this file are welcome.
9
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions are met:
13
14* Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16
17* Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in
19 the documentation and/or other materials provided with the
20 distribution.
21
22* Neither the name of the copyright holders nor the names of
23 contributors may be used to endorse or promote products derived
24 from this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36POSSIBILITY OF SUCH DAMAGE.
37*/
38
39#ifndef XT_H
40#define XT_H
41
42#define XT_DATA_IN() do { \
43 XT_DATA_DDR &= ~(1<<XT_DATA_BIT); \
44 XT_DATA_PORT |= (1<<XT_DATA_BIT); \
45} while (0)
46
47#define XT_DATA_READ() (XT_DATA_PIN&(1<<XT_DATA_BIT))
48
49#define XT_DATA_LO() do { \
50 XT_DATA_PORT &= ~(1<<XT_DATA_BIT); \
51 XT_DATA_DDR |= (1<<XT_DATA_BIT); \
52} while (0)
53
54
55#define XT_CLOCK_IN() do { \
56 XT_CLOCK_DDR &= ~(1<<XT_CLOCK_BIT); \
57 XT_CLOCK_PORT |= (1<<XT_CLOCK_BIT); \
58} while (0)
59
60#define XT_CLOCK_READ() (XT_CLOCK_PIN&(1<<XT_CLOCK_BIT))
61
62#define XT_CLOCK_LO() do { \
63 XT_CLOCK_PORT &= ~(1<<XT_CLOCK_BIT); \
64 XT_CLOCK_DDR |= (1<<XT_CLOCK_BIT); \
65} while (0)
66
67
68void xt_host_init(void);
69uint8_t xt_host_recv(void);
70
71#endif
diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c
new file mode 100644
index 000000000..3823bbd3a
--- /dev/null
+++ b/tmk_core/protocol/xt_interrupt.c
@@ -0,0 +1,173 @@
1/*
2Copyright 2018 Jun WAKO <wakojun@gmail.com>
3Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
4
5This software is licensed with a Modified BSD License.
6All of this is supposed to be Free Software, Open Source, DFSG-free,
7GPL-compatible, and OK to use in both free and proprietary applications.
8Additions and corrections to this file are welcome.
9
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions are met:
13
14* Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16
17* Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in
19 the documentation and/or other materials provided with the
20 distribution.
21
22* Neither the name of the copyright holders nor the names of
23 contributors may be used to endorse or promote products derived
24 from this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36POSSIBILITY OF SUCH DAMAGE.
37*/
38
39#include <stdbool.h>
40#include <avr/interrupt.h>
41#include <util/delay.h>
42#include "xt.h"
43#include "wait.h"
44#include "print.h"
45
46static inline uint8_t pbuf_dequeue(void);
47static inline void pbuf_enqueue(uint8_t data);
48static inline bool pbuf_has_data(void);
49static inline void pbuf_clear(void);
50
51void xt_host_init(void)
52{
53 XT_INT_INIT();
54 XT_INT_OFF();
55
56 /* hard reset */
57#ifdef XT_RESET
58 XT_RESET();
59#endif
60
61 /* soft reset: pull clock line down for 20ms */
62 XT_DATA_LO();
63 XT_CLOCK_LO();
64 _delay_ms(20);
65
66 /* input mode with pullup */
67 XT_CLOCK_IN();
68 XT_DATA_IN();
69
70 XT_INT_ON();
71}
72
73/* get data received by interrupt */
74uint8_t xt_host_recv(void)
75{
76 if (pbuf_has_data()) {
77 return pbuf_dequeue();
78 } else {
79 return 0;
80 }
81}
82
83ISR(XT_INT_VECT)
84{
85 /*
86 * XT signal format consits of 10 or 9 clocks and sends start bits and 8-bit data,
87 * which should be read on falling edge of clock.
88 *
89 * start(0), start(1), bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7
90 *
91 * Original IBM XT keyboard sends start(0) bit while some of clones don't.
92 * Start(0) bit is read as low on data line while start(1) as high.
93 *
94 * https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol
95 */
96 static enum {
97 START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7
98 } state = START;
99 static uint8_t data = 0;
100
101 uint8_t dbit = XT_DATA_READ();
102
103 // This is needed if using PCINT which can be called on both falling and rising edge
104 //if (XT_CLOCK_READ()) return;
105
106 switch (state) {
107 case START:
108 // ignore start(0) bit
109 if (!dbit) return;
110 break;
111 case BIT0 ... BIT7:
112 data >>= 1;
113 if (dbit)
114 data |= 0x80;
115 break;
116 }
117 if (state++ == BIT7) {
118 pbuf_enqueue(data);
119 state = START;
120 data = 0;
121 }
122 return;
123}
124
125/*--------------------------------------------------------------------
126 * Ring buffer to store scan codes from keyboard
127 *------------------------------------------------------------------*/
128#define PBUF_SIZE 32
129static uint8_t pbuf[PBUF_SIZE];
130static uint8_t pbuf_head = 0;
131static uint8_t pbuf_tail = 0;
132static inline void pbuf_enqueue(uint8_t data)
133{
134 uint8_t sreg = SREG;
135 cli();
136 uint8_t next = (pbuf_head + 1) % PBUF_SIZE;
137 if (next != pbuf_tail) {
138 pbuf[pbuf_head] = data;
139 pbuf_head = next;
140 } else {
141 print("pbuf: full\n");
142 }
143 SREG = sreg;
144}
145static inline uint8_t pbuf_dequeue(void)
146{
147 uint8_t val = 0;
148
149 uint8_t sreg = SREG;
150 cli();
151 if (pbuf_head != pbuf_tail) {
152 val = pbuf[pbuf_tail];
153 pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
154 }
155 SREG = sreg;
156
157 return val;
158}
159static inline bool pbuf_has_data(void)
160{
161 uint8_t sreg = SREG;
162 cli();
163 bool has_data = (pbuf_head != pbuf_tail);
164 SREG = sreg;
165 return has_data;
166}
167static inline void pbuf_clear(void)
168{
169 uint8_t sreg = SREG;
170 cli();
171 pbuf_head = pbuf_tail = 0;
172 SREG = sreg;
173}