summaryrefslogtreecommitdiffstats
path: root/tmk_core/common/chibios/suspend.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/chibios/suspend.c')
-rw-r--r--tmk_core/common/chibios/suspend.c77
1 files changed, 48 insertions, 29 deletions
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 6027d69b78..5be1b76777 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -8,58 +8,73 @@
#include "action_util.h"
#include "mousekey.h"
#include "host.h"
-#include "backlight.h"
#include "suspend.h"
#include "wait.h"
+#ifdef BACKLIGHT_ENABLE
+# include "backlight.h"
+#endif
+
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+# include "rgblight.h"
+extern rgblight_config_t rgblight_config;
+static bool rgblight_enabled;
+static bool is_suspended;
+#endif
+
/** \brief suspend idle
*
* FIXME: needs doc
*/
void suspend_idle(uint8_t time) {
- // TODO: this is not used anywhere - what units is 'time' in?
- wait_ms(time);
+ // TODO: this is not used anywhere - what units is 'time' in?
+ wait_ms(time);
}
/** \brief Run keyboard level Power down
*
* FIXME: needs doc
*/
-__attribute__ ((weak))
-void suspend_power_down_user (void) { }
+__attribute__((weak)) void suspend_power_down_user(void) {}
/** \brief Run keyboard level Power down
*
* FIXME: needs doc
*/
-__attribute__ ((weak))
-void suspend_power_down_kb(void) {
- suspend_power_down_user();
-}
+__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
/** \brief suspend power down
*
* FIXME: needs doc
*/
void suspend_power_down(void) {
- // TODO: figure out what to power down and how
- // shouldn't power down TPM/FTM if we want a breathing LED
- // also shouldn't power down USB
+ // TODO: figure out what to power down and how
+ // shouldn't power down TPM/FTM if we want a breathing LED
+ // also shouldn't power down USB
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+# ifdef RGBLIGHT_ANIMATIONS
+ rgblight_timer_disable();
+# endif
+ if (!is_suspended) {
+ is_suspended = true;
+ rgblight_enabled = rgblight_config.enable;
+ rgblight_disable_noeeprom();
+ }
+#endif
- suspend_power_down_kb();
- // on AVR, this enables the watchdog for 15ms (max), and goes to
- // SLEEP_MODE_PWR_DOWN
+ suspend_power_down_kb();
+ // on AVR, this enables the watchdog for 15ms (max), and goes to
+ // SLEEP_MODE_PWR_DOWN
- wait_ms(17);
+ wait_ms(17);
}
/** \brief suspend wakeup condition
*
* FIXME: needs doc
*/
-__attribute__ ((weak)) void matrix_power_up(void) {}
-__attribute__ ((weak)) void matrix_power_down(void) {}
-bool suspend_wakeup_condition(void)
-{
+__attribute__((weak)) void matrix_power_up(void) {}
+__attribute__((weak)) void matrix_power_down(void) {}
+bool suspend_wakeup_condition(void) {
matrix_power_up();
matrix_scan();
matrix_power_down();
@@ -73,25 +88,20 @@ bool suspend_wakeup_condition(void)
*
* FIXME: needs doc
*/
-__attribute__ ((weak))
-void suspend_wakeup_init_user(void) { }
+__attribute__((weak)) void suspend_wakeup_init_user(void) {}
/** \brief run keyboard level code immediately after wakeup
*
* FIXME: needs doc
*/
-__attribute__ ((weak))
-void suspend_wakeup_init_kb(void) {
- suspend_wakeup_init_user();
-}
+__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
/** \brief suspend wakeup condition
*
* run immediately after wakeup
* FIXME: needs doc
*/
-void suspend_wakeup_init(void)
-{
+void suspend_wakeup_init(void) {
// clear keyboard state
// need to do it manually, because we're running from ISR
// and clear_keyboard() calls print
@@ -111,5 +121,14 @@ void suspend_wakeup_init(void)
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif /* BACKLIGHT_ENABLE */
- suspend_wakeup_init_kb();
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+ is_suspended = false;
+ if (rgblight_enabled) {
+ rgblight_enable_noeeprom();
+ }
+# ifdef RGBLIGHT_ANIMATIONS
+ rgblight_timer_enable();
+# endif
+#endif
+ suspend_wakeup_init_kb();
}