forked from mfulz_github/qmk_firmware
Replace blind interface descriptor search in the incomplete AndroidAccessoryHost demo with an intelligent search for the correct interface in the device matching the correct class/subclass/protocol values.
This commit is contained in:
parent
d9c16402b9
commit
55aadf97d5
|
@ -66,18 +66,17 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||
default:
|
||||
return DevControlError;
|
||||
}
|
||||
|
||||
/* The Android Accessory Mode specification mandates that the accessory communications endpoints
|
||||
be in the first interface descriptor (interface 0) */
|
||||
USB_GetNextDescriptorOfType(&CurrConfigBytesRem, &CurrConfigLocation, DTYPE_Interface);
|
||||
|
||||
/* Ensure that an interface was found, and the end of the descriptor was not reached */
|
||||
if (!(CurrConfigBytesRem))
|
||||
return NoCompatibleInterfaceFound;
|
||||
|
||||
/* There should be only one compatible Android Accessory Mode interface in the device, attempt to find it */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DCOMP_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
return NoCompatibleInterfaceFound;
|
||||
}
|
||||
|
||||
while (!(DataINEndpoint) || !(DataOUTEndpoint))
|
||||
{
|
||||
/* Get the next Still Image interface's data endpoint descriptor */
|
||||
/* Get the next Android Accessory Mode interface's data endpoint descriptor */
|
||||
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||
DCOMP_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||
{
|
||||
|
@ -111,7 +110,35 @@ uint8_t ProcessConfigurationDescriptor(void)
|
|||
* 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.
|
||||
*
|
||||
* This comparator searches for the next Endpoint descriptor inside the current interface descriptor, aborting the
|
||||
* This comparator searches for the next Interface descriptor containing the correct Android Accessory Mode Class, Subclass
|
||||
* and Protocol values.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor)
|
||||
{
|
||||
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);
|
||||
|
||||
if ((Interface->Class == ANDROID_INTERFACE_CLASS) &&
|
||||
(Interface->SubClass == ANDROID_INTERFACE_SUBCLASS) &&
|
||||
(Interface->Protocol == ANDROID_INTERFACE_PROTOCOL))
|
||||
{
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
}
|
||||
|
||||
return DESCRIPTOR_SEARCH_NotFound;
|
||||
}
|
||||
|
||||
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
|
||||
* 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.
|
||||
*
|
||||
* This comparator searches for the next bulk Endpoint descriptor inside the current interface descriptor, aborting the
|
||||
* search if another interface descriptor is found before the required endpoint.
|
||||
*
|
||||
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
|
||||
|
@ -125,6 +152,7 @@ uint8_t DCOMP_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)
|
|||
USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
|
||||
|
||||
uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
|
||||
|
||||
if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
|
||||
return DESCRIPTOR_SEARCH_Found;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,10 @@
|
|||
/* Macros: */
|
||||
#define ANDROID_DATA_IN_PIPE 1
|
||||
#define ANDROID_DATA_OUT_PIPE 2
|
||||
|
||||
#define ANDROID_INTERFACE_CLASS 0xFF
|
||||
#define ANDROID_INTERFACE_SUBCLASS 0x42
|
||||
#define ANDROID_INTERFACE_PROTOCOL 0x01
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
|
||||
|
@ -57,6 +61,7 @@
|
|||
/* Function Prototypes: */
|
||||
uint8_t ProcessConfigurationDescriptor(void);
|
||||
|
||||
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor);
|
||||
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* CurrentDescriptor);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue