Skip to content

Commit c64e9aa

Browse files
committed
hooks: Fix for LUFA
1 parent 54e68b0 commit c64e9aa

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

protocol/lufa/lufa.c

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "sleep_led.h"
4949
#endif
5050
#include "suspend.h"
51+
#include "hooks.h"
5152

5253
#include "descriptor.h"
5354
#include "lufa.h"
@@ -180,21 +181,13 @@ void EVENT_USB_Device_Reset(void)
180181
void EVENT_USB_Device_Suspend()
181182
{
182183
print("[S]");
183-
#ifdef SLEEP_LED_ENABLE
184-
sleep_led_enable();
185-
#endif
184+
suspend_entry_hook();
186185
}
187186

188187
void EVENT_USB_Device_WakeUp()
189188
{
190189
print("[W]");
191-
suspend_wakeup_init();
192-
193-
#ifdef SLEEP_LED_ENABLE
194-
sleep_led_disable();
195-
// NOTE: converters may not accept this
196-
led_set(host_keyboard_leds());
197-
#endif
190+
wakeup_hook();
198191
}
199192

200193
#ifdef CONSOLE_ENABLE
@@ -593,6 +586,7 @@ int main(void)
593586
{
594587
setup_mcu();
595588
keyboard_setup();
589+
early_init_hook();
596590
setup_usb();
597591
sei();
598592

@@ -614,13 +608,11 @@ int main(void)
614608
#endif
615609

616610
print("Keyboard start.\n");
611+
late_init_hook();
617612
while (1) {
618613
while (USB_DeviceState == DEVICE_STATE_Suspended) {
619614
print("[s]");
620-
suspend_power_down();
621-
if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
622-
USB_Device_SendRemoteWakeup();
623-
}
615+
suspend_loop_hook();
624616
}
625617

626618
keyboard_task();
@@ -630,3 +622,39 @@ int main(void)
630622
#endif
631623
}
632624
}
625+
626+
627+
/* hooks */
628+
__attribute__((weak))
629+
void early_init_hook(void) {}
630+
631+
__attribute__((weak))
632+
void late_init_hook(void) {}
633+
634+
__attribute__((weak))
635+
void suspend_entry_hook(void)
636+
{
637+
#ifdef SLEEP_LED_ENABLE
638+
sleep_led_enable();
639+
#endif
640+
}
641+
642+
__attribute__((weak))
643+
void suspend_loop_hook(void)
644+
{
645+
suspend_power_down();
646+
if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
647+
USB_Device_SendRemoteWakeup();
648+
}
649+
}
650+
651+
__attribute__((weak))
652+
void wakeup_hook(void)
653+
{
654+
suspend_wakeup_init();
655+
#ifdef SLEEP_LED_ENABLE
656+
sleep_led_disable();
657+
// NOTE: converters may not accept this
658+
led_set(host_keyboard_leds());
659+
#endif
660+
}

0 commit comments

Comments
 (0)