\r
void HID_Task(void)\r
{\r
- /* Check if the USB system is connected to a host */\r
- if (USB_IsConnected)\r
+ /* Device must be connected and configured for the task to run */\r
+ if (!(USB_IsConnected) || !(USB_ConfigurationNumber))\r
+ return;\r
+\r
+ Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);\r
+ \r
+ /* Check to see if a packet has been sent from the host */\r
+ if (Endpoint_IsOUTReceived())\r
{\r
- Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);\r
- \r
- /* Check to see if a packet has been sent from the host */\r
- if (Endpoint_IsOUTReceived())\r
+ /* Check to see if the packet contains data */\r
+ if (Endpoint_IsReadWriteAllowed())\r
{\r
- /* Check to see if the packet contains data */\r
- if (Endpoint_IsReadWriteAllowed())\r
- {\r
- /* Create a temporary buffer to hold the read in report from the host */\r
- uint8_t GenericData[GENERIC_REPORT_SIZE];\r
- \r
- /* Read Generic Report Data */\r
- Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));\r
- \r
- /* Process Generic Report Data */\r
- ProcessGenericHIDReport(GenericData);\r
- }\r
+ /* Create a temporary buffer to hold the read in report from the host */\r
+ uint8_t GenericData[GENERIC_REPORT_SIZE];\r
+ \r
+ /* Read Generic Report Data */\r
+ Endpoint_Read_Stream_LE(&GenericData, sizeof(GenericData));\r
+ \r
+ /* Process Generic Report Data */\r
+ ProcessGenericHIDReport(GenericData);\r
+ }\r
\r
- /* Finalize the stream transfer to send the last packet */\r
- Endpoint_ClearOUT();\r
- } \r
+ /* Finalize the stream transfer to send the last packet */\r
+ Endpoint_ClearOUT();\r
+ } \r
\r
- Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);\r
+ Endpoint_SelectEndpoint(GENERIC_IN_EPNUM);\r
+ \r
+ /* Check to see if the host is ready to accept another packet */\r
+ if (Endpoint_IsINReady())\r
+ {\r
+ /* Create a temporary buffer to hold the report to send to the host */\r
+ uint8_t GenericData[GENERIC_REPORT_SIZE];\r
\r
- /* Check to see if the host is ready to accept another packet */\r
- if (Endpoint_IsINReady())\r
- {\r
- /* Create a temporary buffer to hold the report to send to the host */\r
- uint8_t GenericData[GENERIC_REPORT_SIZE];\r
- \r
- /* Create Generic Report Data */\r
- CreateGenericHIDReport(GenericData);\r
+ /* Create Generic Report Data */\r
+ CreateGenericHIDReport(GenericData);\r
\r
- /* Write Generic Report Data */\r
- Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));\r
+ /* Write Generic Report Data */\r
+ Endpoint_Write_Stream_LE(&GenericData, sizeof(GenericData));\r
\r
- /* Finalize the stream transfer to send the last packet */\r
- Endpoint_ClearIN();\r
- }\r
+ /* Finalize the stream transfer to send the last packet */\r
+ Endpoint_ClearIN();\r
}\r
}\r