123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- #include "ConfigDescriptor.h"
- uint8_t ProcessConfigurationDescriptor(void)
- {
- uint8_t ConfigDescriptorData[512];
- void* CurrConfigLocation = ConfigDescriptorData;
- uint16_t CurrConfigBytesRem;
- USB_Descriptor_Interface_t* CDCControlInterface = NULL;
- USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
- USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
- USB_Descriptor_Endpoint_t* NotificationEndpoint = NULL;
-
- switch (USB_Host_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;
- }
- while (!(DataINEndpoint) || !(DataOUTEndpoint) || !(NotificationEndpoint))
- {
-
- if (!(CDCControlInterface) ||
- USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextCDCDataInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
- {
-
- if (NotificationEndpoint)
- {
-
- if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextCDCDataInterface) != DESCRIPTOR_SEARCH_COMP_Found)
- {
-
- return NoCompatibleInterfaceFound;
- }
-
- DataINEndpoint = NULL;
- DataOUTEndpoint = NULL;
- }
- else
- {
-
- if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextCDCControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)
- {
-
- return NoCompatibleInterfaceFound;
- }
-
- CDCControlInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
-
- NotificationEndpoint = NULL;
- }
-
- continue;
- }
-
- USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
-
- if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
- {
-
- if ((EndpointData->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT)
- NotificationEndpoint = EndpointData;
- else
- DataINEndpoint = EndpointData;
- }
- else
- {
- DataOUTEndpoint = EndpointData;
- }
- }
-
- Pipe_ConfigurePipe(CDC_DATA_IN_PIPE, EP_TYPE_BULK, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, 1);
-
- Pipe_ConfigurePipe(CDC_DATA_OUT_PIPE, EP_TYPE_BULK, DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, 1);
-
- Pipe_ConfigurePipe(CDC_NOTIFICATION_PIPE, EP_TYPE_INTERRUPT, NotificationEndpoint->EndpointAddress, NotificationEndpoint->EndpointSize, 1);
- Pipe_SetInterruptPeriod(NotificationEndpoint->PollingIntervalMS);
-
- return SuccessfulConfigRead;
- }
- uint8_t DComp_NextCDCControlInterface(void* 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 == CDC_CSCP_CDCClass) &&
- (Interface->SubClass == CDC_CSCP_ACMSubclass) &&
- (Interface->Protocol == CDC_CSCP_ATCommandProtocol))
- {
- return DESCRIPTOR_SEARCH_Found;
- }
- }
- return DESCRIPTOR_SEARCH_NotFound;
- }
- uint8_t DComp_NextCDCDataInterface(void* 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 == CDC_CSCP_CDCDataClass) &&
- (Interface->SubClass == CDC_CSCP_NoDataSubclass) &&
- (Interface->Protocol == CDC_CSCP_NoDataProtocol))
- {
- return DESCRIPTOR_SEARCH_Found;
- }
- }
- return DESCRIPTOR_SEARCH_NotFound;
- }
- uint8_t DComp_NextCDCDataInterfaceEndpoint(void* CurrentDescriptor)
- {
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
- if (Header->Type == DTYPE_Endpoint)
- {
- USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
- if (((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_BULK) ||
- ((Endpoint->Attributes & EP_TYPE_MASK) == EP_TYPE_INTERRUPT))
- {
- return DESCRIPTOR_SEARCH_Found;
- }
- }
- else if (Header->Type == DTYPE_Interface)
- {
- return DESCRIPTOR_SEARCH_Fail;
- }
- return DESCRIPTOR_SEARCH_NotFound;
- }
|