123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #include "ConfigDescriptor.h"
- uint8_t ProcessConfigurationDescriptor(void)
- {
- uint8_t ConfigDescriptorData[512];
- void* CurrConfigLocation = ConfigDescriptorData;
- uint16_t CurrConfigBytesRem;
- USB_Descriptor_Interface_t* HIDInterface = NULL;
- USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
- USB_Descriptor_Endpoint_t* DataOUTEndpoint = 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))
- {
-
- if (!(HIDInterface) ||
- USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextHIDInterfaceDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
- {
-
- if (DataINEndpoint)
- break;
-
- if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
- DComp_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)
- {
-
- return NoCompatibleInterfaceFound;
- }
-
- HIDInterface = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Interface_t);
-
- DataOUTEndpoint = NULL;
-
- continue;
- }
-
- USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
-
- if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
- DataINEndpoint = EndpointData;
- else
- DataOUTEndpoint = EndpointData;
- }
-
- Pipe_ConfigurePipe(HID_DATA_IN_PIPE, EP_TYPE_INTERRUPT, DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, 1);
- Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS);
-
- if (DataOUTEndpoint)
- {
-
- Pipe_ConfigurePipe(HID_DATA_OUT_PIPE, EP_TYPE_INTERRUPT, DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, 1);
- }
-
- return SuccessfulConfigRead;
- }
- uint8_t DComp_NextHIDInterface(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 == HID_CLASS)
- {
-
- return DESCRIPTOR_SEARCH_Found;
- }
- }
-
- return DESCRIPTOR_SEARCH_NotFound;
- }
- uint8_t DComp_NextHIDInterfaceDataEndpoint(void* CurrentDescriptor)
- {
- USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
-
- if (Header->Type == DTYPE_Endpoint)
- {
-
- return DESCRIPTOR_SEARCH_Found;
- }
- else if (Header->Type == DTYPE_Interface)
- {
-
- return DESCRIPTOR_SEARCH_Fail;
- }
- else
- {
-
- return DESCRIPTOR_SEARCH_NotFound;
- }
- }
|