mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-25 04:43:02 +00:00
Initial migration of suspend callbacks (#16067)
* Initial migration of suspend logic * Add header
This commit is contained in:
parent
580ef6d88f
commit
135c935990
@ -3,18 +3,6 @@
|
|||||||
#include "md_rgb_matrix.h"
|
#include "md_rgb_matrix.h"
|
||||||
#include "suspend.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
|
/** \brief Suspend power down
|
||||||
*
|
*
|
||||||
* FIXME: needs doc
|
* FIXME: needs doc
|
||||||
@ -27,30 +15,6 @@ void suspend_power_down(void) {
|
|||||||
suspend_power_down_kb();
|
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
|
/** \brief run immediately after wakeup
|
||||||
*
|
*
|
||||||
* FIXME: needs doc
|
* FIXME: needs doc
|
||||||
|
@ -2,12 +2,9 @@
|
|||||||
#include <avr/sleep.h>
|
#include <avr/sleep.h>
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include "matrix.h"
|
|
||||||
#include "action.h"
|
|
||||||
#include "suspend.h"
|
#include "suspend.h"
|
||||||
|
#include "action.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "led.h"
|
|
||||||
#include "host.h"
|
|
||||||
|
|
||||||
#ifdef PROTOCOL_LUFA
|
#ifdef PROTOCOL_LUFA
|
||||||
# include "lufa.h"
|
# include "lufa.h"
|
||||||
@ -78,6 +75,18 @@ static void power_down(uint8_t wdto) {
|
|||||||
// Disable watchdog after sleep
|
// Disable watchdog after sleep
|
||||||
wdt_disable();
|
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
|
#endif
|
||||||
|
|
||||||
/** \brief Suspend power down
|
/** \brief Suspend power down
|
||||||
@ -102,18 +111,6 @@ void suspend_power_down(void) {
|
|||||||
#endif
|
#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
|
/** \brief run immediately after wakeup
|
||||||
*
|
*
|
||||||
* FIXME: needs doc
|
* FIXME: needs doc
|
||||||
@ -124,16 +121,3 @@ void suspend_wakeup_init(void) {
|
|||||||
|
|
||||||
suspend_wakeup_init_quantum();
|
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
|
|
||||||
|
@ -25,34 +25,6 @@ void suspend_power_down(void) {
|
|||||||
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) {
|
|
||||||
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
|
/** \brief suspend wakeup condition
|
||||||
*
|
*
|
||||||
* run immediately after wakeup
|
* run immediately after wakeup
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
PLATFORM_COMMON_DIR = $(PLATFORM_PATH)/$(PLATFORM_KEY)
|
PLATFORM_COMMON_DIR = $(PLATFORM_PATH)/$(PLATFORM_KEY)
|
||||||
|
|
||||||
TMK_COMMON_SRC += \
|
TMK_COMMON_SRC += \
|
||||||
|
$(PLATFORM_PATH)/suspend.c \
|
||||||
$(PLATFORM_COMMON_DIR)/platform.c \
|
$(PLATFORM_COMMON_DIR)/platform.c \
|
||||||
$(PLATFORM_COMMON_DIR)/suspend.c \
|
$(PLATFORM_COMMON_DIR)/suspend.c \
|
||||||
$(PLATFORM_COMMON_DIR)/timer.c \
|
$(PLATFORM_COMMON_DIR)/timer.c \
|
||||||
|
47
platforms/suspend.c
Normal file
47
platforms/suspend.c
Normal file
@ -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;
|
||||||
|
}
|
@ -381,17 +381,6 @@ __attribute__((weak)) void startup_user() {}
|
|||||||
|
|
||||||
__attribute__((weak)) void shutdown_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) {
|
void suspend_power_down_quantum(void) {
|
||||||
#ifndef NO_SUSPEND_POWER_DOWN
|
#ifndef NO_SUSPEND_POWER_DOWN
|
||||||
// Turn off backlight
|
// Turn off backlight
|
||||||
@ -439,18 +428,6 @@ void suspend_power_down_quantum(void) {
|
|||||||
#endif
|
#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) {
|
__attribute__((weak)) void suspend_wakeup_init_quantum(void) {
|
||||||
// Turn on backlight
|
// Turn on backlight
|
||||||
#ifdef BACKLIGHT_ENABLE
|
#ifdef BACKLIGHT_ENABLE
|
||||||
|
Loading…
Reference in New Issue
Block a user