Skip to content

Commit 79cf7e4

Browse files
authored
azalea: return valid os percentage (#945)
Signed-off-by: LeilaCY-Lin <LeilaCY_Lin@compal.com>
1 parent d2b3a16 commit 79cf7e4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,17 @@ enum battery_present battery_is_present(void)
5252

5353
uint32_t get_system_percentage(void)
5454
{
55+
static uint32_t pre_os_percentage;
5556
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
5657
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
57-
58-
return 1000 * memmap_cap / (memmap_lfcc + 1);
58+
uint32_t os_percentage = 1000 * memmap_cap / (memmap_lfcc + 1);
59+
60+
/* ensure this value is valid */
61+
if (os_percentage <= 1000 && os_percentage >= 0) {
62+
pre_os_percentage = os_percentage;
63+
return os_percentage;
64+
} else
65+
return pre_os_percentage;
5966
}
6067

6168
static void battery_percentage_control(void)

0 commit comments

Comments
 (0)