Skip to content

Commit 9b9c616

Browse files
committed
nicla-system: Add getter for fast charge register.
1 parent 8c55e88 commit 9b9c616

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

libraries/Nicla_System/src/BQ25120A.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ uint8_t BQ25120A::getFaultsRegister()
2020
return readByte(BQ25120A_ADDRESS, BQ25120A_FAULTS);
2121
}
2222

23+
uint8_t BQ25120A::getFastChargeControlRegister()
24+
{
25+
return readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG);
26+
}
27+
2328
void BQ25120A::writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
2429
{
2530
setHighImpedanceModeEnabled(false);

libraries/Nicla_System/src/BQ25120A.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class BQ25120A
4141
*/
4242
uint8_t getFaultsRegister();
4343

44+
/**
45+
* @brief Gets the data from the fast charge control register.
46+
* @see Section 9.6.4 of the datasheet.
47+
*
48+
* @return uint8_t The data from the fast charge control register.
49+
*/
50+
uint8_t getFastChargeControlRegister();
51+
4452
/**
4553
* @brief Writes a byte to the BQ25120A over I2C.
4654
* @param address The I2C address of the BQ25120A.

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool nicla::begin(bool mountedOnMkr)
3333
digitalWrite(P0_10, HIGH);
3434
}
3535
Wire1.begin();
36-
_fastChargeRegisterData = _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG);
36+
_fastChargeRegisterData = _pmic.getFastChargeControlRegister();
3737
#ifndef NO_NEED_FOR_WATCHDOG_THREAD
3838
static rtos::Thread th(osPriorityHigh, 768, nullptr, "ping_thread");
3939
th.start(&nicla::pingI2C);
@@ -132,7 +132,7 @@ bool nicla::enableCharge(uint8_t mA, bool disableNtc)
132132
// also set max battery voltage to 4.2V (VBREG)
133133
// _pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_BATTERY_CTRL, (4.2f - 3.6f)*100);
134134

135-
return _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG) == _fastChargeRegisterData;
135+
return _pmic.getFastChargeControlRegister() == _fastChargeRegisterData;
136136
}
137137

138138
uint8_t nicla::getBatteryFaults() {
@@ -324,7 +324,7 @@ OperatingStatus nicla::getOperatingStatus() {
324324

325325
void nicla::synchronizeFastChargeSettings()
326326
{
327-
if (_fastChargeRegisterData != _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG)) {
327+
if (_fastChargeRegisterData != _pmic.getFastChargeControlRegister()) {
328328
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _fastChargeRegisterData);
329329
}
330330
}

0 commit comments

Comments
 (0)