diff options
author | Aseda Aboagye <aaboagye@google.com> | 2018-01-22 11:58:23 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-02-05 23:05:40 -0800 |
commit | ddd4b363afc5593d73154833d23f773e370e6308 (patch) | |
tree | 74e88057a636a6b65747bb0768c184a4316d2ad8 | |
parent | d940d2a991b33b5b1ad9d6a2698ebfcdaa0f59db (diff) | |
download | chrome-ec-ddd4b363afc5593d73154833d23f773e370e6308.tar.gz |
meowth: zoombini: Enable PWM LED support.
BUG=b:69138917
BRANCH=None
TEST=Flash meowth; verify that LEDs behave as expected.
TEST=Repeat above test for zoombini.
Change-Id: I07ae4b4d0f62c653d3d15c493a7ece573551212a
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/888221
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r-- | board/zoombini/board.c | 43 | ||||
-rw-r--r-- | board/zoombini/board.h | 7 | ||||
-rw-r--r-- | board/zoombini/led.c | 188 |
3 files changed, 113 insertions, 125 deletions
diff --git a/board/zoombini/board.c b/board/zoombini/board.c index b6966f1642..8e11ec57dd 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -124,18 +124,25 @@ const struct adc_t adc_channels[] = { }; /* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ -/* TODO(aaboagye): Add the additional Meowth LEDs */ const struct pwm_t pwm_channels[] = { #ifdef BOARD_MEOWTH - [PWM_CH_DB0_LED_RED] = { 3, PWM_CONFIG_DSLEEP, 120 }, - [PWM_CH_DB0_LED_GREEN] = { 0, PWM_CONFIG_DSLEEP, 120 }, - [PWM_CH_DB0_LED_BLUE] = { 2, PWM_CONFIG_DSLEEP, 120 }, - [PWM_CH_DB1_LED_RED] = { 7, PWM_CONFIG_DSLEEP, 120 }, - [PWM_CH_DB1_LED_GREEN] = { 5, PWM_CONFIG_DSLEEP, 120 }, - [PWM_CH_DB1_LED_BLUE] = { 6, PWM_CONFIG_DSLEEP, 120 }, + [PWM_CH_DB0_LED_RED] = { 3, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, + [PWM_CH_DB0_LED_GREEN] = { 0, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, + [PWM_CH_DB0_LED_BLUE] = { 2, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, + [PWM_CH_DB1_LED_RED] = { 7, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, + [PWM_CH_DB1_LED_GREEN] = { 5, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, + [PWM_CH_DB1_LED_BLUE] = { 6, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, #else /* !defined(BOARD_MEOWTH) */ - [PWM_CH_LED_GREEN] = { 0, PWM_CONFIG_DSLEEP, 120 }, - [PWM_CH_LED_RED] = { 2, PWM_CONFIG_DSLEEP, 120 }, + [PWM_CH_LED_GREEN] = { 0, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, + [PWM_CH_LED_RED] = { 2, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + 2400 }, [PWM_CH_KBLIGHT] = { 3, 0, 100 }, #endif /* defined(BOARD_MEOWTH) */ }; @@ -396,24 +403,6 @@ static void board_init(void) } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); -static void board_init_leds_off(void) -{ - /* Initialize the LEDs off. */ -#ifdef BOARD_MEOWTH - /* TODO(aaboagye): Eventually do something with these LEDs. */ - pwm_set_duty(PWM_CH_DB0_LED_RED, 100); - pwm_set_duty(PWM_CH_DB0_LED_GREEN, 100); - pwm_set_duty(PWM_CH_DB0_LED_BLUE, 100); - pwm_set_duty(PWM_CH_DB1_LED_RED, 100); - pwm_set_duty(PWM_CH_DB1_LED_GREEN, 100); - pwm_set_duty(PWM_CH_DB1_LED_BLUE, 100); -#else /* !defined(BOARD_MEOWTH) */ - pwm_set_duty(PWM_CH_LED_RED, 100); - pwm_set_duty(PWM_CH_LED_GREEN, 100); -#endif /* defined(BOARD_MEOWTH) */ -} -DECLARE_HOOK(HOOK_INIT, board_init_leds_off, HOOK_PRIO_INIT_PWM + 1); - void board_overcurrent_event(int port) { /* Sanity check the port. */ diff --git a/board/zoombini/board.h b/board/zoombini/board.h index 2df6a5f7f2..90dfcf252f 100644 --- a/board/zoombini/board.h +++ b/board/zoombini/board.h @@ -101,6 +101,13 @@ #define CONFIG_KEYBOARD_PROTOCOL_MKBP #endif /* defined(BOARD_MEOWTH) */ +#define CONFIG_LED_COMMON +#ifdef BOARD_MEOWTH +#define CONFIG_LED_PWM_COUNT 2 +#else +#define CONFIG_LED_PWM_COUNT 1 +#endif /* defined(BOARD_MEOWTH) */ + #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP diff --git a/board/zoombini/led.c b/board/zoombini/led.c index b74734ea78..f3ee559f3b 100644 --- a/board/zoombini/led.c +++ b/board/zoombini/led.c @@ -3,120 +3,112 @@ * found in the LICENSE file. */ -/* Zoombini LED control to conform to Chrome OS LED behaviour specification. */ +/* Zoombini/Meowth specific LED settings. */ -/* - * TODO(crbug.com/752553): This should be turned into common code such that - * boards that use PWM controlled LEDs can share code to follow the Chrome OS - * LED behaviour spec. If possible, tie into led_policy_std.c. - */ - -#include "charge_state.h" -#include "chipset.h" #include "common.h" -#include "hooks.h" +#include "ec_commands.h" +#include "led_pwm.h" #include "pwm.h" -#include "timer.h" - -enum led_id { - EC_LED_ID_POWER = 0, - EC_LED_ID_BATTERY, - EC_LED_ID_COUNT, -}; +#include "util.h" -static enum pwm_channel led_pwm_ch_map[EC_LED_ID_COUNT] = { +const enum ec_led_id supported_led_ids[] = { #ifdef BOARD_MEOWTH - [EC_LED_ID_POWER] = PWM_CH_DB0_LED_GREEN, - [EC_LED_ID_BATTERY] = PWM_CH_DB0_LED_RED, -#else /* !defined(BOARD_MEOWTH) */ - [EC_LED_ID_POWER] = PWM_CH_LED_GREEN, - [EC_LED_ID_BATTERY] = PWM_CH_LED_RED, + EC_LED_ID_LEFT_LED, + EC_LED_ID_RIGHT_LED, +#else + EC_LED_ID_POWER_LED, #endif /* defined(BOARD_MEOWTH) */ }; +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); -static void set_led_state(enum led_id id, int on) -{ - int val; #ifdef BOARD_MEOWTH - val = on ? 98 : 100; -#else /* !defined(BOARD_MEOWTH) */ - val = on ? 90 : 100; -#endif /* defined(BOARD_MEOWTH) */ - - pwm_set_duty(led_pwm_ch_map[id], val); -} - -static uint8_t power_led_is_pulsing; - -static void pulse_power_led(void); -DECLARE_DEFERRED(pulse_power_led); -static void pulse_power_led(void) -{ - static uint8_t tick_count; - - if (!power_led_is_pulsing) { - tick_count = 0; - return; - } +/* Meowth LED definitions */ +/* We won't be using the blue channel long term. */ +struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = { + /* Red, Green, Blue */ + [EC_LED_COLOR_RED] = { 8, 0, 0 }, + [EC_LED_COLOR_GREEN] = { 0, 8, 0 }, + [EC_LED_COLOR_BLUE] = { 0, 0, 0 }, + [EC_LED_COLOR_YELLOW] = { 8, 24, 0 }, + [EC_LED_COLOR_WHITE] = { 0, 0, 0 }, + [EC_LED_COLOR_AMBER] = { 12, 9, 0 }, +}; - if (tick_count == 0) - set_led_state(EC_LED_ID_POWER, 1); - else - set_led_state(EC_LED_ID_POWER, 0); +/* Two tri-color LEDs with red, green, and blue channels. */ +struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = { + { + PWM_CH_DB0_LED_RED, + PWM_CH_DB0_LED_GREEN, + PWM_CH_DB0_LED_BLUE, + }, + + { + PWM_CH_DB1_LED_RED, + PWM_CH_DB1_LED_GREEN, + PWM_CH_DB1_LED_BLUE, + }, +}; +#else +/* Zoombini LED definitions. */ +struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = { + /* Red, Green, Blue */ + [EC_LED_COLOR_RED] = { 100, 0, 0 }, + [EC_LED_COLOR_GREEN] = { 0, 100, 0 }, + [EC_LED_COLOR_BLUE] = { 0, 0, 0 }, + [EC_LED_COLOR_YELLOW] = { 100, 50, 0 }, + [EC_LED_COLOR_WHITE] = { 0, 0, 0 }, + [EC_LED_COLOR_AMBER] = { 100, 10, 0 }, +}; - /* 4 second period, 25% duty cycle. */ - tick_count = (tick_count + 1) % 4; - hook_call_deferred(&pulse_power_led_data, SECOND); -} +/* A single bi-color LED with red and green channels. */ +struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = { + { + .ch0 = PWM_CH_LED_RED, + .ch1 = PWM_CH_LED_GREEN, + .ch2 = PWM_LED_NO_CHANNEL, + }, +}; +#endif /* !defined(BOARD_MEOWTH) */ -static void power_led_update(void) +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) { - if (chipset_in_state(CHIPSET_STATE_ON)) { - /* Make sure we stop pulsing. */ - power_led_is_pulsing = 0; - /* The power LED must be on in the Active state. */ - set_led_state(EC_LED_ID_POWER, 1); - } else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) { - /* The power LED must pulse in the Suspend state. */ - if (!power_led_is_pulsing) { - power_led_is_pulsing = 1; - pulse_power_led(); - } - } else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) { - /* Make sure we stop pulsing. */ - power_led_is_pulsing = 0; - /* The power LED must be off in the Deep Sleep state. */ - set_led_state(EC_LED_ID_POWER, 0); - } + brightness_range[EC_LED_COLOR_RED] = 100; + brightness_range[EC_LED_COLOR_GREEN] = 100; + brightness_range[EC_LED_COLOR_YELLOW] = 100; + brightness_range[EC_LED_COLOR_AMBER] = 100; + /* Zoombini has no blue channel; it's also going away for Meowth. */ + brightness_range[EC_LED_COLOR_BLUE] = 0; + brightness_range[EC_LED_COLOR_WHITE] = 0; } -static void battery_led_update(void) +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) { - enum charge_state chg_st = charge_get_state(); - - switch (chg_st) { - case PWR_STATE_DISCHARGE: - case PWR_STATE_IDLE: - set_led_state(EC_LED_ID_BATTERY, 0); - break; - - /* - * We don't have another color to distingush full, so make it - * the same as charging. - */ - case PWR_STATE_CHARGE_NEAR_FULL: - case PWR_STATE_CHARGE: - set_led_state(EC_LED_ID_BATTERY, 1); - break; + enum pwm_led_id pwm_id; - default: - break; - } -} + /* Convert ec_led_id to pwm_led_id. */ +#ifdef BOARD_MEOWTH + if (led_id == EC_LED_ID_LEFT_LED) + pwm_id = PWM_LED0; + else if (led_id == EC_LED_ID_RIGHT_LED) + pwm_id = PWM_LED1; +#else + if (led_id == EC_LED_ID_POWER_LED) + pwm_id = PWM_LED0; +#endif /* defined(BOARD_MEOWTH) */ + else + return EC_ERROR_UNKNOWN; + + if (brightness[EC_LED_COLOR_RED]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_RED); + else if (brightness[EC_LED_COLOR_GREEN]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_GREEN); + else if (brightness[EC_LED_COLOR_YELLOW]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_YELLOW); + else if (brightness[EC_LED_COLOR_AMBER]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_AMBER); + else + /* Otherwise, the "color" is "off". */ + set_pwm_led_color(pwm_id, -1); -static void update_leds(void) -{ - power_led_update(); - battery_led_update(); + return EC_SUCCESS; } -DECLARE_HOOK(HOOK_TICK, update_leds, HOOK_PRIO_DEFAULT); |