- USB_KeyboardReport_Data_t KeyboardReportData;\r
- bool SendReport = false;\r
- \r
- /* Check if the USB system is connected to a host */\r
- if (USB_IsConnected)\r
- {\r
- /* Select the Keyboard Report Endpoint */\r
- Endpoint_SelectEndpoint(KEYBOARD_EPNUM);\r
-\r
- /* Check if Keyboard Endpoint Ready for Read/Write */\r
- if (Endpoint_ReadWriteAllowed())\r
- {\r
- /* Only fetch the next key to send once the period between key presses has elapsed */\r
- if (!(KeyDelayRemaining))\r
- {\r
- /* Create the next keyboard report for transmission to the host */\r
- SendReport = GetNextReport(&KeyboardReportData);\r
- }\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
- /* Write the keyboard report if a report is to be sent to the host */\r
- if (SendReport)\r
- {\r
- /* Write Keyboard Report Data */\r
- Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(USB_KeyboardReport_Data_t));\r
-\r
- /* Finalize the stream transfer to send the last packet */\r
- Endpoint_ClearCurrentBank();\r
-\r
- /* Reset the key delay period counter */\r
- KeyDelayRemaining = 2;\r
- }\r
- }\r
- }\r