From 27f917f94503275cfe92ac0a5f76c7971cc25438 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 21 Jul 2023 10:09:22 +0800 Subject: [PATCH] fl16: On sleep pin only turn off backlight Other low power states should be handled perfectly fine by USB suspend, since this is now fixed in chibios. Signed-off-by: Daniel Schaefer --- keyboards/framework/matrix.c | 48 +++++++++++++++++++++++++---------- quantum/backlight/backlight.c | 8 ++++++ quantum/backlight/backlight.h | 1 + 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/keyboards/framework/matrix.c b/keyboards/framework/matrix.c index 7e84cd0c4c..7abad4c2b0 100644 --- a/keyboards/framework/matrix.c +++ b/keyboards/framework/matrix.c @@ -259,26 +259,46 @@ static adc10ksample_t read_adc(void) { * If the host is awake but the keyboard is idle it should enter a low-power state */ bool handle_idle(void) { - bool asleep = readPin(SLEEP_GPIO); + bool asleep = !readPin(SLEEP_GPIO); static uint8_t prev_asleep = -1; - static int host_sleep = 0; - /* reduce the scan speed to 10Hz */ if (prev_asleep != asleep) { prev_asleep = asleep; - if (!asleep) { - suspend_power_down_quantum(); + } +#ifdef RGB_MATRIX_ENABLE + if (rgb_matrix_get_suspend_state() != asleep) { + rgb_matrix_set_suspend_state(asleep); + } +#endif +#ifdef BACKLIGHT_ENABLE + if (!is_backlight_enabled() != asleep) { + if (asleep) { + backlight_disable(); } else { - suspend_wakeup_init_quantum(); - } - } - if (!asleep) { - if (timer_elapsed32(host_sleep) < 100) { - port_wait_for_interrupt(); - return true; - } else { - host_sleep = timer_read32(); + backlight_enable_old_level(); } } +#endif + + // TODO: Try this again later, but for now USB suspend should be fine + // This seems to cause issues with waking up the host by keypresses + // static int host_sleep = 0; + // /* reduce the scan speed to 10Hz */ + // if (prev_asleep != asleep) { + // prev_asleep = asleep; + // if (!asleep) { + // suspend_power_down_quantum(); + // } else { + // suspend_wakeup_init_quantum(); + // } + // } + // if (!asleep) { + // if (timer_elapsed32(host_sleep) < 100) { + // port_wait_for_interrupt(); + // return true; + // } else { + // host_sleep = timer_read32(); + // } + // } return false; } diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index 9d9f944f5d..8977e16d76 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c @@ -104,6 +104,14 @@ void backlight_enable(void) { backlight_set(backlight_config.level); } +void backlight_enable_old_level(void) { + if (backlight_config.enable) return; // do nothing if backlight is already on + + eeconfig_update_backlight(backlight_config.raw); + dprintf("backlight enable\n"); + backlight_set(backlight_config.level); +} + /** \brief Disable backlight * * FIXME: needs doc diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h index 85812bff3a..519025f2d9 100644 --- a/quantum/backlight/backlight.h +++ b/quantum/backlight/backlight.h @@ -49,6 +49,7 @@ _Static_assert(sizeof(backlight_config_t) == sizeof(uint8_t), "Backlight EECONFI void backlight_init(void); void backlight_toggle(void); void backlight_enable(void); +void backlight_enable_old_level(void); void backlight_disable(void); bool is_backlight_enabled(void); void backlight_step(void);