diff options
Diffstat (limited to 'board/moli/led.c')
-rw-r--r-- | board/moli/led.c | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/board/moli/led.c b/board/moli/led.c index 8e30f20c5e..d506864056 100644 --- a/board/moli/led.c +++ b/board/moli/led.c @@ -61,15 +61,21 @@ static int set_color_power(enum led_color color, int duty) return EC_ERROR_UNKNOWN; } - if (blue) + if (blue && duty) { + gpio_set_level(GPIO_LED_BLUE_CONTROL, 1); pwm_set_duty(PWM_CH_LED_BLUE, duty); - else + } else { + gpio_set_level(GPIO_LED_BLUE_CONTROL, 0); pwm_set_duty(PWM_CH_LED_BLUE, 0); + } - if (amber) + if (amber && duty) { + gpio_set_level(GPIO_LED_ORANGE_CONTROL, 1); pwm_set_duty(PWM_CH_LED_AMBER, duty); - else + } else { + gpio_set_level(GPIO_LED_ORANGE_CONTROL, 0); pwm_set_duty(PWM_CH_LED_AMBER, 0); + } return EC_SUCCESS; } @@ -84,9 +90,11 @@ static int set_color(enum ec_led_id id, enum led_color color, int duty) } } -#define LED_PULSE_US (2 * SECOND) -/* 40 msec for nice and smooth transition. */ -#define LED_PULSE_TICK_US (40 * MSEC) +#define LED_PERIOD (4 * SECOND) +#define LED_DUTY_CYCLE (25) +#define LED_PULSE_US (LED_PERIOD * LED_DUTY_CYCLE / 100 / 2) +/* 10 msec for nice and smooth transition. */ +#define LED_PULSE_TICK_US (10 * MSEC) /* * When pulsing is enabled, brightness is incremented by <duty_inc> every @@ -98,17 +106,26 @@ static struct { int duty_inc; enum led_color color; int duty; + uint32_t time_off; } led_pulse; -#define CONFIG_TICK(interval, color) \ - config_tick((interval), 100 / (LED_PULSE_US / (interval)), (color)) +/* + * LED_PERIOD = time_on + time_off; + * time_on = LED_PULSE_US * 2; + * time_off = LED_PERIOD - LED_PULSE_US * 2; + */ +#define CONFIG_TICK(interval, period, color) \ + config_tick((interval), 100 / (LED_PULSE_US / (interval)), \ + LED_PERIOD - LED_PULSE_US * 2, (color)) -static void config_tick(uint32_t interval, int duty_inc, enum led_color color) +static void config_tick(uint32_t interval, int duty_inc, int time_off, + enum led_color color) { led_pulse.interval = interval; led_pulse.duty_inc = duty_inc; led_pulse.color = color; led_pulse.duty = 0; + led_pulse.time_off = time_off; } static void pulse_power_led(enum led_color color) @@ -133,12 +150,15 @@ static void led_tick(void) pulse_power_led(led_pulse.color); elapsed = get_time().le.lo - start; next = led_pulse.interval > elapsed ? led_pulse.interval - elapsed : 0; + next = (led_pulse.duty - led_pulse.duty_inc) ? + next : + next + led_pulse.time_off; hook_call_deferred(&led_tick_data, next); } static void led_suspend(void) { - CONFIG_TICK(LED_PULSE_TICK_US, LED_AMBER); + CONFIG_TICK(LED_PULSE_TICK_US, LED_PERIOD, LED_BLUE); led_tick(); } DECLARE_DEFERRED(led_suspend); @@ -178,7 +198,7 @@ static void led_resume(void) hook_call_deferred(&led_suspend_data, -1); hook_call_deferred(&led_shutdown_data, -1); if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - set_color(EC_LED_ID_POWER_LED, LED_AMBER, 100); + set_color(EC_LED_ID_POWER_LED, LED_BLUE, 100); } DECLARE_HOOK(HOOK_CHIPSET_RESUME, led_resume, HOOK_PRIO_DEFAULT); @@ -186,7 +206,7 @@ void led_alert(int enable) { if (enable) { /* Overwrite the current signal */ - config_tick(1 * SECOND, 100, LED_BLUE); + config_tick(1 * SECOND, 100, 0, LED_AMBER); led_tick(); } else { /* Restore the previous signal */ @@ -203,7 +223,7 @@ void show_critical_error(void) { hook_call_deferred(&led_tick_data, -1); if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - set_color(EC_LED_ID_POWER_LED, LED_BLUE, 100); + set_color(EC_LED_ID_POWER_LED, LED_AMBER, 100); } static int command_led(int argc, char **argv) |