From 2180f57d17a5589291eaf77db999f61a883ef3b6 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Thu, 9 Feb 2012 20:30:27 +0000 Subject: [PATCH] Altered the HID class driver to only try to construct at maximum one packet per USB frame, to reduce CPU usage. --- LUFA.pnproj | 2 +- LUFA/DoxygenPages/ChangeLog.txt | 1 + LUFA/Drivers/USB/Class/Device/HIDClassDevice.c | 5 +++++ LUFA/Drivers/USB/Class/Device/HIDClassDevice.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/LUFA.pnproj b/LUFA.pnproj index 554cb518b7..a6bc6065cf 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/LUFA/DoxygenPages/ChangeLog.txt b/LUFA/DoxygenPages/ChangeLog.txt index c0e73dae5f..1e887f661d 100644 --- a/LUFA/DoxygenPages/ChangeLog.txt +++ b/LUFA/DoxygenPages/ChangeLog.txt @@ -34,6 +34,7 @@ * having to reset the Mass Storage interface * - USB_CONFIG_ATTR_BUSPOWERED constant renamed to USB_CONFIG_ATTR_RESERVED, as this was misnamed (thanks to NXP Semiconductors) * - Reordered board name definition indexes so that a mispelled BOARD compile option will default to BOARD_USER rather than BOARD_USBKEY + * - Altered the HID class driver to only try to construct at maximum one packet per USB frame, to reduce CPU usage * - Library Applications: * - Altered the Mass Storage Host LowLevel demo so that SCSI data STALLs from the attached device can be recovered from automatically without * having to reset the Mass Storage interface diff --git a/LUFA/Drivers/USB/Class/Device/HIDClassDevice.c b/LUFA/Drivers/USB/Class/Device/HIDClassDevice.c index d756b092eb..5c8d878e7e 100644 --- a/LUFA/Drivers/USB/Class/Device/HIDClassDevice.c +++ b/LUFA/Drivers/USB/Class/Device/HIDClassDevice.c @@ -156,6 +156,9 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) if (USB_DeviceState != DEVICE_STATE_Configured) return; + if (HIDInterfaceInfo->State.PrevFrameNum == USB_Device_GetFrameNumber()) + return; + Endpoint_SelectEndpoint(HIDInterfaceInfo->Config.ReportINEndpointNumber); if (Endpoint_IsReadWriteAllowed()) @@ -190,6 +193,8 @@ void HID_Device_USBTask(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo) Endpoint_ClearIN(); } + + HIDInterfaceInfo->State.PrevFrameNum = USB_Device_GetFrameNumber(); } } diff --git a/LUFA/Drivers/USB/Class/Device/HIDClassDevice.h b/LUFA/Drivers/USB/Class/Device/HIDClassDevice.h index ab86da452c..95389f3713 100644 --- a/LUFA/Drivers/USB/Class/Device/HIDClassDevice.h +++ b/LUFA/Drivers/USB/Class/Device/HIDClassDevice.h @@ -113,6 +113,7 @@ struct { bool UsingReportProtocol; /**< Indicates if the HID interface is set to Boot or Report protocol mode. */ + uint16_t PrevFrameNum; /**< Frame number of the previous HID report packet opportunity. */ uint16_t IdleCount; /**< Report idle period, in milliseconds, set by the host. */ uint16_t IdleMSRemaining; /**< Total number of milliseconds remaining before the idle period elapsed - this * should be decremented by the user application if non-zero each millisecond. */