summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2022-02-04 18:10:00 +0000
committerGitHub <noreply@github.com>2022-02-05 05:10:00 +1100
commit135c93599036bbe646a69b568eef9219823a4be9 (patch)
tree2fca5c980cc7bbc2f2db4c54f5fa76006bf741d4
parent580ef6d88f22478112417c4ab3c1ee50211167d2 (diff)
downloadqmk_firmware-135c93599036bbe646a69b568eef9219823a4be9.tar.gz
qmk_firmware-135c93599036bbe646a69b568eef9219823a4be9.zip
Initial migration of suspend callbacks (#16067)
* Initial migration of suspend logic * Add header
-rw-r--r--platforms/arm_atsam/suspend.c36
-rw-r--r--platforms/avr/suspend.c42
-rw-r--r--platforms/chibios/suspend.c28
-rw-r--r--platforms/common.mk1
-rw-r--r--platforms/suspend.c47
-rw-r--r--quantum/quantum.c23
6 files changed, 61 insertions, 116 deletions
diff --git a/platforms/arm_atsam/suspend.c b/platforms/arm_atsam/suspend.c
index 73bebc4308..de2285bc5f 100644
--- a/platforms/arm_atsam/suspend.c
+++ b/platforms/arm_atsam/suspend.c
@@ -3,18 +3,6 @@
#include "md_rgb_matrix.h"
#include "suspend.h"
-/** \brief Run user level Power down
- *
- * FIXME: needs doc
- */
-__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(); }
-
/** \brief Suspend power down
*
* FIXME: needs doc
@@ -27,30 +15,6 @@ void suspend_power_down(void) {
suspend_power_down_kb();
}
-__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();
- for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
- if (matrix_get_row(r)) return true;
- }
- return false;
-}
-
-/** \brief run user level code immediately after wakeup
- *
- * FIXME: needs doc
- */
-__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(); }
-
/** \brief run immediately after wakeup
*
* FIXME: needs doc
diff --git a/platforms/avr/suspend.c b/platforms/avr/suspend.c
index 7b164a34b1..b615979439 100644
--- a/platforms/avr/suspend.c
+++ b/platforms/avr/suspend.c
@@ -2,12 +2,9 @@
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
-#include "matrix.h"
-#include "action.h"
#include "suspend.h"
+#include "action.h"
#include "timer.h"
-#include "led.h"
-#include "host.h"
#ifdef PROTOCOL_LUFA
# include "lufa.h"
@@ -78,6 +75,18 @@ static void power_down(uint8_t wdto) {
// Disable watchdog after sleep
wdt_disable();
}
+
+/* watchdog timeout */
+ISR(WDT_vect) {
+ // compensate timer for sleep
+ switch (wdt_timeout) {
+ case WDTO_15MS:
+ timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
+ break;
+ default:;
+ }
+}
+
#endif
/** \brief Suspend power down
@@ -102,18 +111,6 @@ void suspend_power_down(void) {
#endif
}
-__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();
- for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
- if (matrix_get_row(r)) return true;
- }
- return false;
-}
-
/** \brief run immediately after wakeup
*
* FIXME: needs doc
@@ -124,16 +121,3 @@ void suspend_wakeup_init(void) {
suspend_wakeup_init_quantum();
}
-
-#if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect)
-/* watchdog timeout */
-ISR(WDT_vect) {
- // compensate timer for sleep
- switch (wdt_timeout) {
- case WDTO_15MS:
- timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
- break;
- default:;
- }
-}
-#endif
diff --git a/platforms/chibios/suspend.c b/platforms/chibios/suspend.c
index d10ddf4501..ce03433e3a 100644
--- a/platforms/chibios/suspend.c
+++ b/platforms/chibios/suspend.c
@@ -27,34 +27,6 @@ void suspend_power_down(void) {
/** \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) {
- matrix_power_up();
- matrix_scan();
- matrix_power_down();
- for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
- if (matrix_get_row(r)) return true;
- }
- return false;
-}
-
-/** \brief run user level code immediately after wakeup
- *
- * FIXME: needs doc
- */
-__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(); }
-
-/** \brief suspend wakeup condition
- *
* run immediately after wakeup
* FIXME: needs doc
*/
diff --git a/platforms/common.mk b/platforms/common.mk
index 12ab45f823..2a1fc8d377 100644
--- a/platforms/common.mk
+++ b/platforms/common.mk
@@ -1,6 +1,7 @@
PLATFORM_COMMON_DIR = $(PLATFORM_PATH)/$(PLATFORM_KEY)
TMK_COMMON_SRC += \
+ $(PLATFORM_PATH)/suspend.c \
$(PLATFORM_COMMON_DIR)/platform.c \
$(PLATFORM_COMMON_DIR)/suspend.c \
$(PLATFORM_COMMON_DIR)/timer.c \
diff --git a/platforms/suspend.c b/platforms/suspend.c
new file mode 100644
index 0000000000..cd773764fa
--- /dev/null
+++ b/platforms/suspend.c
@@ -0,0 +1,47 @@
+// Copyright 2022 QMK
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "suspend.h"
+#include "matrix.h"
+
+// TODO: Move to more correct location
+__attribute__((weak)) void matrix_power_up(void) {}
+__attribute__((weak)) void matrix_power_down(void) {}
+
+/** \brief Run user level Power down
+ *
+ * FIXME: needs doc
+ */
+__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(); }
+
+/** \brief run user level code immediately after wakeup
+ *
+ * FIXME: needs doc
+ */
+__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(); }
+
+/** \brief suspend wakeup condition
+ *
+ * FIXME: needs doc
+ */
+bool suspend_wakeup_condition(void) {
+ matrix_power_up();
+ matrix_scan();
+ matrix_power_down();
+ for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
+ if (matrix_get_row(r)) return true;
+ }
+ return false;
+}
diff --git a/quantum/quantum.c b/quantum/quantum.c
index ca3e4027dc..fb6220efa2 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -381,17 +381,6 @@ __attribute__((weak)) void startup_user() {}
__attribute__((weak)) void shutdown_user() {}
-/** \brief Run keyboard level Power down
- *
- * FIXME: needs doc
- */
-__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(); }
-
void suspend_power_down_quantum(void) {
#ifndef NO_SUSPEND_POWER_DOWN
// Turn off backlight
@@ -439,18 +428,6 @@ void suspend_power_down_quantum(void) {
#endif
}
-/** \brief run user level code immediately after wakeup
- *
- * FIXME: needs doc
- */
-__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_quantum(void) {
// Turn on backlight
#ifdef BACKLIGHT_ENABLE