Skip to content

Commit

Permalink
Reset UsbReportUpdateSemaphore if it gets stuck for 100ms. This shoul…
Browse files Browse the repository at this point in the history
…d fix occasional freezes.
  • Loading branch information
mondalaci committed Oct 4, 2018
1 parent 6f2b45c commit 8b69a25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion right/src/usb_report_updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,21 @@ uint32_t UsbReportUpdateCounter;

void UpdateUsbReports(void)
{
static uint32_t lastUpdateTime;

for (uint8_t keyId = 0; keyId < RIGHT_KEY_MATRIX_KEY_COUNT; keyId++) {
KeyStates[SlotId_RightKeyboardHalf][keyId].current = RightKeyMatrix.keyStates[keyId];
}

if (UsbReportUpdateSemaphore && !SleepModeActive) {
return;
if (Timer_GetElapsedTime(&lastUpdateTime) < USB_SEMAPHORE_TIMEOUT) {
return;
} else {
UsbReportUpdateSemaphore = 0;
}
}

lastUpdateTime = CurrentTime;
UsbReportUpdateCounter++;

ResetActiveUsbBasicKeyboardReport();
Expand Down
2 changes: 2 additions & 0 deletions right/src/usb_report_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define SECONDARY_ROLE_MODIFIER_TO_HID_MODIFIER(secondaryRoleModifier) (1 << ((secondaryRoleModifier) - 1))
#define SECONDARY_ROLE_LAYER_TO_LAYER_ID(secondaryRoleLayer) ((secondaryRoleLayer) - SecondaryRole_RightSuper)

#define USB_SEMAPHORE_TIMEOUT 100 // ms

// Typedefs:

typedef enum {
Expand Down

0 comments on commit 8b69a25

Please sign in to comment.