Fix accidentally changed code breaking the HID descriptor parser.
[pub/USBasp.git] / Demos / Host / ClassDriver / MassStorageHost / MassStorageHost.c
index 27662db..d22e074 100644 (file)
@@ -71,9 +71,8 @@ int main(void)
                                uint16_t ConfigDescriptorSize;\r
                                uint8_t  ConfigDescriptorData[512];\r
 \r
-                               if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) ||\r
-                                   (ConfigDescriptorSize > sizeof(ConfigDescriptorData)) ||\r
-                                       (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData)))\r
+                               if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,\r
+                                                                 sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)\r
                                {\r
                                        printf("Error Retrieving Configuration Descriptor.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
@@ -84,7 +83,7 @@ int main(void)
                                if (MS_Host_ConfigurePipes(&FlashDisk_MS_Interface,\r
                                                            ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError)\r
                                {\r
-                                       printf("Attached Device Not a Valid Mouse.\r\n");\r
+                                       printf("Attached Device Not a Valid Mass Storage Device.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -98,7 +97,7 @@ int main(void)
                                        break;\r
                                }\r
                                \r
-                               printf("Mouse Enumerated.\r\n");\r
+                               printf("Mass Storage Device Enumerated.\r\n");\r
                                USB_HostState = HOST_STATE_Configured;\r
                                break;\r
                        case HOST_STATE_Configured:\r
@@ -113,6 +112,8 @@ int main(void)
                                        break;\r
                                }\r
                                \r
+                               printf("Total LUNs: %d - Using first LUN in device.\r\n", (MaxLUNIndex + 1));\r
+                               \r
                                if (MS_Host_ResetMSInterface(&FlashDisk_MS_Interface))\r
                                {\r
                                        printf("Error resetting Mass Storage interface.\r\n");\r
@@ -139,7 +140,7 @@ int main(void)
                                }\r
 \r
                                SCSI_Inquiry_Response_t InquiryData;\r
-                               if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, &InquiryData))\r
+                               if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData))\r
                                {\r
                                        printf("Error retreiving device Inquiry data.\r\n");\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
@@ -150,11 +151,16 @@ int main(void)
                                printf("Vendor \"%.8s\", Product \"%.16s\"\r\n", InquiryData.VendorID, InquiryData.ProductID);\r
                                \r
                                printf("Waiting until ready...\r\n");\r
-                               bool DeviceReady;\r
 \r
-                               do\r
+                               for (;;)\r
                                {\r
-                                       if (MS_Host_TestUnitReady(&FlashDisk_MS_Interface, 0, &DeviceReady))\r
+                                       uint8_t ErrorCode = MS_Host_TestUnitReady(&FlashDisk_MS_Interface, 0);\r
+                                       \r
+                                       if (!(ErrorCode))\r
+                                         break;\r
+\r
+                                       /* Check if an error other than a logical command error (device busy) received */\r
+                                       if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED)\r
                                        {\r
                                                printf("Error waiting for device to be ready.\r\n");\r
                                                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
@@ -162,7 +168,6 @@ int main(void)
                                                break;\r
                                        }\r
                                }\r
-                               while (!(DeviceReady));\r
 \r
                                printf("Retrieving Capacity... ");\r
 \r