summary refs log tree commit diff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-10-25 11:22:02 -0700
committerJack Humbert <jack.humb@gmail.com>2018-10-27 00:17:25 -0400
commitb1bf0879ad2acf3aec1db0f67250b8679e565324 (patch)
tree6aaf36ceaa360b337b8645808406e65057fd0bfc
parentb11a776cef1d5e26e435ed6b4a12711c965abeb6 (diff)
Fix mouse_send() on chibiOS so it won't lock up the firmware
-rw-r--r--tmk_core/protocol/chibios/usb_main.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index e79ff15e89..71892c4f49 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -715,15 +715,16 @@ void send_mouse(report_mouse_t *report) {
     osalSysUnlock();
     return;
   }
-  osalSysUnlock();
 
-  osalSysLock();
   if(usbGetTransmitStatusI(&USB_DRIVER, MOUSE_IN_EPNUM)) {
     /* Need to either suspend, or loop and call unlock/lock during
      * every iteration - otherwise the system will remain locked,
      * no interrupts served, so USB not going through as well.
      * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
-    osalThreadSuspendS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread);
+    if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread, MS2ST(10)==MSG_TIMEOUT)) {
+      osalSysUnlock();
+      return;
+    }
   }
   usbStartTransmitI(&USB_DRIVER, MOUSE_IN_EPNUM, (uint8_t *)report, sizeof(report_mouse_t));
   osalSysUnlock();