X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/7227e133a9cf8d4de1214671211a0d93edb2b4bc..cfe054474ffafddcbba0f6d3f46d3f02473fac96:/LUFA/Drivers/USB/Class/Device/HID.c diff --git a/LUFA/Drivers/USB/Class/Device/HID.c b/LUFA/Drivers/USB/Class/Device/HID.c index bfe97ffbb..0cbd50afc 100644 --- a/LUFA/Drivers/USB/Class/Device/HID.c +++ b/LUFA/Drivers/USB/Class/Device/HID.c @@ -33,16 +33,13 @@ #include "HID.h" -void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) +void HID_Device_ProcessControlRequest(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) { if (!(Endpoint_IsSETUPReceived())) return; - if ((USB_ControlRequest.wIndex != HIDInterfaceInfo->Config.InterfaceNumber) && - (USB_ControlRequest.bRequest != REQ_SetIdle)) - { - return; - } + if (USB_ControlRequest.wIndex != HIDInterfaceInfo->Config.InterfaceNumber) + return; switch (USB_ControlRequest.bRequest) { @@ -51,15 +48,15 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* const HIDInterf { Endpoint_ClearSETUP(); - uint8_t ReportINData[HID_MAX_REPORT_SIZE]; uint16_t ReportINSize; uint8_t ReportID = (USB_ControlRequest.wValue & 0xFF); - memset(ReportINData, 0, sizeof(ReportINData)); + memset(HIDInterfaceInfo->Config.PrevReportINBuffer, 0, HIDInterfaceInfo->Config.PrevReportINBufferSize); - ReportINSize = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData); + CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, + HIDInterfaceInfo->Config.PrevReportINBuffer, &ReportINSize); - Endpoint_Write_Control_Stream_LE(ReportINData, ReportINSize); + Endpoint_Write_Control_Stream_LE(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize); Endpoint_ClearOUT(); } @@ -106,15 +103,11 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* const HIDInterf case REQ_SetIdle: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { - if ((USB_ControlRequest.wIndex == HIDInterfaceInfo->Config.InterfaceNumber) || - (USB_ControlRequest.wValue & 0xFF) == 0) - { - Endpoint_ClearSETUP(); + Endpoint_ClearSETUP(); - HIDInterfaceInfo->State.IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6); + HIDInterfaceInfo->State.IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6); - Endpoint_ClearStatusStage(); - } + Endpoint_ClearStatusStage(); } break; @@ -136,8 +129,8 @@ void HID_Device_ProcessControlPacket(USB_ClassInfo_HID_Device_t* const HIDInterf bool HID_Device_ConfigureEndpoints(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) { memset(&HIDInterfaceInfo->State, 0x00, sizeof(HIDInterfaceInfo->State)); - HIDInterfaceInfo->State.IdleCount = 500; HIDInterfaceInfo->State.UsingReportProtocol = true; + HIDInterfaceInfo->State.IdleCount = 500; if (!(Endpoint_ConfigureEndpoint(HIDInterfaceInfo->Config.ReportINEndpointNumber, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, HIDInterfaceInfo->Config.ReportINEndpointSize, ENDPOINT_BANK_SINGLE))) @@ -157,20 +150,20 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) if (Endpoint_IsReadWriteAllowed()) { - uint8_t ReportINData[HID_MAX_REPORT_SIZE]; + uint8_t ReportINData[HIDInterfaceInfo->Config.PrevReportINBufferSize]; uint8_t ReportID = 0; uint16_t ReportINSize; memset(ReportINData, 0, sizeof(ReportINData)); - ReportINSize = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData); + bool ForceSend = CALLBACK_HID_Device_CreateHIDReport(HIDInterfaceInfo, &ReportID, ReportINData, &ReportINSize); - bool StatesChanged = (memcmp(ReportINData, HIDInterfaceInfo->State.PreviousReportINData, ReportINSize) != 0); + bool StatesChanged = (memcmp(ReportINData, HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINSize) != 0); bool IdlePeriodElapsed = (HIDInterfaceInfo->State.IdleCount && !(HIDInterfaceInfo->State.IdleMSRemaining)); - memcpy(HIDInterfaceInfo->State.PreviousReportINData, ReportINData, ReportINSize); + memcpy(HIDInterfaceInfo->Config.PrevReportINBuffer, ReportINData, ReportINSize); - if (ReportINSize && (StatesChanged || IdlePeriodElapsed)) + if (ReportINSize && (ForceSend || StatesChanged || IdlePeriodElapsed)) { HIDInterfaceInfo->State.IdleMSRemaining = HIDInterfaceInfo->State.IdleCount; @@ -184,4 +177,10 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) } } +void HID_Device_MillisecondElapsed(USB_ClassInfo_HID_Device_t* HIDInterfaceInfo) +{ + if (HIDInterfaceInfo->State.IdleMSRemaining) + HIDInterfaceInfo->State.IdleMSRemaining--; +} + #endif