Oops - with new changes to the way the device Configuration Descriptor is retrieved...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / HID.c
index 6652cdc..f9c42b2 100644 (file)
 #define INCLUDE_FROM_HID_CLASS_HOST_C\r
 #include "HID.h"\r
 \r
 #define INCLUDE_FROM_HID_CLASS_HOST_C\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 HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint16_t ConfigDescriptorSize,\r
                                 uint8_t* ConfigDescriptorData)\r
 {\r
-       uint8_t  FoundEndpoints = 0;\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
 \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
        do\r
        {\r
                if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
@@ -51,14 +55,23 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint
                {\r
                        return HID_ENUMERROR_NoHIDInterfaceFound;\r
                }\r
                {\r
                        return HID_ENUMERROR_NoHIDInterfaceFound;\r
                }\r
-       } while (HIDInterfaceInfo->Config.MatchInterfaceProtocol &&\r
-                DESCRIPTOR_PCAST(ConfigDescriptorData,\r
-                                 USB_Descriptor_Interface_t)->Protocol != HIDInterfaceInfo->Config.HIDInterfaceProtocol);\r
-\r
-       while (FoundEndpoints != ((1 << HID_FOUND_DATAPIPE_IN) | (1 << HID_FOUND_DATAPIPE_OUT)))\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
        {\r
                if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                             DComp_HID_Host_NextInterfaceHIDDataEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                             DComp_HID_Host_NextHIDInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)\r
                {\r
                        if (FoundEndpoints == (1 << HID_FOUND_DATAPIPE_IN))\r
                          break;\r
                {\r
                        if (FoundEndpoints == (1 << HID_FOUND_DATAPIPE_IN))\r
                          break;\r
@@ -72,18 +85,21 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint
                {\r
                        Pipe_ConfigurePipe(HIDInterfaceInfo->Config.DataINPipeNumber, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN,\r
                                                           EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);\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
                        \r
-                       FoundEndpoints |= (1 << HID_FOUND_DATAPIPE_IN);\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
                }\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
                        \r
-                       FoundEndpoints |= (1 << HID_FOUND_DATAPIPE_OUT);                \r
+                       FoundEndpoints |= HID_FOUND_DATAPIPE_OUT;               \r
                }\r
        }\r
 \r
                }\r
        }\r
 \r
+       HIDInterfaceInfo->State.Active = true;\r
        return HID_ENUMERROR_NoError;\r
 }\r
 \r
        return HID_ENUMERROR_NoError;\r
 }\r
 \r
@@ -101,7 +117,7 @@ static uint8_t DComp_HID_Host_NextHIDInterface(void* CurrentDescriptor)
        return DESCRIPTOR_SEARCH_NotFound;\r
 }\r
 \r
        return DESCRIPTOR_SEARCH_NotFound;\r
 }\r
 \r
-static uint8_t DComp_HID_Host_NextInterfaceHIDDataEndpoint(void* CurrentDescriptor)\r
+static uint8_t DComp_HID_Host_NextHIDInterfaceEndpoint(void* CurrentDescriptor)\r
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
        {\r
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)\r
        {\r
@@ -124,4 +140,37 @@ void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)
 \r
 }\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