X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Flufa%2Flufa.c;h=32bc698109b577537ca14f1c144b99232ee2ccef;hb=45e45691e0c03f1b5ea4341c6d90f9a09016a37d;hp=ffa5cfbde6fea5bf27f52e31a931b22fbd24f629;hpb=e23520662dfac30c38c41c87f5593c21f1abfb1d;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index ffa5cfbd..32bc6981 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -642,7 +642,7 @@ int main(void) print_set_sendchar(sendchar); host_set_driver(&lufa_driver); - print("Keyboard init.\n"); + print("\n\nTMK:" STR(TMK_VERSION) "/LUFA\n\n"); hook_early_init(); keyboard_setup(); setup_usb(); @@ -654,6 +654,7 @@ int main(void) keyboard_init(); +#ifndef NO_USB_STARTUP_WAIT_LOOP /* wait for USB startup */ while (USB_DeviceState != DEVICE_STATE_Configured) { #if defined(INTERRUPT_CONTROL_ENDPOINT) @@ -661,19 +662,20 @@ int main(void) #else USB_USBTask(); #endif - matrix_scan(); + hook_usb_startup_wait_loop(); } + print("\nUSB configured.\n"); +#endif hook_late_init(); print("\nKeyboard start.\n"); while (1) { +#ifndef NO_USB_SUSPEND_LOOP while (USB_DeviceState == DEVICE_STATE_Suspended) { -#ifdef LUFA_DEBUG - print("[s]"); -#endif hook_usb_suspend_loop(); } +#endif keyboard_task(); @@ -699,12 +701,12 @@ static uint8_t _led_stats = 0; __attribute__((weak)) void hook_usb_suspend_entry(void) { - // Turn LED off to save power - // Set 0 with putting aside status before suspend and restore - // it after wakeup, then LED is updated at keyboard_task() in main loop + // Turn off LED to save power and keep its status to resotre it later. + // LED status will be updated by keyboard_task() in main loop hopefully. _led_stats = keyboard_led_stats; keyboard_led_stats = 0; - led_set(keyboard_led_stats); + + // Calling long task here can prevent USB state transition matrix_clear(); clear_keyboard(); @@ -716,7 +718,10 @@ void hook_usb_suspend_entry(void) __attribute__((weak)) void hook_usb_suspend_loop(void) { +#ifndef LUFA_DEBUG_UART + // This corrupts debug print when suspend suspend_power_down(); +#endif if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { USB_Device_SendRemoteWakeup(); } @@ -730,10 +735,11 @@ void hook_usb_wakeup(void) sleep_led_disable(); #endif - // Restore LED status - // BIOS/grub won't recognize/enumerate if led_set() takes long(around 40ms?) - // Converters fall into the case and miss wakeup event(timeout to reply?) in the end. - //led_set(host_keyboard_leds()); - // Instead, restore stats and update at keyboard_task() in main loop + // Restore LED status and update at keyboard_task() in main loop keyboard_led_stats = _led_stats; + + // Calling long task here can prevent USB state transition } + +__attribute__((weak)) +void hook_usb_startup_wait_loop(void) {}