Make Endpoint control transfers more reliable; early-abort when an incomplete packet...
[pub/lufa.git] / Demos / Host / ClassDriver / CDCHost / CDCHost.c
index 291e835..cf0a9f3 100644 (file)
@@ -48,11 +48,6 @@ USB_ClassInfo_CDC_Host_t VirtualSerial_CDC_Interface =
                                .DataOUTPipeNumber      = 2,\r
                                .NotificationPipeNumber = 3,\r
                        },\r
-                       \r
-               .State =\r
-                       {\r
-                               // Leave all state values to their defaults                     \r
-                       }\r
        };\r
 \r
        \r
@@ -78,15 +73,14 @@ int main(void)
                                uint8_t  ConfigDescriptorData[512];\r
 \r
                                if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||\r
-                                   (ConfigDescriptorSize > sizeof(ConfigDescriptorData)))\r
+                                   (ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||\r
+                                       (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))\r
                                {\r
                                        printf("Error Retrieving Configuration Descriptor.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
-                                 \r
-                               USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);\r
 \r
                                if (CDC_Host_ConfigurePipes(&VirtualSerial_CDC_Interface,\r
                                                            ConfigDescriptorSize, ConfigDescriptorData) != CDC_ENUMERROR_NoError)\r
@@ -136,7 +130,7 @@ void SetupHardware(void)
 /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
  *  starts the library USB task to begin the enumeration and USB management process.\r
  */\r
-void EVENT_USB_DeviceAttached(void)\r
+void EVENT_USB_Host_DeviceAttached(void)\r
 {\r
        puts_P(PSTR("Device Attached.\r\n"));\r
        LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
@@ -145,7 +139,7 @@ void EVENT_USB_DeviceAttached(void)
 /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
  *  stops the library USB task management process.\r
  */\r
-void EVENT_USB_DeviceUnattached(void)\r
+void EVENT_USB_Host_DeviceUnattached(void)\r
 {\r
        puts_P(PSTR("\r\nDevice Unattached.\r\n"));\r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
@@ -154,18 +148,18 @@ void EVENT_USB_DeviceUnattached(void)
 /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
  *  enumerated by the host and is now ready to be used by the application.\r
  */\r
-void EVENT_USB_DeviceEnumerationComplete(void)\r
+void EVENT_USB_Host_DeviceEnumerationComplete(void)\r
 {\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
-void EVENT_USB_HostError(const uint8_t ErrorCode)\r
+void EVENT_USB_Host_HostError(const uint8_t ErrorCode)\r
 {\r
        USB_ShutDown();\r
 \r
-       puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));\r
-       printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+       printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"\r
+                                " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);\r
 \r
        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
        for(;;);\r
@@ -174,12 +168,12 @@ void EVENT_USB_HostError(const uint8_t ErrorCode)
 /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
  *  enumerating an attached USB device.\r
  */\r
-void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
+void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
 {\r
-       puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));\r
-       printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
-       printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode);\r
-       printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);\r
+       printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"\r
+                                " -- Error Code %d\r\n"\r
+                                " -- Sub Error Code %d\r\n"\r
+                                " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);\r
        \r
        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 }\r