Skip to content

Commit 66bc141

Browse files
committed
nicla-system: Add API for operating system.
1 parent 254eecb commit 66bc141

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

libraries/Nicla_System/examples/NiclaSenseME_BatteryStatus/NiclaSenseME_BatteryStatus.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ void setup()
167167
setupBLE();
168168

169169
nicla::leds.setColor(green);
170+
171+
nicla::enableCharge();
170172
}
171173

172174
void loop()
@@ -216,6 +218,11 @@ void loop()
216218

217219
auto chargeLevel = nicla::getBatteryChargeLevel();
218220
Serial.println("Battery is " + getBatteryChargeLevelDescription(chargeLevel));
221+
222+
bool isCharging = nicla::getOperatingStatus() == OperatingStatus::Charging;
223+
Serial.print("Battery is charging: ");
224+
Serial.println(isCharging ? "Yes" : "No");
225+
219226
Serial.println("----------------------");
220227
}
221228
}

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ uint8_t nicla::getBatteryTemperature() {
319319
return getBatteryStatus() & BATTERY_TEMPERATURE_MASK;
320320
}
321321

322+
323+
OperatingStatus nicla::getOperatingStatus() {
324+
// Extract bits 6 and 7
325+
uint8_t status = _pmic.getStatus() >> 6 & 0b11;
326+
return static_cast<OperatingStatus>(status);
327+
}
328+
329+
322330
void nicla::synchronizeFastChargeSettings()
323331
{
324332
if (_fastChargeRegisterData != _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG)) {

libraries/Nicla_System/src/Nicla_System.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
#define USE_FASTCHG_TO_KICK_WATCHDOG 1
1212

13+
enum class OperatingStatus {
14+
Ready = 0b00,
15+
Charging = 0b01,
16+
ChargingComplete = 0b10,
17+
Error = 0b11
18+
};
19+
1320
// 3 bits are used to indicate the battery charge level
1421
#define BATTERY_CHARGE_MASK 0b00000111
1522
#define BATTERY_FULL 5 // Bit pattern: 101
@@ -26,8 +33,6 @@
2633
#define BATTERY_TEMPERTURE_COOL (2 << 4)
2734
#define BATTERY_TEMPERTURE_WARM (3 << 4)
2835

29-
#define BATTERY_CHARGING (1 << 7)
30-
3136
class nicla {
3237

3338
public:
@@ -133,6 +138,13 @@ class nicla {
133138
static uint8_t getBatteryFaults();
134139

135140

141+
/**
142+
* @brief Get the current operating status of the PMIC.
143+
*
144+
* @return OperatingStatus One of the following: Ready, Charging, ChargingComplete, Error.
145+
*/
146+
static OperatingStatus getOperatingStatus();
147+
136148
static RGBled leds;
137149
static BQ25120A _pmic;
138150

0 commit comments

Comments
 (0)