aboutsummaryrefslogtreecommitdiff
path: root/protocol
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-07-28 17:34:41 +0900
committertmk <nobody@nowhere>2013-07-28 17:34:41 +0900
commitdaa4a4235fd4a88b3b6f64e4a2cf590f28f4b65b (patch)
tree91d6c2de3f98bf11e85868c6cd4802f05a55e60e /protocol
parentc7d309e34bf5d05f245811389bea495d814e2111 (diff)
downloadqmk_firmware-daa4a4235fd4a88b3b6f64e4a2cf590f28f4b65b.tar.gz
qmk_firmware-daa4a4235fd4a88b3b6f64e4a2cf590f28f4b65b.zip
Add NKRO support for LUFA
Diffstat (limited to 'protocol')
-rw-r--r--protocol/lufa/descriptor.c65
-rw-r--r--protocol/lufa/descriptor.h24
-rw-r--r--protocol/lufa/lufa.c28
-rw-r--r--protocol/pjrc/usb_keyboard.c13
4 files changed, 112 insertions, 18 deletions
diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c
index d34ab1c5a..a46ba3ec6 100644
--- a/protocol/lufa/descriptor.c
+++ b/protocol/lufa/descriptor.c
@@ -57,9 +57,11 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
57 HID_RI_REPORT_COUNT(8, 0x08), 57 HID_RI_REPORT_COUNT(8, 0x08),
58 HID_RI_REPORT_SIZE(8, 0x01), 58 HID_RI_REPORT_SIZE(8, 0x01),
59 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), 59 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
60
60 HID_RI_REPORT_COUNT(8, 0x01), 61 HID_RI_REPORT_COUNT(8, 0x01),
61 HID_RI_REPORT_SIZE(8, 0x08), 62 HID_RI_REPORT_SIZE(8, 0x08),
62 HID_RI_INPUT(8, HID_IOF_CONSTANT), 63 HID_RI_INPUT(8, HID_IOF_CONSTANT), /* reserved */
64
63 HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */ 65 HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */
64 HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */ 66 HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */
65 HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */ 67 HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */
@@ -69,6 +71,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
69 HID_RI_REPORT_COUNT(8, 0x01), 71 HID_RI_REPORT_COUNT(8, 0x01),
70 HID_RI_REPORT_SIZE(8, 0x03), 72 HID_RI_REPORT_SIZE(8, 0x03),
71 HID_RI_OUTPUT(8, HID_IOF_CONSTANT), 73 HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
74
72 HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */ 75 HID_RI_USAGE_PAGE(8, 0x07), /* Keyboard */
73 HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */ 76 HID_RI_USAGE_MINIMUM(8, 0x00), /* Reserved (no event indicated) */
74 HID_RI_USAGE_MAXIMUM(8, 0xFF), /* Keyboard Application */ 77 HID_RI_USAGE_MAXIMUM(8, 0xFF), /* Keyboard Application */
@@ -210,11 +213,13 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM NKROReport[] =
210 213
211 HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */ 214 HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */
212 HID_RI_USAGE_MINIMUM(8, 0x00), /* Keyboard 0 */ 215 HID_RI_USAGE_MINIMUM(8, 0x00), /* Keyboard 0 */
213 HID_RI_USAGE_MAXIMUM(8, NKRO_SIZE*8-1), /* Keyboard Right GUI */ 216 HID_RI_USAGE_MAXIMUM(8, (NKRO_EPSIZE-1)*8-1), /* Keyboard Right GUI */
214 HID_RI_LOGICAL_MINIMUM(8, 0x00), 217 HID_RI_LOGICAL_MINIMUM(8, 0x00),
215 HID_RI_LOGICAL_MAXIMUM(8, 0x01), 218 HID_RI_LOGICAL_MAXIMUM(8, 0x01),
216 HID_RI_REPORT_COUNT(8, NKRO_SIZE*8), 219 HID_RI_REPORT_COUNT(8, (NKRO_EPSIZE-1)*8),
217 HID_RI_REPORT_SIZE(8, 0x01), 220 HID_RI_REPORT_SIZE(8, 0x01),
221 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
222 HID_RI_END_COLLECTION(0),
218}; 223};
219#endif 224#endif
220 225
@@ -439,6 +444,48 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
439 .PollingIntervalMS = 0x01 444 .PollingIntervalMS = 0x01
440 }, 445 },
441#endif 446#endif
447
448 /*
449 * NKRO
450 */
451#ifdef NKRO_ENABLE
452 .NKRO_Interface =
453 {
454 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
455
456 .InterfaceNumber = NKRO_INTERFACE,
457 .AlternateSetting = 0x00,
458
459 .TotalEndpoints = 1,
460
461 .Class = HID_CSCP_HIDClass,
462 .SubClass = HID_CSCP_NonBootSubclass,
463 .Protocol = HID_CSCP_NonBootProtocol,
464
465 .InterfaceStrIndex = NO_DESCRIPTOR
466 },
467
468 .NKRO_HID =
469 {
470 .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
471
472 .HIDSpec = VERSION_BCD(01.11),
473 .CountryCode = 0x00,
474 .TotalReportDescriptors = 1,
475 .HIDReportType = HID_DTYPE_Report,
476 .HIDReportLength = sizeof(NKROReport)
477 },
478
479 .NKRO_INEndpoint =
480 {
481 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
482
483 .EndpointAddress = (ENDPOINT_DIR_IN | NKRO_IN_EPNUM),
484 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
485 .EndpointSize = NKRO_EPSIZE,
486 .PollingIntervalMS = 0x01
487 },
488#endif
442}; 489};
443 490
444 491
@@ -536,6 +583,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
536 Size = sizeof(USB_HID_Descriptor_HID_t); 583 Size = sizeof(USB_HID_Descriptor_HID_t);
537 break; 584 break;
538#endif 585#endif
586#ifdef NKRO_ENABLE
587 case NKRO_INTERFACE:
588 Address = &ConfigurationDescriptor.NKRO_HID;
589 Size = sizeof(USB_HID_Descriptor_HID_t);
590 break;
591#endif
539 } 592 }
540 break; 593 break;
541 case HID_DTYPE_Report: 594 case HID_DTYPE_Report:
@@ -562,6 +615,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
562 Size = sizeof(ConsoleReport); 615 Size = sizeof(ConsoleReport);
563 break; 616 break;
564#endif 617#endif
618#ifdef NKRO_ENABLE
619 case NKRO_INTERFACE:
620 Address = &NKROReport;
621 Size = sizeof(NKROReport);
622 break;
623#endif
565 } 624 }
566 break; 625 break;
567 } 626 }
diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h
index 44f20d5a2..9ee1c04d7 100644
--- a/protocol/lufa/descriptor.h
+++ b/protocol/lufa/descriptor.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2012 Jun Wako <wakojun@gmail.com> 2 * Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3 * This file is based on: 3 * This file is based on:
4 * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse 4 * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
5 * LUFA-120219/Demos/Device/Lowlevel/GenericHID 5 * LUFA-120219/Demos/Device/Lowlevel/GenericHID
@@ -78,6 +78,13 @@ typedef struct
78 USB_Descriptor_Endpoint_t Console_INEndpoint; 78 USB_Descriptor_Endpoint_t Console_INEndpoint;
79 USB_Descriptor_Endpoint_t Console_OUTEndpoint; 79 USB_Descriptor_Endpoint_t Console_OUTEndpoint;
80#endif 80#endif
81
82#ifdef NKRO_ENABLE
83 // NKRO HID Interface
84 USB_Descriptor_Interface_t NKRO_Interface;
85 USB_HID_Descriptor_HID_t NKRO_HID;
86 USB_Descriptor_Endpoint_t NKRO_INEndpoint;
87#endif
81} USB_Descriptor_Configuration_t; 88} USB_Descriptor_Configuration_t;
82 89
83 90
@@ -102,9 +109,15 @@ typedef struct
102# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE 109# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
103#endif 110#endif
104 111
112#ifdef NKRO_ENABLE
113# define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
114#else
115# define NKRO_INTERFACE CONSOLE_INTERFACE
116#endif
117
105 118
106/* nubmer of interfaces */ 119/* nubmer of interfaces */
107#define TOTAL_INTERFACES (CONSOLE_INTERFACE + 1) 120#define TOTAL_INTERFACES (NKRO_INTERFACE + 1)
108 121
109 122
110// Endopoint number and size 123// Endopoint number and size
@@ -125,6 +138,12 @@ typedef struct
125#ifdef CONSOLE_ENABLE 138#ifdef CONSOLE_ENABLE
126# define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1) 139# define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
127# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2) 140# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
141#else
142# define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM
143#endif
144
145#ifdef NKRO_ENABLE
146# define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
128#endif 147#endif
129 148
130 149
@@ -132,6 +151,7 @@ typedef struct
132#define MOUSE_EPSIZE 8 151#define MOUSE_EPSIZE 8
133#define EXTRAKEY_EPSIZE 8 152#define EXTRAKEY_EPSIZE 8
134#define CONSOLE_EPSIZE 32 153#define CONSOLE_EPSIZE 32
154#define NKRO_EPSIZE 16
135 155
136 156
137uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 157uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index a863b8d23..c1617cd05 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -220,6 +220,12 @@ void EVENT_USB_Device_ConfigurationChanged(void)
220 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, 220 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
221 CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); 221 CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
222#endif 222#endif
223
224#ifdef NKRO_ENABLE
225 /* Setup NKRO HID Report Endpoints */
226 ConfigSuccess &= ENDPOINT_CONFIG(NKRO_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
227 NKRO_EPSIZE, ENDPOINT_BANK_SINGLE);
228#endif
223} 229}
224 230
225/* 231/*
@@ -350,15 +356,31 @@ static void send_keyboard(report_keyboard_t *report)
350 if (USB_DeviceState != DEVICE_STATE_Configured) 356 if (USB_DeviceState != DEVICE_STATE_Configured)
351 return; 357 return;
352 358
353 // TODO: handle NKRO report
354 /* Select the Keyboard Report Endpoint */ 359 /* Select the Keyboard Report Endpoint */
355 Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); 360#ifdef NKRO_ENABLE
361 if (keyboard_nkro) {
362 Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
363 }
364 else
365#endif
366 {
367 Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
368 }
356 369
357 /* Check if Keyboard Endpoint Ready for Read/Write */ 370 /* Check if Keyboard Endpoint Ready for Read/Write */
358 while (--timeout && !Endpoint_IsReadWriteAllowed()) ; 371 while (--timeout && !Endpoint_IsReadWriteAllowed()) ;
359 372
360 /* Write Keyboard Report Data */ 373 /* Write Keyboard Report Data */
361 Endpoint_Write_Stream_LE(report, sizeof(report_keyboard_t), NULL); 374#ifdef NKRO_ENABLE
375 if (keyboard_nkro) {
376 Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL);
377 }
378 else
379#endif
380 {
381 /* boot mode */
382 Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL);
383 }
362 384
363 /* Finalize the stream transfer to send the last packet */ 385 /* Finalize the stream transfer to send the last packet */
364 Endpoint_ClearIN(); 386 Endpoint_ClearIN();
diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c
index 49b85c179..de798fcc2 100644
--- a/protocol/pjrc/usb_keyboard.c
+++ b/protocol/pjrc/usb_keyboard.c
@@ -57,12 +57,12 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report)
57 57
58#ifdef NKRO_ENABLE 58#ifdef NKRO_ENABLE
59 if (keyboard_nkro) 59 if (keyboard_nkro)
60 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS); 60 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE);
61 else 61 else
62#endif 62#endif
63 { 63 {
64 if (usb_keyboard_protocol) 64 if (usb_keyboard_protocol)
65 result = send_report(report, KBD_ENDPOINT, 0, KBD_REPORT_KEYS); 65 result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE);
66 else 66 else
67 result = send_report(report, KBD_ENDPOINT, 0, 6); 67 result = send_report(report, KBD_ENDPOINT, 0, 6);
68 } 68 }
@@ -104,15 +104,8 @@ static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, ui
104 cli(); 104 cli();
105 UENUM = endpoint; 105 UENUM = endpoint;
106 } 106 }
107 UEDATX = report->mods;
108#ifdef NKRO_ENABLE
109 if (!keyboard_nkro)
110 UEDATX = 0;
111#else
112 UEDATX = 0;
113#endif
114 for (uint8_t i = keys_start; i < keys_end; i++) { 107 for (uint8_t i = keys_start; i < keys_end; i++) {
115 UEDATX = report->keys[i]; 108 UEDATX = report->raw[i];
116 } 109 }
117 UEINTX = 0x3A; 110 UEINTX = 0x3A;
118 SREG = intr_state; 111 SREG = intr_state;