aboutsummaryrefslogtreecommitdiff
path: root/protocol/lufa/lufa.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocol/lufa/lufa.c')
-rw-r--r--protocol/lufa/lufa.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index 86e9f23d1..a43a552a8 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -52,8 +52,8 @@
52#include "descriptor.h" 52#include "descriptor.h"
53#include "lufa.h" 53#include "lufa.h"
54 54
55static uint8_t idle_duration = 0; 55uint8_t keyboard_idle = 0;
56static uint8_t protocol_report = 1; 56uint8_t keyboard_protocol = 1;
57static uint8_t keyboard_led_stats = 0; 57static uint8_t keyboard_led_stats = 0;
58 58
59static report_keyboard_t keyboard_report_sent; 59static report_keyboard_t keyboard_report_sent;
@@ -290,21 +290,26 @@ void EVENT_USB_Device_ControlRequest(void)
290 case HID_REQ_GetProtocol: 290 case HID_REQ_GetProtocol:
291 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) 291 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
292 { 292 {
293 Endpoint_ClearSETUP(); 293 if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
294 while (!(Endpoint_IsINReady())); 294 Endpoint_ClearSETUP();
295 Endpoint_Write_8(protocol_report); 295 while (!(Endpoint_IsINReady()));
296 Endpoint_ClearIN(); 296 Endpoint_Write_8(keyboard_protocol);
297 Endpoint_ClearStatusStage(); 297 Endpoint_ClearIN();
298 Endpoint_ClearStatusStage();
299 }
298 } 300 }
299 301
300 break; 302 break;
301 case HID_REQ_SetProtocol: 303 case HID_REQ_SetProtocol:
302 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) 304 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
303 { 305 {
304 Endpoint_ClearSETUP(); 306 if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
305 Endpoint_ClearStatusStage(); 307 Endpoint_ClearSETUP();
308 Endpoint_ClearStatusStage();
306 309
307 protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00); 310 keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00);
311 clear_keyboard();
312 }
308 } 313 }
309 314
310 break; 315 break;
@@ -314,7 +319,7 @@ void EVENT_USB_Device_ControlRequest(void)
314 Endpoint_ClearSETUP(); 319 Endpoint_ClearSETUP();
315 Endpoint_ClearStatusStage(); 320 Endpoint_ClearStatusStage();
316 321
317 idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8); 322 keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8);
318 } 323 }
319 324
320 break; 325 break;
@@ -323,7 +328,7 @@ void EVENT_USB_Device_ControlRequest(void)
323 { 328 {
324 Endpoint_ClearSETUP(); 329 Endpoint_ClearSETUP();
325 while (!(Endpoint_IsINReady())); 330 while (!(Endpoint_IsINReady()));
326 Endpoint_Write_8(idle_duration); 331 Endpoint_Write_8(keyboard_idle);
327 Endpoint_ClearIN(); 332 Endpoint_ClearIN();
328 Endpoint_ClearStatusStage(); 333 Endpoint_ClearStatusStage();
329 } 334 }
@@ -349,32 +354,28 @@ static void send_keyboard(report_keyboard_t *report)
349 354
350 /* Select the Keyboard Report Endpoint */ 355 /* Select the Keyboard Report Endpoint */
351#ifdef NKRO_ENABLE 356#ifdef NKRO_ENABLE
352 if (keyboard_nkro) { 357 if (keyboard_nkro && keyboard_protocol) {
358 /* Report protocol - NKRO */
353 Endpoint_SelectEndpoint(NKRO_IN_EPNUM); 359 Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
354 360
355 /* Check if write ready for a polling interval around 1ms */ 361 /* Check if write ready for a polling interval around 1ms */
356 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4); 362 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4);
357 if (!Endpoint_IsReadWriteAllowed()) return; 363 if (!Endpoint_IsReadWriteAllowed()) return;
364
365 /* Write Keyboard Report Data */
366 Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL);
358 } 367 }
359 else 368 else
360#endif 369#endif
361 { 370 {
371 /* Boot protocol */
362 Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); 372 Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
363 373
364 /* Check if write ready for a polling interval around 10ms */ 374 /* Check if write ready for a polling interval around 10ms */
365 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); 375 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
366 if (!Endpoint_IsReadWriteAllowed()) return; 376 if (!Endpoint_IsReadWriteAllowed()) return;
367 }
368 377
369 /* Write Keyboard Report Data */ 378 /* Write Keyboard Report Data */
370#ifdef NKRO_ENABLE
371 if (keyboard_nkro) {
372 Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL);
373 }
374 else
375#endif
376 {
377 /* boot mode */
378 Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL); 379 Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL);
379 } 380 }
380 381