Use a semaphore to control the rate at which reports are updated
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "led_display.h"
|
#include "led_display.h"
|
||||||
#include "usb_composite_device.h"
|
#include "usb_composite_device.h"
|
||||||
|
#include "usb_report_updater.h"
|
||||||
|
|
||||||
static usb_basic_keyboard_report_t usbBasicKeyboardReports[2];
|
static usb_basic_keyboard_report_t usbBasicKeyboardReports[2];
|
||||||
uint32_t UsbBasicKeyboardActionCounter;
|
uint32_t UsbBasicKeyboardActionCounter;
|
||||||
@@ -40,6 +41,8 @@ usb_status_t UsbBasicKeyboardCallback(class_handle_t handle, uint32_t event, voi
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
// This report is received when the report has been sent
|
// This report is received when the report has been sent
|
||||||
case kUSB_DeviceHidEventSendResponse:
|
case kUSB_DeviceHidEventSendResponse:
|
||||||
|
UsbReportUpdateSemaphore &= ~(1 << USB_BASIC_KEYBOARD_INTERFACE_INDEX);
|
||||||
|
break;
|
||||||
case kUSB_DeviceHidEventRecvResponse:
|
case kUSB_DeviceHidEventRecvResponse:
|
||||||
case kUSB_DeviceHidEventGetReport:
|
case kUSB_DeviceHidEventGetReport:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "usb_composite_device.h"
|
#include "usb_composite_device.h"
|
||||||
|
#include "usb_report_updater.h"
|
||||||
|
|
||||||
uint32_t UsbMediaKeyboardActionCounter;
|
uint32_t UsbMediaKeyboardActionCounter;
|
||||||
static usb_media_keyboard_report_t usbMediaKeyboardReports[2];
|
static usb_media_keyboard_report_t usbMediaKeyboardReports[2];
|
||||||
@@ -38,6 +39,8 @@ usb_status_t UsbMediaKeyboardCallback(class_handle_t handle, uint32_t event, voi
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
// This report is received when the report has been sent
|
// This report is received when the report has been sent
|
||||||
case kUSB_DeviceHidEventSendResponse:
|
case kUSB_DeviceHidEventSendResponse:
|
||||||
|
UsbReportUpdateSemaphore &= ~(1 << USB_MEDIA_KEYBOARD_INTERFACE_INDEX);
|
||||||
|
break;
|
||||||
case kUSB_DeviceHidEventRecvResponse:
|
case kUSB_DeviceHidEventRecvResponse:
|
||||||
case kUSB_DeviceHidEventGetReport:
|
case kUSB_DeviceHidEventGetReport:
|
||||||
case kUSB_DeviceHidEventSetReport:
|
case kUSB_DeviceHidEventSetReport:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "usb_composite_device.h"
|
#include "usb_composite_device.h"
|
||||||
|
#include "usb_report_updater.h"
|
||||||
|
|
||||||
uint32_t UsbMouseActionCounter;
|
uint32_t UsbMouseActionCounter;
|
||||||
static usb_mouse_report_t usbMouseReports[2];
|
static usb_mouse_report_t usbMouseReports[2];
|
||||||
@@ -38,6 +39,8 @@ usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
// This report is received when the report has been sent
|
// This report is received when the report has been sent
|
||||||
case kUSB_DeviceHidEventSendResponse:
|
case kUSB_DeviceHidEventSendResponse:
|
||||||
|
UsbReportUpdateSemaphore &= ~(1 << USB_MOUSE_INTERFACE_INDEX);
|
||||||
|
break;
|
||||||
case kUSB_DeviceHidEventRecvResponse:
|
case kUSB_DeviceHidEventRecvResponse:
|
||||||
case kUSB_DeviceHidEventGetReport:
|
case kUSB_DeviceHidEventGetReport:
|
||||||
case kUSB_DeviceHidEventSetReport:
|
case kUSB_DeviceHidEventSetReport:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "usb_composite_device.h"
|
#include "usb_composite_device.h"
|
||||||
|
#include "usb_report_updater.h"
|
||||||
|
|
||||||
uint32_t UsbSystemKeyboardActionCounter;
|
uint32_t UsbSystemKeyboardActionCounter;
|
||||||
static usb_system_keyboard_report_t usbSystemKeyboardReports[2];
|
static usb_system_keyboard_report_t usbSystemKeyboardReports[2];
|
||||||
@@ -38,6 +39,8 @@ usb_status_t UsbSystemKeyboardCallback(class_handle_t handle, uint32_t event, vo
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
// This report is received when the report has been sent
|
// This report is received when the report has been sent
|
||||||
case kUSB_DeviceHidEventSendResponse:
|
case kUSB_DeviceHidEventSendResponse:
|
||||||
|
UsbReportUpdateSemaphore &= ~(1 << USB_SYSTEM_KEYBOARD_INTERFACE_INDEX);
|
||||||
|
break;
|
||||||
case kUSB_DeviceHidEventRecvResponse:
|
case kUSB_DeviceHidEventRecvResponse:
|
||||||
case kUSB_DeviceHidEventGetReport:
|
case kUSB_DeviceHidEventGetReport:
|
||||||
case kUSB_DeviceHidEventSetReport:
|
case kUSB_DeviceHidEventSetReport:
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ static uint16_t DoubleTapSwitchLayerReleaseTimeout = 100;
|
|||||||
|
|
||||||
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT];
|
||||||
|
|
||||||
|
volatile uint8_t UsbReportUpdateSemaphore = 0;
|
||||||
|
|
||||||
mouse_kinetic_state_t MouseMoveState = {
|
mouse_kinetic_state_t MouseMoveState = {
|
||||||
.isScroll = false,
|
.isScroll = false,
|
||||||
.upState = SerializedMouseAction_MoveUp,
|
.upState = SerializedMouseAction_MoveUp,
|
||||||
@@ -402,20 +404,16 @@ static void updateActiveUsbReports(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t UsbReportUpdateCounter;
|
uint32_t UsbReportUpdateCounter;
|
||||||
static uint32_t lastMouseUpdateTimeMicros;
|
|
||||||
|
|
||||||
void UpdateUsbReports(void)
|
void UpdateUsbReports(void)
|
||||||
{
|
{
|
||||||
UsbReportUpdateCounter++;
|
usb_status_t status;
|
||||||
if (((usb_device_hid_struct_t *)UsbCompositeDevice.basicKeyboardHandle)->interruptInPipeBusy ||
|
|
||||||
((usb_device_hid_struct_t *)UsbCompositeDevice.mediaKeyboardHandle)->interruptInPipeBusy ||
|
if (UsbReportUpdateSemaphore) {
|
||||||
((usb_device_hid_struct_t *)UsbCompositeDevice.systemKeyboardHandle)->interruptInPipeBusy ||
|
|
||||||
((usb_device_hid_struct_t *)UsbCompositeDevice.mouseHandle)->interruptInPipeBusy) {
|
|
||||||
return;
|
|
||||||
} else if (Timer_GetElapsedTimeMicros(&lastMouseUpdateTimeMicros) < 1000U * USB_BASIC_KEYBOARD_INTERRUPT_IN_INTERVAL) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Timer_SetCurrentTimeMicros(&lastMouseUpdateTimeMicros);
|
|
||||||
|
UsbReportUpdateCounter++;
|
||||||
|
|
||||||
ResetActiveUsbBasicKeyboardReport();
|
ResetActiveUsbBasicKeyboardReport();
|
||||||
ResetActiveUsbMediaKeyboardReport();
|
ResetActiveUsbMediaKeyboardReport();
|
||||||
@@ -426,24 +424,36 @@ void UpdateUsbReports(void)
|
|||||||
|
|
||||||
bool HasUsbBasicKeyboardReportChanged = memcmp(ActiveUsbBasicKeyboardReport, GetInactiveUsbBasicKeyboardReport(), sizeof(usb_basic_keyboard_report_t)) != 0;
|
bool HasUsbBasicKeyboardReportChanged = memcmp(ActiveUsbBasicKeyboardReport, GetInactiveUsbBasicKeyboardReport(), sizeof(usb_basic_keyboard_report_t)) != 0;
|
||||||
if (HasUsbBasicKeyboardReportChanged) {
|
if (HasUsbBasicKeyboardReportChanged) {
|
||||||
UsbBasicKeyboardAction();
|
UsbReportUpdateSemaphore |= 1 << USB_BASIC_KEYBOARD_INTERFACE_INDEX;
|
||||||
|
do {
|
||||||
|
status = UsbBasicKeyboardAction();
|
||||||
|
} while (status != kStatus_USB_Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasUsbMediaKeyboardReportChanged = memcmp(ActiveUsbMediaKeyboardReport, GetInactiveUsbMediaKeyboardReport(), sizeof(usb_media_keyboard_report_t)) != 0;
|
bool HasUsbMediaKeyboardReportChanged = memcmp(ActiveUsbMediaKeyboardReport, GetInactiveUsbMediaKeyboardReport(), sizeof(usb_media_keyboard_report_t)) != 0;
|
||||||
if (HasUsbMediaKeyboardReportChanged) {
|
if (HasUsbMediaKeyboardReportChanged) {
|
||||||
UsbMediaKeyboardAction();
|
UsbReportUpdateSemaphore |= 1 << USB_MEDIA_KEYBOARD_INTERFACE_INDEX;
|
||||||
|
do {
|
||||||
|
status = UsbMediaKeyboardAction();
|
||||||
|
} while (status != kStatus_USB_Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasUsbSystemKeyboardReportChanged = memcmp(ActiveUsbSystemKeyboardReport, GetInactiveUsbSystemKeyboardReport(), sizeof(usb_system_keyboard_report_t)) != 0;
|
bool HasUsbSystemKeyboardReportChanged = memcmp(ActiveUsbSystemKeyboardReport, GetInactiveUsbSystemKeyboardReport(), sizeof(usb_system_keyboard_report_t)) != 0;
|
||||||
if (HasUsbSystemKeyboardReportChanged) {
|
if (HasUsbSystemKeyboardReportChanged) {
|
||||||
UsbSystemKeyboardAction();
|
UsbReportUpdateSemaphore |= 1 << USB_SYSTEM_KEYBOARD_INTERFACE_INDEX;
|
||||||
|
do {
|
||||||
|
status = UsbSystemKeyboardAction();
|
||||||
|
} while (status != kStatus_USB_Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send out the mouse position and wheel values continuously if the report is not zeros, but only send the mouse button states when they change.
|
// Send out the mouse position and wheel values continuously if the report is not zeros, but only send the mouse button states when they change.
|
||||||
bool HasUsbMouseReportChanged = memcmp(ActiveUsbMouseReport, GetInactiveUsbMouseReport(), sizeof(usb_mouse_report_t)) != 0;
|
bool HasUsbMouseReportChanged = memcmp(ActiveUsbMouseReport, GetInactiveUsbMouseReport(), sizeof(usb_mouse_report_t)) != 0;
|
||||||
if (HasUsbMouseReportChanged || ActiveUsbMouseReport->x || ActiveUsbMouseReport->y ||
|
if (HasUsbMouseReportChanged || ActiveUsbMouseReport->x || ActiveUsbMouseReport->y ||
|
||||||
ActiveUsbMouseReport->wheelX || ActiveUsbMouseReport->wheelY) {
|
ActiveUsbMouseReport->wheelX || ActiveUsbMouseReport->wheelY) {
|
||||||
usbMouseAction();
|
UsbReportUpdateSemaphore |= 1 << USB_MOUSE_INTERFACE_INDEX;
|
||||||
|
do {
|
||||||
|
status = usbMouseAction();
|
||||||
|
} while (status != kStatus_USB_Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsHostSleeping && (previousLayer != LayerId_Base || HasUsbBasicKeyboardReportChanged || HasUsbMediaKeyboardReportChanged || HasUsbSystemKeyboardReportChanged || HasUsbMouseReportChanged)) {
|
if (IsHostSleeping && (previousLayer != LayerId_Base || HasUsbBasicKeyboardReportChanged || HasUsbMediaKeyboardReportChanged || HasUsbSystemKeyboardReportChanged || HasUsbMouseReportChanged)) {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
extern mouse_kinetic_state_t MouseMoveState;
|
extern mouse_kinetic_state_t MouseMoveState;
|
||||||
extern mouse_kinetic_state_t MouseScrollState;
|
extern mouse_kinetic_state_t MouseScrollState;
|
||||||
extern uint32_t UsbReportUpdateCounter;
|
extern uint32_t UsbReportUpdateCounter;
|
||||||
|
extern volatile uint8_t UsbReportUpdateSemaphore;
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user