diff --git a/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c b/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c index 2de7b722b2a8b4f869e2dd8b28ba53e9b023a17d..093c7db65d5fcac29516eef46093cd50f5952ed6 100644 --- a/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/GenericHIDHost/ConfigDescriptor.c @@ -51,8 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -66,19 +67,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor @@ -86,9 +80,6 @@ uint8_t ProcessConfigurationDescriptor(void) if (DataINEndpoint) break; - /* Clear any found endpoints */ - DataOUTEndpoint = NULL; - /* Get the next HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) @@ -97,6 +88,12 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Clear any found endpoints */ + DataOUTEndpoint = NULL; + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } diff --git a/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c b/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c index 1d82650431515899a9efdf8e25ab983d7ef65fc9..3eaf7d9609d7b7b6f96f248a60a9e083913678d4 100644 --- a/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/JoystickHostWithParser/ConfigDescriptor.c @@ -51,7 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_HID_t* HIDDescriptor = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,19 +67,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextJoystickInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Get the next HID interface from the configuration descriptor */ @@ -88,6 +83,20 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Get the HID descriptor from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } + + /* Save the HID descriptor for later use */ + HIDDescriptor = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t); + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } @@ -104,7 +113,10 @@ uint8_t ProcessConfigurationDescriptor(void) Pipe_ConfigurePipe(JOYSTICK_DATA_IN_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); - + + /* Get the HID report size from the HID report descriptor */ + HIDReportSize = HIDDescriptor->HIDReportLength; + /* Valid data found, return success */ return SuccessfulConfigRead; } diff --git a/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c b/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c index 988579ce7f769ad29147cd2f38164edd5c1c137a..e1e32ed7cb0d85f8ce193eabb53e575c61d09d67 100644 --- a/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/KeyboardHost/ConfigDescriptor.c @@ -51,7 +51,8 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -66,18 +67,11 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - while (!(DataINEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Get the next HID interface from the configuration descriptor */ @@ -88,6 +82,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c b/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c index bf2c4e051a166398d850f0029e718cd6f645f17e..74817a2f14ee74c71b4f2aab28a9dfdd6cf4d391 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/ConfigDescriptor.c @@ -51,7 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_HID_t* HIDDescriptor = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,30 +67,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - - /* Get the HID descriptor from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - - /* Save the HID report size for later use */ - HIDReportSize = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t)->HIDReportLength; while (!(DataINEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Get the next HID interface from the configuration descriptor */ @@ -99,6 +83,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + /* Get the HID descriptor from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) @@ -107,9 +94,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } - /* Save the HID report size for later use */ - HIDReportSize = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t)->HIDReportLength; - + /* Save the HID descriptor for later use */ + HIDDescriptor = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t); + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } @@ -127,6 +114,9 @@ uint8_t ProcessConfigurationDescriptor(void) DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); + /* Get the HID report size from the HID report descriptor */ + HIDReportSize = HIDDescriptor->HIDReportLength; + /* Valid data found, return success */ return SuccessfulConfigRead; } diff --git a/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c b/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c index 7dda634cc3be2085b0977417bbd59ebe67629405..7feb312512dc85e035a845a61847f9bcb698c418 100644 --- a/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MIDIHost/ConfigDescriptor.c @@ -51,8 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* MIDIInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -67,24 +68,13 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the first MIDI interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextMIDIStreamingInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next MIDI interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(MIDIInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMIDIStreamingDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Clear any found endpoints */ - DataINEndpoint = NULL; - DataOUTEndpoint = NULL; - /* Get the next Mass Storage interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMIDIStreamingInterface) != DESCRIPTOR_SEARCH_COMP_Found) @@ -93,6 +83,13 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + MIDIInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } @@ -102,7 +99,7 @@ uint8_t ProcessConfigurationDescriptor(void) /* If the endpoint is a IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - DataINEndpoint = EndpointData; + DataINEndpoint = EndpointData; else DataOUTEndpoint = EndpointData; } diff --git a/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c b/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c index a91d61ac04d91c277531d8c025a508a8b8e17ac8..3468e0db99921d540753ec84413fbab5ea5197b4 100644 --- a/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MassStorageHost/ConfigDescriptor.c @@ -51,8 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* MSInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -66,25 +67,14 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first Mass Storage interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next Mass Storage interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(MSInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMSInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Clear any found endpoints */ - DataINEndpoint = NULL; - DataOUTEndpoint = NULL; - /* Get the next Mass Storage interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found) @@ -93,6 +83,13 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + MSInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } @@ -102,7 +99,7 @@ uint8_t ProcessConfigurationDescriptor(void) /* If the endpoint is a IN type endpoint */ if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - DataINEndpoint = EndpointData; + DataINEndpoint = EndpointData; else DataOUTEndpoint = EndpointData; } diff --git a/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c b/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c index 4ea8aefe9664ce0a73fc241b0de55538b0ecaa9c..b5d62236e8208b165ea95e396352a282182c521b 100644 --- a/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MouseHost/ConfigDescriptor.c @@ -51,7 +51,8 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,19 +66,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Get the next HID interface from the configuration descriptor */ @@ -88,6 +82,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } diff --git a/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c b/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c index c5afbe4763f0f999c498cd1bfedc3429ca23b9bf..dc8ada8796679fb03603d1ebeeb146924b5e7f30 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/MouseHostWithParser/ConfigDescriptor.c @@ -51,7 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_HID_t* HIDDescriptor = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -66,29 +68,11 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - - /* Get the HID descriptor from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - - /* Save the HID report size for later use */ - HIDReportSize = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t)->HIDReportLength; - while (!(DataINEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Get the next HID interface from the configuration descriptor */ @@ -99,6 +83,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + /* Get the HID descriptor from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) @@ -107,9 +94,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } - /* Save the HID report size for later use */ - HIDReportSize = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t)->HIDReportLength; - + /* Save the HID descriptor for later use */ + HIDDescriptor = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t); + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } @@ -127,6 +114,9 @@ uint8_t ProcessConfigurationDescriptor(void) DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); + /* Get the HID report size from the HID report descriptor */ + HIDReportSize = HIDDescriptor->HIDReportLength; + /* Valid data found, return success */ return SuccessfulConfigRead; } diff --git a/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c b/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c index b16ac668c9580a878b99928a4a12cdebd2077678..89bf488bea249e17ebf3e0bc71249d39407d2e2a 100644 --- a/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/PrinterHost/ConfigDescriptor.c @@ -50,8 +50,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* PrinterInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -66,28 +67,13 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the first Printer interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextBidirectionalPrinterInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } - - /* Save Printer interface details for later use */ - PrinterInterfaceNumber = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t)->InterfaceNumber; - PrinterAltSetting = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t)->AlternateSetting; - while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next Printer interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(PrinterInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextPrinterInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Clear any found endpoints */ - DataINEndpoint = NULL; - DataOUTEndpoint = NULL; - /* Get the next Printer interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextBidirectionalPrinterInterface) != DESCRIPTOR_SEARCH_COMP_Found) @@ -96,9 +82,12 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } - /* Save Printer interface details for later use */ - PrinterInterfaceNumber = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t)->InterfaceNumber; - PrinterAltSetting = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t)->AlternateSetting; + /* Save the interface in case we need to refer back to it later */ + PrinterInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; @@ -114,6 +103,10 @@ uint8_t ProcessConfigurationDescriptor(void) DataOUTEndpoint = EndpointData; } + /* Save Printer interface details for later use */ + PrinterInterfaceNumber = PrinterInterface->InterfaceNumber; + PrinterAltSetting = PrinterInterface->AlternateSetting; + /* Configure the Printer data IN pipe */ Pipe_ConfigurePipe(PRINTER_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); diff --git a/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c b/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c index aa75dd1743c04807cc547899e5c1269b358e8696..58e1408c1ede717c308d785bfee253c1a6c469d6 100644 --- a/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/RNDISEthernetHost/ConfigDescriptor.c @@ -51,9 +51,10 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; - USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; + USB_Descriptor_Interface_t* RNDISControlInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -67,19 +68,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first RNDIS control interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint)) { - /* Get the next RNDIS interface's endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(RNDISControlInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Check if we have already found the control interface's notification endpoint or not */ @@ -107,6 +101,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + RNDISControlInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + /* Clear any found endpoints */ NotificationEndpoint = NULL; } diff --git a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c index 78bca7f949f3233078110554de5fcec19d569eaf..d11dee038b32c91cc1e9dcef3e657f2a5addb12f 100644 --- a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c @@ -51,9 +51,10 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; - USB_Descriptor_Endpoint_t* EventsEndpoint = NULL; + USB_Descriptor_Interface_t* StillImageInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* EventsEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -67,26 +68,14 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first Still Image interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next Still Image interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(StillImageInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextStillImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Clear any found endpoints */ - DataINEndpoint = NULL; - DataOUTEndpoint = NULL; - EventsEndpoint = NULL; - /* Get the next Still Image interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) @@ -95,6 +84,14 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + StillImageInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + EventsEndpoint = NULL; + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; } diff --git a/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c b/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c index a26fa5cceada36da445a809a3a239ef72459d9fd..7d9fb38c0da48e1244a865db7c2f5bbbbe334bb2 100644 --- a/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/VirtualSerialHost/ConfigDescriptor.c @@ -51,9 +51,10 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; - USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; + USB_Descriptor_Interface_t* CDCControlInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -67,19 +68,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first CDC control interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint)) { - /* Get the next CDC interface's endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(CDCControlInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Check if we have already found the control interface's notification endpoint or not */ @@ -107,6 +101,9 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + CDCControlInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + /* Clear any found endpoints */ NotificationEndpoint = NULL; } diff --git a/LUFA/Drivers/USB/Class/Host/MIDI.c b/LUFA/Drivers/USB/Class/Host/MIDI.c index 904e1fef4ae78b8e3d3c3eaf011386c47a94a9be..3d844c2b3d1e7bf3fbc64d43445cec8073e31bce 100644 --- a/LUFA/Drivers/USB/Class/Host/MIDI.c +++ b/LUFA/Drivers/USB/Class/Host/MIDI.c @@ -72,7 +72,7 @@ uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceI USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - DataINEndpoint = EndpointData; + DataINEndpoint = EndpointData; else DataOUTEndpoint = EndpointData; } diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.c b/LUFA/Drivers/USB/Class/Host/MassStorage.c index 0a966cf9b83b292fff3ff4ad1c49a5e221feff3e..2d7956e9f91c7290f9eef71802ebebec72bef98d 100644 --- a/LUFA/Drivers/USB/Class/Host/MassStorage.c +++ b/LUFA/Drivers/USB/Class/Host/MassStorage.c @@ -72,7 +72,7 @@ uint8_t MS_Host_ConfigurePipes(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - DataINEndpoint = EndpointData; + DataINEndpoint = EndpointData; else DataOUTEndpoint = EndpointData; } diff --git a/Projects/MissileLauncher/ConfigDescriptor.c b/Projects/MissileLauncher/ConfigDescriptor.c index 78b4d2fad50b2aab6a280378eb8719218bd4648f..7ee2449c237d0588320342226eec9091489ba9d5 100644 --- a/Projects/MissileLauncher/ConfigDescriptor.c +++ b/Projects/MissileLauncher/ConfigDescriptor.c @@ -51,8 +51,9 @@ uint8_t ProcessConfigurationDescriptor(void) void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; - USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -66,19 +67,12 @@ uint8_t ProcessConfigurationDescriptor(void) default: return ControlError; } - - /* Get the first HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, - DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - /* Descriptor not found, error out */ - return NoCompatibleInterfaceFound; - } while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */ + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor @@ -86,9 +80,6 @@ uint8_t ProcessConfigurationDescriptor(void) if (DataINEndpoint) break; - /* Clear any found endpoints */ - DataOUTEndpoint = NULL; - /* Get the next HID interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) @@ -97,6 +88,12 @@ uint8_t ProcessConfigurationDescriptor(void) return NoCompatibleInterfaceFound; } + /* Save the interface in case we need to refer back to it later */ + HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t); + + /* Clear any found endpoints */ + DataOUTEndpoint = NULL; + /* Skip the remainder of the loop as we have not found an endpoint yet */ continue; }