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

Committer:
rob.meades@u-blox.com
Date:
Tue Jun 06 12:59:11 2017 +0100
Revision:
3:340d65a1a133
Parent:
2:f0bbe0269d67
Child:
8:2a758bf86bb7
Add ability to feed(), set() and get() watchdog timer.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rob.meades@u-blox.com 1:ed57b6ca43ab 1 /* mbed Microcontroller Library
rob.meades@u-blox.com 1:ed57b6ca43ab 2 * Copyright (c) 2017 u-blox
rob.meades@u-blox.com 1:ed57b6ca43ab 3 *
rob.meades@u-blox.com 1:ed57b6ca43ab 4 * Licensed under the Apache License, Version 2.0 (the "License");
rob.meades@u-blox.com 1:ed57b6ca43ab 5 * you may not use this file except in compliance with the License.
rob.meades@u-blox.com 1:ed57b6ca43ab 6 * You may obtain a copy of the License at
rob.meades@u-blox.com 1:ed57b6ca43ab 7 *
rob.meades@u-blox.com 1:ed57b6ca43ab 8 * http://www.apache.org/licenses/LICENSE-2.0
rob.meades@u-blox.com 1:ed57b6ca43ab 9 *
rob.meades@u-blox.com 1:ed57b6ca43ab 10 * Unless required by applicable law or agreed to in writing, software
rob.meades@u-blox.com 1:ed57b6ca43ab 11 * distributed under the License is distributed on an "AS IS" BASIS,
rob.meades@u-blox.com 1:ed57b6ca43ab 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rob.meades@u-blox.com 1:ed57b6ca43ab 13 * See the License for the specific language governing permissions and
rob.meades@u-blox.com 1:ed57b6ca43ab 14 * limitations under the License.
rob.meades@u-blox.com 1:ed57b6ca43ab 15 */
rob.meades@u-blox.com 1:ed57b6ca43ab 16
rob.meades@u-blox.com 1:ed57b6ca43ab 17 #ifndef BATTERY_CHARGER_BQ24295_H
rob.meades@u-blox.com 1:ed57b6ca43ab 18 #define BATTERY_CHARGER_BQ24295_H
rob.meades@u-blox.com 1:ed57b6ca43ab 19
rob.meades@u-blox.com 1:ed57b6ca43ab 20 /**
rob.meades@u-blox.com 1:ed57b6ca43ab 21 * @file battery_charger_bq24295.h
rob.meades@u-blox.com 1:ed57b6ca43ab 22 * This file defines the API to the TI BQ24295 battery charger chip.
rob.meades@u-blox.com 1:ed57b6ca43ab 23 */
rob.meades@u-blox.com 1:ed57b6ca43ab 24
RobMeades 2:f0bbe0269d67 25 /* ----------------------------------------------------------------
RobMeades 2:f0bbe0269d67 26 * COMPILE-TIME MACROS
RobMeades 2:f0bbe0269d67 27 * -------------------------------------------------------------- */
rob.meades@u-blox.com 1:ed57b6ca43ab 28
RobMeades 2:f0bbe0269d67 29 /** Device I2C address. */
rob.meades@u-blox.com 1:ed57b6ca43ab 30 #define BATTERY_CHARGER_BQ24295_ADDRESS 0x6B
rob.meades@u-blox.com 1:ed57b6ca43ab 31
RobMeades 2:f0bbe0269d67 32 /* ----------------------------------------------------------------
RobMeades 2:f0bbe0269d67 33 * CLASSES
RobMeades 2:f0bbe0269d67 34 * -------------------------------------------------------------- */
rob.meades@u-blox.com 1:ed57b6ca43ab 35
RobMeades 2:f0bbe0269d67 36 /** BQ27441 battery charger driver. */
rob.meades@u-blox.com 1:ed57b6ca43ab 37 class BatteryChargerBq24295 {
rob.meades@u-blox.com 1:ed57b6ca43ab 38 public:
RobMeades 2:f0bbe0269d67 39 /** Charger state. */
rob.meades@u-blox.com 1:ed57b6ca43ab 40 typedef enum {
rob.meades@u-blox.com 1:ed57b6ca43ab 41 CHARGER_STATE_UNKNOWN,
rob.meades@u-blox.com 1:ed57b6ca43ab 42 CHARGER_STATE_DISABLED,
rob.meades@u-blox.com 1:ed57b6ca43ab 43 CHARGER_STATE_NO_EXTERNAL_POWER,
rob.meades@u-blox.com 1:ed57b6ca43ab 44 CHARGER_STATE_NOT_CHARGING,
rob.meades@u-blox.com 1:ed57b6ca43ab 45 CHARGER_STATE_PRECHARGE,
rob.meades@u-blox.com 1:ed57b6ca43ab 46 CHARGER_STATE_FAST_CHARGE,
rob.meades@u-blox.com 1:ed57b6ca43ab 47 CHARGER_STATE_COMPLETE,
rob.meades@u-blox.com 1:ed57b6ca43ab 48 MAX_NUM_CHARGER_STATES
rob.meades@u-blox.com 1:ed57b6ca43ab 49 } ChargerState;
rob.meades@u-blox.com 1:ed57b6ca43ab 50
RobMeades 2:f0bbe0269d67 51 /** Charger faults as a bitmap that matches the chip REG09 definitions. */
rob.meades@u-blox.com 1:ed57b6ca43ab 52 typedef enum {
rob.meades@u-blox.com 1:ed57b6ca43ab 53 CHARGER_FAULT_NONE = 0x00,
rob.meades@u-blox.com 1:ed57b6ca43ab 54 CHARGER_FAULT_THERMISTOR_TOO_HOT = 0x01,
rob.meades@u-blox.com 1:ed57b6ca43ab 55 CHARGER_FAULT_THERMISTOR_TOO_COLD = 0x02,
rob.meades@u-blox.com 1:ed57b6ca43ab 56 // Value 0x04 is reserved
rob.meades@u-blox.com 1:ed57b6ca43ab 57 CHARGER_FAULT_BATTERY_OVER_VOLTAGE = 0x08,
rob.meades@u-blox.com 1:ed57b6ca43ab 58 CHARGER_FAULT_INPUT_FAULT = 0x10, //!< Note that the value of CHARGER_FAULT_CHARGE_TIMER_EXPIRED overlaps this, be careful when testing the bitmap.
rob.meades@u-blox.com 1:ed57b6ca43ab 59 CHARGER_FAULT_THERMAL_SHUTDOWN = 0x20, //!< Note that the value of CHARGER_FAULT_CHARGE_TIMER_EXPIRED overlaps this, be careful when testing the bitmap.
rob.meades@u-blox.com 1:ed57b6ca43ab 60 CHARGER_FAULT_CHARGE_TIMER_EXPIRED = 0x30, //!< This looks odd as it overlaps the two above but it matches the register meaning as defined by the chip.
rob.meades@u-blox.com 1:ed57b6ca43ab 61 CHARGER_FAULT_OTG = 0x40,
rob.meades@u-blox.com 1:ed57b6ca43ab 62 CHARGER_FAULT_WATCHDOG_EXPIRED = 0x80,
rob.meades@u-blox.com 1:ed57b6ca43ab 63 MAX_NUM_CHARGER_FAULTS
rob.meades@u-blox.com 1:ed57b6ca43ab 64 } ChargerFault;
rob.meades@u-blox.com 1:ed57b6ca43ab 65
RobMeades 2:f0bbe0269d67 66 /** Constructor. */
rob.meades@u-blox.com 1:ed57b6ca43ab 67 BatteryChargerBq24295(void);
RobMeades 2:f0bbe0269d67 68 /** Destructor. */
rob.meades@u-blox.com 1:ed57b6ca43ab 69 ~BatteryChargerBq24295(void);
rob.meades@u-blox.com 1:ed57b6ca43ab 70
RobMeades 2:f0bbe0269d67 71 /** Initialise the BQ24295 chip.
RobMeades 2:f0bbe0269d67 72 * After initialisation the chip will be put into its lowest
RobMeades 2:f0bbe0269d67 73 * power state and should be configured if the default settings
rob.meades@u-blox.com 3:340d65a1a133 74 * are not satisfactory.
rob.meades@u-blox.com 3:340d65a1a133 75 * Note: the BQ24295 charging chip will automonously charge a
rob.meades@u-blox.com 3:340d65a1a133 76 * LiPo cell that is connected to it, without host interaction.
rob.meades@u-blox.com 3:340d65a1a133 77 * This class is only required where the configuration of the
rob.meades@u-blox.com 3:340d65a1a133 78 * chip needs to be changed or the charger state is to be monitored.
RobMeades 2:f0bbe0269d67 79 * @param pI2c a pointer to the I2C instance to use.
RobMeades 2:f0bbe0269d67 80 * @param address 7-bit I2C address of the battery charger chip.
RobMeades 2:f0bbe0269d67 81 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 82 */
rob.meades@u-blox.com 1:ed57b6ca43ab 83 bool init (I2C * pI2c, uint8_t address = BATTERY_CHARGER_BQ24295_ADDRESS);
rob.meades@u-blox.com 1:ed57b6ca43ab 84
RobMeades 2:f0bbe0269d67 85 /** Get the charger state.
RobMeades 2:f0bbe0269d67 86 * @return the charge state.
RobMeades 2:f0bbe0269d67 87 */
rob.meades@u-blox.com 1:ed57b6ca43ab 88 ChargerState getChargerState(void);
rob.meades@u-blox.com 1:ed57b6ca43ab 89
RobMeades 2:f0bbe0269d67 90 /** Get whether external power is present or not.
RobMeades 2:f0bbe0269d67 91 * @return true if external power is present, otherwise false.
RobMeades 2:f0bbe0269d67 92 */
rob.meades@u-blox.com 1:ed57b6ca43ab 93 bool isExternalPowerPresent(void);
rob.meades@u-blox.com 1:ed57b6ca43ab 94
RobMeades 2:f0bbe0269d67 95 /** Enable charging.
RobMeades 2:f0bbe0269d67 96 * Default is disabled.
RobMeades 2:f0bbe0269d67 97 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 98 */
rob.meades@u-blox.com 1:ed57b6ca43ab 99 bool enableCharging (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 100
RobMeades 2:f0bbe0269d67 101 /** Disable charging.
RobMeades 2:f0bbe0269d67 102 * Default is disabled.
RobMeades 2:f0bbe0269d67 103 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 104 */
rob.meades@u-blox.com 1:ed57b6ca43ab 105 bool disableCharging (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 106
RobMeades 2:f0bbe0269d67 107 /** Get the state of charging (enabled or disabled).
RobMeades 2:f0bbe0269d67 108 * @return true if charging is enabled, otherwise false.
RobMeades 2:f0bbe0269d67 109 */
rob.meades@u-blox.com 1:ed57b6ca43ab 110 bool isChargingEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 111
RobMeades 2:f0bbe0269d67 112 /** Enable OTG charging.
RobMeades 2:f0bbe0269d67 113 * Default is enabled.
RobMeades 2:f0bbe0269d67 114 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 115 */
rob.meades@u-blox.com 1:ed57b6ca43ab 116 bool enableOtg (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 117
RobMeades 2:f0bbe0269d67 118 /** Disable OTG charging.
RobMeades 2:f0bbe0269d67 119 * Default is enabled.
RobMeades 2:f0bbe0269d67 120 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 121 */
rob.meades@u-blox.com 1:ed57b6ca43ab 122 bool disableOtg (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 123
RobMeades 2:f0bbe0269d67 124 /** Determine whether OTG charging is enabled or not.
RobMeades 2:f0bbe0269d67 125 * @return true if OTG charging is enabled, otherwise false.
RobMeades 2:f0bbe0269d67 126 */
rob.meades@u-blox.com 1:ed57b6ca43ab 127 bool isOtgEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 128
RobMeades 2:f0bbe0269d67 129 /** Set the system voltage (the voltage which the
RobMeades 2:f0bbe0269d67 130 * chip will attempt to maintain the system at).
RobMeades 2:f0bbe0269d67 131 * @param voltageMV the voltage limit, in milliVolts.
RobMeades 2:f0bbe0269d67 132 * Range is 3000 mV to 3700 mV, default 3500 mV.
RobMeades 2:f0bbe0269d67 133 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 134 */
rob.meades@u-blox.com 1:ed57b6ca43ab 135 bool setSystemVoltage (int32_t voltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 136
RobMeades 2:f0bbe0269d67 137 /** Get the system voltage.
RobMeades 2:f0bbe0269d67 138 * @param pVoltageMV a place to put the system voltage limit.
RobMeades 2:f0bbe0269d67 139 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 140 */
rob.meades@u-blox.com 1:ed57b6ca43ab 141 bool getSystemVoltage (int32_t *pVoltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 142
RobMeades 2:f0bbe0269d67 143 /** Set the fast charging current limit.
RobMeades 2:f0bbe0269d67 144 * @param currentMA the fast charging current limit, in milliAmps.
RobMeades 2:f0bbe0269d67 145 * Range is 512 mA to 3008 mA, default 1024 mA.
RobMeades 2:f0bbe0269d67 146 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 147 */
rob.meades@u-blox.com 1:ed57b6ca43ab 148 bool setFastChargingCurrentLimit (int32_t currentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 149
RobMeades 2:f0bbe0269d67 150 /** Get the fast charging current limit.
RobMeades 2:f0bbe0269d67 151 * @param pCurrentMA a place to put the fast charging current limit.
RobMeades 2:f0bbe0269d67 152 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 153 */
rob.meades@u-blox.com 1:ed57b6ca43ab 154 bool getFastChargingCurrentLimit (int32_t *pCurrentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 155
RobMeades 2:f0bbe0269d67 156 /** Set the fast charging safety timer.
RobMeades 2:f0bbe0269d67 157 * @param timerHours the charging safety timer value.
RobMeades 2:f0bbe0269d67 158 * Use a value of 0 to indicate that the timer should be disabled.
RobMeades 2:f0bbe0269d67 159 * Timer values will be translated to the nearest (lower) value
RobMeades 2:f0bbe0269d67 160 * out of 5, 8, 12, and 20 hours, default 12 hours.
RobMeades 2:f0bbe0269d67 161 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 162 */
rob.meades@u-blox.com 1:ed57b6ca43ab 163 bool setFastChargingSafetyTimer (int32_t timerHours);
rob.meades@u-blox.com 1:ed57b6ca43ab 164
RobMeades 2:f0bbe0269d67 165 /** Get the fast charging safety timer value.
RobMeades 2:f0bbe0269d67 166 * @param pTimerHours a place to put the charging safety timer value.
RobMeades 2:f0bbe0269d67 167 * Returned value is zero if the fast charging safety timer is disabled.
RobMeades 2:f0bbe0269d67 168 * @return true if charging termination is enabled, otherwise false.
RobMeades 2:f0bbe0269d67 169 */
rob.meades@u-blox.com 1:ed57b6ca43ab 170 bool getFastChargingSafetyTimer (int32_t *pTimerHours);
rob.meades@u-blox.com 1:ed57b6ca43ab 171
RobMeades 2:f0bbe0269d67 172 /** Set ICHG/IPRECH margin (see section 8.3.3.5 of the chip data sheet).
RobMeades 2:f0bbe0269d67 173 * Default is disabled.
RobMeades 2:f0bbe0269d67 174 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 175 */
rob.meades@u-blox.com 1:ed57b6ca43ab 176 bool enableIcghIprechMargin (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 177
RobMeades 2:f0bbe0269d67 178 /** Clear the ICHG/IPRECH margin (see section 8.3.3.5 of the chip data sheet).
RobMeades 2:f0bbe0269d67 179 * Default is disabled.
RobMeades 2:f0bbe0269d67 180 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 181 */
rob.meades@u-blox.com 1:ed57b6ca43ab 182 bool disableIcghIprechMargin (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 183
RobMeades 2:f0bbe0269d67 184 /** Check if the ICHG/IPRECH margin is set (see section 8.3.3.5 of
RobMeades 2:f0bbe0269d67 185 * the chip data sheet).
RobMeades 2:f0bbe0269d67 186 * @return true if the ICHG/IPRECH margin is enabled, otherwise false.
RobMeades 2:f0bbe0269d67 187 */
rob.meades@u-blox.com 1:ed57b6ca43ab 188 bool isIcghIprechMarginEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 189
RobMeades 2:f0bbe0269d67 190 /** Set the charging termination current.
RobMeades 2:f0bbe0269d67 191 * @param currentMA the charging termination current, in milliAmps.
RobMeades 2:f0bbe0269d67 192 * Range is 128 mA to 2048 mA, default is 256 mA.
RobMeades 2:f0bbe0269d67 193 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 194 */
rob.meades@u-blox.com 1:ed57b6ca43ab 195 bool setChargingTerminationCurrent (int32_t currentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 196
RobMeades 2:f0bbe0269d67 197 /** Get the charging termination current.
RobMeades 2:f0bbe0269d67 198 * @param pCurrentMA a place to put the charging termination current.
RobMeades 2:f0bbe0269d67 199 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 200 */
rob.meades@u-blox.com 1:ed57b6ca43ab 201 bool getChargingTerminationCurrent (int32_t *pCurrentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 202
RobMeades 2:f0bbe0269d67 203 /** Enable charging termination.
RobMeades 2:f0bbe0269d67 204 * Default is enabled.
RobMeades 2:f0bbe0269d67 205 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 206 */
rob.meades@u-blox.com 1:ed57b6ca43ab 207 bool enableChargingTermination (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 208
RobMeades 2:f0bbe0269d67 209 /** Disable charging termination.
RobMeades 2:f0bbe0269d67 210 * Default is enabled.
RobMeades 2:f0bbe0269d67 211 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 212 */
rob.meades@u-blox.com 1:ed57b6ca43ab 213 bool disableChargingTermination (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 214
RobMeades 2:f0bbe0269d67 215 /** Get the state of charging termination (enabled or disabled).
RobMeades 2:f0bbe0269d67 216 * @return true if charging termination is enabled, otherwise false.
RobMeades 2:f0bbe0269d67 217 */
rob.meades@u-blox.com 1:ed57b6ca43ab 218 bool isChargingTerminationEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 219
RobMeades 2:f0bbe0269d67 220 /** Set the pre-charging current limit.
RobMeades 2:f0bbe0269d67 221 * @param currentMA the pre-charging current limit, in milliAmps.
RobMeades 2:f0bbe0269d67 222 * Range is 128 mA to 2048 mA, default is 256 mA.
RobMeades 2:f0bbe0269d67 223 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 224 */
rob.meades@u-blox.com 1:ed57b6ca43ab 225 bool setPrechargingCurrentLimit (int32_t currentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 226
RobMeades 2:f0bbe0269d67 227 /** Get the pre-charging current limit.
RobMeades 2:f0bbe0269d67 228 * @param pCurrentMA a place to put the pre-charging current limit.
RobMeades 2:f0bbe0269d67 229 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 230 */
rob.meades@u-blox.com 1:ed57b6ca43ab 231 bool getPrechargingCurrentLimit (int32_t *pCurrentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 232
RobMeades 2:f0bbe0269d67 233 /** Set the charging voltage limit.
RobMeades 2:f0bbe0269d67 234 * @param voltageMV the charging voltage limit, in milliVolts.
RobMeades 2:f0bbe0269d67 235 * Range is 3504 mV to 4400 mV, default is 4208 mV.
RobMeades 2:f0bbe0269d67 236 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 237 */
rob.meades@u-blox.com 1:ed57b6ca43ab 238 bool setChargingVoltageLimit (int32_t voltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 239
RobMeades 2:f0bbe0269d67 240 /** Get the charging voltage limit.
RobMeades 2:f0bbe0269d67 241 * @param pVoltageMV a place to put the charging voltage limit,
RobMeades 2:f0bbe0269d67 242 * in milliVolts.
RobMeades 2:f0bbe0269d67 243 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 244 */
rob.meades@u-blox.com 1:ed57b6ca43ab 245 bool getChargingVoltageLimit (int32_t *pVoltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 246
RobMeades 2:f0bbe0269d67 247 /** Set the pre-charge to fast-charge voltage threshold.
RobMeades 2:f0bbe0269d67 248 * @param voltageMV the threshold, in milliVolts.
RobMeades 2:f0bbe0269d67 249 * Values will be translated to the nearest (highest)
RobMeades 2:f0bbe0269d67 250 * voltage out of 2800 mV and 3000 mV, default is 3000 mV.
RobMeades 2:f0bbe0269d67 251 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 252 */
rob.meades@u-blox.com 1:ed57b6ca43ab 253 bool setFastChargingVoltageThreshold (int32_t voltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 254
RobMeades 2:f0bbe0269d67 255 /** Get the pre-charge to fast-charge voltage threshold.
RobMeades 2:f0bbe0269d67 256 * @param pVoltageMV a place to put the threshold, in milliVolts.
RobMeades 2:f0bbe0269d67 257 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 258 */
rob.meades@u-blox.com 1:ed57b6ca43ab 259 bool getFastChargingVoltageThreshold (int32_t *pVoltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 260
RobMeades 2:f0bbe0269d67 261 /** Set the recharging voltage threshold.
RobMeades 2:f0bbe0269d67 262 * @param voltageMV the recharging voltage threshold, in milliVolts.
RobMeades 2:f0bbe0269d67 263 * Values will be translated to the nearest (highest)
RobMeades 2:f0bbe0269d67 264 * voltage out of 100 mV and 300 mV, default is 100 mV.
RobMeades 2:f0bbe0269d67 265 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 266 */
rob.meades@u-blox.com 1:ed57b6ca43ab 267 bool setRechargingVoltageThreshold (int32_t voltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 268
RobMeades 2:f0bbe0269d67 269 /** Get the recharging voltage threshold.
RobMeades 2:f0bbe0269d67 270 * @param pVoltageMV a place to put the charging voltage threshold, in milliVolts.
RobMeades 2:f0bbe0269d67 271 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 272 */
rob.meades@u-blox.com 1:ed57b6ca43ab 273 bool getRechargingVoltageThreshold (int32_t *pVoltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 274
RobMeades 2:f0bbe0269d67 275 /** Set the boost voltage.
RobMeades 2:f0bbe0269d67 276 * @param voltageMV the boost voltage, in milliVolts.
RobMeades 2:f0bbe0269d67 277 * Range is 4550 mV to 5510 mV, default is 5126 mV.
RobMeades 2:f0bbe0269d67 278 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 279 */
rob.meades@u-blox.com 1:ed57b6ca43ab 280 bool setBoostVoltage (int32_t voltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 281
RobMeades 2:f0bbe0269d67 282 /** Get the boost voltage.
RobMeades 2:f0bbe0269d67 283 * @param pVoltageMV a place to put the boost voltage, in milliVolts.
RobMeades 2:f0bbe0269d67 284 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 285 */
rob.meades@u-blox.com 1:ed57b6ca43ab 286 bool getBoostVoltage (int32_t *pVoltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 287
RobMeades 2:f0bbe0269d67 288 /** Set the boost mode upper temperature limit.
RobMeades 2:f0bbe0269d67 289 * @param temperatureC the temperature in C.
RobMeades 2:f0bbe0269d67 290 * Values will be translated to the nearest (lower)
RobMeades 2:f0bbe0269d67 291 * of 55 C, 60 C and 65 C (disabled by default).
RobMeades 2:f0bbe0269d67 292 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 293 */
rob.meades@u-blox.com 1:ed57b6ca43ab 294 bool setBoostUpperTemperatureLimit (int32_t temperatureC);
rob.meades@u-blox.com 1:ed57b6ca43ab 295
RobMeades 2:f0bbe0269d67 296 /** Get the boost mode upper temperature limit.
RobMeades 2:f0bbe0269d67 297 * If the boost mode upper temperature limit is not
RobMeades 2:f0bbe0269d67 298 * enabled then pTemperatureC will remain untouched and false
RobMeades 2:f0bbe0269d67 299 * will be returned.
RobMeades 2:f0bbe0269d67 300 * @param pTemperatureC a place to put the temperature.
RobMeades 2:f0bbe0269d67 301 * @return true if successful and a limit was set, otherwise false.
RobMeades 2:f0bbe0269d67 302 */
rob.meades@u-blox.com 1:ed57b6ca43ab 303 bool getBoostUpperTemperatureLimit (int32_t *pTemperatureC);
rob.meades@u-blox.com 1:ed57b6ca43ab 304
RobMeades 2:f0bbe0269d67 305 /** Check whether the boost mode upper temperature limit is enabled.
RobMeades 2:f0bbe0269d67 306 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 307 */
rob.meades@u-blox.com 1:ed57b6ca43ab 308 bool isBoostUpperTemperatureLimitEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 309
RobMeades 2:f0bbe0269d67 310 /** Disable the boost mode upper temperature limit.
RobMeades 2:f0bbe0269d67 311 * Default is disabled.
RobMeades 2:f0bbe0269d67 312 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 313 */
rob.meades@u-blox.com 1:ed57b6ca43ab 314 bool disableBoostUpperTemperatureLimit (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 315
RobMeades 2:f0bbe0269d67 316 /** Set the boost mode low temperature limit.
RobMeades 2:f0bbe0269d67 317 * @param temperatureC the temperature in C.
RobMeades 2:f0bbe0269d67 318 * Values will be translated to the nearest (higher)
RobMeades 2:f0bbe0269d67 319 * of -10 C and -20 C, default is -10 C.
RobMeades 2:f0bbe0269d67 320 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 321 */
rob.meades@u-blox.com 1:ed57b6ca43ab 322 bool setBoostLowerTemperatureLimit (int32_t temperatureC);
rob.meades@u-blox.com 1:ed57b6ca43ab 323
RobMeades 2:f0bbe0269d67 324 /** Get the boost mode low temperature limit.
RobMeades 2:f0bbe0269d67 325 * @param pTemperatureC a place to put the temperature.
RobMeades 2:f0bbe0269d67 326 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 327 */
rob.meades@u-blox.com 1:ed57b6ca43ab 328 bool getBoostLowerTemperatureLimit (int32_t *pTemperatureC);
rob.meades@u-blox.com 1:ed57b6ca43ab 329
RobMeades 2:f0bbe0269d67 330 /** Set the input voltage limit. If the input falls below
RobMeades 2:f0bbe0269d67 331 * this level then charging will be ramped down. The limit
RobMeades 2:f0bbe0269d67 332 * does not take effect until enableInputLimits() is called
RobMeades 2:f0bbe0269d67 333 * (default setting is disabled).
RobMeades 2:f0bbe0269d67 334 * @param voltageMV the input voltage limit, in milliVolts.
RobMeades 2:f0bbe0269d67 335 * Range is 3880 mV to 5080 mV, default is 4760 mV.
RobMeades 2:f0bbe0269d67 336 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 337 */
rob.meades@u-blox.com 1:ed57b6ca43ab 338 bool setInputVoltageLimit (int32_t voltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 339
RobMeades 2:f0bbe0269d67 340 /** Get the input voltage limit.
RobMeades 2:f0bbe0269d67 341 * @param pVoltageMV a place to put the input voltage limit.
RobMeades 2:f0bbe0269d67 342 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 343 */
rob.meades@u-blox.com 1:ed57b6ca43ab 344 bool getInputVoltageLimit (int32_t *pVoltageMV);
rob.meades@u-blox.com 1:ed57b6ca43ab 345
RobMeades 2:f0bbe0269d67 346 /** Set the input current limit. If the current drawn
RobMeades 2:f0bbe0269d67 347 * goes above this limit then charging will be ramped down.
RobMeades 2:f0bbe0269d67 348 * The limit does not take effect until enableInputLimits()
RobMeades 2:f0bbe0269d67 349 * is called (default setting is disabled).
RobMeades 2:f0bbe0269d67 350 * @param currentMA the input current limit, in milliAmps.
RobMeades 2:f0bbe0269d67 351 * Range is 100 mA to 3000 mA, default depends upon
RobMeades 2:f0bbe0269d67 352 * hardware configuration, see section 8.3.1.4.3 of
RobMeades 2:f0bbe0269d67 353 * the data sheet.
RobMeades 2:f0bbe0269d67 354 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 355 */
rob.meades@u-blox.com 1:ed57b6ca43ab 356 bool setInputCurrentLimit (int32_t currentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 357
RobMeades 2:f0bbe0269d67 358 /** Get the input current limit.
RobMeades 2:f0bbe0269d67 359 * @param pCurrentMA a place to put the input current limit.
RobMeades 2:f0bbe0269d67 360 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 361 */
rob.meades@u-blox.com 1:ed57b6ca43ab 362 bool getInputCurrentLimit (int32_t *pCurrentMA);
rob.meades@u-blox.com 1:ed57b6ca43ab 363
RobMeades 2:f0bbe0269d67 364 /** Enable input voltage and current limits.
RobMeades 2:f0bbe0269d67 365 * Default is disabled.
RobMeades 2:f0bbe0269d67 366 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 367 */
rob.meades@u-blox.com 1:ed57b6ca43ab 368 bool enableInputLimits (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 369
RobMeades 2:f0bbe0269d67 370 /** Remove any input voltage or current limits.
RobMeades 2:f0bbe0269d67 371 * Default is disabled.
RobMeades 2:f0bbe0269d67 372 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 373 */
rob.meades@u-blox.com 1:ed57b6ca43ab 374 bool disableInputLimits (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 375
RobMeades 2:f0bbe0269d67 376 /** Check whether input limits are enabled.
RobMeades 2:f0bbe0269d67 377 * @return true if input limits are enabled, otherwise false.
RobMeades 2:f0bbe0269d67 378 */
rob.meades@u-blox.com 1:ed57b6ca43ab 379 bool areInputLimitsEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 380
RobMeades 2:f0bbe0269d67 381 /** Set the thermal regulation threshold for the chip.
RobMeades 2:f0bbe0269d67 382 * @param temperatureC the temperature in C.
RobMeades 2:f0bbe0269d67 383 * Values will be translated to the nearest (lower)
RobMeades 2:f0bbe0269d67 384 * of 60 C, 80 C, 100 C and 120 C, default 120 C.
RobMeades 2:f0bbe0269d67 385 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 386 */
rob.meades@u-blox.com 1:ed57b6ca43ab 387 bool setChipThermalRegulationThreshold (int32_t temperatureC);
rob.meades@u-blox.com 1:ed57b6ca43ab 388
RobMeades 2:f0bbe0269d67 389 /** Get the thermal regulation threshold for the chip.
RobMeades 2:f0bbe0269d67 390 * @param pTemperatureC a place to put the temperature.
RobMeades 2:f0bbe0269d67 391 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 392 */
rob.meades@u-blox.com 1:ed57b6ca43ab 393 bool getChipThermalRegulationThreshold (int32_t *pTemperatureC);
rob.meades@u-blox.com 1:ed57b6ca43ab 394
RobMeades 2:f0bbe0269d67 395 /** Get the charger faults.
RobMeades 2:f0bbe0269d67 396 * Note: as with all the other API functions here, this should
RobMeades 2:f0bbe0269d67 397 * not be called from an interrupt function as the comms with the
RobMeades 2:f0bbe0269d67 398 * chip over I2C will take too long.
RobMeades 2:f0bbe0269d67 399 * @return a bit-map of that can be tested against ChargerFault.
RobMeades 2:f0bbe0269d67 400 */
rob.meades@u-blox.com 1:ed57b6ca43ab 401 char getChargerFaults(void);
rob.meades@u-blox.com 1:ed57b6ca43ab 402
rob.meades@u-blox.com 3:340d65a1a133 403 /** Feed the watchdog timer.
rob.meades@u-blox.com 3:340d65a1a133 404 * Use this if it is necessary to keep the BQ24295 chip in Host
rob.meades@u-blox.com 3:340d65a1a133 405 * mode (see section 8.4.1 of the data sheet for details).
rob.meades@u-blox.com 3:340d65a1a133 406 * @return true if successful, otherwise false.
rob.meades@u-blox.com 3:340d65a1a133 407 */
rob.meades@u-blox.com 3:340d65a1a133 408 bool feedWatchdog(void);
rob.meades@u-blox.com 3:340d65a1a133 409
rob.meades@u-blox.com 3:340d65a1a133 410 /** Get the watchdog timer of the BQ24295 chip.
rob.meades@u-blox.com 3:340d65a1a133 411 * @param pWatchdogS a place to put the watchdog timer (in seconds).
rob.meades@u-blox.com 3:340d65a1a133 412 * @return true if successful, otherwise false.
rob.meades@u-blox.com 3:340d65a1a133 413 */
rob.meades@u-blox.com 3:340d65a1a133 414 bool getWatchdog (int32_t *pWatchdogS);
rob.meades@u-blox.com 3:340d65a1a133 415
rob.meades@u-blox.com 3:340d65a1a133 416 /** Set the watchdog timer of the BQ24295 chip.
rob.meades@u-blox.com 3:340d65a1a133 417 * @param watchdogS the watchdog timer (in seconds), 0 to disable,
rob.meades@u-blox.com 3:340d65a1a133 418 * max 160 seconds.
rob.meades@u-blox.com 3:340d65a1a133 419 * @return true if successful, otherwise false.
rob.meades@u-blox.com 3:340d65a1a133 420 */
rob.meades@u-blox.com 3:340d65a1a133 421 bool setWatchdog (int32_t watchdogS);
rob.meades@u-blox.com 3:340d65a1a133 422
RobMeades 2:f0bbe0269d67 423 /** Enable shipping mode.
RobMeades 2:f0bbe0269d67 424 * In shipping mode the battery is disconnected from the system
RobMeades 2:f0bbe0269d67 425 * to avoid leakage. Default is disabled.
RobMeades 2:f0bbe0269d67 426 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 427 */
rob.meades@u-blox.com 1:ed57b6ca43ab 428 bool enableShippingMode (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 429
RobMeades 2:f0bbe0269d67 430 /** Disable shipping mode.
RobMeades 2:f0bbe0269d67 431 * In shipping mode the battery is disconnected from the system
RobMeades 2:f0bbe0269d67 432 * to avoid leakage. Default is disabled.
RobMeades 2:f0bbe0269d67 433 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 434 */
rob.meades@u-blox.com 1:ed57b6ca43ab 435 bool disableShippingMode (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 436
RobMeades 2:f0bbe0269d67 437 /** Check whether shipping mode is enabled.
RobMeades 2:f0bbe0269d67 438 * @return true if input limits are enabled, otherwise false.
RobMeades 2:f0bbe0269d67 439 */
rob.meades@u-blox.com 1:ed57b6ca43ab 440 bool isShippingModeEnabled (void);
rob.meades@u-blox.com 1:ed57b6ca43ab 441
RobMeades 2:f0bbe0269d67 442 /** Advanced function to read a register on the chip.
RobMeades 2:f0bbe0269d67 443 * @param address the address to read from.
RobMeades 2:f0bbe0269d67 444 * @param pValue a place to put the returned value.
RobMeades 2:f0bbe0269d67 445 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 446 */
rob.meades@u-blox.com 1:ed57b6ca43ab 447 bool advancedGet(char address, char *pValue);
rob.meades@u-blox.com 1:ed57b6ca43ab 448
RobMeades 2:f0bbe0269d67 449 /** Advanced function to set a register on the chip.
RobMeades 2:f0bbe0269d67 450 * @param address the address to write to.
RobMeades 2:f0bbe0269d67 451 * @param value the value to write.
RobMeades 2:f0bbe0269d67 452 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 453 */
rob.meades@u-blox.com 1:ed57b6ca43ab 454 bool advancedSet(char address, char value);
rob.meades@u-blox.com 1:ed57b6ca43ab 455
rob.meades@u-blox.com 1:ed57b6ca43ab 456 protected:
RobMeades 2:f0bbe0269d67 457 /** Pointer to the I2C interface. */
rob.meades@u-blox.com 1:ed57b6ca43ab 458 I2C * gpI2c;
RobMeades 2:f0bbe0269d67 459 /** The address of the device. */
rob.meades@u-blox.com 1:ed57b6ca43ab 460 uint8_t gAddress;
RobMeades 2:f0bbe0269d67 461 /** Flag to indicate device is ready */
rob.meades@u-blox.com 1:ed57b6ca43ab 462 bool gReady;
rob.meades@u-blox.com 1:ed57b6ca43ab 463
RobMeades 2:f0bbe0269d67 464 /** Read a register.
RobMeades 2:f0bbe0269d67 465 * Note: gpI2c should be locked before this is called.
RobMeades 2:f0bbe0269d67 466 * @param address the address to read from.
RobMeades 2:f0bbe0269d67 467 * @param pValue a place to put the returned value.
RobMeades 2:f0bbe0269d67 468 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 469 */
rob.meades@u-blox.com 1:ed57b6ca43ab 470 bool getRegister(char address, char *pValue);
rob.meades@u-blox.com 1:ed57b6ca43ab 471
RobMeades 2:f0bbe0269d67 472 /** Set a register.
RobMeades 2:f0bbe0269d67 473 * Note: gpI2c should be locked before this is called.
RobMeades 2:f0bbe0269d67 474 * @param address the address to write to.
RobMeades 2:f0bbe0269d67 475 * @param value the value to write.
RobMeades 2:f0bbe0269d67 476 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 477 */
rob.meades@u-blox.com 1:ed57b6ca43ab 478 bool setRegister(char address, char value);
rob.meades@u-blox.com 1:ed57b6ca43ab 479
RobMeades 2:f0bbe0269d67 480 /** Set a mask of bits in a register.
RobMeades 2:f0bbe0269d67 481 * Note: gpI2c should be locked before this is called.
RobMeades 2:f0bbe0269d67 482 * @param address the address to write to.
RobMeades 2:f0bbe0269d67 483 * @param mask the mask of bits to set.
RobMeades 2:f0bbe0269d67 484 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 485 */
rob.meades@u-blox.com 1:ed57b6ca43ab 486 bool setRegisterBits(char address, char mask);
rob.meades@u-blox.com 1:ed57b6ca43ab 487
RobMeades 2:f0bbe0269d67 488 /** Clear a mask of bits in a register.
RobMeades 2:f0bbe0269d67 489 * Note: gpI2c should be locked before this is called.
RobMeades 2:f0bbe0269d67 490 * @param address the address to write to.
RobMeades 2:f0bbe0269d67 491 * @param mask the mask of bits to clear.
RobMeades 2:f0bbe0269d67 492 * @return true if successful, otherwise false.
RobMeades 2:f0bbe0269d67 493 */
rob.meades@u-blox.com 1:ed57b6ca43ab 494 bool clearRegisterBits(char address, char mask);
rob.meades@u-blox.com 1:ed57b6ca43ab 495 };
rob.meades@u-blox.com 1:ed57b6ca43ab 496
rob.meades@u-blox.com 1:ed57b6ca43ab 497 #endif
rob.meades@u-blox.com 1:ed57b6ca43ab 498
RobMeades 2:f0bbe0269d67 499 /* End Of File */