summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2011-07-10 07:15:57 +0000
committerDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2011-07-10 07:15:57 +0000
commit83af35fdabdc5362f007ec6f683684d9545fcd38 (patch)
tree768f8ff0fd860d20715f45b65b246035be037830
parentfa54581f86a9f2ab71dbddee22d3cfd0ed4a004b (diff)
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.
git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@1852 d5102386-fcda-11dd-9fdb-3debd5008f28
-rw-r--r--Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c48
-rw-r--r--Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h5
2 files changed, 43 insertions, 10 deletions
diff --git a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c
index 664e065a..0dc19e9a 100644
--- a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c
+++ b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.c
@@ -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;
}
diff --git a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h
index 92c0d99a..4989d9d8 100644
--- a/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h
+++ b/Demos/Host/Incomplete/AndroidAccessoryHost/ConfigDescriptor.h
@@ -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