]> git.donarmstrong.com Git - qmk_firmware.git/blob - converter/pc98_usb/config.h
Add serial_uart.c and use it for PC98
[qmk_firmware.git] / converter / pc98_usb / config.h
1 /*
2 Copyright 2012 Jun Wako <wakojun@gmail.com>
3
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.
8
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.
13
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/>.
16 */
17
18 #ifndef CONFIG_H
19 #define CONFIG_H
20
21 #define VENDOR_ID       0xFEED
22 #define PRODUCT_ID      0x9898
23 #define DEVICE_VER      0x0100
24 #define MANUFACTURER    t.m.k.
25 #define PRODUCT         PC98 keyboard converter
26 #define DESCRIPTION     converts PC98 keyboard protocol into USB
27
28
29 /* matrix size */
30 #define MATRIX_ROWS     16
31 #define MATRIX_COLS     8
32
33 /* To use new keymap framework */
34 #define USE_KEYMAP_V2
35
36 /* key combination for command */
37 #define IS_COMMAND()    ( \
38     host_get_first_key() == KC_CANCEL \
39 )
40
41
42 /* PC98 Reset Port shared with TXD */
43 #define PC98_RST_DDR    DDRD
44 #define PC98_RST_PORT   PORTD
45 #define PC98_RST_BIT    3
46 /* PC98 Ready Port */
47 #define PC98_RDY_DDR    DDRD
48 #define PC98_RDY_PORT   PORTD
49 #define PC98_RDY_BIT    4
50 /* PC98 Retry Port */
51 #define PC98_RTY_DDR    DDRD
52 #define PC98_RTY_PORT   PORTD
53 #define PC98_RTY_BIT    5
54
55 /*
56  * PC98 Serial(USART) configuration
57  *     asynchronous, positive logic, 19200baud, bit order: LSB first
58  *     1-start bit, 8-data bit, odd parity, 1-stop bit
59  */
60 /*
61  * Software Serial
62  */
63 #define SERIAL_SOFT_BAUD                19200
64 #define SERIAL_SOFT_PARITY_ODD
65 #define SERIAL_SOFT_BIT_ORDER_LSB
66 #define SERIAL_SOFT_LOGIC_POSITIVE
67 /* RXD Port */
68 #define SERIAL_SOFT_RXD_DDR             DDRD
69 #define SERIAL_SOFT_RXD_PORT            PORTD
70 #define SERIAL_SOFT_RXD_PIN             PIND
71 #define SERIAL_SOFT_RXD_BIT             2
72 #ifdef SERIAL_SOFT_LOGIC_NEGATIVE
73     #define SERIAL_SOFT_RXD_READ()      ~(SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT))
74 #else
75     #define SERIAL_SOFT_RXD_READ()      (SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT))
76 #endif
77 /* RXD Interupt */
78 #define SERIAL_SOFT_RXD_VECT            INT2_vect
79 #define SERIAL_SOFT_RXD_INIT()          do { \
80     /* pin configuration: input with pull-up */ \
81     SERIAL_SOFT_RXD_DDR &= ~(1<<SERIAL_SOFT_RXD_BIT); \
82     SERIAL_SOFT_RXD_PORT |= (1<<SERIAL_SOFT_RXD_BIT); \
83     /* enable interrupt: INT2(falling edge) */ \
84     EICRA |= ((1<<ISC21)|(0<<ISC20)); \
85     EIMSK |= (1<<INT2); \
86     sei(); \
87 } while (0)
88 #define SERIAL_SOFT_RXD_INT_ENTER()
89 #define SERIAL_SOFT_RXD_INT_EXIT()      do { \
90     /* clear interrupt  flag */ \
91     EIFR = (1<<INTF2); \
92 } while (0)
93 /* TXD Port */
94 #define SERIAL_SOFT_TXD_DDR             DDRD
95 #define SERIAL_SOFT_TXD_PORT            PORTD
96 #define SERIAL_SOFT_TXD_PIN             PIND
97 #define SERIAL_SOFT_TXD_BIT             3
98 #ifdef SERIAL_SOFT_LOGIC_NEGATIVE
99     #define SERIAL_SOFT_TXD_ON()        do { \
100         SERIAL_SOFT_TXD_PORT &= ~(1<<SERIAL_SOFT_TXD_BIT); \
101     } while (0)
102     #define SERIAL_SOFT_TXD_OFF()       do { \
103         SERIAL_SOFT_TXD_PORT |=  (1<<SERIAL_SOFT_TXD_BIT); \
104     } while (0)
105 #else
106     #define SERIAL_SOFT_TXD_ON()        do { \
107         SERIAL_SOFT_TXD_PORT |=  (1<<SERIAL_SOFT_TXD_BIT); \
108     } while (0)
109     #define SERIAL_SOFT_TXD_OFF()       do { \
110         SERIAL_SOFT_TXD_PORT &= ~(1<<SERIAL_SOFT_TXD_BIT); \
111     } while (0)
112 #endif
113 #define SERIAL_SOFT_TXD_INIT()          do { \
114     /* pin configuration: output */ \
115     SERIAL_SOFT_TXD_DDR |= (1<<SERIAL_SOFT_TXD_BIT); \
116     /* idle */ \
117     SERIAL_SOFT_TXD_ON(); \
118 } while (0)
119
120
121 /*
122  * Hardware Serial(UART)
123  */
124 #ifdef __AVR_ATmega32U4__
125     #define SERIAL_UART_BAUD       19200
126     #define SERIAL_UART_DATA       UDR1
127     #define SERIAL_UART_UBRR       ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
128     #define SERIAL_UART_RXD_VECT   USART1_RX_vect
129     #define SERIAL_UART_TXD_READY  (UCSR1A&(1<<UDRE1))
130     #define SERIAL_UART_INIT()     do { \
131         UBRR1L = (uint8_t) SERIAL_UART_UBRR;       /* baud rate */ \
132         UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8);  /* baud rate */ \
133         UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \
134         UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); /* TX interrupt, TX: enable */ \
135         UCSR1C |= (1<<UPM11) | (1<<UPM10);  /* parity: none(00), even(01), odd(11) */ \
136         sei(); \
137     } while(0)
138 #else
139     #error "USART configuration is needed."
140 #endif
141
142
143 #endif