X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Flufa%2Flufa.c;h=beec6b2be31d3f30d926f0fbcc652f4bce839473;hb=f43a2df7614503708818c258439d3a7c90d65e95;hp=345630aa90d54dd259f3d995c60d36274e033661;hpb=524c7d133c57fd744906a0269189fe4bc979e894;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 345630aa..beec6b2b 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -48,6 +48,7 @@ #include "sleep_led.h" #endif #include "suspend.h" +#include "hook.h" #include "descriptor.h" #include "lufa.h" @@ -180,21 +181,13 @@ void EVENT_USB_Device_Reset(void) void EVENT_USB_Device_Suspend() { print("[S]"); -#ifdef SLEEP_LED_ENABLE - sleep_led_enable(); -#endif + hook_usb_suspend_entry(); } void EVENT_USB_Device_WakeUp() { print("[W]"); - suspend_wakeup_init(); - -#ifdef SLEEP_LED_ENABLE - sleep_led_disable(); - // NOTE: converters may not accept this - led_set(host_keyboard_leds()); -#endif + hook_usb_wakeup(); } #ifdef CONSOLE_ENABLE @@ -592,6 +585,7 @@ int main(void) __attribute__ ((weak)); int main(void) { setup_mcu(); + hook_early_init(); keyboard_setup(); setup_usb(); sei(); @@ -614,13 +608,11 @@ int main(void) #endif print("Keyboard start.\n"); + hook_late_init(); while (1) { while (USB_DeviceState == DEVICE_STATE_Suspended) { print("[s]"); - suspend_power_down(); - if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { - USB_Device_SendRemoteWakeup(); - } + hook_usb_suspend_loop(); } keyboard_task(); @@ -630,3 +622,39 @@ int main(void) #endif } } + + +/* hooks */ +__attribute__((weak)) +void hook_early_init(void) {} + +__attribute__((weak)) +void hook_late_init(void) {} + + __attribute__((weak)) +void hook_usb_suspend_entry(void) +{ +#ifdef SLEEP_LED_ENABLE + sleep_led_enable(); +#endif +} + +__attribute__((weak)) +void hook_usb_suspend_loop(void) +{ + suspend_power_down(); + if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { + USB_Device_SendRemoteWakeup(); + } +} + +__attribute__((weak)) +void hook_usb_wakeup(void) +{ + suspend_wakeup_init(); +#ifdef SLEEP_LED_ENABLE + sleep_led_disable(); + // NOTE: converters may not accept this + led_set(host_keyboard_leds()); +#endif +}