From 8a92f254e1d87007db2cc0d746a3c2436c91cbe3 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 28 Feb 2018 15:48:06 +0900 Subject: [PATCH] xt_usb: read data on falling edge soft/hard reset See https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol - read data on falling edge of clock - add soft reset and hard reset --- converter/xt_usb/Makefile | 12 +++--- converter/xt_usb/config.h | 19 ++++++++-- tmk_core/protocol.mk | 7 ---- tmk_core/protocol/xt_interrupt.c | 64 +++++++++++++++++++++----------- tmk_core/protocol/xt_io.h | 3 ++ tmk_core/protocol/xt_io_avr.c | 12 ++++++ 6 files changed, 78 insertions(+), 39 deletions(-) diff --git a/converter/xt_usb/Makefile b/converter/xt_usb/Makefile index 395115e3..e7fb6c8a 100644 --- a/converter/xt_usb/Makefile +++ b/converter/xt_usb/Makefile @@ -11,7 +11,9 @@ TMK_DIR = ../../tmk_core TARGET_DIR = . # project specific files -SRC = matrix.c \ +SRC = protocol/xt_interrupt.c \ + protocol/xt_io_avr.c \ + matrix.c \ led.c ifdef KEYMAP @@ -61,7 +63,7 @@ ARCH = AVR8 F_USB = $(F_CPU) # Interrupt driven control endpoint task(+60) -#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # Boot Section Size in *bytes* @@ -71,6 +73,7 @@ F_USB = $(F_CPU) # LUFA bootloader 4096 # USBaspLoader 2048 OPT_DEFS += -DBOOTLOADER_SIZE=512 +#OPT_DEFS += -DBOOTLOADER_SIZE=4096 # Build Options @@ -84,11 +87,6 @@ COMMAND_ENABLE = yes # Commands for debug and configuration NKRO_ENABLE = yes # USB Nkey Rollover -# XT/2 Options -# -XT_USE_INT = yes # uses external interrupt for falling edge of PS/2 clock pin - - # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/converter/xt_usb/config.h b/converter/xt_usb/config.h index a9f44ca8..24bf3c33 100644 --- a/converter/xt_usb/config.h +++ b/converter/xt_usb/config.h @@ -45,8 +45,6 @@ along with this program. If not, see . /* * XT Pin interrupt */ -#ifdef XT_USE_INT -/* uses INT1 for clock line(ATMega32U4) */ #define XT_CLOCK_PORT PORTD #define XT_CLOCK_PIN PIND #define XT_CLOCK_DDR DDRD @@ -55,9 +53,23 @@ along with this program. If not, see . #define XT_DATA_PIN PIND #define XT_DATA_DDR DDRD #define XT_DATA_BIT 0 +#define XT_RST_PORT PORTB +#define XT_RST_PIN PINB +#define XT_RST_DDR DDRB +#define XT_RST_BIT 7 + +/* hard reset: low pulse for 500ms and after that HiZ for safety */ +#define XT_RESET() do { \ + XT_RST_PORT &= ~(1<. EIMSK &= ~(1<= 1 && state <= 8) { - wait_clock_lo(20); - data >>= 1; - if (data_in()) - data |= 0x80; - if (state == 8) - goto END; - state++; - } else { - goto DONE; + // This is needed if using PCINT which can be called on both falling and rising edge + if (clock_in()) return; + + switch (state) { + case START: + // ignore start(0) bit + if (!data_in()) return; + break; + case BIT0 ... BIT7: + data >>= 1; + if (data_in()) + data |= 0x80; + break; + } + if (++state == END) { + pbuf_enqueue(data); + state = START; + data = 0; } - goto RETURN; -END: - pbuf_enqueue(data); -DONE: - state = 0; - data = 0; -RETURN: return; } diff --git a/tmk_core/protocol/xt_io.h b/tmk_core/protocol/xt_io.h index 2e5f31b2..4198e655 100644 --- a/tmk_core/protocol/xt_io.h +++ b/tmk_core/protocol/xt_io.h @@ -4,4 +4,7 @@ bool clock_in(void); bool data_in(void); +void clock_lo(void); +void data_lo(void); + #endif diff --git a/tmk_core/protocol/xt_io_avr.c b/tmk_core/protocol/xt_io_avr.c index 6cd153a1..7775be7f 100644 --- a/tmk_core/protocol/xt_io_avr.c +++ b/tmk_core/protocol/xt_io_avr.c @@ -32,3 +32,15 @@ bool data_in(void) _delay_us(1); return XT_DATA_PIN&(1<