This version is the one to be submitted as a part the Hackster.io contest, Unleash Invisible Intelligence

Committer:
gov1
Date:
Tue Jul 31 16:30:32 2018 +0000
Revision:
0:a761fba7f8a8
complete version with emer. batt low check

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gov1 0:a761fba7f8a8 1 /*******************************************************************************
gov1 0:a761fba7f8a8 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
gov1 0:a761fba7f8a8 3 *
gov1 0:a761fba7f8a8 4 * Permission is hereby granted, free of charge, to any person obtaining a
gov1 0:a761fba7f8a8 5 * copy of this software and associated documentation files (the "Software"),
gov1 0:a761fba7f8a8 6 * to deal in the Software without restriction, including without limitation
gov1 0:a761fba7f8a8 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gov1 0:a761fba7f8a8 8 * and/or sell copies of the Software, and to permit persons to whom the
gov1 0:a761fba7f8a8 9 * Software is furnished to do so, subject to the following conditions:
gov1 0:a761fba7f8a8 10 *
gov1 0:a761fba7f8a8 11 * The above copyright notice and this permission notice shall be included
gov1 0:a761fba7f8a8 12 * in all copies or substantial portions of the Software.
gov1 0:a761fba7f8a8 13 *
gov1 0:a761fba7f8a8 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gov1 0:a761fba7f8a8 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gov1 0:a761fba7f8a8 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gov1 0:a761fba7f8a8 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gov1 0:a761fba7f8a8 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gov1 0:a761fba7f8a8 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gov1 0:a761fba7f8a8 20 * OTHER DEALINGS IN THE SOFTWARE.
gov1 0:a761fba7f8a8 21 *
gov1 0:a761fba7f8a8 22 * Except as contained in this notice, the name of Maxim Integrated
gov1 0:a761fba7f8a8 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gov1 0:a761fba7f8a8 24 * Products, Inc. Branding Policy.
gov1 0:a761fba7f8a8 25 *
gov1 0:a761fba7f8a8 26 * The mere transfer of this software does not imply any licenses
gov1 0:a761fba7f8a8 27 * of trade secrets, proprietary technology, copyrights, patents,
gov1 0:a761fba7f8a8 28 * trademarks, maskwork rights, or any other form of intellectual
gov1 0:a761fba7f8a8 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gov1 0:a761fba7f8a8 30 * ownership rights.
gov1 0:a761fba7f8a8 31 *******************************************************************************
gov1 0:a761fba7f8a8 32 */
gov1 0:a761fba7f8a8 33
gov1 0:a761fba7f8a8 34 #ifndef _MAX17055_H_
gov1 0:a761fba7f8a8 35 #define _MAX17055_H_
gov1 0:a761fba7f8a8 36
gov1 0:a761fba7f8a8 37 #include "mbed.h"
gov1 0:a761fba7f8a8 38
gov1 0:a761fba7f8a8 39 #define MAX17055_I2C_ADDRESS 0x6C
gov1 0:a761fba7f8a8 40
gov1 0:a761fba7f8a8 41 #define MAX17055_NO_ERROR 0
gov1 0:a761fba7f8a8 42 #define MAX17055_ERROR -1
gov1 0:a761fba7f8a8 43
gov1 0:a761fba7f8a8 44 #define MAX17055_V_LSB_MV 7.8125E-5f
gov1 0:a761fba7f8a8 45 #define MAX17055_V_MAX_MIN_LSB_MV 2.0E-2f
gov1 0:a761fba7f8a8 46 #define MAX17055_I_LSB_UV 1.5625E-3f
gov1 0:a761fba7f8a8 47 #define MAX17055_I_MAX_MIN_LSB_MV 0.0004f
gov1 0:a761fba7f8a8 48
gov1 0:a761fba7f8a8 49 /**
gov1 0:a761fba7f8a8 50 * @brief MAX17055 7µA 1-Cell Fuel Gauge with ModelGauge m5 EZ
gov1 0:a761fba7f8a8 51 *
gov1 0:a761fba7f8a8 52 * @details The MAX17055 is a low 7μA operating current fuel gauge which
gov1 0:a761fba7f8a8 53 * implements Maxim ModelGauge™ m5 EZ algorithm. ModelGauge m5 EZ makes
gov1 0:a761fba7f8a8 54 * fuel gauge implementation easy by eliminating battery characterization
gov1 0:a761fba7f8a8 55 * requirements and simplifying host software interaction.
gov1 0:a761fba7f8a8 56 * The ModelGauge m5 EZ robust algorithm provides tolerance against battery
gov1 0:a761fba7f8a8 57 * diversity for most lithium batteries and applications.
gov1 0:a761fba7f8a8 58 * <br>https://www.maximintegrated.com/en/products/power/battery-management/MAX17055.html
gov1 0:a761fba7f8a8 59 *
gov1 0:a761fba7f8a8 60 * @code
gov1 0:a761fba7f8a8 61 * #include "mbed.h"
gov1 0:a761fba7f8a8 62 * #include "MAX17055.h"
gov1 0:a761fba7f8a8 63 *
gov1 0:a761fba7f8a8 64 * // I2C Master 2
gov1 0:a761fba7f8a8 65 * I2C i2c(I2C2_SDA, I2C2_SCL);
gov1 0:a761fba7f8a8 66 *
gov1 0:a761fba7f8a8 67 * MAX17055 max17055(i2c);
gov1 0:a761fba7f8a8 68 *
gov1 0:a761fba7f8a8 69 * int main()
gov1 0:a761fba7f8a8 70 * {
gov1 0:a761fba7f8a8 71 * int status;
gov1 0:a761fba7f8a8 72 * float f_value;
gov1 0:a761fba7f8a8 73 *
gov1 0:a761fba7f8a8 74 * // Set sense resistor value
gov1 0:a761fba7f8a8 75 * max17055.init(0.05f);
gov1 0:a761fba7f8a8 76 *
gov1 0:a761fba7f8a8 77 * // Print status
gov1 0:a761fba7f8a8 78 * max17055.status(&status);
gov1 0:a761fba7f8a8 79 * printf("MAX17055 status: %04X\r\n", (uint16_t)status);
gov1 0:a761fba7f8a8 80 *
gov1 0:a761fba7f8a8 81 * for (;;) {
gov1 0:a761fba7f8a8 82 * // Print formatted voltage, current and temperature values
gov1 0:a761fba7f8a8 83 * max17055.v_cell(&f_value);
gov1 0:a761fba7f8a8 84 * printf("%6.3fV ", f_value);
gov1 0:a761fba7f8a8 85 * max17055.current(&f_value);
gov1 0:a761fba7f8a8 86 * printf("%6.3fI ", f_value);
gov1 0:a761fba7f8a8 87 * max17055.temp(&f_value);
gov1 0:a761fba7f8a8 88 * printf("%6.3fC ", f_value);
gov1 0:a761fba7f8a8 89 * printf("\r\n");
gov1 0:a761fba7f8a8 90 *
gov1 0:a761fba7f8a8 91 * Thread::wait(3000);
gov1 0:a761fba7f8a8 92 * }
gov1 0:a761fba7f8a8 93 * }
gov1 0:a761fba7f8a8 94 * @endcode
gov1 0:a761fba7f8a8 95 */
gov1 0:a761fba7f8a8 96
gov1 0:a761fba7f8a8 97 class MAX17055
gov1 0:a761fba7f8a8 98 {
gov1 0:a761fba7f8a8 99 public:
gov1 0:a761fba7f8a8 100
gov1 0:a761fba7f8a8 101 /**
gov1 0:a761fba7f8a8 102 * @brief Register Address
gov1 0:a761fba7f8a8 103 * @details MAX17055 register addresses
gov1 0:a761fba7f8a8 104 */
gov1 0:a761fba7f8a8 105 typedef enum {
gov1 0:a761fba7f8a8 106 STATUS = 0x00,
gov1 0:a761fba7f8a8 107 V_ALRT_TH,
gov1 0:a761fba7f8a8 108 T_ALRT_TH,
gov1 0:a761fba7f8a8 109 S_ALRT_TH,
gov1 0:a761fba7f8a8 110 AT_RATE,
gov1 0:a761fba7f8a8 111 REP_CAP,
gov1 0:a761fba7f8a8 112 REP_SOC,
gov1 0:a761fba7f8a8 113 AGE,
gov1 0:a761fba7f8a8 114 TEMP,
gov1 0:a761fba7f8a8 115 V_CELL,
gov1 0:a761fba7f8a8 116 CURRENT,
gov1 0:a761fba7f8a8 117 AVG_CURRENT,
gov1 0:a761fba7f8a8 118 Q_RESIDUAL,
gov1 0:a761fba7f8a8 119 MIX_SOC,
gov1 0:a761fba7f8a8 120 AV_SOC,
gov1 0:a761fba7f8a8 121 MIX_CAP,
gov1 0:a761fba7f8a8 122 FULL_CAP_REP,
gov1 0:a761fba7f8a8 123 TTE,
gov1 0:a761fba7f8a8 124 QR_TABLE_00,
gov1 0:a761fba7f8a8 125 FULL_SOC_THR,
gov1 0:a761fba7f8a8 126 R_CELL,
gov1 0:a761fba7f8a8 127 AVG_TA = 0x16,
gov1 0:a761fba7f8a8 128 CYCLES,
gov1 0:a761fba7f8a8 129 DESIGN_CAP,
gov1 0:a761fba7f8a8 130 AVG_V_CELL,
gov1 0:a761fba7f8a8 131 MAX_MIN_TEMP,
gov1 0:a761fba7f8a8 132 MAX_MIN_VOLT,
gov1 0:a761fba7f8a8 133 MAX_MIN_CURR,
gov1 0:a761fba7f8a8 134 CONFIG,
gov1 0:a761fba7f8a8 135 I_CHG_TERM,
gov1 0:a761fba7f8a8 136 AV_CAP,
gov1 0:a761fba7f8a8 137 TTF,
gov1 0:a761fba7f8a8 138 DEV_NAME,
gov1 0:a761fba7f8a8 139 QR_TABLE_10,
gov1 0:a761fba7f8a8 140 FULL_CAP_NOM,
gov1 0:a761fba7f8a8 141 AIN = 0x27,
gov1 0:a761fba7f8a8 142 LEARN_CFG,
gov1 0:a761fba7f8a8 143 FILTER_CFG,
gov1 0:a761fba7f8a8 144 RELAX_CFG,
gov1 0:a761fba7f8a8 145 MISC_CFG,
gov1 0:a761fba7f8a8 146 T_GAIN,
gov1 0:a761fba7f8a8 147 T_OFF,
gov1 0:a761fba7f8a8 148 C_GAIN,
gov1 0:a761fba7f8a8 149 C_OFF,
gov1 0:a761fba7f8a8 150 QR_TABLE_20 = 0x32,
gov1 0:a761fba7f8a8 151 DIE_TEMP = 0x34,
gov1 0:a761fba7f8a8 152 FULL_CAP,
gov1 0:a761fba7f8a8 153 R_COMP0 = 0x38,
gov1 0:a761fba7f8a8 154 TEMP_CO,
gov1 0:a761fba7f8a8 155 V_EMPTY,
gov1 0:a761fba7f8a8 156 F_STAT = 0x3D,
gov1 0:a761fba7f8a8 157 TIMER,
gov1 0:a761fba7f8a8 158 SHDN_TIMER,
gov1 0:a761fba7f8a8 159 USER_MEM1,
gov1 0:a761fba7f8a8 160 QR_TABLE_30 = 0x42,
gov1 0:a761fba7f8a8 161 R_GAIN,
gov1 0:a761fba7f8a8 162 DQ_ACC = 0x45,
gov1 0:a761fba7f8a8 163 DP_ACC,
gov1 0:a761fba7f8a8 164 CONVG_CFG = 0x49,
gov1 0:a761fba7f8a8 165 VF_REM_CAP,
gov1 0:a761fba7f8a8 166 QH = 0x4D,
gov1 0:a761fba7f8a8 167 STATUS_2 = 0xB0,
gov1 0:a761fba7f8a8 168 POWER,
gov1 0:a761fba7f8a8 169 ID_USER_MEM2,
gov1 0:a761fba7f8a8 170 AVG_POWER,
gov1 0:a761fba7f8a8 171 I_ALRT_TH,
gov1 0:a761fba7f8a8 172 TTF_CFG,
gov1 0:a761fba7f8a8 173 CV_MIX_CAP,
gov1 0:a761fba7f8a8 174 CV_HALF_TIME,
gov1 0:a761fba7f8a8 175 CG_TEMP_CO,
gov1 0:a761fba7f8a8 176 CURVE,
gov1 0:a761fba7f8a8 177 HIB_CFG,
gov1 0:a761fba7f8a8 178 CONFIG2,
gov1 0:a761fba7f8a8 179 V_RIPPLE,
gov1 0:a761fba7f8a8 180 RIPPLE_CFG,
gov1 0:a761fba7f8a8 181 TIMER_H,
gov1 0:a761fba7f8a8 182 R_SENSE_USER_MEM3 = 0xD0,
gov1 0:a761fba7f8a8 183 SC_OCV_LIM,
gov1 0:a761fba7f8a8 184 SOC_HOLD,
gov1 0:a761fba7f8a8 185 MAX_PEAK_POWER,
gov1 0:a761fba7f8a8 186 SUS_PEAK_POWER,
gov1 0:a761fba7f8a8 187 PACK_RESISTANCE,
gov1 0:a761fba7f8a8 188 SYS_RESISTANCE,
gov1 0:a761fba7f8a8 189 MIN_SYS_VOLTAGE,
gov1 0:a761fba7f8a8 190 MPP_CURRENT,
gov1 0:a761fba7f8a8 191 SPP_CURRENT,
gov1 0:a761fba7f8a8 192 MODEL_CFG,
gov1 0:a761fba7f8a8 193 AT_Q_RESIDUAL,
gov1 0:a761fba7f8a8 194 AT_TTE,
gov1 0:a761fba7f8a8 195 AT_AV_SOC,
gov1 0:a761fba7f8a8 196 AT_AV_CA
gov1 0:a761fba7f8a8 197 } reg_t;
gov1 0:a761fba7f8a8 198
gov1 0:a761fba7f8a8 199 /**
gov1 0:a761fba7f8a8 200 * MAX17055 constructor
gov1 0:a761fba7f8a8 201 *
gov1 0:a761fba7f8a8 202 * @param i2c I2C object to use.
gov1 0:a761fba7f8a8 203 * @param address Slave Address of the device.
gov1 0:a761fba7f8a8 204 */
gov1 0:a761fba7f8a8 205 MAX17055(I2C &i2c, int address = MAX17055_I2C_ADDRESS);
gov1 0:a761fba7f8a8 206
gov1 0:a761fba7f8a8 207 /**
gov1 0:a761fba7f8a8 208 * MAX17055 destructor
gov1 0:a761fba7f8a8 209 */
gov1 0:a761fba7f8a8 210 ~MAX17055();
gov1 0:a761fba7f8a8 211
gov1 0:a761fba7f8a8 212 /**
gov1 0:a761fba7f8a8 213 * @brief Initialize driver state
gov1 0:a761fba7f8a8 214 * @details Initialize driver with supplied sense resistor value.
gov1 0:a761fba7f8a8 215 * @param value The sense resistor value in ohms
gov1 0:a761fba7f8a8 216 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 217 */
gov1 0:a761fba7f8a8 218 void init(float r_sense);
gov1 0:a761fba7f8a8 219
gov1 0:a761fba7f8a8 220 /**
gov1 0:a761fba7f8a8 221 * @brief Read status register
gov1 0:a761fba7f8a8 222 * @details Read status register.
gov1 0:a761fba7f8a8 223 * @param value The location to store value read
gov1 0:a761fba7f8a8 224 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 225 */
gov1 0:a761fba7f8a8 226 int status(int *value);
gov1 0:a761fba7f8a8 227
gov1 0:a761fba7f8a8 228 /**
gov1 0:a761fba7f8a8 229 * @brief Read VCell register
gov1 0:a761fba7f8a8 230 * @details Read VCell register reports the voltage measured between
gov1 0:a761fba7f8a8 231 * BATT and CSP.
gov1 0:a761fba7f8a8 232 * @param value The location to store value read
gov1 0:a761fba7f8a8 233 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 234 */
gov1 0:a761fba7f8a8 235 int v_cell(int *value);
gov1 0:a761fba7f8a8 236
gov1 0:a761fba7f8a8 237 /**
gov1 0:a761fba7f8a8 238 * @brief Read VCell register
gov1 0:a761fba7f8a8 239 * @details The VCell register reports the voltage measured between
gov1 0:a761fba7f8a8 240 * BATT and CSP.
gov1 0:a761fba7f8a8 241 * @param value The location to store value read
gov1 0:a761fba7f8a8 242 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 243 */
gov1 0:a761fba7f8a8 244 int v_cell(float *value);
gov1 0:a761fba7f8a8 245
gov1 0:a761fba7f8a8 246 /**
gov1 0:a761fba7f8a8 247 * @brief Read AvgVCell register
gov1 0:a761fba7f8a8 248 * @details The AvgVCell register reports an average of the VCell
gov1 0:a761fba7f8a8 249 * register readings.
gov1 0:a761fba7f8a8 250 * @param value The location to store value read
gov1 0:a761fba7f8a8 251 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 252 */
gov1 0:a761fba7f8a8 253 int avg_v_cell(int *value);
gov1 0:a761fba7f8a8 254
gov1 0:a761fba7f8a8 255 /**
gov1 0:a761fba7f8a8 256 * @brief Read AvgVCell register
gov1 0:a761fba7f8a8 257 * @details The AvgVCell register reports an average of the VCell
gov1 0:a761fba7f8a8 258 * register readings.
gov1 0:a761fba7f8a8 259 * @param value The location to store value read
gov1 0:a761fba7f8a8 260 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 261 */
gov1 0:a761fba7f8a8 262 int avg_v_cell(float *value);
gov1 0:a761fba7f8a8 263
gov1 0:a761fba7f8a8 264 /**
gov1 0:a761fba7f8a8 265 * @brief Read MaxMinVolt register
gov1 0:a761fba7f8a8 266 * @details The MaxMinVolt register maintains the maximum and minimum
gov1 0:a761fba7f8a8 267 * of VCell register values since device reset.
gov1 0:a761fba7f8a8 268 * @param value The location to store value read
gov1 0:a761fba7f8a8 269 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 270 */
gov1 0:a761fba7f8a8 271 int max_min_volt(int *max, int *min);
gov1 0:a761fba7f8a8 272
gov1 0:a761fba7f8a8 273 /**
gov1 0:a761fba7f8a8 274 * @brief Read MaxMinVolt register
gov1 0:a761fba7f8a8 275 * @details The MaxMinVolt register maintains the maximum and minimum
gov1 0:a761fba7f8a8 276 * of VCell register values since device reset.
gov1 0:a761fba7f8a8 277 * @param value The location to store value read
gov1 0:a761fba7f8a8 278 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 279 */
gov1 0:a761fba7f8a8 280 int max_min_volt(float *max, float *min);
gov1 0:a761fba7f8a8 281
gov1 0:a761fba7f8a8 282 /**
gov1 0:a761fba7f8a8 283 * @brief Read Current register
gov1 0:a761fba7f8a8 284 * @details The Current register reports the voltage between the
gov1 0:a761fba7f8a8 285 * CSP and CSN pins.
gov1 0:a761fba7f8a8 286 * @param value The location to store value read
gov1 0:a761fba7f8a8 287 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 288 */
gov1 0:a761fba7f8a8 289 int current(int *value);
gov1 0:a761fba7f8a8 290
gov1 0:a761fba7f8a8 291 /**
gov1 0:a761fba7f8a8 292 * @brief Read Current register
gov1 0:a761fba7f8a8 293 * @details The Current register reports the voltage between the
gov1 0:a761fba7f8a8 294 * CSP and CSN pins.
gov1 0:a761fba7f8a8 295 * @param value The location to store value read
gov1 0:a761fba7f8a8 296 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 297 */
gov1 0:a761fba7f8a8 298 int current(float *value);
gov1 0:a761fba7f8a8 299
gov1 0:a761fba7f8a8 300 /**
gov1 0:a761fba7f8a8 301 * @brief Read AvgCurrent register
gov1 0:a761fba7f8a8 302 * @details The AvgCurrent register reports an average of Current
gov1 0:a761fba7f8a8 303 * register readings.
gov1 0:a761fba7f8a8 304 * @param value The location to store value read
gov1 0:a761fba7f8a8 305 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 306 */
gov1 0:a761fba7f8a8 307 int avg_current(int *value);
gov1 0:a761fba7f8a8 308
gov1 0:a761fba7f8a8 309 /**
gov1 0:a761fba7f8a8 310 * @brief Read AvgCurrent register
gov1 0:a761fba7f8a8 311 * @details The AvgCurrent register reports an average of Current
gov1 0:a761fba7f8a8 312 * register readings.
gov1 0:a761fba7f8a8 313 * @param value The location to store value read
gov1 0:a761fba7f8a8 314 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 315 */
gov1 0:a761fba7f8a8 316 int avg_current(float *value);
gov1 0:a761fba7f8a8 317
gov1 0:a761fba7f8a8 318 /**
gov1 0:a761fba7f8a8 319 * @brief Read MinMaxCurr register
gov1 0:a761fba7f8a8 320 * @details The MaxMinCurr register maintains the maximum and
gov1 0:a761fba7f8a8 321 * minimum Current register values since the last IC reset
gov1 0:a761fba7f8a8 322 * or until cleared by host software.
gov1 0:a761fba7f8a8 323 * @param value The location to store value read
gov1 0:a761fba7f8a8 324 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 325 */
gov1 0:a761fba7f8a8 326 int max_min_curr(int *max, int *min);
gov1 0:a761fba7f8a8 327
gov1 0:a761fba7f8a8 328 /**
gov1 0:a761fba7f8a8 329 * @brief Read MinMaxCurrent register
gov1 0:a761fba7f8a8 330 * @details The MaxMinCurr register maintains the maximum and
gov1 0:a761fba7f8a8 331 * minimum Current register values since the last IC reset
gov1 0:a761fba7f8a8 332 * or until cleared by host software.
gov1 0:a761fba7f8a8 333 * @param value The location to store value read
gov1 0:a761fba7f8a8 334 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 335 */
gov1 0:a761fba7f8a8 336 int max_min_curr(float *max, float *min);
gov1 0:a761fba7f8a8 337
gov1 0:a761fba7f8a8 338 /**
gov1 0:a761fba7f8a8 339 * @brief Read Temp register
gov1 0:a761fba7f8a8 340 * @details The Temp register provides the temperature measured
gov1 0:a761fba7f8a8 341 * by the thermistor or die temperature.
gov1 0:a761fba7f8a8 342 * @param value The location to store value read
gov1 0:a761fba7f8a8 343 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 344 */
gov1 0:a761fba7f8a8 345 int temp(int *value);
gov1 0:a761fba7f8a8 346
gov1 0:a761fba7f8a8 347 /**
gov1 0:a761fba7f8a8 348 * @brief Read Temp register
gov1 0:a761fba7f8a8 349 * @details The Temp register provides the temperature measured
gov1 0:a761fba7f8a8 350 * by the thermistor or die temperature.
gov1 0:a761fba7f8a8 351 * @param value The location to store value read
gov1 0:a761fba7f8a8 352 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 353 */
gov1 0:a761fba7f8a8 354 int temp(float *value);
gov1 0:a761fba7f8a8 355
gov1 0:a761fba7f8a8 356 /**
gov1 0:a761fba7f8a8 357 * @brief Read AvgTA register
gov1 0:a761fba7f8a8 358 * @details The AvgTA register reports an average of the readings
gov1 0:a761fba7f8a8 359 * from the Temp register.
gov1 0:a761fba7f8a8 360 * @param value The location to store value read
gov1 0:a761fba7f8a8 361 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 362 */
gov1 0:a761fba7f8a8 363 int avg_ta(int *value);
gov1 0:a761fba7f8a8 364
gov1 0:a761fba7f8a8 365 /**
gov1 0:a761fba7f8a8 366 * @brief Read AvgTA register
gov1 0:a761fba7f8a8 367 * @details The AvgTA register reports an average of the readings
gov1 0:a761fba7f8a8 368 * from the Temp register.
gov1 0:a761fba7f8a8 369 * @param value The location to store value read
gov1 0:a761fba7f8a8 370 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 371 */
gov1 0:a761fba7f8a8 372 int avg_ta(float *value);
gov1 0:a761fba7f8a8 373
gov1 0:a761fba7f8a8 374 /**
gov1 0:a761fba7f8a8 375 * @brief Read MaxMinTemp register
gov1 0:a761fba7f8a8 376 * @details The MaxMinTemp register maintains the maximum and
gov1 0:a761fba7f8a8 377 * minimum Temp register values since the last fuel-gauge reset
gov1 0:a761fba7f8a8 378 * or until cleared by host software.
gov1 0:a761fba7f8a8 379 * @param value The location to store value read
gov1 0:a761fba7f8a8 380 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 381 */
gov1 0:a761fba7f8a8 382 int max_min_temp(int *max, int *min);
gov1 0:a761fba7f8a8 383
gov1 0:a761fba7f8a8 384 /**
gov1 0:a761fba7f8a8 385 * @brief Read MaxMinTemp register
gov1 0:a761fba7f8a8 386 * @details The MaxMinTemp register maintains the maximum and
gov1 0:a761fba7f8a8 387 * minimum Temp register values since the last fuel-gauge reset
gov1 0:a761fba7f8a8 388 * or until cleared by host software.
gov1 0:a761fba7f8a8 389 * @param value The location to store value read
gov1 0:a761fba7f8a8 390 * @returns 0 if no errors, -1 if error
gov1 0:a761fba7f8a8 391 */
gov1 0:a761fba7f8a8 392 int max_min_temp(float *max, float *min);
gov1 0:a761fba7f8a8 393
gov1 0:a761fba7f8a8 394 /**
gov1 0:a761fba7f8a8 395 * @brief Write 8-Bit Register
gov1 0:a761fba7f8a8 396 * @details Writes the given value to the specified register.
gov1 0:a761fba7f8a8 397 * @param reg The register to be written
gov1 0:a761fba7f8a8 398 * @param value The data to be written
gov1 0:a761fba7f8a8 399 * @param verify Verify data after write
gov1 0:a761fba7f8a8 400 * @returns 0 if no errors, -1 if error.
gov1 0:a761fba7f8a8 401 */
gov1 0:a761fba7f8a8 402 int writeReg(reg_t reg, char value, bool verify = false);
gov1 0:a761fba7f8a8 403
gov1 0:a761fba7f8a8 404 /**
gov1 0:a761fba7f8a8 405 * @brief Write 16-Bit Register
gov1 0:a761fba7f8a8 406 * @details Writes the given value to the specified register.
gov1 0:a761fba7f8a8 407 * @param reg The register to be written
gov1 0:a761fba7f8a8 408 * @param value The data to be written
gov1 0:a761fba7f8a8 409 * @param verify Verify data after write
gov1 0:a761fba7f8a8 410 * @returns 0 if no errors, -1 if error.
gov1 0:a761fba7f8a8 411 */
gov1 0:a761fba7f8a8 412 int writeReg(reg_t reg, uint16_t value, bool verify = false);
gov1 0:a761fba7f8a8 413
gov1 0:a761fba7f8a8 414 /**
gov1 0:a761fba7f8a8 415 * @brief Read 8-Bit Register
gov1 0:a761fba7f8a8 416 * @details Reads from the specified register
gov1 0:a761fba7f8a8 417 * @param reg The register to be read
gov1 0:a761fba7f8a8 418 * @param value Pointer for where to store the data
gov1 0:a761fba7f8a8 419 * @returns 0 if no errors, -1 if error.
gov1 0:a761fba7f8a8 420 */
gov1 0:a761fba7f8a8 421 int readReg(reg_t reg, char *value);
gov1 0:a761fba7f8a8 422
gov1 0:a761fba7f8a8 423 /**
gov1 0:a761fba7f8a8 424 * @brief Read 8-Bit Register(s)
gov1 0:a761fba7f8a8 425 * @details Reads len bytes starting from the specified register
gov1 0:a761fba7f8a8 426 * @param reg The register to be read
gov1 0:a761fba7f8a8 427 * @param value Pointer for where to store the data
gov1 0:a761fba7f8a8 428 * @param len Number of bytes to read
gov1 0:a761fba7f8a8 429 * @returns 0 if no errors, -1 if error.
gov1 0:a761fba7f8a8 430 */
gov1 0:a761fba7f8a8 431 int readReg(reg_t reg, char *buf, int len);
gov1 0:a761fba7f8a8 432
gov1 0:a761fba7f8a8 433 /**
gov1 0:a761fba7f8a8 434 * @brief Read 16-Bit Register
gov1 0:a761fba7f8a8 435 * @details Reads from the specified register
gov1 0:a761fba7f8a8 436 * @param reg The register to be read
gov1 0:a761fba7f8a8 437 * @param value Pointer for where to store the data
gov1 0:a761fba7f8a8 438 * @returns 0 if no errors, -1 if error.
gov1 0:a761fba7f8a8 439 */
gov1 0:a761fba7f8a8 440 int readReg16(reg_t reg, int *value);
gov1 0:a761fba7f8a8 441
gov1 0:a761fba7f8a8 442 //** ***************************************************************** **/
gov1 0:a761fba7f8a8 443 //** *********************** added by gv 7/8/2018 ******************** **/
gov1 0:a761fba7f8a8 444 //** ***************************************************************** **/
gov1 0:a761fba7f8a8 445 int MAX17055::soc1(int *value);
gov1 0:a761fba7f8a8 446 int MAX17055::soc2(int *valueLow, int *valueHigh);
gov1 0:a761fba7f8a8 447
gov1 0:a761fba7f8a8 448 int MAX17055::reportSOC(int *valueHigh);
gov1 0:a761fba7f8a8 449
gov1 0:a761fba7f8a8 450 int MAX17055::tte1(int *value);
gov1 0:a761fba7f8a8 451 int MAX17055::tte2(int *valueLow, int *valueHigh);
gov1 0:a761fba7f8a8 452 int MAX17055::writeConfig(void);
gov1 0:a761fba7f8a8 453
gov1 0:a761fba7f8a8 454 private:
gov1 0:a761fba7f8a8 455 I2C &i2c;
gov1 0:a761fba7f8a8 456 int addr;
gov1 0:a761fba7f8a8 457
gov1 0:a761fba7f8a8 458 float r_sense;
gov1 0:a761fba7f8a8 459 float i_lsb;
gov1 0:a761fba7f8a8 460 float i_min_max_lsb;
gov1 0:a761fba7f8a8 461 };
gov1 0:a761fba7f8a8 462
gov1 0:a761fba7f8a8 463 #endif