Skip to content

Commit 3d1e204

Browse files
committed
fwk: modified the charging LED to meet the ERS
Signed-off-by: Josh-Tsai <josh_tsai@compal.com>
1 parent bd60947 commit 3d1e204

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

zephyr/program/lotus/azalea/led_policy.dtsi

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
power-state-charge {
88
charge-state = "LED_PWRS_CHARGE";
9-
/* Battery percent range (>= 0, <= 96) */
10-
batt-lvl = <BATTERY_LEVEL_EMPTY 96>;
9+
/* Battery percent range (>= 0, < 96) */
10+
batt-lvl = <BATTERY_LEVEL_EMPTY 95>;
1111
color-0 {
1212
led-color = <&color_amber>;
1313
};
1414
};
1515

1616
power-state-charge-lvl-2 {
1717
charge-state = "LED_PWRS_CHARGE";
18-
/* Battery percent range (>= 97%, <= 100%) */
19-
batt-lvl = <97 100>;
18+
/* Battery percent range (>= 96%, <= 100%) */
19+
batt-lvl = <96 100>;
2020

2121
color-0 {
2222
led-color = <&color_white>;
@@ -25,8 +25,6 @@
2525

2626
power-state-discharge {
2727
charge-state = "LED_PWRS_DISCHARGE";
28-
/* Battery percent range (>= 11, <= 97) */
29-
batt-lvl = <(BATTERY_LEVEL_LOW + 1) BATTERY_LEVEL_FULL>;
3028

3129
color-0 {
3230
led-color = <&color_off>;

zephyr/program/lotus/include/board_function.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ int chassis_cmd_clear(int type);
2424

2525
__override_proto void project_chassis_function(enum gpio_signal signal);
2626

27+
uint32_t get_system_percentage(void);
28+
2729
#endif /* __CROS_EC_BOARD_FUNCTION_H */

zephyr/program/lotus/lotus/led_policy.dtsi

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
power-state-charge {
88
charge-state = "LED_PWRS_CHARGE";
9-
/* Battery percent range (>= 0, <= 96) */
10-
batt-lvl = <BATTERY_LEVEL_EMPTY 96>;
9+
/* Battery percent range (>= 0, < 96) */
10+
batt-lvl = <BATTERY_LEVEL_EMPTY 95>;
1111
color-0 {
1212
led-color = <&color_amber>;
1313
};
1414
};
1515

1616
power-state-charge-lvl-2 {
1717
charge-state = "LED_PWRS_CHARGE";
18-
/* Battery percent range (>= 97%, <= 100%) */
19-
batt-lvl = <97 100>;
18+
/* Battery percent range (>= 96%, <= 100%) */
19+
batt-lvl = <96 100>;
2020

2121
color-0 {
2222
led-color = <&color_white>;
@@ -25,8 +25,6 @@
2525

2626
power-state-discharge {
2727
charge-state = "LED_PWRS_DISCHARGE";
28-
/* Battery percent range (>= 11, <= 97) */
29-
batt-lvl = <(BATTERY_LEVEL_LOW + 1) BATTERY_LEVEL_FULL>;
3028

3129
color-0 {
3230
led-color = <&color_off>;
@@ -47,11 +45,11 @@
4745

4846
color-0 {
4947
led-color = <&color_red>;
50-
period-ms = <500>;
48+
period-ms = <1000>;
5149
};
5250
color-1 {
5351
led-color = <&color_blue>;
54-
period-ms = <500>;
52+
period-ms = <1000>;
5553
};
5654
};
5755

zephyr/program/lotus/lotus/src/battery.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "battery_smart.h"
1010
#include "battery_fuel_gauge.h"
1111
#include "board_adc.h"
12+
#include "board_function.h"
1213
#include "board_host_command.h"
1314
#include "charger.h"
1415
#include "charge_state.h"
@@ -77,16 +78,22 @@ static void enable_check_battery_timer(void)
7778
}
7879
DECLARE_HOOK(HOOK_INIT, enable_check_battery_timer, HOOK_PRIO_DEFAULT);
7980

81+
uint32_t get_system_percentage(void)
82+
{
83+
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
84+
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
85+
86+
return 1000 * memmap_cap / (memmap_lfcc + 1);
87+
88+
}
89+
8090
static void battery_percentage_control(void)
8191
{
8292
enum ec_charge_control_mode new_mode;
8393
static int in_percentage_control;
84-
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
85-
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
86-
uint32_t batt_os_percentage;
94+
uint32_t batt_os_percentage = get_system_percentage();
8795
int rv;
8896

89-
batt_os_percentage = 1000 * memmap_cap / (memmap_lfcc + 1);
9097
/**
9198
* If the host command EC_CMD_CHARGE_CONTROL set control mode to CHARGE_CONTROL_DISCHARGE
9299
* or CHARGE_CONTROL_IDLE, ignore the battery_percentage_control();

zephyr/program/lotus/src/led.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "system.h"
2525
#include "util.h"
2626

27+
#include "board_function.h"
2728
#include "cypress_pd_common.h"
2829
#include "diagnostics.h"
2930
#include "lid_switch.h"
@@ -274,7 +275,7 @@ static int match_node(int node_idx)
274275
/* Check if this node depends on battery level */
275276
if (node_array[node_idx].batt_lvl[0] != -1) {
276277
int curr_batt_lvl =
277-
DIV_ROUND_NEAREST(charge_get_display_charge(), 10);
278+
DIV_ROUND_NEAREST(get_system_percentage(), 10);
278279

279280
if ((curr_batt_lvl < node_array[node_idx].batt_lvl[0]) ||
280281
(curr_batt_lvl > node_array[node_idx].batt_lvl[1]))

0 commit comments

Comments
 (0)