This class provides APIs to all of the registers of the TI BQ24295 battery charger chip, as used on the u-blox C030 board. This class is not required to charge a battery connected to the C030 board, charging will begin automatically when a battery is connected. This class is only required if the user wishes to monitor the charger's state or change the charger's settings. The caller should instantiate an I2C interface and pass this to init(), which will initialise the chip and place it into its lowest power state. The chip may then be configured using the API calls. Once the chip is configured, battery charging can be enabled. If battery charging is disabled the chip will once more be put into its lowest power state.

Dependents:   example-battery-charger-bq24295 example-C030-out-of-box-demo example-C030-out-of-box-demo Amit

Revision:
3:340d65a1a133
Parent:
2:f0bbe0269d67
Child:
7:cc08662947cd
--- a/bq24295.cpp	Tue Apr 11 09:56:38 2017 +0000
+++ b/bq24295.cpp	Tue Jun 06 12:59:11 2017 +0100
@@ -1665,6 +1665,103 @@
     return bitmap;
 }
 
+// Feed the watchdog timer of the BQ24295 chip.
+bool BatteryChargerBq24295::feedWatchdog (void)
+{
+    bool success = false;
+
+    if (gReady && (gpI2c != NULL)) {
+        gpI2c->lock();
+        // Watchdog reset is done by setting bit 6 of the power on control register
+        // to 1
+        success = setRegisterBits(0x01, (1 << 6));
+#ifdef DEBUG_BQ24295
+        if (success) {
+            printf("BatteryChargerBq24295 (I2C 0x%02x): watchdog fed.\r\n", gAddress >> 1);
+        }
+#endif
+        gpI2c->unlock();
+    }
+
+    return success;
+}
+
+// Get the watchdog timer of the BQ24295 chip.
+bool BatteryChargerBq24295::getWatchdog (int32_t *pWatchdogS)
+{
+    bool success = false;
+    char reg;
+
+    if (gReady && (gpI2c != NULL)) {
+        gpI2c->lock();
+        // Watchdog timer is in bits 4 and 5 of the charger termination/timer control
+        // register, where 0 is disabled 01 is 40 secs, 10 is 80 secs and 11 is 160 secs
+        success = getRegister(0x05, &reg);
+        if (pWatchdogS != NULL) {
+            switch ((reg >> 4) & 0x03) {
+                case 0x00:
+                    *pWatchdogS = 0;
+                break;
+                case 0x01:
+                    *pWatchdogS = 40;
+                break;
+                case 0x02:
+                    *pWatchdogS = 80;
+                break;
+                case 0x03:
+                    *pWatchdogS = 160;
+                break;
+                default:
+                    MBED_ASSERT(false);
+                break;
+            }
+#ifdef DEBUG_BQ24295
+            if (success) {
+                printf("BatteryChargerBq24295 (I2C 0x%02x): watchdog is %d seconds.\r\n", gAddress >> 1, *pWatchdogS);
+            }
+#endif
+        }
+        gpI2c->unlock();
+    }
+
+    return success;
+}
+
+// Set the watchdog timer of the BQ24295 chip.
+bool BatteryChargerBq24295::setWatchdog (int32_t watchdogS)
+{
+    bool success = false;
+    char reg;
+    char regValue = 0;
+
+    if (gReady && (gpI2c != NULL)) {
+        gpI2c->lock();
+        // Watchdog timer is in bits 4 and 5 of the charger termination/timer control
+        // register, where 0 is disabled 01 is 40 secs, 10 is 80 secs and 11 is 160 secs
+        if (watchdogS > 80) {
+            regValue = 0x03;
+        } else if (watchdogS > 40) {
+            regValue = 0x02;
+        } else if (watchdogS > 0) {
+            regValue = 0x01;
+        }
+        if (getRegister(0x05, &reg)) {
+            // Clear the bits then set them
+            reg &= ~(0x03 << 4);
+            reg |= regValue << 4;
+            success = setRegister(0x05, reg);
+#ifdef DEBUG_BQ24295
+            if (success) {
+                printf("BatteryChargerBq24295 (I2C 0x%02x): watchdog set to %d seconds.\r\n", gAddress >> 1, watchdogS);
+            }
+#endif
+        }
+        gpI2c->unlock();
+    }
+
+    return success;
+}
+
 // Enable shipping mode.
 bool BatteryChargerBq24295::enableShippingMode (void)
 {