diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-09-20 14:04:03 -0700 |
---|---|---|
committer | ChromeOS bot <3su6n15k.default@developer.gserviceaccount.com> | 2015-10-29 06:20:03 +0000 |
commit | ce0fab5872c353c3a52be35bd2e21e3b7ca44fb4 (patch) | |
tree | 96c79b5e7f23789e4c0261eceb34f7dfef3f5e3b | |
parent | 056160c6fbbb18c63804c7e8120b8c783c28ac25 (diff) | |
download | chrome-ec-ce0fab5872c353c3a52be35bd2e21e3b7ca44fb4.tar.gz |
common: Add lightbar dimming based on outside light.
Unless the lid is closed, the ALS is used for lightbar dimming.
Change the google colors depending on the light sensor result.
BUG=chrome-os-partner:44400
BRANCH=smaug
TEST=Check all 3 levels of brightness of the lightbar.
Check value using "adb shell ectool lightbar"
Check double tap color are not affected and is using full brightness.
Change-Id: I7b5e2890c3557f1dd3ae719f5f82ffb5fe7b24fb
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/301216
Reviewed-by: Alec Berg <alecaberg@chromium.org>
(cherry picked from commit 7340e804a1e3ffba2f1ffb9bf826a33b8b5fb19c)
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/309592
-rw-r--r-- | board/ryu/board.c | 35 | ||||
-rw-r--r-- | board/ryu/board.h | 1 | ||||
-rw-r--r-- | common/lightbar.c | 42 | ||||
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | include/lightbar.h | 18 | ||||
-rw-r--r-- | include/motion_sense.h | 4 |
6 files changed, 96 insertions, 7 deletions
diff --git a/board/ryu/board.c b/board/ryu/board.c index 661d5af826..d473aa2e77 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -674,6 +674,41 @@ struct motion_sensor_t motion_sensors[] = { }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +struct lb_brightness_def lb_brightness_levels[] = { + { + /* regular brightness */ + .lux = 40, + .color = { + {0x74, 0x58, 0xb4}, /* Segment0: Google blue */ + {0xd6, 0x40, 0x20}, /* Segment1: Google red */ + {0xfa, 0xe6, 0x20}, /* Segment2: Google yellow */ + {0x66, 0xb0, 0x50}, /* Segment3: Google green */ + }, + }, + { + /* 25 - 50% brightness */ + .lux = 20, + .color = { + {0x51, 0x38, 0x7d}, + {0x99, 0x28, 0x15}, + {0xb8, 0x9e, 0x1a}, + {0x44, 0x80, 0x35}, + }, + }, + { + /* 0 .. 25% brightness */ + .lux = 0, + .color = { + {0x3d, 0x28, 0x5c}, + {0x71, 0x28, 0x10}, + {0x8a, 0x6f, 0x10}, + {0x2f, 0x60, 0x25}, + }, + }, +}; +const unsigned int lb_brightness_levels_count = + ARRAY_SIZE(lb_brightness_levels); + static void board_set_usb_switches(int port, int open) { /* If switch is not changing, then return */ diff --git a/board/ryu/board.h b/board/ryu/board.h index e494c2051c..5bcad1d487 100644 --- a/board/ryu/board.h +++ b/board/ryu/board.h @@ -310,6 +310,7 @@ void pp1800_on_off_evt(enum gpio_signal signal); /* ALS sensor is in forced mode */ #define CONFIG_ACCEL_FORCE_MODE_MASK \ ((1 << RYU_LID_LIGHT) | (1 << RYU_LID_PROX)) +#define CONFIG_ALS_LIGHTBAR_DIMMING RYU_LID_LIGHT #endif /* !__ASSEMBLER__ */ diff --git a/common/lightbar.c b/common/lightbar.c index a424fb1fa1..7dbb1e2717 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -18,6 +18,8 @@ #include "host_command.h" #include "lb_common.h" #include "lightbar.h" +#include "lid_switch.h" +#include "motion_sense.h" #include "pwm.h" #include "system.h" #include "task.h" @@ -142,12 +144,6 @@ static const struct lightbar_params_v1 default_params = { }, .s5_idx = PRIMARY_RED, /* flash red */ .color = { -#if defined(BOARD_RYU) - {0x74, 0x58, 0xb4}, /* Segment0: Google blue */ - {0xd6, 0x40, 0x20}, /* Segment1: Google red */ - {0xfa, 0xe6, 0x20}, /* Segment2: Google yellow */ - {0x66, 0xb0, 0x50}, /* Segment3: Google green */ -#else /* * These values have been optically calibrated for the * Samus LEDs to best match the official colors, described at @@ -158,7 +154,6 @@ static const struct lightbar_params_v1 default_params = { {0xbc, 0x50, 0x2c}, /* 1: Google red */ {0xd0, 0xe0, 0x00}, /* 2: Google yellow */ {0x50, 0xa0, 0x40}, /* 3: Google green */ -#endif /* These are primary colors */ {0x00, 0x00, 0xff}, /* 4: full blue */ {0xff, 0x00, 0x00}, /* 5: full red */ @@ -208,6 +203,9 @@ static void lightbar_restore_state(void) #ifdef CONFIG_PWM_KBLIGHT static int last_backlight_level; #endif +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING +static int last_google_color = -1; +#endif static int demo_mode = DEMO_MODE_DEFAULT; @@ -220,11 +218,30 @@ static int quantize_battery_level(int pct) return bl; } +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING +static int lux_level_to_google_color(int lux) +{ + int i; + + if (!lid_is_open()) + /* The lid shades the light sensor, use full brightness. */ + return 0; + + for (i = 0; i < lb_brightness_levels_count ; i++) + if (lux >= lb_brightness_levels[i].lux) + break; + return i; +} +#endif + /* Update the known state. */ static void get_battery_level(void) { int pct = 0; int bl; +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING + int color_id; +#endif if (demo_mode) return; @@ -269,6 +286,17 @@ static void get_battery_level(void) lb_set_brightness(pct); } #endif +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING + /* Read last value (in lux) collected by the motion sensor. */ + /* Convert lux into brightness percentage */ + color_id = lux_level_to_google_color(MOTION_SENSE_LUX); + + if (color_id != last_google_color) { + last_google_color = pct; + memcpy(st.p.color, lb_brightness_levels[color_id].color, + sizeof(lb_brightness_levels[color_id].color)); + } +#endif } /* Forcing functions for demo mode, called by the keyboard task. */ diff --git a/include/config.h b/include/config.h index 32cfb6974e..4535896127 100644 --- a/include/config.h +++ b/include/config.h @@ -87,6 +87,9 @@ */ #undef CONFIG_ALS_SI114X_INT_EVENT +/* Define which ALS sensor is used for dimming the lightbar when dark */ +#undef CONFIG_ALS_LIGHTBAR_DIMMING + /* Support AP hang detection host command and state machine */ #undef CONFIG_AP_HANG_DETECT diff --git a/include/lightbar.h b/include/lightbar.h index 293eeb2ab2..8648e3f3bd 100644 --- a/include/lightbar.h +++ b/include/lightbar.h @@ -34,6 +34,24 @@ enum lb_control { LB_CONT_MAX }; +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING +/* + * For dimming the lightbar in the dark, we define an array to + * describe the expected colors: + * if luminosity is more than 'lux', the color defined will be used. + * The last entry must have lux == 0. + * Defining brightness is not enough to prevent washed color in low + * lux setting. + */ +struct lb_brightness_def { + uint16_t lux; + struct rgb_s color[4]; +}; + +extern struct lb_brightness_def lb_brightness_levels[]; +extern const unsigned lb_brightness_levels_count; +#endif + /* Request a preset sequence from the lightbar task. */ void lightbar_sequence_f(enum lightbar_sequence num, const char *f); #define lightbar_sequence(A) lightbar_sequence_f(A, __func__) diff --git a/include/motion_sense.h b/include/motion_sense.h index ff99c40af4..5dc94b59fd 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -185,4 +185,8 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data, #else #define ALL_MOTION_SENSORS motion_sensor_count #endif + +#ifdef CONFIG_ALS_LIGHTBAR_DIMMING +#define MOTION_SENSE_LUX motion_sensors[CONFIG_ALS_LIGHTBAR_DIMMING].raw_xyz[0] +#endif #endif /* __CROS_EC_MOTION_SENSE_H */ |