* of the USB device after enumeration - the device endpoints are configured and the CDC management tasks are started.\r
*/\r
void EVENT_USB_ConfigurationChanged(void)\r
-{\r
- /* Setup CDC Notification, Rx and Tx Endpoints for the first CDC */\r
- Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
- ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,\r
- ENDPOINT_BANK_SINGLE);\r
-\r
- Endpoint_ConfigureEndpoint(CDC1_TX_EPNUM, EP_TYPE_BULK,\r
- ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,\r
- ENDPOINT_BANK_SINGLE);\r
-\r
- Endpoint_ConfigureEndpoint(CDC1_RX_EPNUM, EP_TYPE_BULK,\r
- ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,\r
- ENDPOINT_BANK_SINGLE);\r
-\r
- /* Setup CDC Notification, Rx and Tx Endpoints for the second CDC */\r
- Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
- ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,\r
- ENDPOINT_BANK_SINGLE);\r
-\r
- Endpoint_ConfigureEndpoint(CDC2_TX_EPNUM, EP_TYPE_BULK,\r
- ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,\r
- ENDPOINT_BANK_SINGLE);\r
-\r
- Endpoint_ConfigureEndpoint(CDC2_RX_EPNUM, EP_TYPE_BULK,\r
- ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,\r
- ENDPOINT_BANK_SINGLE);\r
- \r
+{ \r
/* Indicate USB connected and ready */\r
LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
+\r
+ /* Setup CDC Notification, Rx and Tx Endpoints for the first CDC */\r
+ if (!(Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
+ ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,\r
+ ENDPOINT_BANK_SINGLE)))\r
+ {\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ }\r
+ \r
+ if (!(Endpoint_ConfigureEndpoint(CDC1_TX_EPNUM, EP_TYPE_BULK,\r
+ ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,\r
+ ENDPOINT_BANK_SINGLE)))\r
+ {\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ }\r
+ \r
+ if (!(Endpoint_ConfigureEndpoint(CDC1_RX_EPNUM, EP_TYPE_BULK,\r
+ ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,\r
+ ENDPOINT_BANK_SINGLE)))\r
+ {\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ }\r
+ \r
+ /* Setup CDC Notification, Rx and Tx Endpoints for the second CDC */\r
+ if (!(Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
+ ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,\r
+ ENDPOINT_BANK_SINGLE)))\r
+ {\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ }\r
+ \r
+ if (!(Endpoint_ConfigureEndpoint(CDC2_TX_EPNUM, EP_TYPE_BULK,\r
+ ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,\r
+ ENDPOINT_BANK_SINGLE)))\r
+ {\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ }\r
+ \r
+ if (!(Endpoint_ConfigureEndpoint(CDC2_RX_EPNUM, EP_TYPE_BULK,\r
+ ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,\r
+ ENDPOINT_BANK_SINGLE)))\r
+ {\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ }\r
}\r
\r
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific\r
/* 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