aboutsummaryrefslogtreecommitdiff
path: root/LUFA/Drivers/USB/Class/Host/MassStorage.c
diff options
context:
space:
mode:
authorDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2010-09-30 07:56:47 +0000
committerDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2010-09-30 07:56:47 +0000
commit076783dd8ae11a29c6536fb631b52659642b2ea5 (patch)
treedd3d7d307c56cbcef53911bcd42f93e5ba908ecb /LUFA/Drivers/USB/Class/Host/MassStorage.c
parentcfd8bc836157d853a687d6329327ba221b448e37 (diff)
Fix low level host mode demos not correctly fetching the next endpoint when an invalid interface is discarded.
Update the pipe configuration routines in the host mode class drivers so that they use the same new code to enumerate compatible devices to increase reliability. Add support to the host mode class drivers for non-sequential (but non-overlapping with other interface) pipe numbers. git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@1503 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'LUFA/Drivers/USB/Class/Host/MassStorage.c')
-rw-r--r--LUFA/Drivers/USB/Class/Host/MassStorage.c82
1 files changed, 51 insertions, 31 deletions
diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.c b/LUFA/Drivers/USB/Class/Host/MassStorage.c
index 0366703b..104a358c 100644
--- a/LUFA/Drivers/USB/Class/Host/MassStorage.c
+++ b/LUFA/Drivers/USB/Class/Host/MassStorage.c
@@ -38,58 +38,78 @@
uint8_t MS_Host_ConfigurePipes(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo,
uint16_t ConfigDescriptorSize,
- void* DeviceConfigDescriptor)
+ void* ConfigDescriptorData)
{
- uint8_t FoundEndpoints = 0;
-
+ USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
+ USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
+
memset(&MSInterfaceInfo->State, 0x00, sizeof(MSInterfaceInfo->State));
- if (DESCRIPTOR_TYPE(DeviceConfigDescriptor) != DTYPE_Configuration)
+ if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)
return MS_ENUMERROR_InvalidConfigDescriptor;
-
- if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &DeviceConfigDescriptor,
- DCOMP_MS_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found)
+
+ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
+ DCOMP_MS_Host_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{
- return MS_ENUMERROR_NoMSInterfaceFound;
+ return MS_ENUMERROR_NoCompatibleInterfaceFound;
}
-
- MSInterfaceInfo->State.InterfaceNumber = DESCRIPTOR_PCAST(DeviceConfigDescriptor, USB_Descriptor_Interface_t)->InterfaceNumber;
- while (FoundEndpoints != (MS_FOUND_DATAPIPE_IN | MS_FOUND_DATAPIPE_OUT))
+ MSInterfaceInfo->State.InterfaceNumber = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t)->InterfaceNumber;
+
+ while (!(DataINEndpoint) || !(DataOUTEndpoint))
{
- if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &DeviceConfigDescriptor,
- DCOMP_MS_NextMSInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
+ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
+ DCOMP_MS_Host_NextMSInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{
- return MS_ENUMERROR_EndpointsNotFound;
+ DataINEndpoint = NULL;
+ DataOUTEndpoint = NULL;
+
+ if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
+ DCOMP_MS_Host_NextMSInterface) != DESCRIPTOR_SEARCH_COMP_Found)
+ {
+ return MS_ENUMERROR_NoCompatibleInterfaceFound;
+ }
+
+ MSInterfaceInfo->State.InterfaceNumber = DESCRIPTOR_PCAST(ConfigDescriptorData,
+ USB_Descriptor_Interface_t)->InterfaceNumber;
+
+ continue;
}
- USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(DeviceConfigDescriptor, USB_Descriptor_Endpoint_t);
+ USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);
if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)
+ DataINEndpoint = EndpointData;
+ else
+ DataOUTEndpoint = EndpointData;
+ }
+
+ for (uint8_t PipeNum = 1; PipeNum < PIPE_TOTAL_PIPES; PipeNum++)
+ {
+ if (PipeNum == MSInterfaceInfo->Config.DataINPipeNumber)
{
- Pipe_ConfigurePipe(MSInterfaceInfo->Config.DataINPipeNumber, EP_TYPE_BULK, PIPE_TOKEN_IN,
- EndpointData->EndpointAddress, EndpointData->EndpointSize,
- MSInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
- MSInterfaceInfo->State.DataINPipeSize = EndpointData->EndpointSize;
-
- FoundEndpoints |= MS_FOUND_DATAPIPE_IN;
+ Pipe_ConfigurePipe(PipeNum, EP_TYPE_BULK, PIPE_TOKEN_IN,
+ DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize,
+ MSInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
+
+ MSInterfaceInfo->State.DataINPipeSize = DataINEndpoint->EndpointSize;
}
- else
+ else if (PipeNum == MSInterfaceInfo->Config.DataOUTPipeNumber)
{
- Pipe_ConfigurePipe(MSInterfaceInfo->Config.DataOUTPipeNumber, EP_TYPE_BULK, PIPE_TOKEN_OUT,
- EndpointData->EndpointAddress, EndpointData->EndpointSize,
- MSInterfaceInfo->Config.DataOUTPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
- MSInterfaceInfo->State.DataOUTPipeSize = EndpointData->EndpointSize;
-
- FoundEndpoints |= MS_FOUND_DATAPIPE_OUT;
- }
+ Pipe_ConfigurePipe(PipeNum, EP_TYPE_BULK, PIPE_TOKEN_OUT,
+ DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize,
+ MSInterfaceInfo->Config.DataOUTPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE);
+
+ MSInterfaceInfo->State.DataOUTPipeSize = DataOUTEndpoint->EndpointSize;
+ }
}
MSInterfaceInfo->State.IsActive = true;
+
return MS_ENUMERROR_NoError;
}
-static uint8_t DCOMP_MS_NextMSInterface(void* const CurrentDescriptor)
+static uint8_t DCOMP_MS_Host_NextMSInterface(void* const CurrentDescriptor)
{
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
@@ -107,7 +127,7 @@ static uint8_t DCOMP_MS_NextMSInterface(void* const CurrentDescriptor)
return DESCRIPTOR_SEARCH_NotFound;
}
-static uint8_t DCOMP_MS_NextMSInterfaceEndpoint(void* const CurrentDescriptor)
+static uint8_t DCOMP_MS_Host_NextMSInterfaceEndpoint(void* const CurrentDescriptor)
{
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
{