]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/protocol/chibios/main.c
Chibios: Fix a HardFault bug (wait after start).
[max/tmk_keyboard.git] / tmk_core / protocol / chibios / main.c
index c4666ebd01bfe0d1f89f6daa69af351b92622e14..d588e4de06f9beaab67e8fa82dae5755d1bc2a13 100644 (file)
@@ -101,6 +101,13 @@ int main(void) {
   while(USB_DRIVER.state != USB_ACTIVE)
     chThdSleepMilliseconds(50);
 
+  /* Do need to wait here!
+   * Otherwise the next print might start a transfer on console EP
+   * before the USB is completely ready, which sometimes causes
+   * HardFaults.
+   */
+  chThdSleepMilliseconds(50);
+
   print("USB configured.\n");
 
   /* init TMK modules */
@@ -121,10 +128,10 @@ int main(void) {
       while(USB_DRIVER.state == USB_SUSPENDED) {
         /* Do this in the suspended state */
         suspend_power_down(); // on AVR this deep sleeps for 15ms
-        // TODO: remote wakeup
-        // if(USB_Device_RemoteWakeupEnabled (USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
-          // USB_Device_SendRemoteWakeup();
-        // }
+        /* Remote wakeup */
+        if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
+          send_remote_wakeup(&USB_DRIVER);
+        }
       }
       /* Woken up */
       // variables has been already cleared by the wakeup hook
@@ -135,6 +142,5 @@ int main(void) {
     }
 
     keyboard_task();
-    chThdSleepMilliseconds(5);
   }
 }