- uint8_t* ReportData;\r
- uint8_t ReportSize;\r
-\r
- /* Handle HID Class specific requests */\r
- switch (bRequest)\r
- {\r
- case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
- {\r
- Endpoint_Discard_Word();\r
- \r
- uint16_t wIndex = Endpoint_Read_Word_LE();\r
- \r
- /* Determine if it is the mouse or the keyboard data that is being requested */\r
- if (!(wIndex))\r
- {\r
- ReportData = (uint8_t*)&KeyboardReportData;\r
- ReportSize = sizeof(KeyboardReportData);\r
- }\r
- else\r
- {\r
- ReportData = (uint8_t*)&MouseReportData;\r
- ReportSize = sizeof(MouseReportData);\r
- }\r
-\r
- /* Read in the number of bytes in the report to send to the host */\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
- \r
- /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
- if (wLength > ReportSize)\r
- wLength = ReportSize;\r
-\r
- Endpoint_ClearControlSETUP();\r
- \r
- /* Write the report data to the control endpoint */\r
- Endpoint_Write_Control_Stream_LE(ReportData, wLength);\r
-\r
- /* Clear the report data afterwards */\r
- memset(ReportData, 0, ReportSize);\r
- \r
- /* Finalize the stream transfer to send the last packet or clear the host abort */\r
- Endpoint_ClearControlOUT();\r
- }\r
- \r
- break;\r
- case REQ_SetReport:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
- {\r
- Endpoint_ClearControlSETUP();\r
- \r
- /* Wait until the LED report has been sent by the host */\r
- while (!(Endpoint_IsOUTReceived()));\r
-\r
- /* Read in the LED report from the host */\r
- uint8_t LEDStatus = Endpoint_Read_Byte();\r
- uint8_t LEDMask = LEDS_LED2;\r
- \r
- if (LEDStatus & 0x01) // NUM Lock\r
- LEDMask |= LEDS_LED1;\r
- \r
- if (LEDStatus & 0x02) // CAPS Lock\r
- LEDMask |= LEDS_LED3;\r
-\r
- if (LEDStatus & 0x04) // SCROLL Lock\r
- LEDMask |= LEDS_LED4;\r
-\r
- /* Set the status LEDs to the current HID LED status */\r
- LEDs_SetAllLEDs(LEDMask);\r
-\r
- /* Clear the endpoint data */\r
- Endpoint_ClearControlOUT();\r
-\r
- /* Acknowledge status stage */\r
- while (!(Endpoint_IsINReady()));\r
- Endpoint_ClearControlIN();\r
- }\r
- \r
- break;\r
- }\r