Make HID device class driver reselect the correct endpoint after the user callbacks...
[pub/USBasp.git] / Demos / Host / LowLevel / CDCHost / ConfigDescriptor.c
index baf02a2..7afb702 100644 (file)
  */\r
 uint8_t ProcessConfigurationDescriptor(void)\r
 {\r
  */\r
 uint8_t ProcessConfigurationDescriptor(void)\r
 {\r
-       uint8_t* ConfigDescriptorData;\r
-       uint16_t ConfigDescriptorSize;\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(&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(&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 CDC control interface from the configuration descriptor */\r
        \r
        /* Get the CDC control interface from the configuration descriptor */\r
-       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+       if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
                                      DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
        {\r
                /* Descriptor not found, error out */\r
                return NoCDCInterfaceFound;\r
        }\r
 \r
                                      DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
        {\r
                /* Descriptor not found, error out */\r
                return NoCDCInterfaceFound;\r
        }\r
 \r
-       /* Get the IN and OUT data endpoints for the CDC interface */\r
+       /* Get the IN and OUT data and IN notification endpoints for the CDC interface */\r
        while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT)))\r
        {\r
                /* Fetch the next bulk or interrupt endpoint from the current CDC interface */\r
        while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT)))\r
        {\r
                /* Fetch the next bulk or interrupt endpoint from the current CDC interface */\r
-               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                             DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
+               if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
+                                             DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
                {\r
                        /* Check to see if the control interface's notification pipe has been found, if so search for the data interface */\r
                        if (FoundEndpoints & (1 << CDC_NOTIFICATIONPIPE))\r
                        {\r
                                /* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */\r
                {\r
                        /* Check to see if the control interface's notification pipe has been found, if so search for the data interface */\r
                        if (FoundEndpoints & (1 << CDC_NOTIFICATIONPIPE))\r
                        {\r
                                /* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */\r
-                               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData\r
+                               if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation\r
                                                              DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
                                                              DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
@@ -109,7 +105,7 @@ uint8_t ProcessConfigurationDescriptor(void)
                                Pipe_DisablePipe();\r
                        \r
                                /* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */\r
                                Pipe_DisablePipe();\r
                        \r
                                /* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */\r
-                               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+                               if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
                                                              DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
                                                              DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
@@ -118,15 +114,15 @@ uint8_t ProcessConfigurationDescriptor(void)
                        }\r
 \r
                        /* Fetch the next bulk or interrupt endpoint from the current CDC interface */\r
                        }\r
 \r
                        /* Fetch the next bulk or interrupt endpoint from the current CDC interface */\r
-                       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                     DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                       if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
+                                                     DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
                        {\r
                                /* Descriptor not found, error out */\r
                                return NoEndpointFound;\r
                        }\r
                }\r
                \r
                        {\r
                                /* Descriptor not found, error out */\r
                                return NoEndpointFound;\r
                        }\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 found endpoint is a interrupt or bulk type descriptor */\r
                if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)\r
 \r
                /* Check if the found endpoint is a interrupt or bulk type descriptor */\r
                if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)\r
@@ -138,7 +134,6 @@ uint8_t ProcessConfigurationDescriptor(void)
                                Pipe_ConfigurePipe(CDC_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
 \r
                                Pipe_ConfigurePipe(CDC_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
 \r
-                               Pipe_SetInfiniteINRequests();\r
                                Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS);\r
                                \r
                                /* Set the flag indicating that the notification pipe has been found */\r
                                Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS);\r
                                \r
                                /* Set the flag indicating that the notification pipe has been found */\r
@@ -153,9 +148,6 @@ uint8_t ProcessConfigurationDescriptor(void)
                                /* Configure the data IN pipe */\r
                                Pipe_ConfigurePipe(CDC_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
                                /* Configure the data IN pipe */\r
                                Pipe_ConfigurePipe(CDC_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
-\r
-                               Pipe_SetInfiniteINRequests();\r
-                               Pipe_Unfreeze();\r
                                \r
                                /* Set the flag indicating that the data IN pipe has been found */\r
                                FoundEndpoints |= (1 << CDC_DATAPIPE_IN);\r
                                \r
                                /* Set the flag indicating that the data IN pipe has been found */\r
                                FoundEndpoints |= (1 << CDC_DATAPIPE_IN);\r
@@ -166,8 +158,6 @@ uint8_t ProcessConfigurationDescriptor(void)
                                Pipe_ConfigurePipe(CDC_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
                                \r
                                Pipe_ConfigurePipe(CDC_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT,\r
                                                                   EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
                                \r
-                               Pipe_Unfreeze();\r
-                               \r
                                /* Set the flag indicating that the data OUT pipe has been found */\r
                                FoundEndpoints |= (1 << CDC_DATAPIPE_OUT);\r
                        }\r
                                /* Set the flag indicating that the data OUT pipe has been found */\r
                                FoundEndpoints |= (1 << CDC_DATAPIPE_OUT);\r
                        }\r
@@ -236,7 +226,7 @@ uint8_t DComp_NextCDCDataInterface(void* CurrentDescriptor)
  *\r
  *  \return A value from the DSEARCH_Return_ErrorCodes_t enum\r
  */\r
  *\r
  *  \return A value from the DSEARCH_Return_ErrorCodes_t enum\r
  */\r
-uint8_t DComp_NextInterfaceCDCDataEndpoint(void* CurrentDescriptor)\r
+uint8_t DComp_NextCDCDataInterfaceEndpoint(void* CurrentDescriptor)\r
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
        {\r
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
        {\r