#include "print.h"
#include "util.h"
#include "matrix.h"
+#include "led.h"
#include "debug.h"
#include "protocol/serial.h"
#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);
{
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) {