Oops - with new changes to the way the device Configuration Descriptor is retrieved...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / HID.c
index 99e44a4..f9c42b2 100644 (file)
 #include "../../HighLevel/USBMode.h"\r
 #if defined(USB_CAN_BE_HOST)\r
 \r
 #include "../../HighLevel/USBMode.h"\r
 #if defined(USB_CAN_BE_HOST)\r
 \r
+#define INCLUDE_FROM_HID_CLASS_HOST_C\r
 #include "HID.h"\r
 \r
 #include "HID.h"\r
 \r
+#warning The HID Host mode Class driver is currently incomplete and is for preview purposes only.\r
+\r
+uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint16_t ConfigDescriptorSize,\r
+                                uint8_t* ConfigDescriptorData)\r
+{\r
+       uint8_t FoundEndpoints = 0;\r
+\r
+       memset(&HIDInterfaceInfo->State, 0x00, sizeof(HIDInterfaceInfo->State));\r
+\r
+       if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration)\r
+         return HID_ENUMERROR_InvalidConfigDescriptor;\r
+       \r
+       USB_Descriptor_Interface_t* CurrentHIDInterface;\r
+       \r
+       do\r
+       {\r
+               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+                                                                         DComp_HID_Host_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+               {\r
+                       return HID_ENUMERROR_NoHIDInterfaceFound;\r
+               }\r
+               \r
+               CurrentHIDInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t);\r
+       } while (HIDInterfaceInfo->Config.HIDInterfaceProtocol &&\r
+                (CurrentHIDInterface->Protocol != HIDInterfaceInfo->Config.HIDInterfaceProtocol));\r
+\r
+       HIDInterfaceInfo->State.InterfaceNumber      =\r
+       #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
+                            CurrentHIDInterface->InterfaceNumber;\r
+       #else\r
+                            CurrentHIDInterface->bInterfaceNumber;\r
+       #endif\r
+       HIDInterfaceInfo->State.SupportsBootSubClass = (CurrentHIDInterface->SubClass != 0);\r
+\r
+       while (FoundEndpoints != (HID_FOUND_DATAPIPE_IN | HID_FOUND_DATAPIPE_OUT))\r
+       {\r
+               if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
+                                             DComp_HID_Host_NextHIDInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
+               {\r
+                       if (FoundEndpoints == (1 << HID_FOUND_DATAPIPE_IN))\r
+                         break;\r
+                               \r
+                       return HID_ENUMERROR_EndpointsNotFound;\r
+               }\r
+               \r
+               USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t);\r
+\r
+               if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN)\r
+               {\r
+                       Pipe_ConfigurePipe(HIDInterfaceInfo->Config.DataINPipeNumber, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,\r
+                                                          EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
+                       HIDInterfaceInfo->State.DataINPipeSize = EndpointData->EndpointSize;\r
+                       \r
+                       FoundEndpoints |= HID_FOUND_DATAPIPE_IN;\r
+               }\r
+               else\r
+               {\r
+                       Pipe_ConfigurePipe(HIDInterfaceInfo->Config.DataOUTPipeNumber, EP_TYPE_INTERRUPT, PIPE_TOKEN_OUT,\r
+                                                          EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\r
+                       HIDInterfaceInfo->State.DataOUTPipeSize = EndpointData->EndpointSize;\r
+                       \r
+                       FoundEndpoints |= HID_FOUND_DATAPIPE_OUT;               \r
+               }\r
+       }\r
+\r
+       HIDInterfaceInfo->State.Active = true;\r
+       return HID_ENUMERROR_NoError;\r
+}\r
+\r
+static uint8_t DComp_HID_Host_NextHIDInterface(void* CurrentDescriptor)\r
+{\r
+       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
+       {\r
+               USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,\r
+                                                                               USB_Descriptor_Interface_t);\r
+       \r
+               if (CurrentInterface->Class == HID_INTERFACE_CLASS)\r
+                 return DESCRIPTOR_SEARCH_Found;\r
+       }\r
+       \r
+       return DESCRIPTOR_SEARCH_NotFound;\r
+}\r
+\r
+static uint8_t DComp_HID_Host_NextHIDInterfaceEndpoint(void* CurrentDescriptor)\r
+{\r
+       if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
+       {\r
+               USB_Descriptor_Endpoint_t* CurrentEndpoint = DESCRIPTOR_PCAST(CurrentDescriptor,\r
+                                                                             USB_Descriptor_Endpoint_t);       \r
+\r
+               if (!(Pipe_IsEndpointBound(CurrentEndpoint->EndpointAddress)))\r
+                 return DESCRIPTOR_SEARCH_Found;\r
+       }\r
+       else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
+       {\r
+               return DESCRIPTOR_SEARCH_Fail;\r
+       }\r
+\r
+       return DESCRIPTOR_SEARCH_NotFound;\r
+}\r
+\r
+void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)\r
+{\r
+\r
+}\r
+\r
+bool HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)\r
+{\r
+       bool ReportReceived;\r
+\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(HIDInterfaceInfo->State.Active))\r
+         return false;\r
+\r
+       Pipe_SelectPipe(HIDInterfaceInfo->Config.DataINPipeNumber);\r
+       Pipe_Unfreeze();\r
+       \r
+       ReportReceived = Pipe_IsReadWriteAllowed();\r
+       \r
+       Pipe_Freeze();\r
+\r
+       return ReportReceived;\r
+}\r
+\r
+uint8_t USB_HID_Host_SetProtocol(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, bool UseReportProtocol)\r
+{\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+               {\r
+                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
+                       .bRequest      = REQ_SetProtocol,\r
+                       .wValue        = UseReportProtocol,\r
+                       .wIndex        = HIDInterfaceInfo->State.InterfaceNumber,\r
+                       .wLength       = 0,\r
+               };\r
+\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+       \r
+       return USB_Host_SendControlRequest(NULL);\r
+}\r
+\r
 #endif\r
 #endif\r