File tree Expand file tree Collapse file tree 1 file changed +42
-14
lines changed Expand file tree Collapse file tree 1 file changed +42
-14
lines changed Original file line number Diff line number Diff line change 48
48
#include "sleep_led.h"
49
49
#endif
50
50
#include "suspend.h"
51
+ #include "hooks.h"
51
52
52
53
#include "descriptor.h"
53
54
#include "lufa.h"
@@ -180,21 +181,13 @@ void EVENT_USB_Device_Reset(void)
180
181
void EVENT_USB_Device_Suspend ()
181
182
{
182
183
print ("[S]" );
183
- #ifdef SLEEP_LED_ENABLE
184
- sleep_led_enable ();
185
- #endif
184
+ suspend_entry_hook ();
186
185
}
187
186
188
187
void EVENT_USB_Device_WakeUp ()
189
188
{
190
189
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 ();
198
191
}
199
192
200
193
#ifdef CONSOLE_ENABLE
@@ -593,6 +586,7 @@ int main(void)
593
586
{
594
587
setup_mcu ();
595
588
keyboard_setup ();
589
+ early_init_hook ();
596
590
setup_usb ();
597
591
sei ();
598
592
@@ -614,13 +608,11 @@ int main(void)
614
608
#endif
615
609
616
610
print ("Keyboard start.\n" );
611
+ late_init_hook ();
617
612
while (1 ) {
618
613
while (USB_DeviceState == DEVICE_STATE_Suspended ) {
619
614
print ("[s]" );
620
- suspend_power_down ();
621
- if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition ()) {
622
- USB_Device_SendRemoteWakeup ();
623
- }
615
+ suspend_loop_hook ();
624
616
}
625
617
626
618
keyboard_task ();
@@ -630,3 +622,39 @@ int main(void)
630
622
#endif
631
623
}
632
624
}
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
+ }
You can’t perform that action at this time.
0 commit comments