+/** Sends the next HID report to the host, via the keyboard data endpoint. */\r
+static inline void SendNextReport(void)\r
+{\r
+ USB_KeyboardReport_Data_t KeyboardReportData;\r
+ bool SendReport;\r
+ \r
+ /* Create the next keyboard report for transmission to the host */\r
+ SendReport = CreateKeyboardReport(&KeyboardReportData);\r
+ \r
+ /* Check if the idle period is set and has elapsed */\r
+ if (IdleCount && !(IdleMSRemaining))\r
+ {\r
+ /* Idle period elapsed, indicate that a report must be sent */\r
+ SendReport = true;\r
+ \r
+ /* Reset the idle time remaining counter, must multiply by 4 to get the duration in milliseconds */\r
+ IdleMSRemaining = (IdleCount << 2);\r
+ }\r
+ \r
+ /* Select the Keyboard Report Endpoint */\r
+ Endpoint_SelectEndpoint(KEYBOARD_EPNUM);\r
+\r
+ /* Check if Keyboard Endpoint Ready for Read/Write, and if we should send a report */\r
+ if (Endpoint_ReadWriteAllowed() && SendReport)\r
+ {\r
+ /* Write Keyboard Report Data */\r
+ Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
+\r
+ /* Finalize the stream transfer to send the last packet */\r
+ Endpoint_ClearCurrentBank();\r
+ }\r
+}\r
+\r
+/** Reads the next LED status report from the host from the LED data endpoint, if one has been sent. */\r
+static inline void ReceiveNextReport(void)\r
+{\r
+ /* Select the Keyboard LED Report Endpoint */\r
+ Endpoint_SelectEndpoint(KEYBOARD_LEDS_EPNUM);\r
+\r
+ /* Check if Keyboard LED Endpoint Ready for Read/Write */\r
+ if (!(Endpoint_ReadWriteAllowed()))\r
+ return;\r
+\r
+ /* Read in the LED report from the host */\r
+ uint8_t LEDReport = Endpoint_Read_Byte();\r
+\r
+ /* Handshake the OUT Endpoint - clear endpoint and ready for next report */\r
+ Endpoint_ClearCurrentBank();\r
+\r
+ /* Process the read LED report from the host */\r
+ ProcessLEDReport(LEDReport);\r
+}\r
+\r