@@ -50,6 +50,24 @@ enum Current_Limit_mask {
50
50
CURRENT_LIM_3000,
51
51
};
52
52
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
+
53
71
PMICClass::PMICClass (TwoWire & wire) :
54
72
_wire(&wire)
55
73
{
@@ -1195,6 +1213,73 @@ bool PMICClass::isBatteryInOverVoltage() {
1195
1213
return 0 ;
1196
1214
}
1197
1215
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
+
1198
1283
/* ******************************************************************************
1199
1284
* Function Name : getVersion
1200
1285
* Description : Return the version number of the chip
0 commit comments