Change Host mode class driver Pipe configuration routines -- better to let the applic...
[pub/USBasp.git] / Demos / Host / ClassDriver / MouseHost / MouseHost.c
index 88518a8..c2850cf 100644 (file)
@@ -76,10 +76,31 @@ int main(void)
                        case HOST_STATE_Addressed:\r
                                LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
                        \r
-                               if (HID_Host_ConfigurePipes(&Mouse_HID_Interface, 512) != HID_ENUMERROR_NoError)\r
+                               uint16_t ConfigDescriptorSize;\r
+                               uint8_t  ConfigDescriptorData[512];\r
+\r
+                               if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
+                               {\r
+                                       printf("Error Retrieving Device Descriptor.\r\n");\r
+                                       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+                                       USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+                                       break;\r
+                               }\r
+                               \r
+                               if (ConfigDescriptorSize > 512)\r
                                {\r
-                                       printf("Attached device is not a valid Mouse.\r\n");\r
-                                       \r
+                                       printf("Device Descriptor Too Large To Process.\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 (HID_Host_ConfigurePipes(&Mouse_HID_Interface,\r
+                                                           ConfigDescriptorSize, ConfigDescriptorData) != HID_ENUMERROR_NoError)\r
+                               {\r
+                                       printf("Attached Device Not a Valid Mouse.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -88,7 +109,6 @@ int main(void)
                                if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)\r
                                {\r
                                        printf("Error Setting Device Configuration.\r\n");\r
-\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r