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
|
@ -67,17 +67,16 @@ uint8_t ProcessConfigurationDescriptor(void)
|
||||||
return DevControlError;
|
return DevControlError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The Android Accessory Mode specification mandates that the accessory communications endpoints
|
/* There should be only one compatible Android Accessory Mode interface in the device, attempt to find it */
|
||||||
be in the first interface descriptor (interface 0) */
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
USB_GetNextDescriptorOfType(&CurrConfigBytesRem, &CurrConfigLocation, DTYPE_Interface);
|
DCOMP_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found)
|
||||||
|
{
|
||||||
/* Ensure that an interface was found, and the end of the descriptor was not reached */
|
return NoCompatibleInterfaceFound;
|
||||||
if (!(CurrConfigBytesRem))
|
}
|
||||||
return NoCompatibleInterfaceFound;
|
|
||||||
|
|
||||||
while (!(DataINEndpoint) || !(DataOUTEndpoint))
|
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,
|
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
|
||||||
DCOMP_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
|
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
|
* 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 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.
|
* 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
|
||||||
|
@ -125,6 +152,7 @@ uint8_t DCOMP_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)
|
||||||
USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
|
USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
|
||||||
|
|
||||||
uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
|
uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
|
||||||
|
|
||||||
if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
|
if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
|
||||||
return DESCRIPTOR_SEARCH_Found;
|
return DESCRIPTOR_SEARCH_Found;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,10 @@
|
||||||
#define ANDROID_DATA_IN_PIPE 1
|
#define ANDROID_DATA_IN_PIPE 1
|
||||||
#define ANDROID_DATA_OUT_PIPE 2
|
#define ANDROID_DATA_OUT_PIPE 2
|
||||||
|
|
||||||
|
#define ANDROID_INTERFACE_CLASS 0xFF
|
||||||
|
#define ANDROID_INTERFACE_SUBCLASS 0x42
|
||||||
|
#define ANDROID_INTERFACE_PROTOCOL 0x01
|
||||||
|
|
||||||
/* Enums: */
|
/* Enums: */
|
||||||
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
|
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
|
||||||
enum AndroidHost_GetConfigDescriptorDataCodes_t
|
enum AndroidHost_GetConfigDescriptorDataCodes_t
|
||||||
|
@ -57,6 +61,7 @@
|
||||||
/* Function Prototypes: */
|
/* Function Prototypes: */
|
||||||
uint8_t ProcessConfigurationDescriptor(void);
|
uint8_t ProcessConfigurationDescriptor(void);
|
||||||
|
|
||||||
|
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor);
|
||||||
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* CurrentDescriptor);
|
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* CurrentDescriptor);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue