Skip to content

Commit de3833d

Browse files
JohnAZoidbergquinchou77
authored andcommitted
fwk: Use macros to define auto ALS levels
Just a refactoring, shouldn't change behavior. BUG=Reviewing changes and I see many magic numbers BRANCH=fwk-main TEST=Check auto ALS brightness of power button and keyboard backlight Signed-off-by: Daniel Schaefer <[email protected]> (cherry picked from commit 89d66a0582b4abeb79015d7f77e01bc7dff35c71)
1 parent 8860a8f commit de3833d

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

zephyr/program/framework/include/led.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@
2525
#define PINS_ARRAY(id) DT_CAT(PINS_ARRAY_, id)
2626
#define DATA_NODE(node_id) DT_CAT(DATA_NODE_, node_id)
2727

28+
/* Above this threshold (in lux) power button brightness is high is off, else on */
29+
#define FP_LED_HIGH_ALS_THRESH 130
30+
#define FP_LED_MED_ALS_THRESH 100
31+
#define FP_LED_MED_LOW_ALS_THRESH 70
32+
#define FP_LED_LOW_ALS_THRESH 40
33+
2834
#define FP_LED_HIGH 55
2935
#define FP_LED_MEDIUM 40
3036
#define FP_LED_MEDIUM_LOW 28
3137
#define FP_LED_LOW 15
3238
#define FP_LED_ULTRA_LOW 8
3339

40+
/* Above this threshold (in lux) keyboard backlight is off, else on */
41+
#define KB_BL_THRESHOLD 5
42+
3443
enum led_color {
3544
LED_OFF,
3645
LED_RED,

zephyr/program/framework/src/led.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,23 @@ static int als_lux_get(void)
164164
uint16_t real_illuminance = *(uint16_t *)host_get_memmap(EC_MEMMAP_ALS);
165165
timestamp_t now = get_time();
166166

167-
/*
168-
* before als_task stable return data (als.c common)
169-
* keep 2 second of the lightness to default high
170-
**/
171167
if (chipset_in_state(CHIPSET_STATE_ON) && !als_stable) {
172168
if (now.val > als_init_deadline.val + 2 * SECOND) {
173169
als_stable = true;
174170
als_init_deadline.val = 0;
175171
}
176-
real_illuminance = 1000;
172+
/*
173+
* before ALS returns stable data (als.c common)
174+
* keep 2 second of the lightness to default high
175+
* power button brightness
176+
**/
177+
real_illuminance = FP_LED_HIGH_ALS_THRESH + 1;
177178
} else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
178179
als_init_deadline.val = now.val;
179180
if (als_stable) {
180181
als_stable = false;
181-
real_illuminance = 10;
182+
/* Default keyboard backlight to off */
183+
real_illuminance = KB_BL_THRESHOLD + 1;
182184
/* clear als data and set default level for next time bootup */
183185
*(uint16_t *)host_get_memmap(EC_MEMMAP_ALS) = 0;
184186
system_set_bbram(SYSTEM_BBRAM_IDX_FP_LED_LEVEL, FP_LED_HIGH);
@@ -232,7 +234,7 @@ void auto_als_led_brightness(void)
232234
chipset_in_state(CHIPSET_STATE_ON)) {
233235
last_kbbl_led_brightness = kblight_get();
234236

235-
if (als_lux > 5)
237+
if (als_lux > KB_BL_THRESHOLD)
236238
kb_brightness = KEYBOARD_BL_BRIGHTNESS_OFF;
237239
else
238240
kb_brightness = KEYBOARD_BL_BRIGHTNESS_ULT_LOW;
@@ -252,13 +254,13 @@ void auto_als_led_brightness(void)
252254

253255
if (fp_led_auto_is_enable() &&
254256
chipset_in_state(CHIPSET_STATE_ON)) {
255-
if (als_lux > 130)
257+
if (als_lux > FP_LED_HIGH_ALS_THRESH)
256258
led_brightness = FP_LED_HIGH;
257-
else if (als_lux > 100)
259+
else if (als_lux > FP_LED_MED_ALS_THRESH)
258260
led_brightness = FP_LED_MEDIUM;
259-
else if (als_lux > 70)
261+
else if (als_lux > FP_LED_MED_LOW_ALS_THRESH)
260262
led_brightness = FP_LED_MEDIUM_LOW;
261-
else if (als_lux > 40)
263+
else if (als_lux > FP_LED_LOW_ALS_THRESH)
262264
led_brightness = FP_LED_LOW;
263265
else
264266
led_brightness = FP_LED_ULTRA_LOW;

0 commit comments

Comments
 (0)