Changed the parameters and behaviour of the USB_GetDeviceConfigDescriptor() function...
[pub/lufa.git] / Demos / Host / LowLevel / PrinterHost / ConfigDescriptor.c
index d4eaff9..22d84c5 100644 (file)
@@ -36,32 +36,26 @@ uint8_t PrinterAltSetting;
 \r
 uint8_t ProcessConfigurationDescriptor(void)\r
 {\r
-       uint8_t* ConfigDescriptorData;\r
-       uint16_t ConfigDescriptorSize;\r
-       uint8_t  ErrorCode;\r
+       uint8_t  ConfigDescriptorData[512];\r
+       uint8_t* CurrConfigLocation = ConfigDescriptorData;\r
+       uint16_t CurrConfigBytesRem;\r
        uint8_t  FoundEndpoints = 0;\r
-       \r
-       /* Get Configuration Descriptor size from the device */\r
-       if (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
-         return ControlError;\r
-       \r
-       /* Ensure that the Configuration Descriptor isn't too large */\r
-       if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE)\r
-         return DescriptorTooLarge;\r
-         \r
-       /* Allocate enough memory for the entire config descriptor */\r
-       ConfigDescriptorData = alloca(ConfigDescriptorSize);\r
 \r
        /* Retrieve the entire configuration descriptor into the allocated buffer */\r
-       USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData);\r
-       \r
-       /* Validate returned data - ensure first entry is a configuration header descriptor */\r
-       if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)\r
-         return InvalidConfigDataReturned;\r
+       switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))\r
+       {\r
+               case HOST_GETCONFIG_Successful:\r
+                       break;\r
+               case HOST_GETCONFIG_InvalidData:\r
+                       return InvalidConfigDataReturned;\r
+               case HOST_GETCONFIG_BuffOverflow:\r
+                       return DescriptorTooLarge;\r
+               default:\r
+                       return ControlError;\r
+       }\r
        \r
        /* Get the printer interface from the configuration descriptor */\r
-       if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                  DComp_NextBidirectionalPrinterInterface)))\r
+       if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextBidirectionalPrinterInterface))\r
        {\r
                /* Descriptor not found, error out */\r
                return NoInterfaceFound;\r
@@ -74,8 +68,7 @@ uint8_t ProcessConfigurationDescriptor(void)
        while (FoundEndpoints != ((1 << PRINTER_DATA_OUT_PIPE) | (1 << PRINTER_DATA_IN_PIPE)))\r
        {\r
                /* Fetch the next bulk endpoint from the current printer interface */\r
-               if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                          DComp_NextInterfaceBulkDataEndpoint)))\r
+               if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextInterfaceBulkDataEndpoint))\r
                {\r
                        /* Descriptor not found, error out */\r
                        return NoEndpointFound;\r