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 */
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
}
keyboard_task();
- chThdSleepMilliseconds(5);
}
}