Skip to content

Commit 5bbdc85

Browse files
committed
[modify] stop polling when BP is YES
Signed-off-by: Leo_Tsai <[email protected]>
1 parent 09b7776 commit 5bbdc85

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

board/hx20/battery.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static const struct battery_info info = {
4040
.discharging_max_c = 62,
4141
};
4242

43+
static enum battery_present batt_pres_prev = BP_NOT_SURE;
4344
static uint8_t charging_maximum_level = NEED_RESTORE;
4445
static int old_btp;
4546

@@ -100,20 +101,31 @@ static int battery_check_disconnect(void)
100101

101102
enum battery_present battery_is_present(void)
102103
{
103-
enum battery_present bp;
104+
enum battery_present batt_pres;
104105
int mv;
105106

106107
mv = adc_read_channel(ADC_VCIN1_BATT_TEMP);
107-
bp = (mv < 3000 ? BP_YES : BP_NO);
108+
batt_pres = (mv < 3000 ? BP_YES : BP_NO);
108109

109110
if (mv == ADC_READ_ERROR)
110111
return BP_NO;
111-
else if (!bp)
112+
113+
/*
114+
* If the battery is present now and was present last time we checked,
115+
* return early.
116+
*/
117+
if (batt_pres == BP_YES && batt_pres_prev == batt_pres)
118+
return batt_pres;
119+
120+
121+
if (!batt_pres)
112122
return BP_NO;
113123
else if (battery_check_disconnect() != BATTERY_NOT_DISCONNECTED)
114124
return BP_NOT_SURE;
115-
else
116-
return bp;
125+
126+
batt_pres_prev = batt_pres;
127+
128+
return batt_pres;
117129
}
118130

119131
#ifdef CONFIG_EMI_REGION1

0 commit comments

Comments
 (0)