]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - converter/ps2_usb/config_vusb.h
Merge branch 'newdir'
[max/tmk_keyboard.git] / converter / ps2_usb / config_vusb.h
1 /*
2 Copyright 2011 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
22 #define VENDOR_ID       0xFEED
23 #define PRODUCT_ID      0x2233
24 // TODO: share these strings with usbconfig.h
25 // Edit usbconfig.h to change these.
26 #define MANUFACTURER    t.m.k.
27 #define PRODUCT         PS/2 keyboard converter
28 #define DESCRIPTION     convert PS/2 keyboard to USB
29
30
31 /* matrix size */
32 #define MATRIX_ROWS 32  // keycode bit: 3-0
33 #define MATRIX_COLS 8   // keycode bit: 6-4
34
35
36 /* key combination for command */
37 #define IS_COMMAND() ( \
38     keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) || \
39     keyboard_report->mods == (MOD_BIT(KB_LCTRL) | MOD_BIT(KB_RSHIFT)) \
40 )
41
42
43 /* mouse keys */
44 #ifdef MOUSEKEY_ENABLE
45 #   define MOUSEKEY_DELAY_TIME 255
46 #endif
47
48
49 /* PS/2 lines */
50 #define PS2_CLOCK_PORT  PORTD
51 #define PS2_CLOCK_PIN   PIND
52 #define PS2_CLOCK_DDR   DDRD
53 #define PS2_CLOCK_BIT   4
54 #define PS2_DATA_PORT   PORTD
55 #define PS2_DATA_PIN    PIND
56 #define PS2_DATA_DDR    DDRD
57 #define PS2_DATA_BIT    0
58
59
60 // Synchronous USART is used to receive data from keyboard.
61 // Use RXD pin for PS/2 DATA line and XCK for PS/2 CLOCK.
62 // NOTE: This is recomended strongly if you use V-USB library.
63 #define PS2_USE_USART
64
65 // External or Pin Change Interrupt is used to receive data from keyboard.
66 // Use INT1 or PCINTxx for PS/2 CLOCK line. see below.
67 //#define PS2_USE_INT
68
69
70 #ifdef PS2_USE_USART
71 // synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge
72 // set DDR of CLOCK as input to be slave
73 #define PS2_USART_INIT() do {   \
74     PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);   \
75     PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);     \
76     UCSR0C = ((1 << UMSEL00) |  \
77               (3 << UPM00)   |  \
78               (0 << USBS0)   |  \
79               (3 << UCSZ00)  |  \
80               (0 << UCPOL0));   \
81     UCSR0A = 0;                 \
82     UBRR0H = 0;                 \
83     UBRR0L = 0;                 \
84 } while (0)
85 #define PS2_USART_RX_INT_ON() do {  \
86     UCSR0B = ((1 << RXCIE0) |       \
87               (1 << RXEN0));        \
88 } while (0)
89 #define PS2_USART_RX_POLL_ON() do { \
90     UCSR0B = (1 << RXEN0);          \
91 } while (0)
92 #define PS2_USART_OFF() do {    \
93     UCSR0C = 0;                 \
94     UCSR0B &= ~((1 << RXEN0) |  \
95                 (1 << TXEN0));  \
96 } while (0)
97 #define PS2_USART_RX_READY      (UCSR0A & (1<<RXC0))
98 #define PS2_USART_RX_DATA       UDR0
99 #define PS2_USART_ERROR         (UCSR0A & ((1<<FE0) | (1<<DOR0) | (1<<UPE0)))
100 #define PS2_USART_RX_VECT       USART_RX_vect
101 #endif
102
103
104 #ifdef PS2_USE_INT
105 /* INT1
106 #define PS2_INT_INIT()  do {    \
107     EICRA |= ((1<<ISC11) |      \
108               (0<<ISC10));      \
109 } while (0)
110 #define PS2_INT_ON()  do {      \
111     EIMSK |= (1<<INT1);         \
112 } while (0)
113 #define PS2_INT_OFF() do {      \
114     EIMSK &= ~(1<<INT1);        \
115 } while (0)
116 #define PS2_INT_VECT    INT1_vect
117 */
118
119 /* PCINT20 */
120 #define PS2_INT_INIT()  do {    \
121     PCICR  |= (1<<PCIE2);       \
122 } while (0)
123 #define PS2_INT_ON()  do {      \
124     PCMSK2 |= (1<<PCINT20);     \
125 } while (0)
126 #define PS2_INT_OFF() do {      \
127     PCMSK2 &= ~(1<<PCINT20);    \
128     PCICR  &= ~(1<<PCIE2);      \
129 } while (0)
130 #define PS2_INT_VECT    PCINT2_vect
131 #endif
132
133 #endif