From d3332d32daacde13cb0ff488d1c1dd0f79a3d423 Mon Sep 17 00:00:00 2001 From: John Hickey Date: Mon, 9 May 2016 22:56:33 -0700 Subject: [PATCH] Add hardware serial support for sun_usb converter Tested with a Sun Type 5c keyboard and a 7404 inverter. --- converter/sun_usb/Makefile | 11 ++- converter/sun_usb/README | 4 +- converter/sun_usb/config.h | 135 +++++++++++++++++++++++-------------- 3 files changed, 95 insertions(+), 55 deletions(-) diff --git a/converter/sun_usb/Makefile b/converter/sun_usb/Makefile index f046bfdd..12eceb5e 100644 --- a/converter/sun_usb/Makefile +++ b/converter/sun_usb/Makefile @@ -11,8 +11,8 @@ TARGET_DIR = . SRC = keymap.c \ matrix.c \ led.c \ - command_extra.c \ - protocol/serial_soft.c + command_extra.c + CONFIG_H = config.h @@ -64,8 +64,15 @@ MOUSEKEY_ENABLE = yes # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = yes # Console for debug COMMAND_ENABLE = yes # Commands for debug and configuration +#HARDWARE_SERIAL = yes # Use hardware serial (requires inverted serial, see README) #NKRO_ENABLE = yes # USB Nkey Rollover +ifdef HARDWARE_SERIAL + SRC := protocol/serial_uart.c $(SRC) + OPT_DEFS += -DHARDWARE_SERIAL +else + SRC := protocol/serial_soft.c $(SRC) +endif # Boot Section Size in bytes # Teensy halfKay 512 diff --git a/converter/sun_usb/README b/converter/sun_usb/README index 98340dd3..405a86ba 100644 --- a/converter/sun_usb/README +++ b/converter/sun_usb/README @@ -48,7 +48,9 @@ Frame format: 1-Start bit, 8-Data bits, No-Parity, 1-Stop bit To use AVR UART engine you need external inverter in front of RX and TX pin. Otherwise you can software serial routine to communicate the keyboard. -This converter uses software method, you doesn't need any inverter part. +This converter uses software method by default, so you don't need any inverter part. But +it can also be built with 'make HARDWARE_SERIAL=y' to enable hardware serial if there +is an inverter present. Good results have been obtained using a 74LS04 and hardware serial. Commands From System To Keyboard diff --git a/converter/sun_usb/config.h b/converter/sun_usb/config.h index 66036da9..414fd563 100644 --- a/converter/sun_usb/config.h +++ b/converter/sun_usb/config.h @@ -39,57 +39,88 @@ along with this program. If not, see . /* legacy keymap support */ #define USE_LEGACY_KEYMAP - -/* Serial(USART) configuration - * asynchronous, negative logic, 1200baud, no flow control - * 1-start bit, 8-data bit, non parity, 1-stop bit +/* HARDWARE_SERAIL assumes that a logic inverter (7404) is placed + * in front of RX/TX to produce the positive logic the MCU expects. + * The default is Software Serial. */ -#define SERIAL_SOFT_BAUD 1200 -#define SERIAL_SOFT_PARITY_NONE -#define SERIAL_SOFT_BIT_ORDER_LSB -#define SERIAL_SOFT_LOGIC_NEGATIVE -/* RXD Port */ -#define SERIAL_SOFT_RXD_ENABLE -#define SERIAL_SOFT_RXD_DDR DDRD -#define SERIAL_SOFT_RXD_PORT PORTD -#define SERIAL_SOFT_RXD_PIN PIND -#define SERIAL_SOFT_RXD_BIT 2 -#define SERIAL_SOFT_RXD_VECT INT2_vect -/* RXD Interupt */ -#ifdef SERIAL_SOFT_LOGIC_NEGATIVE -/* enable interrupt: INT2(rising edge) */ -#define INTR_TRIG_EDGE ((1<>8); /* baud rate */ \ + UCSR1B = (1<