lufa: Integrate EXTRAKEY into MOUSE interface

This commit is contained in:
tmk 2021-06-22 23:26:56 +09:00
parent 2b07c0bd00
commit 5948ea0ac6
3 changed files with 33 additions and 100 deletions

View file

@ -119,15 +119,18 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] =
#endif #endif
}; };
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
{ {
#ifdef MOUSE_ENABLE
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x02), /* Mouse */ HID_RI_USAGE(8, 0x02), /* Mouse */
HID_RI_COLLECTION(8, 0x01), /* Application */ HID_RI_COLLECTION(8, 0x01), /* Application */
HID_RI_USAGE(8, 0x01), /* Pointer */ HID_RI_USAGE(8, 0x01), /* Pointer */
HID_RI_COLLECTION(8, 0x00), /* Physical */ HID_RI_COLLECTION(8, 0x00), /* Physical */
HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
HID_RI_USAGE_PAGE(8, 0x09), /* Button */ HID_RI_USAGE_PAGE(8, 0x09), /* Button */
HID_RI_USAGE_MINIMUM(8, 0x01), /* Button 1 */ HID_RI_USAGE_MINIMUM(8, 0x01), /* Button 1 */
HID_RI_USAGE_MAXIMUM(8, 0x08), /* Button 8 */ HID_RI_USAGE_MAXIMUM(8, 0x08), /* Button 8 */
@ -183,12 +186,9 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
HID_RI_END_COLLECTION(0), HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0), HID_RI_END_COLLECTION(0),
};
#endif #endif
#ifdef EXTRAKEY_ENABLE #ifdef EXTRAKEY_ENABLE
const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtrakeyReport[] =
{
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x80), /* System Control */ HID_RI_USAGE(8, 0x80), /* System Control */
HID_RI_COLLECTION(8, 0x01), /* Application */ HID_RI_COLLECTION(8, 0x01), /* Application */
@ -214,6 +214,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ExtrakeyReport[] =
HID_RI_REPORT_COUNT(8, 1), HID_RI_REPORT_COUNT(8, 1),
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),
#endif
}; };
#endif #endif
@ -370,7 +371,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
/* /*
* Mouse * Mouse
*/ */
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
.Mouse_Interface = .Mouse_Interface =
{ {
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
@ -381,8 +382,13 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.TotalEndpoints = 1, .TotalEndpoints = 1,
.Class = HID_CSCP_HIDClass, .Class = HID_CSCP_HIDClass,
#if defined(MOUSE_ENABLE)
.SubClass = HID_CSCP_BootSubclass, .SubClass = HID_CSCP_BootSubclass,
.Protocol = HID_CSCP_MouseBootProtocol, .Protocol = HID_CSCP_MouseBootProtocol,
#else
.SubClass = HID_CSCP_NonBootSubclass,
.Protocol = HID_CSCP_NonBootProtocol,
#endif
.InterfaceStrIndex = NO_DESCRIPTOR .InterfaceStrIndex = NO_DESCRIPTOR
}, },
@ -405,49 +411,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM), .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_IN_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MOUSE_EPSIZE, .EndpointSize = MOUSE_EPSIZE,
.PollingIntervalMS = 0x0A .PollingIntervalMS = 0x01
},
#endif
/*
* Extra
*/
#ifdef EXTRAKEY_ENABLE
.Extrakey_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = EXTRAKEY_INTERFACE,
.AlternateSetting = 0x00,
.TotalEndpoints = 1,
.Class = HID_CSCP_HIDClass,
.SubClass = HID_CSCP_NonBootSubclass,
.Protocol = HID_CSCP_NonBootProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.Extrakey_HID =
{
.Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
.HIDSpec = VERSION_BCD(1,1,1),
.CountryCode = 0x00,
.TotalReportDescriptors = 1,
.HIDReportType = HID_DTYPE_Report,
.HIDReportLength = sizeof(ExtrakeyReport)
},
.Extrakey_INEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_IN | EXTRAKEY_IN_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = EXTRAKEY_EPSIZE,
.PollingIntervalMS = 0x0A
}, },
#endif #endif
@ -623,18 +587,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
Address = &ConfigurationDescriptor.Keyboard_HID; Address = &ConfigurationDescriptor.Keyboard_HID;
Size = sizeof(USB_HID_Descriptor_HID_t); Size = sizeof(USB_HID_Descriptor_HID_t);
break; break;
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
case MOUSE_INTERFACE: case MOUSE_INTERFACE:
Address = &ConfigurationDescriptor.Mouse_HID; Address = &ConfigurationDescriptor.Mouse_HID;
Size = sizeof(USB_HID_Descriptor_HID_t); Size = sizeof(USB_HID_Descriptor_HID_t);
break; break;
#endif #endif
#ifdef EXTRAKEY_ENABLE
case EXTRAKEY_INTERFACE:
Address = &ConfigurationDescriptor.Extrakey_HID;
Size = sizeof(USB_HID_Descriptor_HID_t);
break;
#endif
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
case CONSOLE_INTERFACE: case CONSOLE_INTERFACE:
Address = &ConfigurationDescriptor.Console_HID; Address = &ConfigurationDescriptor.Console_HID;
@ -655,18 +613,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
Address = &KeyboardReport; Address = &KeyboardReport;
Size = sizeof(KeyboardReport); Size = sizeof(KeyboardReport);
break; break;
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
case MOUSE_INTERFACE: case MOUSE_INTERFACE:
Address = &MouseReport; Address = &MouseReport;
Size = sizeof(MouseReport); Size = sizeof(MouseReport);
break; break;
#endif #endif
#ifdef EXTRAKEY_ENABLE
case EXTRAKEY_INTERFACE:
Address = &ExtrakeyReport;
Size = sizeof(ExtrakeyReport);
break;
#endif
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
case CONSOLE_INTERFACE: case CONSOLE_INTERFACE:
Address = &ConsoleReport; Address = &ConsoleReport;

View file

@ -57,20 +57,13 @@ typedef struct
USB_HID_Descriptor_HID_t Keyboard_HID; USB_HID_Descriptor_HID_t Keyboard_HID;
USB_Descriptor_Endpoint_t Keyboard_INEndpoint; USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
// Mouse HID Interface // Mouse HID Interface
USB_Descriptor_Interface_t Mouse_Interface; USB_Descriptor_Interface_t Mouse_Interface;
USB_HID_Descriptor_HID_t Mouse_HID; USB_HID_Descriptor_HID_t Mouse_HID;
USB_Descriptor_Endpoint_t Mouse_INEndpoint; USB_Descriptor_Endpoint_t Mouse_INEndpoint;
#endif #endif
#ifdef EXTRAKEY_ENABLE
// Extrakey HID Interface
USB_Descriptor_Interface_t Extrakey_Interface;
USB_HID_Descriptor_HID_t Extrakey_HID;
USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
#endif
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
// Console HID Interface // Console HID Interface
USB_Descriptor_Interface_t Console_Interface; USB_Descriptor_Interface_t Console_Interface;
@ -91,22 +84,16 @@ typedef struct
/* index of interface */ /* index of interface */
#define KEYBOARD_INTERFACE 0 #define KEYBOARD_INTERFACE 0
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
# define MOUSE_INTERFACE (KEYBOARD_INTERFACE + 1) # define MOUSE_INTERFACE (KEYBOARD_INTERFACE + 1)
#else #else
# define MOUSE_INTERFACE KEYBOARD_INTERFACE # define MOUSE_INTERFACE KEYBOARD_INTERFACE
#endif #endif
#ifdef EXTRAKEY_ENABLE
# define EXTRAKEY_INTERFACE (MOUSE_INTERFACE + 1)
#else
# define EXTRAKEY_INTERFACE MOUSE_INTERFACE
#endif
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
# define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1) # define CONSOLE_INTERFACE (MOUSE_INTERFACE + 1)
#else #else
# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE # define CONSOLE_INTERFACE MOUSE_INTERFACE
#endif #endif
#ifdef NKRO_6KRO_ENABLE #ifdef NKRO_6KRO_ENABLE
@ -123,23 +110,17 @@ typedef struct
// Endopoint number and size // Endopoint number and size
#define KEYBOARD_IN_EPNUM 1 #define KEYBOARD_IN_EPNUM 1
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
# define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1) # define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1)
#else #else
# define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM # define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM
#endif #endif
#ifdef EXTRAKEY_ENABLE
# define EXTRAKEY_IN_EPNUM (MOUSE_IN_EPNUM + 1)
#else
# define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
#endif
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
# define CONSOLE_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1) # define CONSOLE_IN_EPNUM (MOUSE_IN_EPNUM + 1)
# define CONSOLE_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 1) # define CONSOLE_OUT_EPNUM (MOUSE_IN_EPNUM + 1)
#else #else
# define CONSOLE_OUT_EPNUM EXTRAKEY_IN_EPNUM # define CONSOLE_OUT_EPNUM MOUSE_IN_EPNUM
#endif #endif
#ifdef NKRO_6KRO_ENABLE #ifdef NKRO_6KRO_ENABLE
@ -150,13 +131,18 @@ typedef struct
/* Check number of endpoints. ATmega32u2 has only four except for control endpoint. */ /* Check number of endpoints. ATmega32u2 has only four except for control endpoint. */
#if defined(__AVR_ATmega32U2__) && NKRO_IN_EPNUM > 4 #if defined(__AVR_ATmega32U2__) && NKRO_IN_EPNUM > 4
# error "Endpoints are not available enough to support all functions. Disable some of build options in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO)" # error "Endpoints are not available enough to support all functions. Disable some of build options in Makefile.(MOUSEKEY, CONSOLE, NKRO)"
#endif #endif
#define KEYBOARD_EPSIZE 8 #define KEYBOARD_EPSIZE 8
#if defined(MOUSE_EXT_REPORT)
#define MOUSE_EPSIZE 10
#else
#define MOUSE_EPSIZE 8 #define MOUSE_EPSIZE 8
#define EXTRAKEY_EPSIZE 8 #endif
#define CONSOLE_EPSIZE 32 #define CONSOLE_EPSIZE 32
#define NKRO_EPSIZE 32 #define NKRO_EPSIZE 32

View file

@ -336,18 +336,12 @@ void EVENT_USB_Device_ConfigurationChanged(void)
#endif #endif
ENDPOINT_BANK_SINGLE); ENDPOINT_BANK_SINGLE);
#ifdef MOUSE_ENABLE #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
/* Setup Mouse HID Report Endpoint */ /* Setup Mouse HID Report Endpoint */
ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
#endif #endif
#ifdef EXTRAKEY_ENABLE
/* Setup Extra HID Report Endpoint */
ConfigSuccess &= ENDPOINT_CONFIG(EXTRAKEY_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE);
#endif
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
/* Setup Console HID Report Endpoints */ /* Setup Console HID Report Endpoints */
ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
@ -572,6 +566,7 @@ static void send_mouse(report_mouse_t *report)
if (!Endpoint_IsReadWriteAllowed()) return; if (!Endpoint_IsReadWriteAllowed()) return;
/* Write Mouse Report Data */ /* Write Mouse Report Data */
Endpoint_Write_8(REPORT_ID_MOUSE);
Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL); Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL);
/* Finalize the stream transfer to send the last packet */ /* Finalize the stream transfer to send the last packet */
@ -591,7 +586,7 @@ static void send_system(uint16_t data)
.report_id = REPORT_ID_SYSTEM, .report_id = REPORT_ID_SYSTEM,
.usage = data - SYSTEM_POWER_DOWN + 1 .usage = data - SYSTEM_POWER_DOWN + 1
}; };
Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */ /* Check if write ready for a polling interval around 10ms */
while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
@ -614,7 +609,7 @@ static void send_consumer(uint16_t data)
.report_id = REPORT_ID_CONSUMER, .report_id = REPORT_ID_CONSUMER,
.usage = data .usage = data
}; };
Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM); Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
/* Check if write ready for a polling interval around 10ms */ /* Check if write ready for a polling interval around 10ms */
while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);