/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
- /* Acknowledge status stage */\r
- while (!(Endpoint_IsINReady()));\r
- Endpoint_ClearIN();\r
+ Endpoint_ClearStatusStage();\r
}\r
\r
break;\r
char* ReportString = NULL;\r
uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
static bool ActionSent = false;\r
-\r
- char* JoystickStrings[] =\r
- {\r
- "Joystick Up\r\n",\r
- "Joystick Down\r\n",\r
- "Joystick Left\r\n",\r
- "Joystick Right\r\n",\r
- "Joystick Pressed\r\n",\r
- };\r
+ char* JoystickStrings[] =\r
+ {\r
+ "Joystick Up\r\n",\r
+ "Joystick Down\r\n",\r
+ "Joystick Left\r\n",\r
+ "Joystick Right\r\n",\r
+ "Joystick Pressed\r\n",\r
+ };\r
+ \r
+ /* Device must be connected and configured for the task to run */\r
+ if (USB_DeviceState != DEVICE_STATE_Configured)\r
+ return;\r
\r
/* Determine if a joystick action has occurred */\r
if (JoyStatus_LCL & JOY_UP)\r
Endpoint_ClearIN();\r
\r
/* Wait until the endpoint is ready for another packet */\r
- while (!(Endpoint_IsINReady()));\r
+ while (!(Endpoint_IsINReady()))\r
+ {\r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return;\r
+ }\r
\r
/* Send an empty packet to ensure that the host does not buffer data sent to it */\r
Endpoint_ClearIN();\r
*/\r
void CDC2_Task(void)\r
{\r
+ /* Device must be connected and configured for the task to run */\r
+ if (USB_DeviceState != DEVICE_STATE_Configured)\r
+ return;\r
+\r
/* Select the Serial Rx Endpoint */\r
Endpoint_SelectEndpoint(CDC2_RX_EPNUM);\r
\r
Endpoint_ClearIN();\r
\r
/* Wait until the endpoint is ready for the next packet */\r
- while (!(Endpoint_IsINReady()));\r
+ while (!(Endpoint_IsINReady()))\r
+ {\r
+ if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+ return;\r
+ }\r
\r
/* Send an empty packet to prevent host buffering */\r
Endpoint_ClearIN();\r