Skip to content

Commit da39f78

Browse files
committed
Added Charging Safety Timer Management
Added Charging Safety Timer Management in order to fix #11
1 parent bc6ea2c commit da39f78

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/BQ24195.cpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ bool PMICClass::enableCharging() {
459459
DATA = DATA & 0b11001111;
460460
DATA = DATA | 0b00010000;
461461
return writeRegister(POWERON_CONFIG_REGISTER, DATA);
462+
463+
// enable Charging Safety Timer
464+
DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);
465+
466+
if (DATA == -1) {
467+
return 0;
468+
}
469+
470+
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA | 0b00001000));
462471
}
463472

464473
/*******************************************************************************
@@ -475,7 +484,18 @@ bool PMICClass::disableCharging() {
475484
return 0;
476485
}
477486

478-
return writeRegister(POWERON_CONFIG_REGISTER, DATA & 0xCF);
487+
if (writeRegister(POWERON_CONFIG_REGISTER, DATA & 0xCF)){
488+
return 0;
489+
}
490+
491+
// disable Charging Safety Timer
492+
DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);
493+
494+
if (DATA == -1) {
495+
return 0;
496+
}
497+
498+
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11110110));
479499
}
480500

481501
/*******************************************************************************
@@ -773,6 +793,46 @@ bool PMICClass::disableWatchdog(void) {
773793
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11001110));
774794
}
775795

796+
/*******************************************************************************
797+
* Function Name : enableSafetyChargeTimer
798+
* Description : Enable Safety Charge timer
799+
* Input : NONE
800+
* Return : 0 on Error, 1 on Success
801+
*******************************************************************************/
802+
bool PMICClass::enableSafetyChargeTimer(void) {
803+
804+
int DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);
805+
806+
if (DATA == -1) {
807+
return 0;
808+
}
809+
810+
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA | 0b00001000));
811+
}
812+
813+
814+
/*******************************************************************************
815+
* Function Name : disableSafetyChargeTimer
816+
* Description : Disable Safety Charge timer
817+
* Input : NONE
818+
* Return : 0 on Error, 1 on Success
819+
*******************************************************************************/
820+
bool PMICClass::disableSafetyChargeTimer(void) {
821+
int DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER) & 0x30;
822+
823+
if (DATA == 0x10 && PMIC.chargeStatus() != CHARGE_TERMINATION_DONE )){
824+
return 0;
825+
}
826+
827+
DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);
828+
829+
if (DATA == -1) {
830+
return 0;
831+
}
832+
833+
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11110110));
834+
}
835+
776836
/*******************************************************************************
777837
* Function Name : setThermalRegulationTemperature
778838
* Description : Sets the Thermal Regulation Threshold

src/BQ24195.h

Lines changed: 2 additions & 0 deletions
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+
bool enableSafetyChargeTimer(void);
90+
bool disableSafetyChargeTimer(void);
8991

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

0 commit comments

Comments
 (0)