diff options
Diffstat (limited to 'Demos/Host/LowLevel/StillImageHost')
3 files changed, 55 insertions, 57 deletions
diff --git a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c index 9f740c1f0..583df3bcc 100644 --- a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.c @@ -50,7 +50,10 @@ uint8_t ProcessConfigurationDescriptor(void) uint8_t ConfigDescriptorData[512]; void* CurrConfigLocation = ConfigDescriptorData; uint16_t CurrConfigBytesRem; - uint8_t FoundEndpoints = 0; + + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Endpoint_t* EventsEndpoint = NULL; /* Retrieve the entire configuration descriptor into the allocated buffer */ switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) @@ -65,69 +68,64 @@ uint8_t ProcessConfigurationDescriptor(void) return ControlError; } - /* Get the Still Image interface from the configuration descriptor */ + /* Get the first Still Image interface from the configuration descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ - return NoInterfaceFound; + return NoCompatibleInterfaceFound; } - /* Get the IN and OUT data and event endpoints for the Still Image interface */ - while (FoundEndpoints != ((1 << SIMAGE_EVENTS_PIPE) | (1 << SIMAGE_DATA_IN_PIPE) | (1 << SIMAGE_DATA_OUT_PIPE))) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - /* Fetch the next endpoint from the current Still Image interface */ + /* Get the next Still Image interface's data endpoint descriptor */ if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextStillImageInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - /* Descriptor not found, error out */ - return NoEndpointFound; + /* Clear any found endpoints */ + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + EventsEndpoint = NULL; + + /* Get the next Still Image interface from the configuration descriptor */ + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextStillImageInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + /* Descriptor not found, error out */ + return NoCompatibleInterfaceFound; + } } - + + /* Retrieve the endpoint address from the endpoint descriptor */ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t); - /* Check if the found endpoint is a interrupt or bulk type descriptor */ - if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + /* If the endpoint is a IN type endpoint */ + if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) { - /* If the endpoint is a IN type interrupt endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the events pipe */ - Pipe_ConfigurePipe(SIMAGE_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); - - /* Set the flag indicating that the events pipe has been found */ - FoundEndpoints |= (1 << SIMAGE_EVENTS_PIPE); - } + /* Check if the found endpoint is a interrupt or bulk type descriptor */ + if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT) + EventsEndpoint = EndpointData; + else + DataINEndpoint = EndpointData; } else { - /* Check if the endpoint is a bulk IN or bulk OUT endpoint */ - if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) - { - /* Configure the data IN pipe */ - Pipe_ConfigurePipe(SIMAGE_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - /* Set the flag indicating that the data IN pipe has been found */ - FoundEndpoints |= (1 << SIMAGE_DATA_IN_PIPE); - } - else - { - /* Configure the data OUT pipe */ - Pipe_ConfigurePipe(SIMAGE_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - PIPE_BANK_DOUBLE); - - /* Set the flag indicating that the data OUT pipe has been found */ - FoundEndpoints |= (1 << SIMAGE_DATA_OUT_PIPE); - } + DataOUTEndpoint = EndpointData; } } + + /* Configure the Still Image data IN pipe */ + Pipe_ConfigurePipe(SIMAGE_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Still Image data OUT pipe */ + Pipe_ConfigurePipe(SIMAGE_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE); + + /* Configure the Still Image events pipe */ + Pipe_ConfigurePipe(SIMAGE_EVENTS_PIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + EventsEndpoint->EndpointAddress, EventsEndpoint->EndpointSize, PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(EventsEndpoint->PollingIntervalMS); /* Valid data found, return success */ return SuccessfulConfigRead; diff --git a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h index 631352d4f..929d658cd 100644 --- a/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h +++ b/Demos/Host/LowLevel/StillImageHost/ConfigDescriptor.h @@ -51,6 +51,15 @@ /** Interface Class value for the Still Image Device protocol. */ #define SIMAGE_PROTOCOL 0x01 + /** Pipe number of the Still Image data IN pipe. */ + #define SIMAGE_DATA_IN_PIPE 1 + + /** Pipe number of the Still Image data OUT pipe. */ + #define SIMAGE_DATA_OUT_PIPE 2 + + /** Pipe number of the Still Image events pipe. */ + #define SIMAGE_EVENTS_PIPE 3 + /* Enums: */ /** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */ enum StillImageHost_GetConfigDescriptorDataCodes_t @@ -59,8 +68,7 @@ ControlError = 1, /**< A control request to the device failed to complete successfully */ DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */ InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */ - NoInterfaceFound = 4, /**< A compatible SI interface was not found in the device's Configuration Descriptor */ - NoEndpointFound = 5, /**< The correct SI endpoint descriptors were not found in the device's SI interface */ + NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */ }; /* Function Prototypes: */ diff --git a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h index c91a80122..f2bb18953 100644 --- a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h +++ b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.h @@ -40,17 +40,9 @@ #include <LUFA/Drivers/USB/USB.h> #include "PIMACodes.h" + #include "../StillImageHost.h" - /* Macros: */ - /** Pipe number of the Still Image data IN pipe. */ - #define SIMAGE_DATA_IN_PIPE 0x01 - - /** Pipe number of the Still Image data OUT pipe. */ - #define SIMAGE_DATA_OUT_PIPE 0x02 - - /** Pipe number of the Still Image events pipe. */ - #define SIMAGE_EVENTS_PIPE 0x03 - + /* Macros: */ /** Length in bytes of a given Unicode string's character length. * * \param[in] chars Total number of Unicode characters in the string |