X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Fchibios%2Fmain.c;h=9c5254fa6120165f14b5530628b1704b1deeaf4b;hb=78e05bd172aca74b30293d9c5964ef3c706ad4db;hp=b62cfa9c57e8392131e652be40135b69a41ef376;hpb=83a3de38b710d0eb5a752ffded6da2e8bf818b22;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index b62cfa9c..9c5254fa 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -35,6 +35,7 @@ #include "sleep_led.h" #endif #include "suspend.h" +#include "hook.h" /* ------------------------- @@ -58,6 +59,22 @@ host_driver_t chibios_driver = { send_consumer }; +/* Default hooks definitions. */ +__attribute__((weak)) +void hook_early_init(void) {} + +__attribute__((weak)) +void hook_late_init(void) {} + +__attribute__((weak)) +void hook_usb_suspend_loop(void) { + /* Do this in the suspended state */ + suspend_power_down(); // on AVR this deep sleeps for 15ms + /* Remote wakeup */ + if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) { + send_remote_wakeup(&USB_DRIVER); + } +} /* TESTING * Amber LED blinker thread, times are in milliseconds. @@ -91,6 +108,8 @@ int main(void) { // TESTING // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL); + hook_early_init(); + /* Init USB */ init_usb_driver(&USB_DRIVER); @@ -101,6 +120,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 */ @@ -113,21 +139,18 @@ int main(void) { print("Keyboard start.\n"); + hook_late_init(); + /* Main loop */ while(true) { if(USB_DRIVER.state == USB_SUSPENDED) { print("[s]"); while(USB_DRIVER.state == USB_SUSPENDED) { - /* Do this in the suspended state */ - suspend_power_down(); // on AVR this deep sleeps for 15ms - /* Remote wakeup */ - if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) { - send_remote_wakeup(&USB_DRIVER); - } + hook_usb_suspend_loop(); } /* Woken up */ - // variables has been already cleared by the wakeup hook + // variables have been already cleared send_keyboard_report(); #ifdef MOUSEKEY_ENABLE mousekey_send();