]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/protocol/chibios/usb_main.c
Merge remote-tracking branch 'upstream/master' into chibios
[max/tmk_keyboard.git] / tmk_core / protocol / chibios / usb_main.c
index 09de7196368d47eba1cdcb26060d3daa332760a5..ee2788e5247711b04242ff31e865081f8f53bd7c 100644 (file)
@@ -1036,7 +1036,11 @@ void send_remote_wakeup(USBDriver *usbp) {
   chThdSleepMilliseconds(15);
   USB0->CTL &= ~USBx_CTL_RESUME;
 #endif /* KINETIS_USB_USE_USB0 */
-#else /* K20x || KL2x */
+#elif defined(STM32F0XX) || defined(STM32F1XX) /* K20x || KL2x */
+  STM32_USB->CNTR |= CNTR_RESUME;
+  chThdSleepMilliseconds(15);
+  STM32_USB->CNTR &= ~CNTR_RESUME;
+#else /* STM32F0XX || STM32F1XX */
 #warning Sending remote wakeup packet not implemented for your platform.
 #endif /* K20x || KL2x */
 }
@@ -1117,19 +1121,26 @@ void send_keyboard(report_keyboard_t *report) {
   }
   osalSysUnlock();
 
+  bool ep_not_ready;
 #ifdef NKRO_ENABLE
   if(keyboard_nkro) {  /* NKRO protocol */
     usbPrepareTransmit(&USB_DRIVER, NKRO_ENDPOINT, (uint8_t *)report, sizeof(report_keyboard_t));
-    osalSysLock();
-    usbStartTransmitI(&USB_DRIVER, NKRO_ENDPOINT);
-    osalSysUnlock();
+    /* need to wait until the previous packet has made it through */
+    do {
+        osalSysLock();
+        ep_not_ready = usbStartTransmitI(&USB_DRIVER, NKRO_ENDPOINT);
+        osalSysUnlock();
+    } while (ep_not_ready);
   } else
 #endif /* NKRO_ENABLE */
   { /* boot protocol */
-    usbPrepareTransmit(&USB_DRIVER, KBD_ENDPOINT, (uint8_t *)report, sizeof(report_keyboard_t));
-    osalSysLock();
-    usbStartTransmitI(&USB_DRIVER, KBD_ENDPOINT);
-    osalSysUnlock();
+    usbPrepareTransmit(&USB_DRIVER, KBD_ENDPOINT, (uint8_t *)report, KBD_EPSIZE);
+    /* need to wait until the previous packet has made it through */
+    do {
+        osalSysLock();
+        ep_not_ready = usbStartTransmitI(&USB_DRIVER, KBD_ENDPOINT);
+        osalSysUnlock();
+    } while (ep_not_ready);
   }
   keyboard_report_sent = *report;
 }
@@ -1312,10 +1323,13 @@ int8_t sendchar(uint8_t c) {
     return 0;
   }
   osalSysUnlock();
-  /* should get suspended and wait if the queue is full
-   * but it's not blocking even if noone is listening,
-   *  because the USB packets are sent anyway */
-  return(chOQPut(&console_queue, c));
+  /* Timeout after 5us if the queue is full.
+   * Increase this timeout if too much stuff is getting
+   * dropped (i.e. the buffer is getting full too fast
+   * for USB/HIDRAW to dequeue). Another possibility
+   * for fixing this kind of thing is to increase
+   * CONSOLE_QUEUE_CAPACITY. */
+  return(chOQPutTimeout(&console_queue, c, US2ST(5)));
 }
 
 #else /* CONSOLE_ENABLE */