X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=converter%2Fibmpc_usb%2Fibmpc_usb.c;h=99e65a4a3bfbb29654cae43572fe4ea1a604e3e5;hb=9f041460313bc16e3f8a9677faced4d38d343d9a;hp=eb71d3335c721ef80b2524036b835c0387ceadbc;hpb=8e7027f11573d4f28aa352986da406c07b99df0a;p=max%2Ftmk_keyboard.git diff --git a/converter/ibmpc_usb/ibmpc_usb.c b/converter/ibmpc_usb/ibmpc_usb.c index eb71d333..99e65a4a 100644 --- a/converter/ibmpc_usb/ibmpc_usb.c +++ b/converter/ibmpc_usb/ibmpc_usb.c @@ -1,5 +1,5 @@ /* -Copyright 2019 Jun Wako +Copyright 2019,2020 Jun Wako This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -68,6 +68,7 @@ static uint16_t read_keyboard_id(void) if (code == -1) { id = 0x0000; goto DONE; } // AT id = (code & 0xFF)<<8; + // Mouse responds with one-byte 00, this returns 00FF [y] p.14 code = read_wait(500); id |= code & 0xFF; @@ -218,25 +219,50 @@ uint8_t matrix_scan(void) case READ_ID: xprintf("R%u ", timer_read()); + // SKIDATA-2-DE(and some other keyboards?) stores 'Code Set' setting in nonvlatile memory + // and keeps it until receiving reset. Sending reset here may be useful to clear it, perhaps. + // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#select-alternate-scan-codesf0 + //ibmpc_host_send(0xFF); // reset command + //read_wait(500); // BAT takes 600-900ms(84-key) or 300-500ms(101/102-key) [8] 4-7, 4-39 + keyboard_id = read_keyboard_id(); if (ibmpc_error) { xprintf("\nERR:%02X\n", ibmpc_error); ibmpc_error = IBMPC_ERR_NONE; } - if (0xAB00 == (keyboard_id & 0xFF00)) { // CodeSet2 PS/2 - keyboard_kind = PC_AT; - } else if (0xBF00 == (keyboard_id & 0xFF00)) { // CodeSet3 Terminal - keyboard_kind = PC_TERMINAL; - } else if (0x0000 == keyboard_id) { // CodeSet2 AT + if (0x0000 == keyboard_id) { // CodeSet2 AT(IBM PC AT 84-key) keyboard_kind = PC_AT; - } else if (0xFFFF == keyboard_id) { // CodeSet1 XT + } else if (0xFFFF == keyboard_id) { // CodeSet1 XT keyboard_kind = PC_XT; - } else if (0xFFFE == keyboard_id) { // CodeSet2 PS/2 fails to response? + } else if (0xFFFE == keyboard_id) { // CodeSet2 PS/2 fails to response? keyboard_kind = PC_AT; - } else if (0x00FF == keyboard_id) { // Mouse is not supported + } else if (0x00FF == keyboard_id) { // Mouse is not supported xprintf("Mouse: not supported\n"); keyboard_kind = NONE; +#ifdef G80_2551_SUPPORT + } else if (0xAB86 == keyboard_id || + 0xAB85 == keyboard_id) { // For G80-2551 and other 122-key terminal + // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#ab86 + // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#ab85 + + if ((0xFA == ibmpc_host_send(0xF0)) && + (0xFA == ibmpc_host_send(0x03))) { + // switch to code set 3 + keyboard_kind = PC_TERMINAL; + } else { + keyboard_kind = PC_AT; + } +#endif + } else if (0xBFB0 == keyboard_id) { // IBM RT Keyboard + // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#bfb0 + // TODO: LED indicator fix + //keyboard_kind = PC_TERMINAL_IBM_RT; + keyboard_kind = PC_TERMINAL; + } else if (0xAB00 == (keyboard_id & 0xFF00)) { // CodeSet2 PS/2 + keyboard_kind = PC_AT; + } else if (0xBF00 == (keyboard_id & 0xFF00)) { // CodeSet3 Terminal + keyboard_kind = PC_TERMINAL; } else { keyboard_kind = PC_AT; } @@ -254,6 +280,7 @@ uint8_t matrix_scan(void) led_set(host_keyboard_leds()); break; case PC_TERMINAL: + // Set all keys to make/break type ibmpc_host_send(0xF8); break; default: @@ -327,7 +354,7 @@ void matrix_clear(void) void led_set(uint8_t usb_led) { - if (keyboard_kind != PC_AT) return; + //if (keyboard_kind != PC_AT) return; uint8_t ibmpc_led = 0; if (usb_led & (1< F13 case 0x18: return 0x10; // (WWW favourites) -> F14 case 0x20: return 0x18; // (WWW refresh) -> F15 @@ -691,7 +718,7 @@ static int8_t process_cs2(void) state = INIT; break; case 0x84: // Alt'd PrintScreen - matrix_make(0x6F); + matrix_make(0x7F); state = INIT; break; case 0xAA: // Self-test passed @@ -738,7 +765,7 @@ static int8_t process_cs2(void) state = INIT; break; case 0x84: // Alt'd PrintScreen - matrix_break(0x6F); + matrix_break(0x7F); state = INIT; break; default: @@ -830,15 +857,19 @@ static int8_t process_cs2(void) /* * Terminal: Scan Code Set 3 * - * See [3], [7] - * - * Scan code 0x83 and 0x84 are handled exceptioanally to fit into 1-byte range index. + * See [3], [7] and + * https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#scan-code-set-3 */ static int8_t process_cs3(void) { static enum { READY, F0, +#ifdef G80_2551_SUPPORT + // G80-2551 four extra keys around cursor keys + G80, + G80_F0, +#endif } state = READY; uint16_t code = ibmpc_host_recv(); @@ -861,18 +892,41 @@ static int8_t process_cs3(void) case 0xF0: state = F0; break; - case 0x83: // F7 + case 0x83: // PrintScreen matrix_make(0x02); break; - case 0x84: // keypad - + case 0x84: // Keypad * matrix_make(0x7F); break; + case 0x85: // Muhenkan + matrix_make(0x0B); + break; + case 0x86: // Henkan + matrix_make(0x06); + break; + case 0x87: // Hiragana + matrix_make(0x00); + break; + case 0x8B: // Left GUI + matrix_make(0x01); + break; + case 0x8C: // Right GUI + matrix_make(0x09); + break; + case 0x8D: // Application + matrix_make(0x0A); + break; +#ifdef G80_2551_SUPPORT + case 0x80: // G80-2551 four extra keys around cursor keys + state = G80; + break; +#endif default: // normal key make if (code < 0x80) { matrix_make(code); } else { xprintf("!CS3_READY!\n"); - return -1; + //return -1; } } break; @@ -889,24 +943,100 @@ static int8_t process_cs3(void) state = READY; return -1; break; - case 0x83: // F7 + case 0x83: // PrintScreen matrix_break(0x02); state = READY; break; - case 0x84: // keypad - + case 0x84: // Keypad * matrix_break(0x7F); state = READY; break; + case 0x85: // Muhenkan + matrix_break(0x0B); + state = READY; + break; + case 0x86: // Henkan + matrix_break(0x06); + state = READY; + break; + case 0x87: // Hiragana + matrix_break(0x00); + state = READY; + break; + case 0x8B: // Left GUI + matrix_break(0x01); + state = READY; + break; + case 0x8C: // Right GUI + matrix_break(0x09); + state = READY; + break; + case 0x8D: // Application + matrix_break(0x0A); + state = READY; + break; default: state = READY; if (code < 0x80) { matrix_break(code); } else { xprintf("!CS3_F0!\n"); - return -1; + //return -1; } } break; +#ifdef G80_2551_SUPPORT + /* + * G80-2551 terminal keyboard support + * https://deskthority.net/wiki/Cherry_G80-2551 + * https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#g80-2551-in-code-set-3 + */ + case G80: // G80-2551 four extra keys around cursor keys + switch (code) { + case (0x26): // TD= -> JYEN + matrix_make(0x5D); + break; + case (0x25): // page with edge -> NUHS + matrix_make(0x53); + break; + case (0x16): // two pages -> RO + matrix_make(0x51); + break; + case (0x1E): // calc -> KANA + matrix_make(0x00); + break; + case (0xF0): + state = G80_F0; + return 0; + default: + // Not supported + matrix_clear(); + break; + } + state = READY; + break; + case G80_F0: + switch (code) { + case (0x26): // TD= -> JYEN + matrix_break(0x5D); + break; + case (0x25): // page with edge -> NUHS + matrix_break(0x53); + break; + case (0x16): // two pages -> RO + matrix_break(0x51); + break; + case (0x1E): // calc -> KANA + matrix_break(0x00); + break; + default: + // Not supported + matrix_clear(); + break; + } + state = READY; + break; +#endif } return 0; } @@ -941,6 +1071,9 @@ static int8_t process_cs3(void) * [7] The IBM 6110344 Keyboard - Scan Code Set 3 of 122-key terminal keyboard * https://www.seasip.info/VintagePC/ibm_6110344.html * + * [8] IBM PC AT Technical Reference 1986 + * http://bitsavers.org/pdf/ibm/pc/at/6183355_PC_AT_Technical_Reference_Mar86.pdf + * * [y] TrackPoint Engineering Specifications for version 3E * https://web.archive.org/web/20100526161812/http://wwwcssrv.almaden.ibm.com/trackpoint/download.html *