Commit 5ce8380a authored by Dean Camera's avatar Dean Camera
Browse files

Fix XPLAINBridge code broken during the changes to the Rescue Clock generation...

Fix XPLAINBridge code broken during the changes to the Rescue Clock generation in the AVRISP-MKII clone project.

Change over all low level host mode project's descriptor comparator routines to perform the descriptor casting in a temp variable to make the code clearer and easier to modify (despite being more verbose).
parent 3bf760ad
...@@ -119,7 +119,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) ...@@ -119,7 +119,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Turn on Start-of-Frame events for tracking HID report period exiry */ /* Turn on Start-of-Frame events for tracking HID report period expiry */
USB_Device_EnableSOFEvents(); USB_Device_EnableSOFEvents();
/* Indicate endpoint configuration success or failure */ /* Indicate endpoint configuration success or failure */
......
...@@ -132,10 +132,12 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -132,10 +132,12 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextInterfaceBluetoothDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextInterfaceBluetoothDataEndpoint(void* CurrentDescriptor)
{ {
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
/* Determine the type of the current descriptor */ /* Determine the type of the current descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) if (Header->Type == DTYPE_Endpoint)
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) else if (Header->Type == DTYPE_Interface)
return DESCRIPTOR_SEARCH_Fail; return DESCRIPTOR_SEARCH_Fail;
else else
return DESCRIPTOR_SEARCH_NotFound; return DESCRIPTOR_SEARCH_NotFound;
......
...@@ -135,11 +135,15 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -135,11 +135,15 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextHIDInterface(void* CurrentDescriptor) uint8_t DComp_NextHIDInterface(void* CurrentDescriptor)
{ {
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
/* Determine if the current descriptor is an interface descriptor */ /* Determine if the current descriptor is an interface descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the HID descriptor class, break out if correct class/protocol interface found */ /* Check the HID descriptor class, break out if correct class/protocol interface found */
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == HID_CSCP_HIDClass) if (Interface->Class == HID_CSCP_HIDClass)
{ {
/* Indicate that the descriptor being searched for has been found */ /* Indicate that the descriptor being searched for has been found */
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
...@@ -161,13 +165,15 @@ uint8_t DComp_NextHIDInterface(void* CurrentDescriptor) ...@@ -161,13 +165,15 @@ uint8_t DComp_NextHIDInterface(void* CurrentDescriptor)
*/ */
uint8_t DComp_NextHIDInterfaceDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextHIDInterfaceDataEndpoint(void* CurrentDescriptor)
{ {
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
/* Determine the type of the current descriptor */ /* Determine the type of the current descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) if (Header->Type == DTYPE_Endpoint)
{ {
/* Indicate that the descriptor being searched for has been found */ /* Indicate that the descriptor being searched for has been found */
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) else if (Header->Type == DTYPE_Interface)
{ {
/* Indicate that the search has failed prematurely and should be aborted */ /* Indicate that the search has failed prematurely and should be aborted */
return DESCRIPTOR_SEARCH_Fail; return DESCRIPTOR_SEARCH_Fail;
......
...@@ -131,10 +131,14 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -131,10 +131,14 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextJoystickInterface(void* CurrentDescriptor) uint8_t DComp_NextJoystickInterface(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the HID descriptor class, break out if correct class interface found */ /* Check the HID descriptor class, break out if correct class interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == HID_CSCP_HIDClass)) if ((Interface->Class == HID_CSCP_HIDClass))
{ {
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
...@@ -147,24 +151,21 @@ uint8_t DComp_NextJoystickInterface(void* CurrentDescriptor) ...@@ -147,24 +151,21 @@ uint8_t DComp_NextJoystickInterface(void* CurrentDescriptor)
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found. * descriptor processing if an incompatible descriptor configuration is found.
* *
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor, * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
* aborting the search if another interface descriptor is found before the required endpoint. * search if another interface descriptor is found before the required endpoint.
* *
* \return A value from the DSEARCH_Return_ErrorCodes_t enum * \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/ */
uint8_t DComp_NextJoystickInterfaceDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextJoystickInterfaceDataEndpoint(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
{
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
return DESCRIPTOR_SEARCH_Found;
}
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
return DESCRIPTOR_SEARCH_Fail;
}
return DESCRIPTOR_SEARCH_NotFound; if (Header->Type == DTYPE_Endpoint)
return DESCRIPTOR_SEARCH_Found;
else if (Header->Type == DTYPE_Interface)
return DESCRIPTOR_SEARCH_Fail;
else
return DESCRIPTOR_SEARCH_NotFound;
} }
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's /** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
...@@ -177,7 +178,9 @@ uint8_t DComp_NextJoystickInterfaceDataEndpoint(void* CurrentDescriptor) ...@@ -177,7 +178,9 @@ uint8_t DComp_NextJoystickInterfaceDataEndpoint(void* CurrentDescriptor)
*/ */
uint8_t DComp_NextHID(void* CurrentDescriptor) uint8_t DComp_NextHID(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == HID_DTYPE_HID) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == HID_DTYPE_HID)
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
else else
return DESCRIPTOR_SEARCH_NotFound; return DESCRIPTOR_SEARCH_NotFound;
......
...@@ -116,11 +116,15 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -116,11 +116,15 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor) uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */ /* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == HID_CSCP_HIDClass) && if ((Interface->Class == HID_CSCP_HIDClass) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == HID_CSCP_KeyboardBootProtocol)) (Interface->Protocol == HID_CSCP_KeyboardBootProtocol))
{ {
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
...@@ -133,23 +137,20 @@ uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor) ...@@ -133,23 +137,20 @@ uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor)
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found. * descriptor processing if an incompatible descriptor configuration is found.
* *
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor, * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
* aborting the search if another interface descriptor is found before the required endpoint. * search if another interface descriptor is found before the required endpoint.
* *
* \return A value from the DSEARCH_Return_ErrorCodes_t enum * \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/ */
uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
{
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) if (Header->Type == DTYPE_Endpoint)
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} else if (Header->Type == DTYPE_Interface)
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) return DESCRIPTOR_SEARCH_Fail;
{ else
return DESCRIPTOR_SEARCH_Fail; return DESCRIPTOR_SEARCH_NotFound;
}
return DESCRIPTOR_SEARCH_NotFound;
} }
...@@ -131,10 +131,14 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -131,10 +131,14 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor) uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the HID descriptor class, break out if correct class interface found */ /* Check the HID descriptor class, break out if correct class interface found */
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == HID_CSCP_HIDClass) if (Interface->Class == HID_CSCP_HIDClass)
{ {
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
...@@ -147,24 +151,21 @@ uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor) ...@@ -147,24 +151,21 @@ uint8_t DComp_NextKeyboardInterface(void* CurrentDescriptor)
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found. * descriptor processing if an incompatible descriptor configuration is found.
* *
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor, * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
* aborting the search if another interface descriptor is found before the required endpoint. * search if another interface descriptor is found before the required endpoint.
* *
* \return A value from the DSEARCH_Return_ErrorCodes_t enum * \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/ */
uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
{
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
return DESCRIPTOR_SEARCH_Found;
}
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
return DESCRIPTOR_SEARCH_Fail;
}
return DESCRIPTOR_SEARCH_NotFound; if (Header->Type == DTYPE_Endpoint)
return DESCRIPTOR_SEARCH_Found;
else if (Header->Type == DTYPE_Interface)
return DESCRIPTOR_SEARCH_Fail;
else
return DESCRIPTOR_SEARCH_NotFound;
} }
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's /** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
...@@ -177,9 +178,11 @@ uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor) ...@@ -177,9 +178,11 @@ uint8_t DComp_NextKeyboardInterfaceDataEndpoint(void* CurrentDescriptor)
*/ */
uint8_t DComp_NextHID(void* CurrentDescriptor) uint8_t DComp_NextHID(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == HID_DTYPE_HID) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == HID_DTYPE_HID)
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) else if (Header->Type == DTYPE_Interface)
return DESCRIPTOR_SEARCH_Fail; return DESCRIPTOR_SEARCH_Fail;
else else
return DESCRIPTOR_SEARCH_NotFound; return DESCRIPTOR_SEARCH_NotFound;
......
...@@ -126,12 +126,16 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -126,12 +126,16 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextMIDIStreamingInterface(void* CurrentDescriptor) uint8_t DComp_NextMIDIStreamingInterface(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the MIDI descriptor class, subclass and protocol, break out if correct data interface found */ /* Check the MIDI descriptor class, subclass and protocol, break out if correct data interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == AUDIO_CSCP_AudioClass) && if ((Interface->Class == AUDIO_CSCP_AudioClass) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == AUDIO_CSCP_MIDIStreamingSubclass) && (Interface->SubClass == AUDIO_CSCP_MIDIStreamingSubclass) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == AUDIO_CSCP_StreamingProtocol)) (Interface->Protocol == AUDIO_CSCP_StreamingProtocol))
{ {
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
...@@ -151,16 +155,17 @@ uint8_t DComp_NextMIDIStreamingInterface(void* CurrentDescriptor) ...@@ -151,16 +155,17 @@ uint8_t DComp_NextMIDIStreamingInterface(void* CurrentDescriptor)
*/ */
uint8_t DComp_NextMIDIStreamingDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextMIDIStreamingDataEndpoint(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Endpoint)
{ {
uint8_t EndpointType = (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);
/* Check the endpoint type, break out if correct BULK type endpoint found */ /* Check the endpoint type, break out if correct BULK type endpoint found */
if (EndpointType == EP_TYPE_BULK) if ((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_BULK)
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) else if (Header->Type == DTYPE_Interface)
{ {
return DESCRIPTOR_SEARCH_Fail; return DESCRIPTOR_SEARCH_Fail;
} }
......
...@@ -126,12 +126,16 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -126,12 +126,16 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextMSInterface(void* CurrentDescriptor) uint8_t DComp_NextMSInterface(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the descriptor class and protocol, break out if correct class/protocol interface found */ /* Check the descriptor class and protocol, break out if correct class/protocol interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == MASS_STORE_CLASS) && if ((Interface->Class == MASS_STORE_CLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == MASS_STORE_SUBCLASS) && (Interface->SubClass == MASS_STORE_SUBCLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == MASS_STORE_PROTOCOL)) (Interface->Protocol == MASS_STORE_PROTOCOL))
{ {
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
...@@ -151,16 +155,17 @@ uint8_t DComp_NextMSInterface(void* CurrentDescriptor) ...@@ -151,16 +155,17 @@ uint8_t DComp_NextMSInterface(void* CurrentDescriptor)
*/ */
uint8_t DComp_NextMSInterfaceBulkDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextMSInterfaceBulkDataEndpoint(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Endpoint)
{ {
uint8_t EndpointType = (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
USB_Descriptor_Endpoint_t).Attributes & EP_TYPE_MASK);
/* Check the endpoint type, break out if correct BULK type endpoint found */ /* Check the endpoint type, break out if correct BULK type endpoint found */
if (EndpointType == EP_TYPE_BULK) if ((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_BULK)
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) else if (Header->Type == DTYPE_Interface)
{ {
return DESCRIPTOR_SEARCH_Fail; return DESCRIPTOR_SEARCH_Fail;
} }
......
...@@ -116,12 +116,16 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -116,12 +116,16 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextMouseInterface(void* CurrentDescriptor) uint8_t DComp_NextMouseInterface(void* CurrentDescriptor)
{ {
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
/* Determine if the current descriptor is an interface descriptor */ /* Determine if the current descriptor is an interface descriptor */
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */ /* Check the HID descriptor class and protocol, break out if correct class/protocol interface found */
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == HID_CSCP_HIDClass) && if ((Interface->Class == HID_CSCP_HIDClass) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == HID_CSCP_MouseBootProtocol)) (Interface->Protocol == HID_CSCP_MouseBootProtocol))
{ {
/* Indicate that the descriptor being searched for has been found */ /* Indicate that the descriptor being searched for has been found */
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
...@@ -136,30 +140,21 @@ uint8_t DComp_NextMouseInterface(void* CurrentDescriptor) ...@@ -136,30 +140,21 @@ uint8_t DComp_NextMouseInterface(void* CurrentDescriptor)
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found. * descriptor processing if an incompatible descriptor configuration is found.
* *
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor, * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
* aborting the search if another interface descriptor is found before the required endpoint. * search if another interface descriptor is found before the required endpoint.
* *
* \return A value from the DSEARCH_Return_ErrorCodes_t enum * \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/ */
uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor)
{ {
/* Determine the type of the current descriptor */ USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
{
/* Check if the current Endpoint descriptor is of type IN */
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
{
/* Indicate that the descriptor being searched for has been found */
return DESCRIPTOR_SEARCH_Found;
}
}
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
/* Indicate that the search has failed prematurely and should be aborted */
return DESCRIPTOR_SEARCH_Fail;
}
/* Current descriptor does not match what this comparator is looking for */ /* Determine the type of the current descriptor */
return DESCRIPTOR_SEARCH_NotFound; if (Header->Type == DTYPE_Endpoint)
return DESCRIPTOR_SEARCH_Found;
else if (Header->Type == DTYPE_Interface)
return DESCRIPTOR_SEARCH_Fail;
else
return DESCRIPTOR_SEARCH_NotFound;
} }
...@@ -131,10 +131,14 @@ uint8_t ProcessConfigurationDescriptor(void) ...@@ -131,10 +131,14 @@ uint8_t ProcessConfigurationDescriptor(void)
*/ */
uint8_t DComp_NextMouseInterface(void* CurrentDescriptor) uint8_t DComp_NextMouseInterface(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{ {
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
/* Check the HID descriptor class, break out if correct class interface found */ /* Check the HID descriptor class, break out if correct class interface found */
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == HID_CSCP_HIDClass) if (Interface->Class == HID_CSCP_HIDClass)
{ {
return DESCRIPTOR_SEARCH_Found; return DESCRIPTOR_SEARCH_Found;
} }
...@@ -147,24 +151,21 @@ uint8_t DComp_NextMouseInterface(void* CurrentDescriptor) ...@@ -147,24 +151,21 @@ uint8_t DComp_NextMouseInterface(void* CurrentDescriptor)
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration * configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found. * descriptor processing if an incompatible descriptor configuration is found.
* *
* This comparator searches for the next IN Endpoint descriptor inside the current interface descriptor, * This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
* aborting the search if another interface descriptor is found before the required endpoint. * search if another interface descriptor is found before the required endpoint.
* *
* \return A value from the DSEARCH_Return_ErrorCodes_t enum * \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/ */
uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor) uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
{
if (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Endpoint_t).EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
return DESCRIPTOR_SEARCH_Found;
}
else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
return DESCRIPTOR_SEARCH_Fail;
}
return DESCRIPTOR_SEARCH_NotFound; if (Header->Type == DTYPE_Endpoint)
return DESCRIPTOR_SEARCH_Found;
else if (Header->Type == DTYPE_Interface)
return DESCRIPTOR_SEARCH_Fail;
else
return DESCRIPTOR_SEARCH_NotFound;
} }
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's /** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
...@@ -177,7 +178,9 @@ uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor) ...@@ -177,7 +178,9 @@ uint8_t DComp_NextMouseInterfaceDataEndpoint(void* CurrentDescriptor)
*/ */
uint8_t DComp_NextHID(void* CurrentDescriptor) uint8_t DComp_NextHID(void* CurrentDescriptor)
{ {
if (DESCRIPTOR_TYPE(CurrentDescriptor) == HID_DTYPE_HID) USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == HID_DTYPE_HID)