X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f1199200e167a737a4676378da184387e543830c..cf610c5c91c3eee02dec7ca848acc8da831ad98a:/Demos/Host/LowLevel/CDCHost/ConfigDescriptor.c diff --git a/Demos/Host/LowLevel/CDCHost/ConfigDescriptor.c b/Demos/Host/LowLevel/CDCHost/ConfigDescriptor.c index baf02a216..7afb702c2 100644 --- a/Demos/Host/LowLevel/CDCHost/ConfigDescriptor.c +++ b/Demos/Host/LowLevel/CDCHost/ConfigDescriptor.c @@ -47,48 +47,44 @@ */ uint8_t ProcessConfigurationDescriptor(void) { - uint8_t* ConfigDescriptorData; - uint16_t ConfigDescriptorSize; + uint8_t ConfigDescriptorData[512]; + uint8_t* CurrConfigLocation = ConfigDescriptorData; + uint16_t CurrConfigBytesRem; uint8_t FoundEndpoints = 0; - - /* Get Configuration Descriptor size from the device */ - if (USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) - return ControlError; - - /* Ensure that the Configuration Descriptor isn't too large */ - if (ConfigDescriptorSize > MAX_CONFIG_DESCRIPTOR_SIZE) - return DescriptorTooLarge; - - /* Allocate enough memory for the entire config descriptor */ - ConfigDescriptorData = alloca(ConfigDescriptorSize); /* Retrieve the entire configuration descriptor into the allocated buffer */ - USB_GetDeviceConfigDescriptor(&ConfigDescriptorSize, ConfigDescriptorData); - - /* Validate returned data - ensure first entry is a configuration header descriptor */ - if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) - return InvalidConfigDataReturned; + switch (USB_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData))) + { + case HOST_GETCONFIG_Successful: + break; + case HOST_GETCONFIG_InvalidData: + return InvalidConfigDataReturned; + case HOST_GETCONFIG_BuffOverflow: + return DescriptorTooLarge; + default: + return ControlError; + } /* Get the CDC control interface from the configuration descriptor */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoCDCInterfaceFound; } - /* Get the IN and OUT data endpoints for the CDC interface */ + /* Get the IN and OUT data and IN notification endpoints for the CDC interface */ while (FoundEndpoints != ((1 << CDC_NOTIFICATIONPIPE) | (1 << CDC_DATAPIPE_IN) | (1 << CDC_DATAPIPE_OUT))) { /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextCDCDataInterfaceEndpoint) != 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, + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ @@ -109,7 +105,7 @@ uint8_t ProcessConfigurationDescriptor(void) Pipe_DisablePipe(); /* Get the next CDC control interface from the configuration descriptor (CDC class has two CDC interfaces) */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ @@ -118,15 +114,15 @@ uint8_t ProcessConfigurationDescriptor(void) } /* Fetch the next bulk or interrupt endpoint from the current CDC interface */ - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DComp_NextInterfaceCDCDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) + if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation, + DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { /* Descriptor not found, error out */ return NoEndpointFound; } } - USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); + 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) @@ -138,7 +134,6 @@ uint8_t ProcessConfigurationDescriptor(void) Pipe_ConfigurePipe(CDC_NOTIFICATIONPIPE, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - Pipe_SetInfiniteINRequests(); Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS); /* Set the flag indicating that the notification pipe has been found */ @@ -153,9 +148,6 @@ uint8_t ProcessConfigurationDescriptor(void) /* Configure the data IN pipe */ Pipe_ConfigurePipe(CDC_DATAPIPE_IN, EP_TYPE_BULK, PIPE_TOKEN_IN, EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - - Pipe_SetInfiniteINRequests(); - Pipe_Unfreeze(); /* Set the flag indicating that the data IN pipe has been found */ FoundEndpoints |= (1 << CDC_DATAPIPE_IN); @@ -166,8 +158,6 @@ uint8_t ProcessConfigurationDescriptor(void) Pipe_ConfigurePipe(CDC_DATAPIPE_OUT, EP_TYPE_BULK, PIPE_TOKEN_OUT, EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); - Pipe_Unfreeze(); - /* Set the flag indicating that the data OUT pipe has been found */ FoundEndpoints |= (1 << CDC_DATAPIPE_OUT); } @@ -236,7 +226,7 @@ uint8_t DComp_NextCDCDataInterface(void* CurrentDescriptor) * * \return A value from the DSEARCH_Return_ErrorCodes_t enum */ -uint8_t DComp_NextInterfaceCDCDataEndpoint(void* CurrentDescriptor) +uint8_t DComp_NextCDCDataInterfaceEndpoint(void* CurrentDescriptor) { if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) {