Fix device mode for the U4 parts.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / CDC.c
index 79c207e..0f81d0e 100644 (file)
@@ -40,33 +40,26 @@ uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo
                                 uint16_t ConfigDescriptorSize,
                                 void* ConfigDescriptorData)
 {
-       USB_Descriptor_Endpoint_t* DataINEndpoint       = NULL;
-       USB_Descriptor_Endpoint_t* DataOUTEndpoint      = NULL;
-       USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL;
+       USB_Descriptor_Endpoint_t*  DataINEndpoint       = NULL;
+       USB_Descriptor_Endpoint_t*  DataOUTEndpoint      = NULL;
+       USB_Descriptor_Endpoint_t*  NotificationEndpoint = NULL;
+       USB_Descriptor_Interface_t* CDCControlInterface  = NULL;
 
        memset(&CDCInterfaceInfo->State, 0x00, sizeof(CDCInterfaceInfo->State));
 
        if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
          return CDC_ENUMERROR_InvalidConfigDescriptor;
 
-       if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
-                                     DCOMP_CDC_Host_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
-       {
-               return CDC_ENUMERROR_NoCompatibleInterfaceFound;
-       }
-       
-       CDCInterfaceInfo->State.ControlInterfaceNumber = DESCRIPTOR_PCAST(ConfigDescriptorData,
-                                                                         USB_Descriptor_Interface_t)->InterfaceNumber;
-
        while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint))
        {
-               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
+               if (!(CDCControlInterface) ||
+                   USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
                                              DCOMP_CDC_Host_NextCDCInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
                {
                        if (NotificationEndpoint)
                        {
                                if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
-                                                                                         DCOMP_CDC_Host_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
+                                                             DCOMP_CDC_Host_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
                                {
                                        return CDC_ENUMERROR_NoCompatibleInterfaceFound;
                                }                       
@@ -77,13 +70,12 @@ uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo
                        else
                        {
                                if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
-                                                                                         DCOMP_CDC_Host_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
+                                                             DCOMP_CDC_Host_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
                                {
                                        return CDC_ENUMERROR_NoCompatibleInterfaceFound;
                                }
 
-                               CDCInterfaceInfo->State.ControlInterfaceNumber = DESCRIPTOR_PCAST(ConfigDescriptorData,
-                                                                                                USB_Descriptor_Interface_t)->InterfaceNumber;
+                               CDCControlInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t);
 
                                NotificationEndpoint = NULL;
                        }
@@ -111,7 +103,7 @@ uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo
                if (PipeNum == CDCInterfaceInfo->Config.DataINPipeNumber)
                {
                        Pipe_ConfigurePipe(PipeNum, EP_TYPE_BULK, PIPE_TOKEN_IN,
-                                                          DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize,
+                                          DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize,
                                           CDCInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
 
                        CDCInterfaceInfo->State.DataINPipeSize = DataINEndpoint->EndpointSize;
@@ -135,6 +127,7 @@ uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo
                }
        }
 
+       CDCInterfaceInfo->State.ControlInterfaceNumber = CDCControlInterface->InterfaceNumber;
        CDCInterfaceInfo->State.ControlLineStates.HostToDevice = (CDC_CONTROL_LINE_OUT_RTS | CDC_CONTROL_LINE_OUT_DTR);
        CDCInterfaceInfo->State.ControlLineStates.DeviceToHost = (CDC_CONTROL_LINE_IN_DCD  | CDC_CONTROL_LINE_IN_DSR);
        CDCInterfaceInfo->State.IsActive = true;
@@ -151,7 +144,7 @@ static uint8_t DCOMP_CDC_Host_NextCDCControlInterface(void* const CurrentDescrip
        
                if ((CurrentInterface->Class    == CDC_CONTROL_CLASS)    &&
                    (CurrentInterface->SubClass == CDC_CONTROL_SUBCLASS) &&
-                       (CurrentInterface->Protocol == CDC_CONTROL_PROTOCOL))
+                   (CurrentInterface->Protocol == CDC_CONTROL_PROTOCOL))
                {
                        return DESCRIPTOR_SEARCH_Found;
                }
@@ -169,7 +162,7 @@ static uint8_t DCOMP_CDC_Host_NextCDCDataInterface(void* const CurrentDescriptor
        
                if ((CurrentInterface->Class    == CDC_DATA_CLASS)    &&
                    (CurrentInterface->SubClass == CDC_DATA_SUBCLASS) &&
-                       (CurrentInterface->Protocol == CDC_DATA_PROTOCOL))
+                   (CurrentInterface->Protocol == CDC_DATA_PROTOCOL))
                {
                        return DESCRIPTOR_SEARCH_Found;
                }