@@ -18,11 +18,13 @@ uint8_t nicla::_fastChargeRegisterData = 0;
18
18
// / Enabled is the default value also represented in the TS Control Register (Bit 7 = 1).
19
19
bool nicla::_ntcEnabled = true ;
20
20
21
- void nicla::pingI2C () {
22
- while (1 ) {
23
- // already protected by a mutex on Wire operations
24
- synchronizeFastChargeSettings ();
25
- delay (10000 );
21
+ void nicla::pingI2C (bool useWriteOperation) {
22
+ // PMIC commands already protected by a mutex on Wire operations.
23
+ if (useWriteOperation){
24
+ // Write the current charging settings to the register to reset the watchdog timer.
25
+ _pmic.writeByte (BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _fastChargeRegisterData);
26
+ } else {
27
+ _pmic.getStatusRegister ();
26
28
}
27
29
}
28
30
@@ -36,9 +38,16 @@ bool nicla::begin(bool mountedOnMkr)
36
38
}
37
39
Wire1.begin ();
38
40
_fastChargeRegisterData = _pmic.getFastChargeControlRegister ();
41
+
39
42
#ifndef NO_NEED_FOR_WATCHDOG_THREAD
43
+ // If not using the BHY2 library, we need to start a thread to ping the PMIC every 10 seconds.
40
44
static rtos::Thread th (osPriorityHigh, 768 , nullptr , " ping_thread" );
41
- th.start (&nicla::pingI2C);
45
+ th.start ([]() {
46
+ while (1 ) {
47
+ pingI2C ();
48
+ delay (10000 );
49
+ }
50
+ });
42
51
#endif
43
52
started = true ;
44
53
@@ -390,16 +399,8 @@ OperatingStatus nicla::getOperatingStatus() {
390
399
return static_cast <OperatingStatus>(status);
391
400
}
392
401
393
-
394
- void nicla::synchronizeFastChargeSettings ()
395
- {
396
- if (_fastChargeRegisterData != _pmic.getFastChargeControlRegister ()) {
397
- _pmic.writeByte (BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _fastChargeRegisterData);
398
- }
399
- }
400
-
401
402
void nicla::checkChgReg (){
402
- synchronizeFastChargeSettings ();
403
+ pingI2C ();
403
404
}
404
405
405
406
0 commit comments