aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-11-28 15:50:17 +0900
committertmk <nobody@nowhere>2013-11-28 15:50:55 +0900
commit10b2b1ae431b31b2ae29228dcaccb5ea292bbf9a (patch)
tree8ce43042c9988a35051667aede10e8afc7dcf204
parent8b4fa599cf485f5d06314938a228a88dabb0b7f5 (diff)
downloadqmk_firmware-10b2b1ae431b31b2ae29228dcaccb5ea292bbf9a.tar.gz
qmk_firmware-10b2b1ae431b31b2ae29228dcaccb5ea292bbf9a.zip
Fix key stack and PS/2 Overrun
-rw-r--r--converter/ps2_usb/config.h86
-rw-r--r--converter/ps2_usb/matrix.c33
2 files changed, 73 insertions, 46 deletions
diff --git a/converter/ps2_usb/config.h b/converter/ps2_usb/config.h
index 1ad2bd1b4..c9bab1b07 100644
--- a/converter/ps2_usb/config.h
+++ b/converter/ps2_usb/config.h
@@ -40,6 +40,52 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
40) 40)
41 41
42 42
43//#define NO_SUSPEND_POWER_DOWN
44
45
46/*
47 * PS/2 Busywait
48 */
49#ifdef PS2_USE_BUSYWAIT
50#define PS2_CLOCK_PORT PORTD
51#define PS2_CLOCK_PIN PIND
52#define PS2_CLOCK_DDR DDRD
53#define PS2_CLOCK_BIT 5
54#define PS2_DATA_PORT PORTD
55#define PS2_DATA_PIN PIND
56#define PS2_DATA_DDR DDRD
57#define PS2_DATA_BIT 2
58#endif
59
60/*
61 * PS/2 Pin interrupt
62 */
63#ifdef PS2_USE_INT
64/* uses INT1 for clock line(ATMega32U4) */
65#define PS2_CLOCK_PORT PORTD
66#define PS2_CLOCK_PIN PIND
67#define PS2_CLOCK_DDR DDRD
68#define PS2_CLOCK_BIT 1
69#define PS2_DATA_PORT PORTD
70#define PS2_DATA_PIN PIND
71#define PS2_DATA_DDR DDRD
72#define PS2_DATA_BIT 2
73#define PS2_INT_INIT() do { \
74 EICRA |= ((1<<ISC11) | \
75 (0<<ISC10)); \
76} while (0)
77#define PS2_INT_ON() do { \
78 EIMSK |= (1<<INT1); \
79} while (0)
80#define PS2_INT_OFF() do { \
81 EIMSK &= ~(1<<INT1); \
82} while (0)
83#define PS2_INT_VECT INT1_vect
84#endif
85
86/*
87 * PS/2 USART
88 */
43#ifdef PS2_USE_USART 89#ifdef PS2_USE_USART
44#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) 90#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
45/* XCK for clock line and RXD for data line */ 91/* XCK for clock line and RXD for data line */
@@ -51,7 +97,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
51#define PS2_DATA_PIN PIND 97#define PS2_DATA_PIN PIND
52#define PS2_DATA_DDR DDRD 98#define PS2_DATA_DDR DDRD
53#define PS2_DATA_BIT 2 99#define PS2_DATA_BIT 2
54
55/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ 100/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
56/* set DDR of CLOCK as input to be slave */ 101/* set DDR of CLOCK as input to be slave */
57#define PS2_USART_INIT() do { \ 102#define PS2_USART_INIT() do { \
@@ -82,7 +127,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
82#define PS2_USART_RX_DATA UDR1 127#define PS2_USART_RX_DATA UDR1
83#define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1))) 128#define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
84#define PS2_USART_RX_VECT USART1_RX_vect 129#define PS2_USART_RX_VECT USART1_RX_vect
85
86#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) 130#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
87/* XCK for clock line and RXD for data line */ 131/* XCK for clock line and RXD for data line */
88#define PS2_CLOCK_PORT PORTD 132#define PS2_CLOCK_PORT PORTD
@@ -93,7 +137,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
93#define PS2_DATA_PIN PIND 137#define PS2_DATA_PIN PIND
94#define PS2_DATA_DDR DDRD 138#define PS2_DATA_DDR DDRD
95#define PS2_DATA_BIT 0 139#define PS2_DATA_BIT 0
96
97/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ 140/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
98/* set DDR of CLOCK as input to be slave */ 141/* set DDR of CLOCK as input to be slave */
99#define PS2_USART_INIT() do { \ 142#define PS2_USART_INIT() do { \
@@ -127,41 +170,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
127#endif 170#endif
128#endif 171#endif
129 172
130
131#ifdef PS2_USE_INT
132/* uses INT1 for clock line(ATMega32U4) */
133#define PS2_CLOCK_PORT PORTD
134#define PS2_CLOCK_PIN PIND
135#define PS2_CLOCK_DDR DDRD
136#define PS2_CLOCK_BIT 5
137#define PS2_DATA_PORT PORTD
138#define PS2_DATA_PIN PIND
139#define PS2_DATA_DDR DDRD
140#define PS2_DATA_BIT 2
141
142#define PS2_INT_INIT() do { \
143 EICRA |= ((1<<ISC11) | \
144 (0<<ISC10)); \
145} while (0)
146#define PS2_INT_ON() do { \
147 EIMSK |= (1<<INT1); \
148} while (0)
149#define PS2_INT_OFF() do { \
150 EIMSK &= ~(1<<INT1); \
151} while (0)
152#define PS2_INT_VECT INT1_vect
153#endif
154
155
156#ifdef PS2_USE_BUSYWAIT
157#define PS2_CLOCK_PORT PORTD
158#define PS2_CLOCK_PIN PIND
159#define PS2_CLOCK_DDR DDRD
160#define PS2_CLOCK_BIT 5
161#define PS2_DATA_PORT PORTD
162#define PS2_DATA_PIN PIND
163#define PS2_DATA_DDR DDRD
164#define PS2_DATA_BIT 2
165#endif
166
167#endif 173#endif
diff --git a/converter/ps2_usb/matrix.c b/converter/ps2_usb/matrix.c
index aa0c38c68..45344c0f7 100644
--- a/converter/ps2_usb/matrix.c
+++ b/converter/ps2_usb/matrix.c
@@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29 29
30static void matrix_make(uint8_t code); 30static void matrix_make(uint8_t code);
31static void matrix_break(uint8_t code); 31static void matrix_break(uint8_t code);
32static void matrix_clear(void);
32#ifdef MATRIX_HAS_GHOST 33#ifdef MATRIX_HAS_GHOST
33static bool matrix_has_ghost_in_row(uint8_t row); 34static bool matrix_has_ghost_in_row(uint8_t row);
34#endif 35#endif
@@ -84,6 +85,7 @@ uint8_t matrix_cols(void)
84 85
85void matrix_init(void) 86void matrix_init(void)
86{ 87{
88 debug_enable = true;
87 ps2_host_init(); 89 ps2_host_init();
88 90
89 // initialize matrix state: all keys off 91 // initialize matrix state: all keys off
@@ -209,16 +211,18 @@ uint8_t matrix_scan(void)
209 state = INIT; 211 state = INIT;
210 break; 212 break;
211 case 0x00: // Overrun [3]p.25 213 case 0x00: // Overrun [3]p.25
212 print("Overrun\n"); 214 matrix_clear();
213 clear_keyboard(); 215 clear_keyboard();
216 print("Overrun\n");
214 state = INIT; 217 state = INIT;
215 break; 218 break;
216 default: // normal key make 219 default: // normal key make
217 if (code < 0x80) { 220 if (code < 0x80) {
218 matrix_make(code); 221 matrix_make(code);
219 } else { 222 } else {
220 xprintf("unexpected scan code at INIT: %02X\n", code); 223 matrix_clear();
221 clear_keyboard(); 224 clear_keyboard();
225 xprintf("unexpected scan code at INIT: %02X\n", code);
222 } 226 }
223 state = INIT; 227 state = INIT;
224 } 228 }
@@ -239,8 +243,9 @@ uint8_t matrix_scan(void)
239 if (code < 0x80) { 243 if (code < 0x80) {
240 matrix_make(code|0x80); 244 matrix_make(code|0x80);
241 } else { 245 } else {
242 xprintf("unexpected scan code at E0: %02X\n", code); 246 matrix_clear();
243 clear_keyboard(); 247 clear_keyboard();
248 xprintf("unexpected scan code at E0: %02X\n", code);
244 } 249 }
245 state = INIT; 250 state = INIT;
246 } 251 }
@@ -255,12 +260,18 @@ uint8_t matrix_scan(void)
255 matrix_break(PRINT_SCREEN); 260 matrix_break(PRINT_SCREEN);
256 state = INIT; 261 state = INIT;
257 break; 262 break;
263 case 0xF0:
264 matrix_clear();
265 clear_keyboard();
266 xprintf("unexpected scan code at F0: F0(clear and cont.)\n");
267 break;
258 default: 268 default:
259 if (code < 0x80) { 269 if (code < 0x80) {
260 matrix_break(code); 270 matrix_break(code);
261 } else { 271 } else {
262 xprintf("unexpected scan code at F0: %02X\n", code); 272 matrix_clear();
263 clear_keyboard(); 273 clear_keyboard();
274 xprintf("unexpected scan code at F0: %02X\n", code);
264 } 275 }
265 state = INIT; 276 state = INIT;
266 } 277 }
@@ -275,8 +286,9 @@ uint8_t matrix_scan(void)
275 if (code < 0x80) { 286 if (code < 0x80) {
276 matrix_break(code|0x80); 287 matrix_break(code|0x80);
277 } else { 288 } else {
278 xprintf("unexpected scan code at E0_F0: %02X\n", code); 289 matrix_clear();
279 clear_keyboard(); 290 clear_keyboard();
291 xprintf("unexpected scan code at E0_F0: %02X\n", code);
280 } 292 }
281 state = INIT; 293 state = INIT;
282 } 294 }
@@ -369,10 +381,13 @@ uint8_t matrix_scan(void)
369 } 381 }
370 } 382 }
371 383
372 if (ps2_error > PS2_ERR_STARTBIT3) { 384 // TODO: request RESEND when error occurs?
385/*
386 if (PS2_IS_FAILED(ps2_error)) {
373 uint8_t ret = ps2_host_send(PS2_RESEND); 387 uint8_t ret = ps2_host_send(PS2_RESEND);
374 xprintf("Resend: %02X\n", ret); 388 xprintf("Resend: %02X\n", ret);
375 } 389 }
390*/
376 return 1; 391 return 1;
377} 392}
378 393
@@ -464,3 +479,9 @@ static void matrix_break(uint8_t code)
464 is_modified = true; 479 is_modified = true;
465 } 480 }
466} 481}
482
483inline
484static void matrix_clear(void)
485{
486 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
487}