From d3332d32daacde13cb0ff488d1c1dd0f79a3d423 Mon Sep 17 00:00:00 2001 From: John Hickey Date: Mon, 9 May 2016 22:56:33 -0700 Subject: [PATCH 1/2] 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< Date: Sat, 14 May 2016 14:29:05 -0700 Subject: [PATCH 2/2] Make Bell and Click work on Sun Type 5c. It seems that the Sun Type 5c keyboard will not send the arrow key codes if both shift keys are pressed. To get bell and keyclick working, I used Home/End as toggle keys instead. --- converter/sun_usb/command_extra.c | 53 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/converter/sun_usb/command_extra.c b/converter/sun_usb/command_extra.c index aba3fe6d..08f3a710 100644 --- a/converter/sun_usb/command_extra.c +++ b/converter/sun_usb/command_extra.c @@ -5,41 +5,47 @@ #include "print.h" #include "command.h" +bool sun_bell = false; +bool sun_click = false; + + bool command_extra(uint8_t code) { switch (code) { case KC_H: case KC_SLASH: /* ? */ print("\n\n----- Sun converter Help -----\n"); - print("Up: Bell On\n"); - print("Down: Bell Off\n"); - print("Left: Click On\n"); - print("Right: Click Off\n"); - print("PgUp: LED all On\n"); - print("PgDown: LED all On\n"); - print("Insert: Layout\n"); - print("Delete: Reset\n"); + print("Home: Toggle Bell\n"); + print("End: Toggle Click\n"); + print("PgUp: LED all On\n"); + print("PgDown: LED all On\n"); + print("Insert: Layout\n"); + print("Delete: Reset\n"); return false; case KC_DEL: print("Reset\n"); serial_send(0x01); break; - case KC_UP: - print("Bell On\n"); - serial_send(0x02); - break; - case KC_DOWN: - print("Bell Off\n"); - serial_send(0x03); - break; - case KC_LEFT: - print("Click On\n"); - serial_send(0x0A); - break; - case KC_RIGHT: - print("Click Off\n"); - serial_send(0x0B); + case KC_HOME: + sun_bell = !sun_bell; + if (sun_bell) { + print("Bell On\n"); + serial_send(0x02); + } else { + print("Bell Off\n"); + serial_send(0x03); + } break; + case KC_END: + sun_click = !sun_click; + if (sun_click) { + print("Click On\n"); + serial_send(0x0A); + } else { + print("Click Off\n"); + serial_send(0x0B); + } + break; case KC_PGUP: print("LED all on\n"); serial_send(0x0E); @@ -55,6 +61,7 @@ bool command_extra(uint8_t code) serial_send(0x0F); break; default: + xprintf("Unknown extra command: %02X\n", code); return false; } return true;