Fixed LowLevel JoystickHostWithParser demo not saving the chosen HID interface's report descriptor size.

Simplified low level Host demo configuration descriptor parser routines.
pull/1469/head
Dean Camera 14 years ago
parent d36c96d6a5
commit c8942ef469

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
@ -67,18 +68,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint))
{ {
/* Get the next HID interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(HIDInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor /* 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) if (DataINEndpoint)
break; break;
/* Clear any found endpoints */
DataOUTEndpoint = NULL;
/* Get the next HID interface from the configuration descriptor */ /* Get the next HID interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)
@ -97,6 +88,12 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

@ -51,6 +51,8 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_HID_t* HIDDescriptor = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */ /* Retrieve the entire configuration descriptor into the allocated buffer */
@ -66,7 +68,14 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; return ControlError;
} }
/* Get the first HID interface from the configuration descriptor */ while (!(DataINEndpoint))
{
/* 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 */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
@ -74,20 +83,20 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; return NoCompatibleInterfaceFound;
} }
while (!(DataINEndpoint)) /* Save the interface in case we need to refer back to it later */
{ HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
/* Get the next HID interface's data endpoint descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, /* Get the HID descriptor from the configuration descriptor */
DComp_NextJoystickInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{
/* Get the next HID interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextJoystickInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Descriptor not found, error out */ /* Descriptor not found, error out */
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }
@ -105,6 +114,9 @@ uint8_t ProcessConfigurationDescriptor(void)
DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);
Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
/* Get the HID report size from the HID report descriptor */
HIDReportSize = HIDDescriptor->HIDReportLength;
/* Valid data found, return success */ /* Valid data found, return success */
return SuccessfulConfigRead; return SuccessfulConfigRead;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */ /* Retrieve the entire configuration descriptor into the allocated buffer */
@ -66,18 +67,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint))
{ {
/* Get the next HID interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(HIDInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Get the next HID interface from the configuration descriptor */ /* Get the next HID interface from the configuration descriptor */
@ -88,6 +82,9 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

@ -51,6 +51,8 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_HID_t* HIDDescriptor = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */ /* Retrieve the entire configuration descriptor into the allocated buffer */
@ -66,29 +68,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint))
{ {
/* Get the next HID interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(HIDInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextKeyboardInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Get the next HID interface from the configuration descriptor */ /* Get the next HID interface from the configuration descriptor */
@ -99,6 +83,9 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Get the HID descriptor from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
@ -107,8 +94,8 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; return NoCompatibleInterfaceFound;
} }
/* Save the HID report size for later use */ /* Save the HID descriptor for later use */
HIDReportSize = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t)->HIDReportLength; HIDDescriptor = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t);
/* Skip the remainder of the loop as we have not found an endpoint yet */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
@ -127,6 +114,9 @@ uint8_t ProcessConfigurationDescriptor(void)
DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);
Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
/* Get the HID report size from the HID report descriptor */
HIDReportSize = HIDDescriptor->HIDReportLength;
/* Valid data found, return success */ /* Valid data found, return success */
return SuccessfulConfigRead; return SuccessfulConfigRead;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* MIDIInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
@ -67,24 +68,13 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint))
{ {
/* Get the next MIDI interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(MIDIInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextMIDIStreamingDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextMIDIStreamingDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Clear any found endpoints */
DataINEndpoint = NULL;
DataOUTEndpoint = NULL;
/* Get the next Mass Storage interface from the configuration descriptor */ /* Get the next Mass Storage interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextMIDIStreamingInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextMIDIStreamingInterface) != DESCRIPTOR_SEARCH_COMP_Found)
@ -93,6 +83,13 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* MSInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
@ -67,24 +68,13 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint))
{ {
/* Get the next Mass Storage interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(MSInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextMSInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextMSInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Clear any found endpoints */
DataINEndpoint = NULL;
DataOUTEndpoint = NULL;
/* Get the next Mass Storage interface from the configuration descriptor */ /* Get the next Mass Storage interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found)
@ -93,6 +83,13 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */ /* Retrieve the entire configuration descriptor into the allocated buffer */
@ -66,18 +67,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint))
{ {
/* Get the next HID interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(HIDInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Get the next HID interface from the configuration descriptor */ /* Get the next HID interface from the configuration descriptor */
@ -88,6 +82,9 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

@ -51,6 +51,8 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_HID_t* HIDDescriptor = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */ /* Retrieve the entire configuration descriptor into the allocated buffer */
@ -66,29 +68,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint))
{ {
/* Get the next HID interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(HIDInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextMouseInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Get the next HID interface from the configuration descriptor */ /* Get the next HID interface from the configuration descriptor */
@ -99,6 +83,9 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Get the HID descriptor from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHID) != DESCRIPTOR_SEARCH_COMP_Found)
@ -107,8 +94,8 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; return NoCompatibleInterfaceFound;
} }
/* Save the HID report size for later use */ /* Save the HID descriptor for later use */
HIDReportSize = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t)->HIDReportLength; HIDDescriptor = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_HID_t);
/* Skip the remainder of the loop as we have not found an endpoint yet */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
@ -127,6 +114,9 @@ uint8_t ProcessConfigurationDescriptor(void)
DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);
Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
/* Get the HID report size from the HID report descriptor */
HIDReportSize = HIDDescriptor->HIDReportLength;
/* Valid data found, return success */ /* Valid data found, return success */
return SuccessfulConfigRead; return SuccessfulConfigRead;
} }

@ -50,6 +50,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* PrinterInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
@ -66,28 +67,13 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint))
{ {
/* Get the next Printer interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(PrinterInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextPrinterInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextPrinterInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Clear any found endpoints */
DataINEndpoint = NULL;
DataOUTEndpoint = NULL;
/* Get the next Printer interface from the configuration descriptor */ /* Get the next Printer interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextBidirectionalPrinterInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextBidirectionalPrinterInterface) != DESCRIPTOR_SEARCH_COMP_Found)
@ -96,9 +82,12 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; return NoCompatibleInterfaceFound;
} }
/* Save Printer interface details for later use */ /* Save the interface in case we need to refer back to it later */
PrinterInterfaceNumber = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t)->InterfaceNumber; PrinterInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
PrinterAltSetting = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t)->AlternateSetting;
/* Clear any found endpoints */
DataINEndpoint = NULL;
DataOUTEndpoint = NULL;
/* Skip the remainder of the loop as we have not found an endpoint yet */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
@ -114,6 +103,10 @@ uint8_t ProcessConfigurationDescriptor(void)
DataOUTEndpoint = EndpointData; DataOUTEndpoint = EndpointData;
} }
/* Save Printer interface details for later use */
PrinterInterfaceNumber = PrinterInterface->InterfaceNumber;
PrinterAltSetting = PrinterInterface->AlternateSetting;
/* Configure the Printer data IN pipe */ /* Configure the Printer data IN pipe */
Pipe_ConfigurePipe(PRINTER_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, Pipe_ConfigurePipe(PRINTER_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN,
DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* RNDISControlInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL;
@ -68,18 +69,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint))
{ {
/* Get the next RNDIS interface's endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(RNDISControlInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Check if we have already found the control interface's notification endpoint or not */ /* Check if we have already found the control interface's notification endpoint or not */
@ -107,6 +101,9 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Clear any found endpoints */
NotificationEndpoint = NULL; NotificationEndpoint = NULL;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* StillImageInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
USB_Descriptor_Endpoint_t* EventsEndpoint = NULL; USB_Descriptor_Endpoint_t* EventsEndpoint = NULL;
@ -68,25 +69,13 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint))
{ {
/* Get the next Still Image interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(StillImageInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextStillImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) 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 */ /* Get the next Still Image interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found)
@ -95,6 +84,14 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* CDCControlInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL; USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL;
@ -68,18 +69,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint))
{ {
/* Get the next CDC interface's endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(CDCControlInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Check if we have already found the control interface's notification endpoint or not */ /* Check if we have already found the control interface's notification endpoint or not */
@ -107,6 +101,9 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Clear any found endpoints */
NotificationEndpoint = NULL; NotificationEndpoint = NULL;
} }

@ -51,6 +51,7 @@ uint8_t ProcessConfigurationDescriptor(void)
void* CurrConfigLocation = ConfigDescriptorData; void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem; uint16_t CurrConfigBytesRem;
USB_Descriptor_Interface_t* HIDInterface = NULL;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
@ -67,18 +68,11 @@ uint8_t ProcessConfigurationDescriptor(void)
return ControlError; 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)) while (!(DataINEndpoint) || !(DataOUTEndpoint))
{ {
/* Get the next HID interface's data endpoint descriptor */ /* See if we've found a likely compatible interface, and if there is an endpoint within that interface */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (!(HIDInterface) ||
USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{ {
/* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor /* 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) if (DataINEndpoint)
break; break;
/* Clear any found endpoints */
DataOUTEndpoint = NULL;
/* Get the next HID interface from the configuration descriptor */ /* Get the next HID interface from the configuration descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)
@ -97,6 +88,12 @@ uint8_t ProcessConfigurationDescriptor(void)
return NoCompatibleInterfaceFound; 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 */ /* Skip the remainder of the loop as we have not found an endpoint yet */
continue; continue;
} }

Loading…
Cancel
Save