]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/protocol/chibios/usb_main.c
Send usb wakeup through ChibiOS
[qmk_firmware.git] / tmk_core / protocol / chibios / usb_main.c
index d0c72c46c7c6fc6f85f3827901e8361a8400e589..caa2770b5c53f5ecd08b6241ee3946aca2f9e587 100644 (file)
@@ -27,6 +27,7 @@
 #include "sleep_led.h"
 #include "led.h"
 #endif
+#include "wait.h"
 
 #ifdef NKRO_ENABLE
   #include "keycode_config.h"
  * ---------------------------------------------------------
  */
 
+#ifndef usb_lld_connect_bus
+  #define usb_lld_connect_bus(usbp)
+#endif
+
+#ifndef usb_lld_disconnect_bus
+  #define usb_lld_disconnect_bus(usbp)
+#endif
+
 uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
 uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
 uint16_t keyboard_led_stats __attribute__((aligned(2))) = 0;
@@ -137,7 +146,7 @@ static const uint8_t keyboard_hid_report_desc_data[] = {
   0x95, KBD_REPORT_KEYS,          //   Report Count (),
   0x75, 0x08,                //   Report Size (8),
   0x15, 0x00,                //   Logical Minimum (0),
-  0x25, 0xFF,                //   Logical Maximum(255),
+  0x26, 0xFF, 0x00,          //   Logical Maximum(255),
   0x05, 0x07,                //   Usage Page (Key Codes),
   0x19, 0x00,                //   Usage Minimum (0),
   0x29, 0xFF,                //   Usage Maximum (255),
@@ -769,10 +778,6 @@ static const USBEndpointConfig nkro_ep_config = {
  * TODO: maybe disable some things when connection is lost? */
 static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
   switch(event) {
-  case USB_EVENT_RESET:
-    //TODO: from ISR! print("[R]");
-    return;
-
   case USB_EVENT_ADDRESS:
     return;
 
@@ -795,12 +800,15 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
 #endif /* NKRO_ENABLE */
     osalSysUnlockFromISR();
     return;
-
   case USB_EVENT_SUSPEND:
     //TODO: from ISR! print("[S]");
 #ifdef SLEEP_LED_ENABLE
     sleep_led_enable();
 #endif /* SLEEP_LED_ENABLE */
+    /* Falls into.*/
+  case USB_EVENT_UNCONFIGURED:
+    /* Falls into.*/
+  case USB_EVENT_RESET:
     return;
 
   case USB_EVENT_WAKEUP:
@@ -1017,38 +1025,17 @@ void init_usb_driver(USBDriver *usbp) {
    * after a reset.
    */
   usbDisconnectBus(usbp);
-  chThdSleepMilliseconds(1500);
+  wait_ms(1500);
   usbStart(usbp, &usbcfg);
   usbConnectBus(usbp);
 
   chVTObjectInit(&keyboard_idle_timer);
 #ifdef CONSOLE_ENABLE
-  obqObjectInit(&console_buf_queue, console_queue_buffer, CONSOLE_EPSIZE, CONSOLE_QUEUE_CAPACITY, console_queue_onotify, (void*)usbp);
+  obqObjectInit(&console_buf_queue, false, console_queue_buffer, CONSOLE_EPSIZE, CONSOLE_QUEUE_CAPACITY, console_queue_onotify, (void*)usbp);
   chVTObjectInit(&console_flush_timer);
 #endif
 }
 
-/*
- * Send remote wakeup packet
- * Note: should not be called from ISR
- */
-void send_remote_wakeup(USBDriver *usbp) {
-  (void)usbp;
-#if defined(K20x) || defined(KL2x)
-#if KINETIS_USB_USE_USB0
-  USB0->CTL |= USBx_CTL_RESUME;
-  chThdSleepMilliseconds(15);
-  USB0->CTL &= ~USBx_CTL_RESUME;
-#endif /* KINETIS_USB_USE_USB0 */
-#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 */
-}
-
 /* ---------------------------------------------------------
  *                  Keyboard functions
  * ---------------------------------------------------------