Synchronise with the 090605 release.
[pub/USBasp.git] / Demos / Host / CDCHost / ConfigDescriptor.c
index eb80ec3..baf02a2 100644 (file)
@@ -52,7 +52,7 @@ uint8_t ProcessConfigurationDescriptor(void)
        uint8_t  FoundEndpoints = 0;\r
        \r
        /* Get Configuration Descriptor size from the device */\r
-       if (USB_Host_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
+       if (USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful)\r
          return ControlError;\r
        \r
        /* Ensure that the Configuration Descriptor isn't too large */\r
@@ -63,14 +63,15 @@ uint8_t ProcessConfigurationDescriptor(void)
        ConfigDescriptorData = alloca(ConfigDescriptorSize);\r
 \r
        /* Retrieve the entire configuration descriptor into the allocated buffer */\r
-       USB_Host_GetDeviceConfigDescriptor(&ConfigDescriptorSize, ConfigDescriptorData);\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
        \r
-       /* Get the CDC interface from the configuration descriptor */\r
-       if (USB_Host_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextCDCInterface))\r
+       /* Get the CDC control interface from the configuration descriptor */\r
+       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+                                     DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
        {\r
                /* Descriptor not found, error out */\r
                return NoCDCInterfaceFound;\r
@@ -80,19 +81,45 @@ uint8_t ProcessConfigurationDescriptor(void)
        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_Host_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                  NextInterfaceCDCDataEndpoint))\r
+               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+                                             DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
                {\r
-                       /* Get the next CDC interface from the configuration descriptor (CDC class has two CDC interfaces) */\r
-                       if (USB_Host_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextCDCInterface))\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
-                               /* Descriptor not found, error out */\r
-                               return NoCDCInterfaceFound;\r
+                               /* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */\r
+                               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, \r
+                                                             DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                               {\r
+                                       /* Descriptor not found, error out */\r
+                                       return NoCDCInterfaceFound;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* Clear the found endpoints mask, since any already processed endpoints aren't in the CDC interface we need */\r
+                               FoundEndpoints = 0;\r
+\r
+                               /* Disable any already configured pipes from the invalid CDC interfaces */\r
+                               Pipe_SelectPipe(CDC_NOTIFICATIONPIPE);\r
+                               Pipe_DisablePipe();\r
+                               Pipe_SelectPipe(CDC_DATAPIPE_IN);\r
+                               Pipe_DisablePipe();\r
+                               Pipe_SelectPipe(CDC_DATAPIPE_OUT);\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
+                                                             DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                               {\r
+                                       /* Descriptor not found, error out */\r
+                                       return NoCDCInterfaceFound;\r
+                               }\r
                        }\r
 \r
                        /* Fetch the next bulk or interrupt endpoint from the current CDC interface */\r
-                       if (USB_Host_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                                                          NextInterfaceCDCDataEndpoint))\r
+                       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+                                                     DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
                        {\r
                                /* Descriptor not found, error out */\r
                                return NoEndpointFound;\r
@@ -155,11 +182,11 @@ uint8_t ProcessConfigurationDescriptor(void)
  *  configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration\r
  *  descriptor processing if an incompatible descriptor configuration is found.\r
  *\r
- *  This comparator searches for the next Interface descriptor of the correct CDC Class, Subclass and Protocol values.\r
+ *  This comparator searches for the next Interface descriptor of the correct CDC control Class, Subclass and Protocol values.\r
  *\r
  *  \return A value from the DSEARCH_Return_ErrorCodes_t enum\r
  */\r
-DESCRIPTOR_COMPARATOR(NextCDCInterface)\r
+uint8_t DComp_NextCDCControlInterface(void* CurrentDescriptor)\r
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
        {\r
@@ -168,19 +195,35 @@ DESCRIPTOR_COMPARATOR(NextCDCInterface)
                    (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == CDC_CONTROL_SUBCLASS) &&\r
                    (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == CDC_CONTROL_PROTOCOL))\r
                {\r
-                       return Descriptor_Search_Found;\r
+                       return DESCRIPTOR_SEARCH_Found;\r
                }\r
+       }\r
+       \r
+       return DESCRIPTOR_SEARCH_NotFound;\r
+}\r
 \r
+/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's\r
+ *  configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration\r
+ *  descriptor processing if an incompatible descriptor configuration is found.\r
+ *\r
+ *  This comparator searches for the next Interface descriptor of the correct CDC data Class, Subclass and Protocol values.\r
+ *\r
+ *  \return A value from the DSEARCH_Return_ErrorCodes_t enum\r
+ */\r
+uint8_t DComp_NextCDCDataInterface(void* CurrentDescriptor)\r
+{\r
+       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
+       {\r
                /* Check the CDC descriptor class, subclass and protocol, break out if correct data interface found */\r
                if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class    == CDC_DATA_CLASS)    &&\r
                    (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == CDC_DATA_SUBCLASS) &&\r
                    (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == CDC_DATA_PROTOCOL))\r
                {\r
-                       return Descriptor_Search_Found;\r
+                       return DESCRIPTOR_SEARCH_Found;\r
                }\r
        }\r
        \r
-       return Descriptor_Search_NotFound;\r
+       return DESCRIPTOR_SEARCH_NotFound;\r
 }\r
 \r
 /** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's\r
@@ -193,7 +236,7 @@ DESCRIPTOR_COMPARATOR(NextCDCInterface)
  *\r
  *  \return A value from the DSEARCH_Return_ErrorCodes_t enum\r
  */\r
-DESCRIPTOR_COMPARATOR(NextInterfaceCDCDataEndpoint)\r
+uint8_t DComp_NextInterfaceCDCDataEndpoint(void* CurrentDescriptor)\r
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
        {\r
@@ -201,12 +244,12 @@ DESCRIPTOR_COMPARATOR(NextInterfaceCDCDataEndpoint)
                                                        USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);\r
        \r
                if ((EndpointType == EP_TYPE_BULK) || (EndpointType == EP_TYPE_INTERRUPT))\r
-                 return Descriptor_Search_Found;\r
+                 return DESCRIPTOR_SEARCH_Found;\r
        }\r
        else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
        {\r
-               return Descriptor_Search_Fail;\r
+               return DESCRIPTOR_SEARCH_Fail;\r
        }\r
 \r
-       return Descriptor_Search_NotFound;\r
+       return DESCRIPTOR_SEARCH_NotFound;\r
 }\r