summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-04-25 10:26:14 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2019-04-26 16:54:40 +0000
commitdd3300b065043fa1a3caa5dc796714f21f5171ac (patch)
tree2e0d4f58cb550b6de5e42d9a30504110f35b2671
parent9d9205b1bc2ff9536ae71d16ac7beb71697a0d1b (diff)
downloadchrome-ec-dd3300b065043fa1a3caa5dc796714f21f5171ac.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/c/chromiumos/platform/ec/+/1585385 Reviewed-by: YH Lin <yueherngl@chromium.org> Commit-Queue: YH Lin <yueherngl@chromium.org> Tested-by: YH Lin <yueherngl@chromium.org>
-rw-r--r--board/flapjack/led.c23
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;
}