]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
pc98_usb: Update protocol commands
authortmk <hasu@tmk-kbd.com>
Sat, 2 Jun 2018 11:40:08 +0000 (20:40 +0900)
committertmk <hasu@tmk-kbd.com>
Thu, 7 Jun 2018 08:22:08 +0000 (17:22 +0900)
converter/pc98_usb/config.h
converter/pc98_usb/matrix.c

index 6793c7945999777eb11ac0e4105003f9125a1867..9341708ffaa9c4080e959c2b88e317c12f2d862d 100644 (file)
@@ -123,6 +123,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
         UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \
         UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); /* TX interrupt, TX: enable */ \
         UCSR1C |= (1<<UPM11) | (1<<UPM10);  /* parity: none(00), even(01), odd(11) */ \
+        DDRD  &= ~(1<<2); PORTD |=  (1<<2); /* Pull-up RXD pin */ \
         sei(); \
     } while(0)
 #else
index c6b6253aac3c3851ac30e464a8aa5096429d6b8a..54bb30414d7b458859ecf21f7d137386f0c2815a 100644 (file)
@@ -22,6 +22,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "print.h"
 #include "util.h"
 #include "matrix.h"
+#include "led.h"
 #include "debug.h"
 #include "protocol/serial.h"
 
@@ -47,38 +48,46 @@ static uint8_t matrix[MATRIX_ROWS];
 #define COL(code)      (code&0x07)
 
 
-static void pc98_inhibit_repeat(void)
+static void pc98_send(uint8_t data)
 {
-    uint8_t code;
-
-    while (serial_recv()) ;
-RETRY:
     PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
-    _delay_ms(500);
-    serial_send(0x9C);
-
+    _delay_ms(1);
+    serial_send(data);
+    _delay_ms(1);
     PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
-    _delay_ms(100);
-    while (!(code = serial_recv())) ;
-    print("PC98: send 9C: "); print_hex8(code); print("\n");
-    if (code != 0xFA) goto RETRY;
+}
 
+static int16_t pc98_wait_response(void)
+{
+    int16_t code = -1;
+    uint8_t timeout = 255;
+    while (timeout-- && (code = serial_recv2()) == -1) _delay_ms(1);
+    return code;
+}
 
+static void pc98_inhibit_repeat(void)
+{
+    uint16_t code;
 
-    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
+    // clear recv buffer
+    while (serial_recv()) ;
+RETRY:
     _delay_ms(100);
-    serial_send(0x70);
+    pc98_send(0x9C);
+    code = pc98_wait_response();
+    if (code != -1) xprintf("PC98: send 9C: %02X\n", code);
+    if (code != 0xFA) goto RETRY;
 
-    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
     _delay_ms(100);
-    //code = serial_recv();
-    while (!(code = serial_recv())) ;
-    print("PC98: send 70: "); print_hex8(code); print("\n");
+    pc98_send(0x70);
+    code = pc98_wait_response();
+    if (code != -1) xprintf("PC98: send 70: %02X\n", code);
     if (code != 0xFA) goto RETRY;
 }
 
 void matrix_init(void)
 {
+    debug_keyboard = true;
     PC98_RST_DDR |= (1<<PC98_RST_BIT);
     PC98_RDY_DDR |= (1<<PC98_RDY_BIT);
     PC98_RTY_DDR |= (1<<PC98_RTY_BIT);
@@ -116,24 +125,11 @@ uint8_t matrix_scan(void)
 {
     uint16_t code;
     PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
-    _delay_us(30);
+    //_delay_us(30);
     code = serial_recv2();
     PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
     if (code == -1) return 0;
 
-if (code == 0x60) {
-    pc98_inhibit_repeat();
-
-/*
-    PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
-    _delay_ms(100);
-    serial_send(0x96);
-    PC98_RDY_PORT &= ~(1<<PC98_RDY_BIT);
-*/
-
-    return 0;
-}
-
     print_hex8(code); print(" ");
 
     if (code&0x80) {