Skip to content

Commit 2346af7

Browse files
JohnAZoidbergquinchou77
authored andcommitted
fwk: Immediately adjust KB backlight if switching to auto
last_kbbl_led_brightness should be an int compared with kb_brightness, which is int, so it does not make as a bool. BUG=When cycling through brightness with FN+SPACE after high, switching to auto the backlight will stay high. It doesn't adjust to the current brightness until the ALS brightness changes between off/on. TEST=press FN+space 4 times from off and make sure that in auto mode kb backlight immediately updates to ultra-low or off BRANCH=fwk-main Signed-off-by: Daniel Schaefer <dhs@frame.work> (cherry picked from commit 8e02721)
1 parent 0aa077c commit 2346af7

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

zephyr/program/framework/include/led.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ int fp_led_auto_is_enable(void);
188188

189189
int kbbl_auto_dim_is_enable(void);
190190

191+
void auto_als_led_reset(void);
192+
191193
/**
192194
* Return the current tick time from led driver
193195
*

zephyr/program/framework/src/keyboard_customization_13.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,15 @@ int functional_hotkey(uint16_t *key_code, int8_t pressed)
415415
return EC_ERROR_UNIMPLEMENTED;
416416
}
417417
break;
418-
case SCANCODE_SPACE: /* TODO: TOGGLE_KEYBOARD_BACKLIGHT */
418+
case SCANCODE_SPACE: /* Keyboard backlight */
419419
if (fn_table_set(pressed, KB_FN_SPACE)) {
420420
if (pressed) {
421421
if (kbbl_auto_dim_is_enable())
422422
bl_brightness = KEYBOARD_BL_BRIGHTNESS_AUTO;
423423
else
424424
bl_brightness = kblight_get();
425425

426+
/* Cycle through off, 3 levels of brightness and on */
426427
switch (bl_brightness) {
427428
case KEYBOARD_BL_BRIGHTNESS_OFF:
428429
bl_brightness = KEYBOARD_BL_BRIGHTNESS_LOW;
@@ -435,8 +436,10 @@ int functional_hotkey(uint16_t *key_code, int8_t pressed)
435436
break;
436437
case KEYBOARD_BL_BRIGHTNESS_HIGH:
437438
kb_als_auto_brightness = true;
439+
auto_als_led_reset();
438440
return EC_ERROR_UNIMPLEMENTED;
439441
break;
442+
case KEYBOARD_BL_BRIGHTNESS_AUTO:
440443
default:
441444
bl_brightness = KEYBOARD_BL_BRIGHTNESS_OFF;
442445
kb_als_auto_brightness = false;

zephyr/program/framework/src/led.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static bool pre_fingerprint_led_state;
152152
static bool fp_als_auto_brightness;
153153
static bool last_fp_led_brightness;
154154
#ifdef CONFIG_PLATFORM_EC_KEYBOARD
155-
static bool last_kbbl_led_brightness;
155+
static int last_kbbl_led_brightness;
156156
#endif
157157
static int prev_als_lux;
158158

@@ -257,6 +257,8 @@ void auto_als_led_brightness(void)
257257

258258
#ifdef CONFIG_PLATFORM_EC_KEYBOARD
259259
if (kbbl_auto_dim_is_enable()) {
260+
last_kbbl_led_brightness = kblight_get();
261+
260262
if (als_lux > 5)
261263
kb_brightness = KEYBOARD_BL_BRIGHTNESS_OFF;
262264
else
@@ -270,6 +272,17 @@ void auto_als_led_brightness(void)
270272
#endif
271273
}
272274

275+
/*
276+
* Force ALS dependent brightness (keyboard, powerbutton) to immediately adjust
277+
* based on ALS measurement, if they're enabled. Useeful if the setting was just enabled.
278+
*/
279+
void auto_als_led_reset(void)
280+
{
281+
prev_als_lux = 0;
282+
if (IS_ENABLED(CONFIG_PLATFORM_EC_DEDICATED_ALS))
283+
auto_als_led_brightness();
284+
}
285+
273286
test_export_static enum power_state get_chipset_state(void)
274287
{
275288
enum power_state chipset_state = 0;

0 commit comments

Comments
 (0)