Skip to content

Commit

Permalink
Added Charging Safety Timer Management
Browse files Browse the repository at this point in the history
Added Charging Safety Timer Management in order to fix arduino-libraries#11
  • Loading branch information
Rocketct committed Jun 10, 2022
1 parent bc6ea2c commit da39f78
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/BQ24195.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,15 @@ bool PMICClass::enableCharging() {
DATA = DATA & 0b11001111;
DATA = DATA | 0b00010000;
return writeRegister(POWERON_CONFIG_REGISTER, DATA);

// enable Charging Safety Timer
DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);

if (DATA == -1) {
return 0;
}

return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA | 0b00001000));
}

/*******************************************************************************
Expand All @@ -475,7 +484,18 @@ bool PMICClass::disableCharging() {
return 0;
}

return writeRegister(POWERON_CONFIG_REGISTER, DATA & 0xCF);
if (writeRegister(POWERON_CONFIG_REGISTER, DATA & 0xCF)){
return 0;
}

// disable Charging Safety Timer
DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);

if (DATA == -1) {
return 0;
}

return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11110110));
}

/*******************************************************************************
Expand Down Expand Up @@ -773,6 +793,46 @@ bool PMICClass::disableWatchdog(void) {
return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11001110));
}

/*******************************************************************************
* Function Name : enableSafetyChargeTimer
* Description : Enable Safety Charge timer
* Input : NONE
* Return : 0 on Error, 1 on Success
*******************************************************************************/
bool PMICClass::enableSafetyChargeTimer(void) {

int DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);

if (DATA == -1) {
return 0;
}

return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA | 0b00001000));
}


/*******************************************************************************
* Function Name : disableSafetyChargeTimer
* Description : Disable Safety Charge timer
* Input : NONE
* Return : 0 on Error, 1 on Success
*******************************************************************************/
bool PMICClass::disableSafetyChargeTimer(void) {
int DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER) & 0x30;

if (DATA == 0x10 && PMIC.chargeStatus() != CHARGE_TERMINATION_DONE )){
return 0;
}

DATA = readRegister(CHARGE_TIMER_CONTROL_REGISTER);

if (DATA == -1) {
return 0;
}

return writeRegister(CHARGE_TIMER_CONTROL_REGISTER, (DATA & 0b11110110));
}

/*******************************************************************************
* Function Name : setThermalRegulationTemperature
* Description : Sets the Thermal Regulation Threshold
Expand Down
2 changes: 2 additions & 0 deletions src/BQ24195.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class PMICClass {

// Charge Timer Control Register
bool disableWatchdog(void);
bool enableSafetyChargeTimer(void);
bool disableSafetyChargeTimer(void);

// Misc Operation Control Register
bool enableDPDM(void);
Expand Down

0 comments on commit da39f78

Please sign in to comment.