X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Fchibios%2Fmain.c;h=d588e4de06f9beaab67e8fa82dae5755d1bc2a13;hb=fdf808ee24fe8cdfbad7d3f6db905489549564bb;hp=589675aa125e81568a338270beb247b97b79bf6c;hpb=a24ddf3403670724b798d18e1d39bc3f0751aecf;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index 589675aa..d588e4de 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -26,6 +26,8 @@ #include "host_driver.h" #include "keyboard.h" #include "action.h" +#include "action_util.h" +#include "mousekey.h" #include "led.h" #include "sendchar.h" #include "debug.h" @@ -69,9 +71,9 @@ host_driver_t chibios_driver = { // while(true) { // if(blinkLed) { // blinkLed = 0; -// palSetPad(GPIOC, GPIOC_LED_ORANGE); +// palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); // chThdSleepMilliseconds(100); -// palClearPad(GPIOC, GPIOC_LED_ORANGE); +// palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); // } // chThdSleepMilliseconds(100); // } @@ -86,10 +88,6 @@ int main(void) { halInit(); chSysInit(); - palSetPad(GPIOC, GPIOC_LED_BLUE); - chThdSleepMilliseconds(400); - palClearPad(GPIOC, GPIOC_LED_BLUE); - // TESTING // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL); @@ -103,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 */ @@ -117,9 +122,25 @@ int main(void) { /* Main loop */ while(true) { - /* TODO: check for suspended event */ + + 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); + } + } + /* Woken up */ + // variables has been already cleared by the wakeup hook + send_keyboard_report(); +#ifdef MOUSEKEY_ENABLE + mousekey_send(); +#endif /* MOUSEKEY_ENABLE */ + } keyboard_task(); - chThdSleepMilliseconds(5); } }