@@ -150,14 +150,22 @@ bool nicla::enableCharging(uint16_t mA)
150150 // Also sets the input current limit to 350mA.
151151 _pmic.writeByte (BQ25120A_ADDRESS, BQ25120A_ILIM_UVLO_CTRL, 0x3F );
152152
153- // Set safety timer to 9 hours (Bit 1+2 0b10) to give the battery enough of time to charge.
154- // Set it to 0b11 to disable safety timers. See: Table 24 in the datasheet.
155- uint8_t dpmTimerRegisterData = _pmic.readByte (BQ25120A_ADDRESS, BQ25120A_VIN_DPM);
156- dpmTimerRegisterData |= 0b00000100 ; // Set Bit 2 to 1
157- dpmTimerRegisterData &= 0b11111101 ; // Set Bit 1 to 0
153+ configureChargingSafetyTimer (ChargingSafetyTimerOption::NineHours);
154+
155+ return _pmic.getFastChargeControlRegister () == _fastChargeRegisterData;
156+ }
157+
158+ bool nicla::configureChargingSafetyTimer (ChargingSafetyTimerOption option){
159+ // See: Table 24 in the datasheet.
160+ // The two bits need to be shifted to skip the unused LSB.
161+ uint8_t timerValue = static_cast <uint8_t >(option) << 1 ;
162+ uint8_t dpmTimerRegisterData = _pmic.readByte (BQ25120A_ADDRESS, BQ25120A_VIN_DPM);
163+
164+ dpmTimerRegisterData &= 0b11111001 ; // Clear bits 1 and 2
165+ dpmTimerRegisterData |= timerValue; // Update bits 1 and 2
158166 _pmic.writeByte (BQ25120A_ADDRESS, BQ25120A_VIN_DPM, dpmTimerRegisterData);
159167
160- return _pmic.getFastChargeControlRegister ( ) == _fastChargeRegisterData ;
168+ return _pmic.readByte (BQ25120A_ADDRESS, BQ25120A_VIN_DPM ) == dpmTimerRegisterData ;
161169}
162170
163171bool nicla::disableCharging ()
0 commit comments