X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/c166dfc64ea10903a43a429709a92dc7ef9ee9dc..accadba2dda2614d6a6669cb7eba9d8357274bfe:/LUFA/Drivers/USB/Class/Host/HID.c diff --git a/LUFA/Drivers/USB/Class/Host/HID.c b/LUFA/Drivers/USB/Class/Host/HID.c index 0642ecd40..ce1ceb1ca 100644 --- a/LUFA/Drivers/USB/Class/Host/HID.c +++ b/LUFA/Drivers/USB/Class/Host/HID.c @@ -40,74 +40,88 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo uint16_t ConfigDescriptorSize, void* ConfigDescriptorData) { - uint8_t FoundEndpoints = 0; - + USB_Descriptor_Endpoint_t* DataINEndpoint = NULL; + USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL; + USB_Descriptor_Interface_t* HIDInterface = NULL; + USB_HID_Descriptor_HID_t* HIDDescriptor = NULL; + memset(&HIDInterfaceInfo->State, 0x00, sizeof(HIDInterfaceInfo->State)); - + if (DESCRIPTOR_TYPE(ConfigDescriptorData) != DTYPE_Configuration) return HID_ENUMERROR_InvalidConfigDescriptor; - - USB_Descriptor_Interface_t* CurrentHIDInterface; - - do - { - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, - DCOMP_HID_Host_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) - { - return HID_ENUMERROR_NoHIDInterfaceFound; - } - - CurrentHIDInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t); - } while (HIDInterfaceInfo->Config.HIDInterfaceProtocol && - (CurrentHIDInterface->Protocol != HIDInterfaceInfo->Config.HIDInterfaceProtocol)); - - HIDInterfaceInfo->State.InterfaceNumber = CurrentHIDInterface->InterfaceNumber; - HIDInterfaceInfo->State.SupportsBootProtocol = (CurrentHIDInterface->SubClass != HID_NON_BOOT_PROTOCOL); - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, DCOMP_HID_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) + while (!(DataINEndpoint) || !(DataOUTEndpoint)) { - return HID_ENUMERROR_NoHIDDescriptorFound; - } - - HIDInterfaceInfo->State.HIDReportSize = DESCRIPTOR_CAST(ConfigDescriptorData, USB_HID_Descriptor_HID_t).HIDReportLength; - - while (FoundEndpoints != (HID_FOUND_DATAPIPE_IN | HID_FOUND_DATAPIPE_OUT)) - { - if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + if (!(HIDInterface) || + USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, DCOMP_HID_Host_NextHIDInterfaceEndpoint) != DESCRIPTOR_SEARCH_COMP_Found) { - if (FoundEndpoints & HID_FOUND_DATAPIPE_IN) + if (DataINEndpoint || DataOUTEndpoint) break; + + do + { + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + DCOMP_HID_Host_NextHIDInterface) != DESCRIPTOR_SEARCH_COMP_Found) + { + return HID_ENUMERROR_NoCompatibleInterfaceFound; + } - return HID_ENUMERROR_EndpointsNotFound; + HIDInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t); + } while (HIDInterfaceInfo->Config.HIDInterfaceProtocol && + (HIDInterface->Protocol != HIDInterfaceInfo->Config.HIDInterfaceProtocol)); + + if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData, + DCOMP_HID_Host_NextHID) != DESCRIPTOR_SEARCH_COMP_Found) + { + return HID_ENUMERROR_NoCompatibleInterfaceFound; + } + + HIDDescriptor = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_HID_Descriptor_HID_t); + + DataINEndpoint = NULL; + DataOUTEndpoint = NULL; + + continue; } USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Endpoint_t); if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) + DataINEndpoint = EndpointData; + else + DataOUTEndpoint = EndpointData; + } + + for (uint8_t PipeNum = 1; PipeNum < PIPE_TOTAL_PIPES; PipeNum++) + { + if (PipeNum == HIDInterfaceInfo->Config.DataINPipeNumber) { - Pipe_ConfigurePipe(HIDInterfaceInfo->Config.DataINPipeNumber, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - HIDInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE); - HIDInterfaceInfo->State.DataINPipeSize = EndpointData->EndpointSize; + Pipe_ConfigurePipe(PipeNum, EP_TYPE_INTERRUPT, PIPE_TOKEN_IN, + DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, + HIDInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataINEndpoint->PollingIntervalMS); - FoundEndpoints |= HID_FOUND_DATAPIPE_IN; + HIDInterfaceInfo->State.DataINPipeSize = DataINEndpoint->EndpointSize; } - else + else if (PipeNum == HIDInterfaceInfo->Config.DataOUTPipeNumber) { - Pipe_ConfigurePipe(HIDInterfaceInfo->Config.DataOUTPipeNumber, EP_TYPE_INTERRUPT, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, - HIDInterfaceInfo->Config.DataOUTPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE); - HIDInterfaceInfo->State.DataOUTPipeSize = EndpointData->EndpointSize; - + Pipe_ConfigurePipe(PipeNum, EP_TYPE_INTERRUPT, PIPE_TOKEN_OUT, + DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, + HIDInterfaceInfo->Config.DataOUTPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE); + Pipe_SetInterruptPeriod(DataOUTEndpoint->PollingIntervalMS); + + HIDInterfaceInfo->State.DataOUTPipeSize = DataOUTEndpoint->EndpointSize; HIDInterfaceInfo->State.DeviceUsesOUTPipe = true; - - FoundEndpoints |= HID_FOUND_DATAPIPE_OUT; } } - - HIDInterfaceInfo->State.LargestReportSize = 8; + + HIDInterfaceInfo->State.InterfaceNumber = HIDInterface->InterfaceNumber; + HIDInterfaceInfo->State.HIDReportSize = HIDDescriptor->HIDReportLength; + HIDInterfaceInfo->State.SupportsBootProtocol = (HIDInterface->SubClass != HID_BOOTP_NonBootProtocol); + HIDInterfaceInfo->State.LargestReportSize = 8; HIDInterfaceInfo->State.IsActive = true; + return HID_ENUMERROR_NoError; } @@ -125,14 +139,14 @@ static uint8_t DCOMP_HID_Host_NextHIDInterface(void* const CurrentDescriptor) return DESCRIPTOR_SEARCH_NotFound; } -static uint8_t DCOMP_HID_NextHID(void* const CurrentDescriptor) +static uint8_t DCOMP_HID_Host_NextHID(void* const CurrentDescriptor) { - if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_HID) + if (DESCRIPTOR_TYPE(CurrentDescriptor) == HID_DTYPE_HID) return DESCRIPTOR_SEARCH_Found; else if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) return DESCRIPTOR_SEARCH_Fail; else - return DESCRIPTOR_SEARCH_NotFound; + return DESCRIPTOR_SEARCH_NotFound; } static uint8_t DCOMP_HID_Host_NextHIDInterfaceEndpoint(void* const CurrentDescriptor) @@ -161,18 +175,18 @@ uint8_t HID_Host_ReceiveReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceI USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - .bRequest = REQ_SetReport, - .wValue = ((REPORT_ITEM_TYPE_In + 1) << 8) | ReportID, + .bRequest = HID_REQ_SetReport, + .wValue = ((HID_REPORT_ITEM_In + 1) << 8) | ReportID, .wIndex = HIDInterfaceInfo->State.InterfaceNumber, - .wLength = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, ReportID, REPORT_ITEM_TYPE_In), + .wLength = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, ReportID, HID_REPORT_ITEM_In), }; Pipe_SelectPipe(PIPE_CONTROLPIPE); return USB_Host_SendControlRequest(Buffer); -} +} #endif - + uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, void* Buffer) { @@ -198,7 +212,7 @@ uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, *(BufferPos++) = ReportID; } - ReportSize = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, ReportID, REPORT_ITEM_TYPE_In); + ReportSize = USB_GetHIDReportSize(HIDInterfaceInfo->Config.HIDParserData, ReportID, HID_REPORT_ITEM_In); } else #endif @@ -209,7 +223,7 @@ uint8_t HID_Host_ReceiveReport(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo, if ((ErrorCode = Pipe_Read_Stream_LE(BufferPos, ReportSize, NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError) return ErrorCode; - Pipe_ClearIN(); + Pipe_ClearIN(); Pipe_Freeze(); return PIPE_RWSTREAM_NoError; @@ -227,7 +241,7 @@ uint8_t HID_Host_SendReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo if ((USB_HostState != HOST_STATE_Configured) || !(HIDInterfaceInfo->State.IsActive)) return false; - if (HIDInterfaceInfo->State.DeviceUsesOUTPipe && (ReportType == REPORT_ITEM_TYPE_Out)) + if (HIDInterfaceInfo->State.DeviceUsesOUTPipe && (ReportType == HID_REPORT_ITEM_Out)) { uint8_t ErrorCode; @@ -251,7 +265,7 @@ uint8_t HID_Host_SendReportByID(USB_ClassInfo_HID_Host_t* const HIDInterfaceInfo USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - .bRequest = REQ_SetReport, + .bRequest = HID_REQ_SetReport, #if !defined(HID_HOST_BOOT_PROTOCOL_ONLY) .wValue = ((ReportType + 1) << 8) | ReportID, #else @@ -291,7 +305,7 @@ uint8_t HID_Host_SetBootProtocol(USB_ClassInfo_HID_Host_t* const HIDInterfaceInf USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - .bRequest = REQ_SetProtocol, + .bRequest = HID_REQ_SetProtocol, .wValue = 0, .wIndex = HIDInterfaceInfo->State.InterfaceNumber, .wLength = 0, @@ -322,7 +336,7 @@ uint8_t HID_Host_SetReportProtocol(USB_ClassInfo_HID_Host_t* const HIDInterfaceI { .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE), .bRequest = REQ_GetDescriptor, - .wValue = (DTYPE_Report << 8), + .wValue = (HID_DTYPE_Report << 8), .wIndex = HIDInterfaceInfo->State.InterfaceNumber, .wLength = HIDInterfaceInfo->State.HIDReportSize, }; @@ -337,7 +351,7 @@ uint8_t HID_Host_SetReportProtocol(USB_ClassInfo_HID_Host_t* const HIDInterfaceI USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - .bRequest = REQ_SetProtocol, + .bRequest = HID_REQ_SetProtocol, .wValue = 1, .wIndex = HIDInterfaceInfo->State.InterfaceNumber, .wLength = 0,