Skip to content

Commit fcd8e80

Browse files
authored
Merge pull request #31 from alexsee75/master
Added FastChargeTimer Setting (get and set)
2 parents 301cce3 + 1ba3157 commit fcd8e80

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/BQ24195.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ enum Current_Limit_mask {
5050
CURRENT_LIM_3000,
5151
};
5252

53+
enum Fast_Charge_Timer_Setting {
54+
FAST_CHARGE_TIMER_05H = 0b000,
55+
FAST_CHARGE_TIMER_08H = 0b010,
56+
FAST_CHARGE_TIMER_12H = 0b100,
57+
FAST_CHARGE_TIMER_20H = 0b110
58+
};
59+
60+
enum Charge_Timer_Control_Register_Bits {
61+
CHARGE_TIMER_CONTROL_REGISTER_RESERVED = 0,
62+
CHARGE_TIMER_CONTROL_REGISTER_CHG_TIMER_0,
63+
CHARGE_TIMER_CONTROL_REGISTER_CHG_TIMER_1,
64+
CHARGE_TIMER_CONTROL_REGISTER_EN_TIMER,
65+
CHARGE_TIMER_CONTROL_REGISTER_WATCHDOG_0,
66+
CHARGE_TIMER_CONTROL_REGISTER_WATCHDOG_1,
67+
CHARGE_TIMER_CONTROL_REGISTER_TERM_STAT,
68+
CHARGE_TIMER_CONTROL_REGISTER_EN_TERM
69+
};
70+
5371
PMICClass::PMICClass(TwoWire & wire) :
5472
_wire(&wire)
5573
{
@@ -1195,6 +1213,73 @@ bool PMICClass::isBatteryInOverVoltage() {
11951213
return 0;
11961214
}
11971215

1216+
1217+
/*******************************************************************************
1218+
* Function Name : setFastChargeTimerSetting
1219+
* Description : Sets the charging safety timer
1220+
* Input : safety timer duration in hours (rounds up)
1221+
* Return : 0 on Error, 1 on Success
1222+
*******************************************************************************/
1223+
bool PMICClass::setFastChargeTimerSetting(float const hours) {
1224+
1225+
int const DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);
1226+
1227+
if (DATA == -1) {
1228+
return 0;
1229+
}
1230+
1231+
// first disable timer
1232+
if (!writeRegister(CHARGE_TIMER_CONTROL_REGISTER, DATA & ~((1<<CHARGE_TIMER_CONTROL_REGISTER_EN_TIMER)))) {
1233+
return 0;
1234+
}
1235+
1236+
// mask out previous fast charge timer value and ensure timer is enabled afterwards
1237+
byte mask = DATA & ~((1<<CHARGE_TIMER_CONTROL_REGISTER_CHG_TIMER_0) | (1<<CHARGE_TIMER_CONTROL_REGISTER_CHG_TIMER_1)) | (1<<CHARGE_TIMER_CONTROL_REGISTER_EN_TIMER);
1238+
byte timer_val;
1239+
1240+
if (hours > 12) {
1241+
timer_val = FAST_CHARGE_TIMER_20H;
1242+
} else if (hours > 8) {
1243+
timer_val = FAST_CHARGE_TIMER_12H;
1244+
} else if (hours > 5) {
1245+
timer_val = FAST_CHARGE_TIMER_08H;
1246+
} else {
1247+
timer_val = FAST_CHARGE_TIMER_05H;
1248+
}
1249+
1250+
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (mask | timer_val));
1251+
}
1252+
1253+
/*******************************************************************************
1254+
* Function Name : getFastChargeTimerSetting
1255+
* Description : Query the PMIC and returns the fast charge timer setting
1256+
* Input : NONE
1257+
* Return : NAN on Error, fast charge timer limit value on Success
1258+
*******************************************************************************/
1259+
float PMICClass::getFastChargeTimerSetting(void) {
1260+
int const DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);
1261+
1262+
if (DATA == -1) {
1263+
return NAN;
1264+
}
1265+
1266+
byte mask = DATA & ((1<<CHARGE_TIMER_CONTROL_REGISTER_CHG_TIMER_0) | (1<<CHARGE_TIMER_CONTROL_REGISTER_CHG_TIMER_1));
1267+
1268+
switch (mask) {
1269+
case FAST_CHARGE_TIMER_05H:
1270+
return 5.0;
1271+
case FAST_CHARGE_TIMER_08H:
1272+
return 8.0;
1273+
case FAST_CHARGE_TIMER_12H:
1274+
return 12.0;
1275+
case FAST_CHARGE_TIMER_20H:
1276+
return 20.0;
1277+
default:
1278+
return NAN;
1279+
}
1280+
return NAN;
1281+
}
1282+
11981283
/*******************************************************************************
11991284
* Function Name : getVersion
12001285
* Description : Return the version number of the chip

src/BQ24195.h

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class PMICClass {
8686

8787
// Charge Timer Control Register
8888
bool disableWatchdog(void);
89+
float getFastChargeTimerSetting();
90+
bool setFastChargeTimerSetting(float const hours);
8991

9092
// Misc Operation Control Register
9193
bool enableDPDM(void);

0 commit comments

Comments
 (0)