Skip to content

Commit edaf109

Browse files
committed
nicla-system: Use getFaultsRegister to query faults register.
1 parent 3b0af63 commit edaf109

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

libraries/Nicla_System/src/BQ25120A.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ uint8_t BQ25120A::getStatusRegister()
1515
return readByte(BQ25120A_ADDRESS, BQ25120A_STATUS);
1616
}
1717

18+
uint8_t BQ25120A::getFaultsRegister()
19+
{
20+
return readByte(BQ25120A_ADDRESS, BQ25120A_FAULTS);
21+
}
22+
1823
void BQ25120A::writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
1924
{
2025
setHighImpedanceModeEnabled(false);

libraries/Nicla_System/src/BQ25120A.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class BQ25120A
2626
BQ25120A() {};
2727

2828
uint8_t getStatusRegister();
29+
uint8_t getFaultsRegister();
30+
2931
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data);
3032
uint8_t readByte(uint8_t address, uint8_t subAddress);
3133

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool nicla::enableCharge(uint8_t mA, bool disableNtc)
137137

138138
uint8_t nicla::getBatteryFaults() {
139139
// Skips the mask bits (4 LSBs)
140-
return (_pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAULTS) >> 4) & 0b1111;
140+
return (_pmic.getFaultsRegister() >> 4) & 0b1111;
141141
}
142142

143143
void nicla::setBatteryNTCEnabled(bool enabled){
@@ -222,7 +222,7 @@ int8_t nicla::getBatteryPercentage(bool useLatchedValue) {
222222
Example: 0 11 111 00 -> 90% + 8% = 98 - 100% of VBATREG
223223
*/
224224
constexpr uint8_t BAT_UVLO_FAULT = 0b00100000; // Battery Under-Voltage Lock-Out fault
225-
uint8_t faults = _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAULTS);
225+
uint8_t faults = _pmic.getFaultsRegister();
226226
if(faults & BAT_UVLO_FAULT) return -1; // Battery is not connected or voltage is too low
227227

228228
// Write 1 to VBMON_READ to trigger a new reading

0 commit comments

Comments
 (0)