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:
2:f0bbe0269d67
Parent:
1:ed57b6ca43ab
Child:
3:340d65a1a133
--- a/bq24295.cpp	Mon Apr 10 11:04:15 2017 +0100
+++ b/bq24295.cpp	Tue Apr 11 09:56:38 2017 +0000
@@ -29,19 +29,19 @@
 # include <stdio.h>
 #endif
 
-// ----------------------------------------------------------------
-// COMPILE-TIME MACROS
-// ----------------------------------------------------------------
+/* ----------------------------------------------------------------
+ * COMPILE-TIME MACROS
+ * -------------------------------------------------------------- */
 
-// ----------------------------------------------------------------
-// PRIVATE VARIABLES
-// ----------------------------------------------------------------
+/* ----------------------------------------------------------------
+ * PRIVATE VARIABLES
+ * -------------------------------------------------------------- */
 
-// ----------------------------------------------------------------
-// GENERIC PRIVATE FUNCTIONS
-// ----------------------------------------------------------------
+/* ----------------------------------------------------------------
+ * GENERIC PRIVATE FUNCTIONS
+ * -------------------------------------------------------------- */
 
-/// Read from a register.
+// Read from a register.
 bool BatteryChargerBq24295::getRegister(char address, char *pValue)
 {
     bool success = false;
@@ -66,7 +66,7 @@
     return success;
 }
 
-/// Write to a register.
+// Write to a register.
 bool BatteryChargerBq24295::setRegister(char address, char value)
 {
     bool success = false;
@@ -86,7 +86,7 @@
     return success;
 }
 
-/// Set a mask of bits in a register.
+// Set a mask of bits in a register.
 bool BatteryChargerBq24295::setRegisterBits(char address, char mask)
 {
     bool success = false;
@@ -102,7 +102,7 @@
     return success;
 }
 
-/// Clear a mask of bits in a register.
+// Clear a mask of bits in a register.
 bool BatteryChargerBq24295::clearRegisterBits(char address, char mask)
 {
     bool success = false;
@@ -118,23 +118,23 @@
     return success;
 }
 
-//----------------------------------------------------------------
-// PUBLIC FUNCTIONS
-// ----------------------------------------------------------------
+/* ----------------------------------------------------------------
+ * PUBLIC FUNCTIONS
+ * -------------------------------------------------------------- */
 
-/// Constructor.
+// Constructor.
 BatteryChargerBq24295::BatteryChargerBq24295(void)
 {
     gpI2c = NULL;
     gReady = false;
 }
 
-/// Destructor.
+// Destructor.
 BatteryChargerBq24295::~BatteryChargerBq24295(void)
 {
 }
 
-/// Initialise ourselves.
+// Initialise ourselves.
 bool BatteryChargerBq24295::init (I2C * pI2c, uint8_t address)
 {
     char reg;
@@ -166,7 +166,7 @@
     return gReady;
 }
 
-/// Get the charge state.
+// Get the charge state.
 BatteryChargerBq24295::ChargerState BatteryChargerBq24295::getChargerState(void)
 {
     BatteryChargerBq24295::ChargerState chargerState = CHARGER_STATE_UNKNOWN;
@@ -233,7 +233,7 @@
     return chargerState;
 }
 
-/// Get whether external power is present or not.
+// Get whether external power is present or not.
 bool BatteryChargerBq24295::isExternalPowerPresent(void)
 {
     bool isPresent = false;
@@ -282,7 +282,7 @@
     return success;
 }
 
-/// Disable charging.
+// Disable charging.
 bool BatteryChargerBq24295::disableCharging (void)
 {
     bool success = false;
@@ -302,7 +302,7 @@
     return success;
 }
 
-/// Get the whether charging is enabled or disabled.
+// Get the whether charging is enabled or disabled.
 bool BatteryChargerBq24295::isChargingEnabled (void)
 {
     bool isEnabled = false;
@@ -330,7 +330,7 @@
     return isEnabled;
 }
 
-/// Enable OTG charging.
+// Enable OTG charging.
 bool BatteryChargerBq24295::enableOtg (void)
 {
     bool success = false;
@@ -350,7 +350,7 @@
     return success;
 }
 
-/// Disable OTG charging.
+// Disable OTG charging.
 bool BatteryChargerBq24295::disableOtg (void)
 {
     bool success = false;
@@ -370,7 +370,7 @@
     return success;
 }
 
-/// Get whether OTG charging is enabled or not.
+// Get whether OTG charging is enabled or not.
 bool BatteryChargerBq24295::isOtgEnabled (void)
 {
     bool isEnabled = false;
@@ -398,7 +398,7 @@
     return isEnabled;
 }
 
-/// Set the system voltage.
+// Set the system voltage.
 bool BatteryChargerBq24295::setSystemVoltage (int32_t voltageMV)
 {
     bool success = false;
@@ -440,7 +440,7 @@
     return success;
 }
 
-/// Get the system voltage.
+// Get the system voltage.
 bool BatteryChargerBq24295::getSystemVoltage (int32_t *pVoltageMV)
 {
     bool success = false;
@@ -470,7 +470,7 @@
     return success;
 }
 
-/// Set the fast charging current limit.
+// Set the fast charging current limit.
 bool BatteryChargerBq24295::setFastChargingCurrentLimit (int32_t currentMA)
 {
     bool success = false;
@@ -506,7 +506,7 @@
     return success;
 }
 
-/// Get the fast charging current limit.
+// Get the fast charging current limit.
 bool BatteryChargerBq24295::getFastChargingCurrentLimit (int32_t *pCurrentMA)
 {
     bool success = false;
@@ -536,7 +536,7 @@
     return success;
 }
 
-/// Enable the ICHG/IPRECH margin.
+// Enable the ICHG/IPRECH margin.
 bool BatteryChargerBq24295::enableIcghIprechMargin (void)
 {
     bool success = false;
@@ -556,7 +556,7 @@
     return success;
 }
 
-/// Disable the ICHG/IPRECH margin.
+// Disable the ICHG/IPRECH margin.
 bool BatteryChargerBq24295::disableIcghIprechMargin (void)
 {
     bool success = false;
@@ -576,7 +576,7 @@
     return success;
 }
 
-/// Check if the ICHG/IPRECH margin is set.
+// Check if the ICHG/IPRECH margin is set.
 bool BatteryChargerBq24295::isIcghIprechMarginEnabled (void)
 {
     bool isEnabled = false;
@@ -604,7 +604,7 @@
     return isEnabled;
 }
     
-/// Set the fast charging safety timer.
+// Set the fast charging safety timer.
 bool BatteryChargerBq24295::setFastChargingSafetyTimer (int32_t timerHours)
 {
     bool success = false;
@@ -649,7 +649,7 @@
     return success;
 }
 
-/// Get the value of the fast charging safety timer.
+// Get the value of the fast charging safety timer.
 bool BatteryChargerBq24295::getFastChargingSafetyTimer (int32_t *pTimerHours)
 {
     bool success = false;
@@ -694,7 +694,7 @@
     return success;
 }
 
-/// Set the charging termination current.
+// Set the charging termination current.
 bool BatteryChargerBq24295::setChargingTerminationCurrent (int32_t currentMA)
 {
     bool success = false;
@@ -730,7 +730,7 @@
     return success;
 }
 
-/// Get the charging termination current.
+// Get the charging termination current.
 bool BatteryChargerBq24295::getChargingTerminationCurrent (int32_t *pCurrentMA)
 {
     bool success = false;
@@ -759,7 +759,7 @@
     return success;
 }
 
-/// Enable charging termination.
+// Enable charging termination.
 bool BatteryChargerBq24295::enableChargingTermination (void)
 {
     bool success = false;
@@ -779,7 +779,7 @@
     return success;
 }
 
-/// Disable charging termination.
+// Disable charging termination.
 bool BatteryChargerBq24295::disableChargingTermination (void)
 {
     bool success = false;
@@ -799,7 +799,7 @@
     return success;
 }
 
-/// Get the state of charging termination (enabled or disabled)
+// Get the state of charging termination (enabled or disabled)
 bool BatteryChargerBq24295::isChargingTerminationEnabled (void)
 {
     bool isEnabled = false;
@@ -827,7 +827,7 @@
     return isEnabled;
 }
 
-/// Set the pre-charging current limit.
+// Set the pre-charging current limit.
 bool BatteryChargerBq24295::setPrechargingCurrentLimit (int32_t currentMA)
 {
     bool success = false;
@@ -863,7 +863,7 @@
     return success;
 }
 
-/// Get the pre-charging current limit.
+// Get the pre-charging current limit.
 bool BatteryChargerBq24295::getPrechargingCurrentLimit (int32_t *pCurrentMA)
 {
     bool success = false;
@@ -893,7 +893,7 @@
     return success;
 }
 
-/// Set the charging voltage limit.
+// Set the charging voltage limit.
 bool BatteryChargerBq24295::setChargingVoltageLimit (int32_t voltageMV)
 {
     bool success = false;
@@ -929,7 +929,7 @@
     return success;
 }
 
-/// Get the charging voltage limit.
+// Get the charging voltage limit.
 bool BatteryChargerBq24295::getChargingVoltageLimit (int32_t *pVoltageMV)
 {
     bool success = false;
@@ -959,7 +959,7 @@
     return success;
 }
 
-/// Set the pre-charge to fast-charge voltage threshold.
+// Set the pre-charge to fast-charge voltage threshold.
 bool BatteryChargerBq24295::setFastChargingVoltageThreshold (int32_t voltageMV)
 {
     bool success = false;
@@ -985,7 +985,7 @@
     return success;
 }
 
-/// Get the pre-charge to fast-charge voltage threshold.
+// Get the pre-charge to fast-charge voltage threshold.
 bool BatteryChargerBq24295::getFastChargingVoltageThreshold (int32_t *pVoltageMV)
 {
     bool success = false;
@@ -1017,7 +1017,7 @@
     return success;
 }
 
-/// Set the recharging voltage threshold.
+// Set the recharging voltage threshold.
 bool BatteryChargerBq24295::setRechargingVoltageThreshold (int32_t voltageMV)
 {
     bool success = false;
@@ -1043,7 +1043,7 @@
     return success;
 }
 
-/// Get the recharging voltage threshold.
+// Get the recharging voltage threshold.
 bool BatteryChargerBq24295::getRechargingVoltageThreshold (int32_t *pVoltageMV)
 {
     bool success = false;
@@ -1075,7 +1075,7 @@
     return success;
 }
 
-/// Set the boost voltage.
+// Set the boost voltage.
 bool BatteryChargerBq24295::setBoostVoltage (int32_t voltageMV)
 {
     bool success = false;
@@ -1116,7 +1116,7 @@
     return success;
 }
 
-/// Get the boost voltage.
+// Get the boost voltage.
 bool BatteryChargerBq24295::getBoostVoltage (int32_t *pVoltageMV)
 {
     bool success = false;
@@ -1146,7 +1146,7 @@
     return success;
 }
 
-/// Set the boost mode low temperature limit.
+// Set the boost mode low temperature limit.
 bool BatteryChargerBq24295::setBoostUpperTemperatureLimit (int32_t temperatureC)
 {
     bool success = false;
@@ -1181,7 +1181,7 @@
     return success;
 }
 
-/// Get the boost mode upper temperature limit.
+// Get the boost mode upper temperature limit.
 bool BatteryChargerBq24295::getBoostUpperTemperatureLimit (int32_t *pTemperatureC)
 {
     bool success = false;
@@ -1221,7 +1221,7 @@
     return success;
 }
     
-/// Check whether the boost mode upper temperature limit is enabled.
+// Check whether the boost mode upper temperature limit is enabled.
 bool BatteryChargerBq24295::isBoostUpperTemperatureLimitEnabled (void)
 {
     bool isEnabled = false;
@@ -1249,7 +1249,7 @@
     return isEnabled;
 }
 
-/// Disable the boost mode upper temperature limit.
+// Disable the boost mode upper temperature limit.
 bool BatteryChargerBq24295::disableBoostUpperTemperatureLimit (void)
 {
     bool success = false;
@@ -1270,7 +1270,7 @@
     return success;
 }
 
-/// Set the boost mode upper temperature limit.
+// Set the boost mode upper temperature limit.
 bool BatteryChargerBq24295::setBoostLowerTemperatureLimit (int32_t temperatureC)
 {
     bool success = false;
@@ -1296,7 +1296,7 @@
     return success;
 }
 
-/// Get the boost mode low temperature limit.
+// Get the boost mode low temperature limit.
 bool BatteryChargerBq24295::getBoostLowerTemperatureLimit (int32_t *pTemperatureC)
 {
     bool success = false;
@@ -1328,7 +1328,7 @@
     return success;
 }
     
-/// Set the input voltage limit.
+// Set the input voltage limit.
 bool BatteryChargerBq24295::setInputVoltageLimit (int32_t voltageMV)
 {
     bool success = false;
@@ -1364,7 +1364,7 @@
     return success;
 }
 
-/// Get the input voltage limit.
+// Get the input voltage limit.
 bool BatteryChargerBq24295::getInputVoltageLimit (int32_t *pVoltageMV)
 {
     bool success = false;
@@ -1394,7 +1394,7 @@
     return success;
 }
 
-/// Set the input current limit.
+// Set the input current limit.
 bool BatteryChargerBq24295::setInputCurrentLimit (int32_t currentMA)
 {
     bool success = false;
@@ -1445,7 +1445,7 @@
     return success;
 }
 
-/// Get the input current limit.
+// Get the input current limit.
 bool BatteryChargerBq24295::getInputCurrentLimit (int32_t *pCurrentMA)
 {
     bool success = false;
@@ -1499,7 +1499,7 @@
     return success;
 }
 
-/// Enable input voltage or current limits.
+// Enable input voltage or current limits.
 bool BatteryChargerBq24295::enableInputLimits (void)
 {
     bool success = false;
@@ -1519,7 +1519,7 @@
     return success;
 }
 
-/// Remove any input voltage or current limits.
+// Remove any input voltage or current limits.
 bool BatteryChargerBq24295::disableInputLimits (void)
 {
     bool success = false;
@@ -1539,7 +1539,7 @@
     return success;
 }
 
-/// Check if input limits are enabled.
+// Check if input limits are enabled.
 bool BatteryChargerBq24295::areInputLimitsEnabled (void)
 {
     bool areEnabled = false;
@@ -1567,7 +1567,7 @@
     return areEnabled;
 }
 
-/// Set the thermal regulation threshold for the chip.
+// Set the thermal regulation threshold for the chip.
 bool BatteryChargerBq24295::setChipThermalRegulationThreshold (int32_t temperatureC)
 {
     bool success = false;
@@ -1604,7 +1604,7 @@
     return success;
 }
 
-/// Get the thermal regulation threshold for the chip.
+// Get the thermal regulation threshold for the chip.
 bool BatteryChargerBq24295::getChipThermalRegulationThreshold (int32_t *pTemperatureC)
 {
     bool success = false;
@@ -1644,7 +1644,7 @@
     return success;
 }
     
-/// Get the charger fault status as a bitmap.
+// Get the charger fault status as a bitmap.
 char BatteryChargerBq24295::getChargerFaults(void)
 {
     char bitmap = (char) CHARGER_FAULT_NONE;
@@ -1665,7 +1665,7 @@
     return bitmap;
 }
 
-/// Enable shipping mode.
+// Enable shipping mode.
 bool BatteryChargerBq24295::enableShippingMode (void)
 {
     bool success = false;
@@ -1688,7 +1688,7 @@
     return success;
 }
 
-/// Disable shipping mode.
+// Disable shipping mode.
 bool BatteryChargerBq24295::disableShippingMode (void)
 {
     bool success = false;
@@ -1711,7 +1711,7 @@
     return success;
 }
 
-/// Check if shipping mode is enabled.
+// Check if shipping mode is enabled.
 bool BatteryChargerBq24295::isShippingModeEnabled (void)
 {
     bool isEnabled = false;
@@ -1742,7 +1742,7 @@
     return isEnabled;
 }
 
-/// Read a register on the chip.
+// Read a register on the chip.
 bool BatteryChargerBq24295::advancedGet(char address, char *pValue)
 {
     bool success = false;
@@ -1766,7 +1766,7 @@
     return success;
 }
 
-/// Set a register on the chip.
+// Set a register on the chip.
 // TODO test
 bool BatteryChargerBq24295::advancedSet(char address, char value)
 {
@@ -1787,4 +1787,4 @@
     return success;
 }
 
-// End Of File
+/* End Of File */