]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/protocol/lufa/lufa.c
Merge pull request #355 from papodaca/XT
[max/tmk_keyboard.git] / tmk_core / protocol / lufa / lufa.c
index 345630aa90d54dd259f3d995c60d36274e033661..beec6b2be31d3f30d926f0fbcc652f4bce839473 100644 (file)
@@ -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
+}