Changed the parameters and behaviour of the USB_GetDeviceConfigDescriptor() function...
[pub/lufa.git] / Demos / Host / LowLevel / MouseHostWithParser / ConfigDescriptor.c
index 1d28351..fa06741 100644 (file)
  */\r
 uint8_t ProcessConfigurationDescriptor(void)\r
 {\r
-       uint8_t* ConfigDescriptorData;\r
-       uint16_t ConfigDescriptorSize;\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
+       uint8_t  ConfigDescriptorData[512];\r
+       uint8_t* CurrConfigLocation = ConfigDescriptorData;\r
+       uint16_t CurrConfigBytesRem;\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 mouse interface from the configuration descriptor */\r
-       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+       if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
                                      DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
        {\r
                /* Descriptor not found, error out */\r
@@ -77,7 +73,7 @@ uint8_t ProcessConfigurationDescriptor(void)
        }\r
        \r
        /* Get the mouse interface's HID descriptor */\r
-       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+       if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
                                      DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)\r
        {\r
                /* Descriptor not found, error out */\r
@@ -88,7 +84,7 @@ uint8_t ProcessConfigurationDescriptor(void)
        HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength;\r
 \r
        /* Get the mouse interface's data endpoint descriptor */\r
-       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+       if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
                                      DComp_NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
        {\r
                /* Descriptor not found, error out */\r