From 135c93599036bbe646a69b568eef9219823a4be9 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 4 Feb 2022 18:10:00 +0000 Subject: [PATCH] Initial migration of suspend callbacks (#16067) * Initial migration of suspend logic * Add header --- platforms/arm_atsam/suspend.c | 36 --------------------------- platforms/avr/suspend.c | 42 ++++++++++--------------------- platforms/chibios/suspend.c | 28 --------------------- platforms/common.mk | 1 + platforms/suspend.c | 47 +++++++++++++++++++++++++++++++++++ quantum/quantum.c | 23 ----------------- 6 files changed, 61 insertions(+), 116 deletions(-) create mode 100644 platforms/suspend.c diff --git a/platforms/arm_atsam/suspend.c b/platforms/arm_atsam/suspend.c index 73bebc4308f..de2285bc5f6 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 7b164a34b1a..b6159794393 100644 --- a/platforms/avr/suspend.c +++ b/platforms/avr/suspend.c @@ -2,12 +2,9 @@ #include #include #include -#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 d10ddf45015..ce03433e3a2 100644 --- a/platforms/chibios/suspend.c +++ b/platforms/chibios/suspend.c @@ -25,34 +25,6 @@ void suspend_power_down(void) { 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) { - 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 diff --git a/platforms/common.mk b/platforms/common.mk index 12ab45f8235..2a1fc8d377b 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 00000000000..cd773764fab --- /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 ca3e4027dc6..fb6220efa26 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