From 76d5e99bb8765030a7f99e7b5adf9bae7f92e0ba Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Fri, 15 May 2009 08:02:30 +0000 Subject: Fix to previous patch (make CDCHost demo deallocate pipes when an invalid CDC interface is skipped). Remove the saving of the USB_GetNextDescriptorComp() return value in all host demos, since it went unused anyway; replaced with a simple check against the success error code for clarity. --- Demos/Host/CDCHost/ConfigDescriptor.c | 24 ++++++++++++++-------- Demos/Host/GenericHIDHost/ConfigDescriptor.c | 6 ++++-- Demos/Host/KeyboardHost/ConfigDescriptor.c | 5 +++-- .../Host/KeyboardHostWithParser/ConfigDescriptor.c | 11 +++++----- Demos/Host/MassStorageHost/ConfigDescriptor.c | 9 ++++---- Demos/Host/MouseHost/ConfigDescriptor.c | 5 +++-- Demos/Host/MouseHostWithParser/ConfigDescriptor.c | 11 +++++----- Demos/Host/StillImageHost/ConfigDescriptor.c | 5 +++-- 8 files changed, 44 insertions(+), 32 deletions(-) (limited to 'Demos/Host') diff --git a/Demos/Host/CDCHost/ConfigDescriptor.c b/Demos/Host/CDCHost/ConfigDescriptor.c index 29afbfaa1..faad3ccd2 100644 --- a/Demos/Host/CDCHost/ConfigDescriptor.c +++ b/Demos/Host/CDCHost/ConfigDescriptor.c @@ -70,7 +70,8 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the CDC control interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextCDCControlInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoCDCInterfaceFound; @@ -81,13 +82,14 @@ uint8_t ProcessConfigurationDescriptor(void) { /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceCDCDataEndpoint)) + NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Check to see if the control interface's notification pipe has been found, if so search for the data interface */ if (FoundEndpoints & (1 << CDC_NOTIFICATIONPIPE)) { /* Get the next CDC data interface from the configuration descriptor (CDC class has two CDC interfaces) */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextCDCDataInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoCDCInterfaceFound; @@ -98,13 +100,17 @@ uint8_t ProcessConfigurationDescriptor(void) /* Clear the found endpoints mask, since any already processed endpoints aren't in the CDC interface we need */ FoundEndpoints = 0; - /* Disable any already configured endpoints from the invalid CDC interfaces */ - Endpoint_DisableEndpoint(CDC_NOTIFICATIONPIPE); - Endpoint_DisableEndpoint(CDC_DATAPIPE_IN); - Endpoint_DisableEndpoint(CDC_DATAPIPE_OUT); + /* Disable any already configured pipes from the invalid CDC interfaces */ + Pipe_SelectPipe(CDC_NOTIFICATIONPIPE); + Pipe_DisablePipe(); + Pipe_SelectPipe(CDC_DATAPIPE_IN); + Pipe_DisablePipe(); + Pipe_SelectPipe(CDC_DATAPIPE_OUT); + Pipe_DisablePipe(); /* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextCDCControlInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoCDCInterfaceFound; @@ -113,7 +119,7 @@ uint8_t ProcessConfigurationDescriptor(void) /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceCDCDataEndpoint)) + NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; diff --git a/Demos/Host/GenericHIDHost/ConfigDescriptor.c b/Demos/Host/GenericHIDHost/ConfigDescriptor.c index ef99359a9..1c0a6b291 100644 --- a/Demos/Host/GenericHIDHost/ConfigDescriptor.c +++ b/Demos/Host/GenericHIDHost/ConfigDescriptor.c @@ -71,7 +71,8 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the HID interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextHIDInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDInterfaceFound; @@ -80,7 +81,8 @@ uint8_t ProcessConfigurationDescriptor(void) while (FoundEndpoints != ((1 << HID_DATA_IN_PIPE) | (1 << HID_DATA_OUT_PIPE))) { /* Get the next HID interface's data endpoint descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextInterfaceHIDDataEndpoint)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextInterfaceHIDDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Not all HID devices have an OUT endpoint - if we've reached the end of the HID descriptor * but only found the mandatory IN endpoint, it's safe to continue with the device enumeration */ diff --git a/Demos/Host/KeyboardHost/ConfigDescriptor.c b/Demos/Host/KeyboardHost/ConfigDescriptor.c index 303f06dc1..b0233d98c 100644 --- a/Demos/Host/KeyboardHost/ConfigDescriptor.c +++ b/Demos/Host/KeyboardHost/ConfigDescriptor.c @@ -69,7 +69,8 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the keyboard interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextKeyboardInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDInterfaceFound; @@ -77,7 +78,7 @@ uint8_t ProcessConfigurationDescriptor(void) /* Get the keyboard interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceKeyboardDataEndpoint)) + NextInterfaceKeyboardDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; diff --git a/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.c b/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.c index 9b56823ef..9cdf6f88a 100644 --- a/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/KeyboardHostWithParser/ConfigDescriptor.c @@ -49,7 +49,6 @@ uint8_t ProcessConfigurationDescriptor(void) { uint8_t* ConfigDescriptorData; uint16_t ConfigDescriptorSize; - uint8_t ErrorCode; /* Get Configuration Descriptor size from the device */ if (USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) @@ -70,14 +69,16 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the keyboard interface from the configuration descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextKeyboardInterface))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextKeyboardInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDInterfaceFound; } /* Get the keyboard interface's HID descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextHID))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextHID) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDDescriptorFound; @@ -87,8 +88,8 @@ uint8_t ProcessConfigurationDescriptor(void) HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength; /* Get the keyboard interface's data endpoint descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceKeyboardDataEndpoint))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextInterfaceKeyboardDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; diff --git a/Demos/Host/MassStorageHost/ConfigDescriptor.c b/Demos/Host/MassStorageHost/ConfigDescriptor.c index 6642e1c5c..c02f3b0de 100644 --- a/Demos/Host/MassStorageHost/ConfigDescriptor.c +++ b/Demos/Host/MassStorageHost/ConfigDescriptor.c @@ -49,7 +49,6 @@ uint8_t ProcessConfigurationDescriptor(void) { uint8_t* ConfigDescriptorData; uint16_t ConfigDescriptorSize; - uint8_t ErrorCode; uint8_t FoundEndpoints = 0; /* Get Configuration Descriptor size from the device */ @@ -71,8 +70,8 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the mass storage interface from the configuration descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextMassStorageInterface))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextMassStorageInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoInterfaceFound; @@ -82,8 +81,8 @@ uint8_t ProcessConfigurationDescriptor(void) while (FoundEndpoints != ((1 << MASS_STORE_DATA_IN_PIPE) | (1 << MASS_STORE_DATA_OUT_PIPE))) { /* Fetch the next bulk endpoint from the current mass storage interface */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceBulkDataEndpoint))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextInterfaceBulkDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; diff --git a/Demos/Host/MouseHost/ConfigDescriptor.c b/Demos/Host/MouseHost/ConfigDescriptor.c index f29eda16e..435a4f90c 100644 --- a/Demos/Host/MouseHost/ConfigDescriptor.c +++ b/Demos/Host/MouseHost/ConfigDescriptor.c @@ -69,7 +69,8 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the mouse interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextMouseInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDInterfaceFound; @@ -77,7 +78,7 @@ uint8_t ProcessConfigurationDescriptor(void) /* Get the mouse interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceMouseDataEndpoint)) + NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; diff --git a/Demos/Host/MouseHostWithParser/ConfigDescriptor.c b/Demos/Host/MouseHostWithParser/ConfigDescriptor.c index 486a0c7fb..c00852372 100644 --- a/Demos/Host/MouseHostWithParser/ConfigDescriptor.c +++ b/Demos/Host/MouseHostWithParser/ConfigDescriptor.c @@ -49,7 +49,6 @@ uint8_t ProcessConfigurationDescriptor(void) { uint8_t* ConfigDescriptorData; uint16_t ConfigDescriptorSize; - uint8_t ErrorCode; /* Get Configuration Descriptor size from the device */ if (USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) @@ -70,14 +69,16 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the mouse interface from the configuration descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextMouseInterface))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextMouseInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDInterfaceFound; } /* Get the mouse interface's HID descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextHID))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextHID) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoHIDDescriptorFound; @@ -87,8 +88,8 @@ uint8_t ProcessConfigurationDescriptor(void) HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_HID_t).HIDReportLength; /* Get the mouse interface's data endpoint descriptor */ - if ((ErrorCode = USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextInterfaceMouseDataEndpoint))) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextInterfaceMouseDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; diff --git a/Demos/Host/StillImageHost/ConfigDescriptor.c b/Demos/Host/StillImageHost/ConfigDescriptor.c index 5e2916ba2..b58dfb8bd 100644 --- a/Demos/Host/StillImageHost/ConfigDescriptor.c +++ b/Demos/Host/StillImageHost/ConfigDescriptor.c @@ -70,7 +70,8 @@ uint8_t ProcessConfigurationDescriptor(void) return InvalidConfigDataReturned; /* Get the Still Image interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, NextStillImageInterface)) + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoInterfaceFound; @@ -81,7 +82,7 @@ uint8_t ProcessConfigurationDescriptor(void) { /* Fetch the next endpoint from the current Still Image interface */ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - NextSImageInterfaceDataEndpoint)) + NextSImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; -- cgit v1.2.3