summaryrefslogtreecommitdiff
path: root/board/redrix/led.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/redrix/led.c')
-rw-r--r--board/redrix/led.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/board/redrix/led.c b/board/redrix/led.c
index 86e60b725a..c8654b3589 100644
--- a/board/redrix/led.c
+++ b/board/redrix/led.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -24,16 +24,14 @@
#define POWER_LED_OFF 1
#define LED_TICK_INTERVAL_MS (500 * MSEC)
-#define LED_CYCLE_TIME_MS (2000 * MSEC)
-#define LED_TICKS_PER_CYCLE (LED_CYCLE_TIME_MS / LED_TICK_INTERVAL_MS)
-#define LED_ON_TIME_MS (1000 * MSEC)
-#define LED_ON_TICKS (LED_ON_TIME_MS / LED_TICK_INTERVAL_MS)
-
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_LEFT_LED,
- EC_LED_ID_RIGHT_LED,
- EC_LED_ID_POWER_LED
-};
+#define LED_CYCLE_TIME_MS (2000 * MSEC)
+#define LED_TICKS_PER_CYCLE (LED_CYCLE_TIME_MS / LED_TICK_INTERVAL_MS)
+#define LED_ON_TIME_MS (1000 * MSEC)
+#define LED_ON_TICKS (LED_ON_TIME_MS / LED_TICK_INTERVAL_MS)
+
+const enum ec_led_id supported_led_ids[] = { EC_LED_ID_LEFT_LED,
+ EC_LED_ID_RIGHT_LED,
+ EC_LED_ID_POWER_LED };
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
@@ -41,22 +39,19 @@ enum led_color {
LED_OFF = 0,
LED_AMBER,
LED_WHITE,
- LED_COLOR_COUNT /* Number of colors, not a color itself */
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
};
-enum led_port {
- LEFT_PORT = 0,
- RIGHT_PORT
-};
+enum led_port { LEFT_PORT = 0, RIGHT_PORT };
static void led_set_color_battery(int port, enum led_color color)
{
enum gpio_signal amber_led, white_led;
amber_led = (port == RIGHT_PORT ? GPIO_C1_CHARGE_LED_AMBER_L :
- GPIO_C0_CHARGE_LED_AMBER_L);
+ GPIO_C0_CHARGE_LED_AMBER_L);
white_led = (port == RIGHT_PORT ? GPIO_C1_CHARGE_LED_WHITE_L :
- GPIO_C0_CHARGE_LED_WHITE_L);
+ GPIO_C0_CHARGE_LED_WHITE_L);
switch (color) {
case LED_WHITE:
@@ -151,16 +146,15 @@ static void set_active_port_color(enum led_color color)
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED))
led_set_color_battery(RIGHT_PORT,
- (port == RIGHT_PORT) ? color : LED_OFF);
+ (port == RIGHT_PORT) ? color : LED_OFF);
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
led_set_color_battery(LEFT_PORT,
- (port == LEFT_PORT) ? color : LED_OFF);
+ (port == LEFT_PORT) ? color : LED_OFF);
}
static void led_set_battery(void)
{
static unsigned int battery_ticks;
- uint32_t chflags = charge_get_flags();
battery_ticks++;
@@ -172,43 +166,52 @@ static void led_set_battery(void)
case PWR_STATE_DISCHARGE:
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) {
if (charge_get_percent() < 10)
- led_set_color_battery(RIGHT_PORT,
- (battery_ticks % LED_TICKS_PER_CYCLE
- < LED_ON_TICKS) ? LED_AMBER : LED_OFF);
+ led_set_color_battery(
+ RIGHT_PORT,
+ (battery_ticks % LED_TICKS_PER_CYCLE <
+ LED_ON_TICKS) ?
+ LED_AMBER :
+ LED_OFF);
else
led_set_color_battery(RIGHT_PORT, LED_OFF);
}
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) {
if (charge_get_percent() < 10)
- led_set_color_battery(LEFT_PORT,
- (battery_ticks % LED_TICKS_PER_CYCLE
- < LED_ON_TICKS) ? LED_AMBER : LED_OFF);
+ led_set_color_battery(
+ LEFT_PORT,
+ (battery_ticks % LED_TICKS_PER_CYCLE <
+ LED_ON_TICKS) ?
+ LED_AMBER :
+ LED_OFF);
else
led_set_color_battery(LEFT_PORT, LED_OFF);
}
break;
case PWR_STATE_ERROR:
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) {
- led_set_color_battery(RIGHT_PORT, (battery_ticks & 0x1)
- ? LED_AMBER : LED_OFF);
+ led_set_color_battery(
+ RIGHT_PORT,
+ (battery_ticks & 0x1) ? LED_AMBER : LED_OFF);
}
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) {
- led_set_color_battery(LEFT_PORT, (battery_ticks & 0x1)
- ? LED_AMBER : LED_OFF);
+ led_set_color_battery(LEFT_PORT, (battery_ticks & 0x1) ?
+ LED_AMBER :
+ LED_OFF);
}
break;
case PWR_STATE_CHARGE_NEAR_FULL:
set_active_port_color(LED_WHITE);
break;
case PWR_STATE_IDLE: /* External power connected in IDLE */
- if (chflags & CHARGE_FLAG_FORCE_IDLE)
- set_active_port_color((battery_ticks %
- LED_TICKS_PER_CYCLE < LED_ON_TICKS) ?
- LED_AMBER : LED_OFF);
- else
- set_active_port_color(LED_WHITE);
+ set_active_port_color(LED_WHITE);
+ break;
+ case PWR_STATE_FORCED_IDLE:
+ set_active_port_color(
+ (battery_ticks % LED_TICKS_PER_CYCLE < LED_ON_TICKS) ?
+ LED_AMBER :
+ LED_OFF);
break;
default:
/* Other states don't alter LED behavior */