diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-04-25 10:26:14 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-30 06:07:55 -0700 |
commit | 94ec130c609248da647460e0093801e0593e6fa9 (patch) | |
tree | d2a166719beebea44322278309963770d1a04d85 | |
parent | e5d7819b7277e97fb5adc3e6387b991a1c10a578 (diff) | |
download | chrome-ec-94ec130c609248da647460e0093801e0593e6fa9.tar.gz |
Flapjack: Turn off LED when brightness == 0
Currently, when the brightness passed to led_set_brightness is zero,
the current is set to 4mA and the pwm duty is set to the brightness.
Since duty == 0 means 1/32 (instead of 0/32), this doesn't turn off
the LED.
This patch makes the current explicitly set to 0mA if the brightness
is zero.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/131205169
BRANCH=none
TEST=buildall
Change-Id: I7f581349713d30f10acb3797ab08b15aa2d50f00
Reviewed-on: https://chromium-review.googlesource.com/1584351
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: YH Lin <yueherngl@chromium.org>
-rw-r--r-- | board/flapjack/led.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/board/flapjack/led.c b/board/flapjack/led.c index 2d170e45a4..165d549eb7 100644 --- a/board/flapjack/led.c +++ b/board/flapjack/led.c @@ -97,17 +97,26 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) brightness_range[EC_LED_COLOR_BLUE] = max; } +static void set_current_and_pwm_duty(uint8_t brightness, + enum mt6370_led_index color) +{ + if (brightness) { + /* Current is fixed at 4mA. Brightness is controlled by duty. */ + mt6370_led_set_brightness(color, 1); + mt6370_led_set_pwm_dim_duty(color, brightness); + } else { + /* off */ + mt6370_led_set_brightness(color, 0); + } +} + int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) { if (led_id != EC_LED_ID_BATTERY_LED) return EC_ERROR_INVAL; - /* Current is fixed at 4mA. Brightness is controlled by duty only. */ - mt6370_led_set_brightness(LED_RED, 1); - mt6370_led_set_brightness(LED_GRN, 1); - mt6370_led_set_brightness(LED_BLU, 1); - mt6370_led_set_pwm_dim_duty(LED_RED, brightness[EC_LED_COLOR_RED]); - mt6370_led_set_pwm_dim_duty(LED_GRN, brightness[EC_LED_COLOR_GREEN]); - mt6370_led_set_pwm_dim_duty(LED_BLU, brightness[EC_LED_COLOR_BLUE]); + set_current_and_pwm_duty(brightness[EC_LED_COLOR_RED], LED_RED); + set_current_and_pwm_duty(brightness[EC_LED_COLOR_GREEN], LED_GRN); + set_current_and_pwm_duty(brightness[EC_LED_COLOR_BLUE], LED_BLU); return EC_SUCCESS; } |