diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-06-25 10:24:41 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-27 16:53:34 +0000 |
commit | 62cf5a2462e754f47c300fab75053db691171f3d (patch) | |
tree | 37d8ddbe173ef62fbdd9c8186dd45afc56a40684 | |
parent | ba1d10a7586dbacd33a7c101a2a2404c237a79e0 (diff) | |
download | chrome-ec-62cf5a2462e754f47c300fab75053db691171f3d.tar.gz |
Nami: Set LED pattern only when pattern is different
This patch makes EC check the currently active LED pattern before
setting a new pattern. This will prevent a power LED from blinking
every time the soc changes.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/135897885
BRANCH=Nami
TEST=Verify LED behavior on Sona
Change-Id: I5175dcd12c17c405bdb41f8fd6d370cf0ab272e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1680660
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | board/nami/led.c | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/board/nami/led.c b/board/nami/led.c index b09f15fd1d..3e7132756d 100644 --- a/board/nami/led.c +++ b/board/nami/led.c @@ -322,9 +322,37 @@ static struct { uint8_t pulse; } tick[2]; -static void config_tick(enum ec_led_id id, const struct led_pattern *pattern) +static void tick_battery(void); +DECLARE_DEFERRED(tick_battery); +static void tick_power(void); +DECLARE_DEFERRED(tick_power); +static void cancel_tick(enum ec_led_id id) { - uint32_t stride = PULSE_INTERVAL(pattern->pulse); + if (id == EC_LED_ID_BATTERY_LED) + hook_call_deferred(&tick_battery_data, -1); + else + hook_call_deferred(&tick_power_data, -1); +} + +static int config_tick(enum ec_led_id id, const struct led_pattern *pattern) +{ + static const struct led_pattern *patterns[2]; + uint32_t stride; + + if (pattern == patterns[id]) + /* This pattern was already set */ + return -1; + + patterns[id] = pattern; + + if (!pattern->pulse) { + /* This is a steady pattern. cancel the tick */ + cancel_tick(id); + set_color(id, pattern->color, 100); + return 1; + } + + stride = PULSE_INTERVAL(pattern->pulse); if (IS_PULSING(pattern->pulse)) { tick[id].interval = LED_PULSE_TICK_US; tick[id].duty_inc = 100 / (stride / LED_PULSE_TICK_US); @@ -336,6 +364,8 @@ static void config_tick(enum ec_led_id id, const struct led_pattern *pattern) tick[id].duty = 0; tick[id].alternate = 0; tick[id].pulse = pattern->pulse; + + return 0; } /* @@ -376,37 +406,28 @@ static uint32_t tick_led(enum ec_led_id id) return next > elapsed ? next - elapsed : 0; } -static void tick_battery(void); -DECLARE_DEFERRED(tick_battery); static void tick_battery(void) { hook_call_deferred(&tick_battery_data, tick_led(EC_LED_ID_BATTERY_LED)); } -static void tick_power(void); -DECLARE_DEFERRED(tick_power); static void tick_power(void) { hook_call_deferred(&tick_power_data, tick_led(EC_LED_ID_POWER_LED)); } -static void cancel_tick(enum ec_led_id id) -{ - if (id == EC_LED_ID_BATTERY_LED) - hook_call_deferred(&tick_battery_data, -1); - else - hook_call_deferred(&tick_power_data, -1); -} - static void start_tick(enum ec_led_id id, const struct led_pattern *pattern) { - if (!pattern->pulse) { - cancel_tick(id); - set_color(id, pattern->color, 100); + if (config_tick(id, pattern)) + /* + * If this pattern is already active, ticking must have started + * already. So, we don't re-start ticking to prevent LED from + * blinking at every SOC change. + * + * If this pattern is static, we skip ticking as well. + */ return; - } - config_tick(id, pattern); if (id == EC_LED_ID_BATTERY_LED) tick_battery(); else |