2 Copyright 2012 Jun Wako <wakojun@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #define VENDOR_ID 0xFEED
22 #define PRODUCT_ID 0x9801
23 #define DEVICE_VER 0x0101
24 #define MANUFACTURER t.m.k.
25 #define PRODUCT PC98 keyboard converter
26 #define DESCRIPTION converts PC98 keyboard protocol into USB
30 #define MATRIX_ROWS 16
33 /* key combination for command */
34 #define IS_COMMAND() ( \
35 keyboard_report->keys[0] == KC_STOP || \
36 keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) \
40 /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
41 #define LOCKING_SUPPORT_ENABLE
42 /* Locking resynchronize hack */
43 #define LOCKING_RESYNC_ENABLE
45 /* Control LED indicatiors, which doesn't work well with locking support */
46 #define PC98_LED_CONTROL
49 /* PC98 Reset Port shared with TXD */
50 #define PC98_RST_DDR DDRD
51 #define PC98_RST_PORT PORTD
52 #define PC98_RST_BIT 3
54 #define PC98_RDY_DDR DDRD
55 #define PC98_RDY_PORT PORTD
56 #define PC98_RDY_BIT 4
58 #define PC98_RTY_DDR DDRD
59 #define PC98_RTY_PORT PORTD
60 #define PC98_RTY_BIT 1
63 * PC98 Serial(USART) configuration
64 * asynchronous, positive logic, 19200baud, bit order: LSB first
65 * 1-start bit, 8-data bit, odd parity, 1-stop bit
70 * Add protocol/serial_soft.c to SRC in Makefile
72 #define SERIAL_SOFT_BAUD 19200
73 #define SERIAL_SOFT_PARITY_ODD
74 #define SERIAL_SOFT_BIT_ORDER_LSB
75 #define SERIAL_SOFT_LOGIC_POSITIVE
77 #define SERIAL_SOFT_RXD_DDR DDRD
78 #define SERIAL_SOFT_RXD_PORT PORTD
79 #define SERIAL_SOFT_RXD_PIN PIND
80 #define SERIAL_SOFT_RXD_BIT 2
81 #define SERIAL_SOFT_RXD_READ() (SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT))
83 #define SERIAL_SOFT_RXD_VECT INT2_vect
84 #define SERIAL_SOFT_RXD_INIT() do { \
85 /* pin configuration: input with pull-up */ \
86 SERIAL_SOFT_RXD_DDR &= ~(1<<SERIAL_SOFT_RXD_BIT); \
87 SERIAL_SOFT_RXD_PORT |= (1<<SERIAL_SOFT_RXD_BIT); \
88 /* enable interrupt: INT2(falling edge) */ \
89 EICRA |= ((1<<ISC21)|(0<<ISC20)); \
93 #define SERIAL_SOFT_RXD_INT_ENTER()
94 #define SERIAL_SOFT_RXD_INT_EXIT() do { \
95 /* clear interrupt flag */ \
99 #define SERIAL_SOFT_TXD_DDR DDRD
100 #define SERIAL_SOFT_TXD_PORT PORTD
101 #define SERIAL_SOFT_TXD_PIN PIND
102 #define SERIAL_SOFT_TXD_BIT 3
103 #define SERIAL_SOFT_TXD_HI() do { SERIAL_SOFT_TXD_PORT |= (1<<SERIAL_SOFT_TXD_BIT); } while (0)
104 #define SERIAL_SOFT_TXD_LO() do { SERIAL_SOFT_TXD_PORT &= ~(1<<SERIAL_SOFT_TXD_BIT); } while (0)
105 #define SERIAL_SOFT_TXD_INIT() do { \
106 /* pin configuration: output */ \
107 SERIAL_SOFT_TXD_DDR |= (1<<SERIAL_SOFT_TXD_BIT); \
109 SERIAL_SOFT_TXD_ON(); \
114 * Hardware Serial(UART)
115 * Add protocol/serial_uart.c to SRC in Makefile
117 #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__)
118 #define SERIAL_UART_BAUD 19200
119 #define SERIAL_UART_DATA UDR1
120 #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
121 #define SERIAL_UART_RXD_VECT USART1_RX_vect
122 #define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
123 #define SERIAL_UART_INIT() do { \
124 UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \
125 UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \
126 UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \
127 UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); /* TX interrupt, TX: enable */ \
128 UCSR1C |= (1<<UPM11) | (1<<UPM10); /* parity: none(00), even(01), odd(11) */ \
129 DDRD &= ~(1<<2); PORTD |= (1<<2); /* Pull-up RXD pin */ \
133 #error "USART configuration is needed."