Make HID device class driver reselect the correct endpoint after the user callbacks...
[pub/USBasp.git] / Demos / Host / LowLevel / PrinterHost / ConfigDescriptor.c
index d4eaff9..b4f97ed 100644 (file)
@@ -36,52 +36,45 @@ uint8_t PrinterAltSetting;
 \r
 uint8_t ProcessConfigurationDescriptor(void)\r
 {\r
 \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
        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
 \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
        \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
        }\r
        \r
        {\r
                /* Descriptor not found, error out */\r
                return NoInterfaceFound;\r
        }\r
        \r
-       PrinterInterfaceNumber = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).InterfaceNumber;\r
-       PrinterAltSetting      = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).AlternateSetting;\r
+       PrinterInterfaceNumber = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_Interface_t).InterfaceNumber;\r
+       PrinterAltSetting      = DESCRIPTOR_CAST(CurrConfigLocation, USB_Descriptor_Interface_t).AlternateSetting;\r
 \r
        /* Get the IN and OUT data endpoints for the printer interface */\r
        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
 \r
        /* Get the IN and OUT data endpoints for the printer interface */\r
        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_NextPrinterInterfaceBulkDataEndpoint))\r
                {\r
                        /* Descriptor not found, error out */\r
                        return NoEndpointFound;\r
                }\r
                \r
                {\r
                        /* Descriptor not found, error out */\r
                        return NoEndpointFound;\r
                }\r
                \r
-               USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);\r
+               USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);\r
 \r
                /* Check if the endpoint is a bulk IN or bulk OUT endpoint, set appropriate globals */\r
                if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)\r
 \r
                /* Check if the endpoint is a bulk IN or bulk OUT endpoint, set appropriate globals */\r
                if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)\r
@@ -130,7 +123,7 @@ uint8_t DComp_NextBidirectionalPrinterInterface(void* CurrentDescriptor)
        return DESCRIPTOR_SEARCH_NotFound;\r
 }\r
 \r
        return DESCRIPTOR_SEARCH_NotFound;\r
 }\r
 \r
-uint8_t DComp_NextInterfaceBulkDataEndpoint(void* CurrentDescriptor)\r
+uint8_t DComp_NextPrinterInterfaceBulkDataEndpoint(void* CurrentDescriptor)\r
 {\r
        /* PURPOSE: Find next interface bulk endpoint descriptor before next interface descriptor */\r
 \r
 {\r
        /* PURPOSE: Find next interface bulk endpoint descriptor before next interface descriptor */\r
 \r