lufa: Integrate NKRO into infterface 0
Build options for Keyboard:
NKRO_ENABLE - NKRO shares interface 0 with Boot/6KRO
this can save Endpoint resources of MCU
NKRO_6KRO_ENABLE - NKRO has its own interface
this is equivalent to old NKRO impl.
Otherwise - Boot/6KRO interface 0 only
This commit is contained in:
parent
3341801f21
commit
d5bdc55b17
3 changed files with 61 additions and 11 deletions
|
|
@ -46,6 +46,8 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
|
const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
|
||||||
{
|
{
|
||||||
|
#ifndef NKRO_ENABLE
|
||||||
|
/* 6KRO - Boot protocol */
|
||||||
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
|
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
|
||||||
HID_RI_USAGE(8, 0x06), /* Keyboard */
|
HID_RI_USAGE(8, 0x06), /* Keyboard */
|
||||||
HID_RI_COLLECTION(8, 0x01), /* Application */
|
HID_RI_COLLECTION(8, 0x01), /* Application */
|
||||||
|
|
@ -81,6 +83,40 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
|
||||||
HID_RI_REPORT_SIZE(8, 0x08),
|
HID_RI_REPORT_SIZE(8, 0x08),
|
||||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||||
HID_RI_END_COLLECTION(0),
|
HID_RI_END_COLLECTION(0),
|
||||||
|
#else
|
||||||
|
/* NKRO - Report protocol */
|
||||||
|
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
|
||||||
|
HID_RI_USAGE(8, 0x06), /* Keyboard */
|
||||||
|
HID_RI_COLLECTION(8, 0x01), /* Application */
|
||||||
|
HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */
|
||||||
|
HID_RI_USAGE_MINIMUM(8, 0xE0), /* Keyboard Left Control */
|
||||||
|
HID_RI_USAGE_MAXIMUM(8, 0xE7), /* Keyboard Right GUI */
|
||||||
|
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||||
|
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
|
||||||
|
HID_RI_REPORT_COUNT(8, 0x08),
|
||||||
|
HID_RI_REPORT_SIZE(8, 0x01),
|
||||||
|
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
|
||||||
|
HID_RI_USAGE_PAGE(8, 0x08), /* LEDs */
|
||||||
|
HID_RI_USAGE_MINIMUM(8, 0x01), /* Num Lock */
|
||||||
|
HID_RI_USAGE_MAXIMUM(8, 0x05), /* Kana */
|
||||||
|
HID_RI_REPORT_COUNT(8, 0x05),
|
||||||
|
HID_RI_REPORT_SIZE(8, 0x01),
|
||||||
|
HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
|
||||||
|
HID_RI_REPORT_COUNT(8, 0x01),
|
||||||
|
HID_RI_REPORT_SIZE(8, 0x03),
|
||||||
|
HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
|
||||||
|
|
||||||
|
HID_RI_USAGE_PAGE(8, 0x07), /* Key Codes */
|
||||||
|
HID_RI_USAGE_MINIMUM(8, 0x00), /* Keyboard 0 */
|
||||||
|
HID_RI_USAGE_MAXIMUM(8, (NKRO_EPSIZE-1)*8-1), /* Keyboard Right GUI */
|
||||||
|
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||||
|
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
|
||||||
|
HID_RI_REPORT_COUNT(8, (NKRO_EPSIZE-1)*8),
|
||||||
|
HID_RI_REPORT_SIZE(8, 0x01),
|
||||||
|
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_RI_END_COLLECTION(0),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MOUSE_ENABLE
|
#ifdef MOUSE_ENABLE
|
||||||
|
|
@ -203,7 +239,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] =
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
const USB_Descriptor_HIDReport_Datatype_t PROGMEM NKROReport[] =
|
const USB_Descriptor_HIDReport_Datatype_t PROGMEM NKROReport[] =
|
||||||
{
|
{
|
||||||
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
|
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
|
||||||
|
|
@ -322,8 +358,13 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
||||||
|
|
||||||
.EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM),
|
.EndpointAddress = (ENDPOINT_DIR_IN | KEYBOARD_IN_EPNUM),
|
||||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||||
|
#ifdef NKRO_ENABLE
|
||||||
|
.EndpointSize = NKRO_EPSIZE,
|
||||||
|
.PollingIntervalMS = 0x01
|
||||||
|
#else
|
||||||
.EndpointSize = KEYBOARD_EPSIZE,
|
.EndpointSize = KEYBOARD_EPSIZE,
|
||||||
.PollingIntervalMS = 0x0A
|
.PollingIntervalMS = 0x0A
|
||||||
|
#endif
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -465,7 +506,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
||||||
/*
|
/*
|
||||||
* NKRO
|
* NKRO
|
||||||
*/
|
*/
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
.NKRO_Interface =
|
.NKRO_Interface =
|
||||||
{
|
{
|
||||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||||
|
|
@ -600,7 +641,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
||||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
case NKRO_INTERFACE:
|
case NKRO_INTERFACE:
|
||||||
Address = &ConfigurationDescriptor.NKRO_HID;
|
Address = &ConfigurationDescriptor.NKRO_HID;
|
||||||
Size = sizeof(USB_HID_Descriptor_HID_t);
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
||||||
|
|
@ -632,7 +673,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
||||||
Size = sizeof(ConsoleReport);
|
Size = sizeof(ConsoleReport);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
case NKRO_INTERFACE:
|
case NKRO_INTERFACE:
|
||||||
Address = &NKROReport;
|
Address = &NKROReport;
|
||||||
Size = sizeof(NKROReport);
|
Size = sizeof(NKROReport);
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ typedef struct
|
||||||
USB_Descriptor_Endpoint_t Console_OUTEndpoint;
|
USB_Descriptor_Endpoint_t Console_OUTEndpoint;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
// NKRO HID Interface
|
// NKRO HID Interface
|
||||||
USB_Descriptor_Interface_t NKRO_Interface;
|
USB_Descriptor_Interface_t NKRO_Interface;
|
||||||
USB_HID_Descriptor_HID_t NKRO_HID;
|
USB_HID_Descriptor_HID_t NKRO_HID;
|
||||||
|
|
@ -109,7 +109,7 @@ typedef struct
|
||||||
# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
|
# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
# define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
|
# define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
|
||||||
#else
|
#else
|
||||||
# define NKRO_INTERFACE CONSOLE_INTERFACE
|
# define NKRO_INTERFACE CONSOLE_INTERFACE
|
||||||
|
|
@ -142,7 +142,7 @@ typedef struct
|
||||||
# define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM
|
# define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
# define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
|
# define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
|
||||||
#else
|
#else
|
||||||
# define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
|
# define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
|
||||||
|
|
|
||||||
|
|
@ -329,7 +329,12 @@ void EVENT_USB_Device_ConfigurationChanged(void)
|
||||||
|
|
||||||
/* Setup Keyboard HID Report Endpoints */
|
/* Setup Keyboard HID Report Endpoints */
|
||||||
ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||||
KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
|
#ifdef NKRO_ENABLE
|
||||||
|
NKRO_EPSIZE,
|
||||||
|
#else
|
||||||
|
KEYBOARD_EPSIZE,
|
||||||
|
#endif
|
||||||
|
ENDPOINT_BANK_SINGLE);
|
||||||
|
|
||||||
#ifdef MOUSE_ENABLE
|
#ifdef MOUSE_ENABLE
|
||||||
/* Setup Mouse HID Report Endpoint */
|
/* Setup Mouse HID Report Endpoint */
|
||||||
|
|
@ -353,7 +358,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
/* Setup NKRO HID Report Endpoints */
|
/* Setup NKRO HID Report Endpoints */
|
||||||
ConfigSuccess &= ENDPOINT_CONFIG(NKRO_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
ConfigSuccess &= ENDPOINT_CONFIG(NKRO_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
|
||||||
NKRO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
NKRO_EPSIZE, ENDPOINT_BANK_SINGLE);
|
||||||
|
|
@ -414,7 +419,7 @@ void EVENT_USB_Device_ControlRequest(void)
|
||||||
// Interface
|
// Interface
|
||||||
switch (USB_ControlRequest.wIndex) {
|
switch (USB_ControlRequest.wIndex) {
|
||||||
case KEYBOARD_INTERFACE:
|
case KEYBOARD_INTERFACE:
|
||||||
#ifdef NKRO_ENABLE
|
#ifdef NKRO_6KRO_ENABLE
|
||||||
case NKRO_INTERFACE:
|
case NKRO_INTERFACE:
|
||||||
#endif
|
#endif
|
||||||
Endpoint_ClearSETUP();
|
Endpoint_ClearSETUP();
|
||||||
|
|
@ -515,10 +520,14 @@ static void send_keyboard(report_keyboard_t *report)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Select the Keyboard Report Endpoint */
|
/* Select the Keyboard Report Endpoint */
|
||||||
#ifdef NKRO_ENABLE
|
#if defined(NKRO_ENABLE) || defined(NKRO_6KRO_ENABLE)
|
||||||
if (keyboard_protocol && keyboard_nkro) {
|
if (keyboard_protocol && keyboard_nkro) {
|
||||||
/* Report protocol - NKRO */
|
/* Report protocol - NKRO */
|
||||||
|
#if defined(NKRO_6KRO_ENABLE)
|
||||||
Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
|
Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
|
||||||
|
#else
|
||||||
|
Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check if write ready for a polling interval around 1ms */
|
/* Check if write ready for a polling interval around 1ms */
|
||||||
while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(8);
|
while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(8);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue