This is a library for the MAX17055 Li+ Battery Fuel Gauge.
Dependents: Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot
Fork of max17055 by
max17055.h@5:a18a189588dc, 2017-10-02 (annotated)
- Committer:
- fneirab
- Date:
- Mon Oct 02 21:59:00 2017 +0000
- Revision:
- 5:a18a189588dc
- Parent:
- 4:a4d6ae2182c2
- Child:
- 6:5ced10109ebf
changes might have affected the compile. Saved for safety.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fneirab | 4:a4d6ae2182c2 | 1 | /******************************************************************//** |
fneirab | 4:a4d6ae2182c2 | 2 | * @file max17055.h |
fneirab | 4:a4d6ae2182c2 | 3 | * |
fneirab | 5:a18a189588dc | 4 | * @author Felipe Neira - Maxim Integrated - TTS |
fneirab | 4:a4d6ae2182c2 | 5 | * |
fneirab | 4:a4d6ae2182c2 | 6 | * @version 1.0 |
fneirab | 4:a4d6ae2182c2 | 7 | * |
fneirab | 4:a4d6ae2182c2 | 8 | * Started: 11SEP17 |
fneirab | 4:a4d6ae2182c2 | 9 | * |
fneirab | 4:a4d6ae2182c2 | 10 | * Updated: |
fneirab | 4:a4d6ae2182c2 | 11 | * |
fneirab | 4:a4d6ae2182c2 | 12 | * @brief Source file for MAX31855 class |
fneirab | 4:a4d6ae2182c2 | 13 | * |
fneirab | 4:a4d6ae2182c2 | 14 | ******************************************************************************** |
fneirab | 4:a4d6ae2182c2 | 15 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
fneirab | 4:a4d6ae2182c2 | 16 | * |
fneirab | 4:a4d6ae2182c2 | 17 | * Permission is hereby granted, free of charge, to any person obtaining a |
fneirab | 4:a4d6ae2182c2 | 18 | * copy of this software and associated documentation files (the "Software"), |
fneirab | 4:a4d6ae2182c2 | 19 | * to deal in the Software without restriction, including without limitation |
fneirab | 4:a4d6ae2182c2 | 20 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
fneirab | 4:a4d6ae2182c2 | 21 | * and/or sell copies of the Software, and to permit persons to whom the |
fneirab | 4:a4d6ae2182c2 | 22 | * Software is furnished to do so, subject to the following conditions: |
fneirab | 4:a4d6ae2182c2 | 23 | * |
fneirab | 4:a4d6ae2182c2 | 24 | * The above copyright notice and this permission notice shall be included |
fneirab | 4:a4d6ae2182c2 | 25 | * in all copies or substantial portions of the Software. |
fneirab | 4:a4d6ae2182c2 | 26 | * |
fneirab | 4:a4d6ae2182c2 | 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
fneirab | 4:a4d6ae2182c2 | 28 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
fneirab | 4:a4d6ae2182c2 | 29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
fneirab | 4:a4d6ae2182c2 | 30 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
fneirab | 4:a4d6ae2182c2 | 31 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
fneirab | 4:a4d6ae2182c2 | 32 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
fneirab | 4:a4d6ae2182c2 | 33 | * OTHER DEALINGS IN THE SOFTWARE. |
fneirab | 4:a4d6ae2182c2 | 34 | * |
fneirab | 4:a4d6ae2182c2 | 35 | * Except as contained in this notice, the name of Maxim Integrated |
fneirab | 4:a4d6ae2182c2 | 36 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
fneirab | 4:a4d6ae2182c2 | 37 | * Products, Inc. Branding Policy. |
fneirab | 4:a4d6ae2182c2 | 38 | * |
fneirab | 4:a4d6ae2182c2 | 39 | * The mere transfer of this software does not imply any licenses |
fneirab | 4:a4d6ae2182c2 | 40 | * of trade secrets, proprietary technology, copyrights, patents, |
fneirab | 4:a4d6ae2182c2 | 41 | * trademarks, maskwork rights, or any other form of intellectual |
fneirab | 4:a4d6ae2182c2 | 42 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
fneirab | 4:a4d6ae2182c2 | 43 | * ownership rights. |
fneirab | 4:a4d6ae2182c2 | 44 | * |
fneirab | 4:a4d6ae2182c2 | 45 | ******************************************************************************/ |
fneirab | 0:80c39eb8f3ba | 46 | |
fneirab | 0:80c39eb8f3ba | 47 | #ifndef __MAX17055_H_ |
fneirab | 0:80c39eb8f3ba | 48 | #define __MAX17055_H_ |
fneirab | 0:80c39eb8f3ba | 49 | |
fneirab | 0:80c39eb8f3ba | 50 | // Include |
fneirab | 0:80c39eb8f3ba | 51 | #include "mbed.h" |
fneirab | 0:80c39eb8f3ba | 52 | |
fneirab | 2:ff7db397b70f | 53 | /* STATUS register bits */ |
fneirab | 2:ff7db397b70f | 54 | #define MAX17055_STATUS_BST (1 << 3) |
fneirab | 2:ff7db397b70f | 55 | #define MAX17055_STATUS_POR (1 << 1) |
fneirab | 2:ff7db397b70f | 56 | |
fneirab | 5:a18a189588dc | 57 | /// Model loading options |
fneirab | 4:a4d6ae2182c2 | 58 | #define MODEL_LOADING_OPTION1 1 |
fneirab | 4:a4d6ae2182c2 | 59 | #define MODEL_LOADING_OPTION2 2 |
fneirab | 4:a4d6ae2182c2 | 60 | #define MODEL_LOADING_OPTION3 3 |
fneirab | 4:a4d6ae2182c2 | 61 | |
fneirab | 0:80c39eb8f3ba | 62 | |
fneirab | 0:80c39eb8f3ba | 63 | /** |
fneirab | 0:80c39eb8f3ba | 64 | * @brief Library for the MAX17055\n |
fneirab | 0:80c39eb8f3ba | 65 | * The MAX17055 is a low 7μA operating current fuel gauge |
fneirab | 0:80c39eb8f3ba | 66 | * which implements Maxim ModelGauge™ m5 EZ algorithm. |
fneirab | 0:80c39eb8f3ba | 67 | * ModelGauge m5 EZ makes fuel gauge implementation easy |
fneirab | 0:80c39eb8f3ba | 68 | * by eliminating battery characterization requirements |
fneirab | 0:80c39eb8f3ba | 69 | * and simplifying host software interaction. |
fneirab | 0:80c39eb8f3ba | 70 | * The ModelGauge m5 EZ robust algorithm provides tolerance against |
fneirab | 0:80c39eb8f3ba | 71 | * battery diversity for most lithium batteries and applications. |
fneirab | 0:80c39eb8f3ba | 72 | * Communication is through an SPI-compatible interface. |
fneirab | 0:80c39eb8f3ba | 73 | * |
fneirab | 0:80c39eb8f3ba | 74 | * @code |
fneirab | 0:80c39eb8f3ba | 75 | * #include "mbed.h" |
fneirab | 0:80c39eb8f3ba | 76 | * #include "MAX170155.h" |
fneirab | 0:80c39eb8f3ba | 77 | * |
fneirab | 0:80c39eb8f3ba | 78 | * |
fneirab | 0:80c39eb8f3ba | 79 | * // Hardware serial port |
fneirab | 0:80c39eb8f3ba | 80 | * Serial serial(USBTX, USBRX); |
fneirab | 0:80c39eb8f3ba | 81 | * |
fneirab | 0:80c39eb8f3ba | 82 | * //SPI communications |
fneirab | 0:80c39eb8f3ba | 83 | * I2C i2c(SCL, SDA); |
fneirab | 0:80c39eb8f3ba | 84 | * |
fneirab | 0:80c39eb8f3ba | 85 | * //Fuel Gauge |
fneirab | 0:80c39eb8f3ba | 86 | * MAX17055 max17055(i2C, Sutff );//To be completed |
fneirab | 0:80c39eb8f3ba | 87 | * |
fneirab | 0:80c39eb8f3ba | 88 | * |
fneirab | 0:80c39eb8f3ba | 89 | * int main(void) |
fneirab | 0:80c39eb8f3ba | 90 | * { |
fneirab | 0:80c39eb8f3ba | 91 | * CODE CODE |
fneirab | 0:80c39eb8f3ba | 92 | * while(true) |
fneirab | 0:80c39eb8f3ba | 93 | * { |
fneirab | 0:80c39eb8f3ba | 94 | * CODE CODE |
fneirab | 0:80c39eb8f3ba | 95 | * } |
fneirab | 0:80c39eb8f3ba | 96 | * } |
fneirab | 0:80c39eb8f3ba | 97 | * @endcode |
fneirab | 0:80c39eb8f3ba | 98 | */ |
fneirab | 0:80c39eb8f3ba | 99 | |
fneirab | 5:a18a189588dc | 100 | /** |
fneirab | 5:a18a189588dc | 101 | * @brief Saved Fuel Gauge Parameters |
fneirab | 5:a18a189588dc | 102 | * @details Struct with saved fuel Gauge Parametrs |
fneirab | 5:a18a189588dc | 103 | */ |
fneirab | 5:a18a189588dc | 104 | |
fneirab | 5:a18a189588dc | 105 | struct saved_fuel_gauge_params_t{ |
fneirab | 5:a18a189588dc | 106 | int rcomp0; /**< Explain */ |
fneirab | 5:a18a189588dc | 107 | int temp_co; /**< Explain */ |
fneirab | 5:a18a189588dc | 108 | int full_cap_rep; /**< Explain */ |
fneirab | 5:a18a189588dc | 109 | int cycles; /**< Explain */ |
fneirab | 5:a18a189588dc | 110 | int full_cap_nom; /**< Explain */ |
fneirab | 5:a18a189588dc | 111 | } ; |
fneirab | 5:a18a189588dc | 112 | |
fneirab | 5:a18a189588dc | 113 | /** |
fneirab | 5:a18a189588dc | 114 | * @brief Saved Fuel Gauge Parameters |
fneirab | 5:a18a189588dc | 115 | * @details Struct with saved fuel Gauge Parametrs |
fneirab | 5:a18a189588dc | 116 | */ |
fneirab | 0:80c39eb8f3ba | 117 | |
fneirab | 4:a4d6ae2182c2 | 118 | |
fneirab | 5:a18a189588dc | 119 | struct max17055_platform_data{ |
fneirab | 4:a4d6ae2182c2 | 120 | uint16_t designcap;/**< struct value 1 */ |
fneirab | 4:a4d6ae2182c2 | 121 | uint16_t ichgterm; /**< struct value 2 */ |
fneirab | 4:a4d6ae2182c2 | 122 | uint16_t vempty; /**< struct value 3 */ |
fneirab | 5:a18a189588dc | 123 | int vcharge; /**< struct value 1 */ |
fneirab | 4:a4d6ae2182c2 | 124 | |
fneirab | 5:a18a189588dc | 125 | uint16_t learncfg; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 126 | uint16_t relaxcfg; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 127 | uint16_t config; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 128 | uint16_t config2; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 129 | uint16_t fullsocthr;/**< struct value 1 */ |
fneirab | 5:a18a189588dc | 130 | uint16_t tgain; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 131 | uint16_t toff; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 132 | uint16_t curve; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 133 | uint16_t rcomp0; /**< struct value 1 */ |
fneirab | 5:a18a189588dc | 134 | uint16_t tempco; /**< struct value 1 */ |
fneirab | 4:a4d6ae2182c2 | 135 | uint16_t qrtable00; |
fneirab | 4:a4d6ae2182c2 | 136 | uint16_t qrtable10; |
fneirab | 4:a4d6ae2182c2 | 137 | uint16_t qrtable20; |
fneirab | 4:a4d6ae2182c2 | 138 | uint16_t qrtable30; |
fneirab | 4:a4d6ae2182c2 | 139 | |
fneirab | 4:a4d6ae2182c2 | 140 | uint16_t dpacc; |
fneirab | 4:a4d6ae2182c2 | 141 | uint16_t modelcfg; |
fneirab | 4:a4d6ae2182c2 | 142 | |
fneirab | 4:a4d6ae2182c2 | 143 | //uint16_t model_data[MAX17055_TABLE_SIZE]; |
fneirab | 4:a4d6ae2182c2 | 144 | int (*get_charging_status)(void); |
fneirab | 4:a4d6ae2182c2 | 145 | int model_option; |
fneirab | 5:a18a189588dc | 146 | /** |
fneirab | 4:a4d6ae2182c2 | 147 | * rsense in miliOhms. |
fneirab | 4:a4d6ae2182c2 | 148 | * default 10 (if rsense = 0) as it is the recommended value by |
fneirab | 4:a4d6ae2182c2 | 149 | * the datasheet although it can be changed by board designers. |
fneirab | 4:a4d6ae2182c2 | 150 | */ |
fneirab | 5:a18a189588dc | 151 | unsigned int rsense; |
fneirab | 5:a18a189588dc | 152 | int volt_min; /**< in mV */ |
fneirab | 5:a18a189588dc | 153 | int volt_max; /**< in mV */ |
fneirab | 5:a18a189588dc | 154 | int temp_min; /**< in DegreC */ |
fneirab | 5:a18a189588dc | 155 | int temp_max; /**< in DegreeC */ |
fneirab | 5:a18a189588dc | 156 | int soc_max; /**< in percent */ |
fneirab | 5:a18a189588dc | 157 | int soc_min; /**< in percent */ |
fneirab | 5:a18a189588dc | 158 | int curr_max; /**< in mA */ |
fneirab | 5:a18a189588dc | 159 | int curr_min; /**< in mA */ |
fneirab | 5:a18a189588dc | 160 | } ; |
fneirab | 5:a18a189588dc | 161 | |
fneirab | 5:a18a189588dc | 162 | |
fneirab | 4:a4d6ae2182c2 | 163 | |
fneirab | 5:a18a189588dc | 164 | //! BATTERY Battery Parameters Class |
fneirab | 5:a18a189588dc | 165 | /*! |
fneirab | 5:a18a189588dc | 166 | Generic API for battery parameters |
fneirab | 5:a18a189588dc | 167 | */ |
fneirab | 5:a18a189588dc | 168 | class BATTERY |
fneirab | 5:a18a189588dc | 169 | { |
fneirab | 5:a18a189588dc | 170 | |
fneirab | 5:a18a189588dc | 171 | public: |
fneirab | 5:a18a189588dc | 172 | |
fneirab | 0:80c39eb8f3ba | 173 | |
fneirab | 5:a18a189588dc | 174 | struct battery_cfg_t{ |
fneirab | 5:a18a189588dc | 175 | int capacity; //!< The rated capacity in mAh of the battery |
fneirab | 5:a18a189588dc | 176 | int voltageMax; //!< The maximum voltage in mV that should be used for charging |
fneirab | 5:a18a189588dc | 177 | int voltageNom; //!< The normal voltage in mV of the battery near mid charge |
fneirab | 5:a18a189588dc | 178 | int voltageMin; //!< The minimum voltage in mV that the battery should be discharged |
fneirab | 5:a18a189588dc | 179 | int temperatureMax; //!< The maximum temperature in degrees C where charging is allowed |
fneirab | 5:a18a189588dc | 180 | int temperatureMin; //!< The minimum temperature in degrees C where charging is allowed |
fneirab | 5:a18a189588dc | 181 | int currentCharge; //!< The current as a percentage of capicity used for charging |
fneirab | 5:a18a189588dc | 182 | int currentTerm; //!< The current as a percentage of capacity to stop charging |
fneirab | 5:a18a189588dc | 183 | int currentPre; //!< The current as a percentage of capacity for pre-charging |
fneirab | 5:a18a189588dc | 184 | } ; |
fneirab | 5:a18a189588dc | 185 | |
fneirab | 5:a18a189588dc | 186 | |
fneirab | 5:a18a189588dc | 187 | |
fneirab | 0:80c39eb8f3ba | 188 | |
fneirab | 4:a4d6ae2182c2 | 189 | }; |
fneirab | 0:80c39eb8f3ba | 190 | |
fneirab | 4:a4d6ae2182c2 | 191 | /******************************************************************//** |
fneirab | 4:a4d6ae2182c2 | 192 | * MAX17055 Class |
fneirab | 4:a4d6ae2182c2 | 193 | **********************************************************************/ |
fneirab | 4:a4d6ae2182c2 | 194 | /// MAX17055 Battery Fuel Gauge Class |
fneirab | 0:80c39eb8f3ba | 195 | /** Generic API for a battery fuel gauge |
fneirab | 0:80c39eb8f3ba | 196 | */ |
fneirab | 0:80c39eb8f3ba | 197 | class MAX17055 |
fneirab | 0:80c39eb8f3ba | 198 | { |
fneirab | 0:80c39eb8f3ba | 199 | |
fneirab | 0:80c39eb8f3ba | 200 | public: |
fneirab | 0:80c39eb8f3ba | 201 | |
fneirab | 0:80c39eb8f3ba | 202 | ///7-bit slave address |
fneirab | 0:80c39eb8f3ba | 203 | static const uint8_t I2C_ADRS = 0x36; //Slave address 0x6C or 0x36 for 7 MSbit Addres |
fneirab | 0:80c39eb8f3ba | 204 | ///8-bit write address |
fneirab | 0:80c39eb8f3ba | 205 | static const uint8_t I2C_W_ADRS = 0x6C; |
fneirab | 0:80c39eb8f3ba | 206 | ///8-bit read address |
fneirab | 0:80c39eb8f3ba | 207 | static const uint8_t I2C_R_ADRS = 0x6D; |
fneirab | 0:80c39eb8f3ba | 208 | /////Max # Bytes in FIFO |
fneirab | 0:80c39eb8f3ba | 209 | // static const uint16_t MAX_FIFO_BYTES = 288; |
fneirab | 0:80c39eb8f3ba | 210 | // ///# of bytes per LED channel |
fneirab | 0:80c39eb8f3ba | 211 | // static const uint8_t BYTES_PER_CH = 3; |
fneirab | 0:80c39eb8f3ba | 212 | |
fneirab | 5:a18a189588dc | 213 | struct BATTERY::battery_cfg_t batt_con; |
fneirab | 5:a18a189588dc | 214 | struct max17055_platform_data design_data; |
fneirab | 5:a18a189588dc | 215 | struct saved_fuel_gauge_params_t fuelGauge_params; |
fneirab | 0:80c39eb8f3ba | 216 | |
fneirab | 0:80c39eb8f3ba | 217 | |
fneirab | 0:80c39eb8f3ba | 218 | |
fneirab | 0:80c39eb8f3ba | 219 | /** |
fneirab | 4:a4d6ae2182c2 | 220 | * @brief Register Addresses for the MAX17055 |
fneirab | 5:a18a189588dc | 221 | * @details Enumerated register addresses |
fneirab | 0:80c39eb8f3ba | 222 | */ |
fneirab | 0:80c39eb8f3ba | 223 | enum Registers_e { |
fneirab | 5:a18a189588dc | 224 | MAX17055_STATUS_REG = 0x00, /**< 0x00 */ |
fneirab | 5:a18a189588dc | 225 | MAX17055_VALRTTH_REG = 0x01, /**< 0x01 */ |
fneirab | 5:a18a189588dc | 226 | MAX17055_TALRTTH_REG = 0x02, /**< 0x02 */ |
fneirab | 5:a18a189588dc | 227 | MAX17055_SALRTTH_REG = 0x03, /**< 0x04 */ |
fneirab | 5:a18a189588dc | 228 | MAX17055_REPCAP_REG = 0x05, /**< 0x05 */ |
fneirab | 5:a18a189588dc | 229 | MAX17055_REPSOC_REG = 0x06, /**< 0x06 */ |
fneirab | 5:a18a189588dc | 230 | MAX17055_TEMP_REG = 0x08, /**< 0x07 */ |
fneirab | 5:a18a189588dc | 231 | MAX17055_VCELL_REG = 0x09, /**< 0x08 */ |
fneirab | 5:a18a189588dc | 232 | MAX17055_CURRENT_REG = 0x0A, /**< 0x0A */ |
fneirab | 5:a18a189588dc | 233 | MAX17055_AVGCURRENT_REG = 0x0B, /**< 0x0B */ |
fneirab | 5:a18a189588dc | 234 | MAX17055_REMCAP_REG = 0x0F, /**< 0x0F */ |
fneirab | 0:80c39eb8f3ba | 235 | |
fneirab | 5:a18a189588dc | 236 | MAX17055_FULLCAPREP_REG = 0x10, /**< 0x10 */ |
fneirab | 5:a18a189588dc | 237 | MAX17055_TTE_REG = 0X11, /**< 0x11 */ |
fneirab | 5:a18a189588dc | 238 | MAX17055_QRTABLE00_REG = 0x12, /**< 0x12 */ |
fneirab | 5:a18a189588dc | 239 | MAX17055_FULLSOCTHR_REG = 0x13, /**< 0x13 */ |
fneirab | 0:80c39eb8f3ba | 240 | MAX17055_CYCLES_REG = 0x17, |
fneirab | 0:80c39eb8f3ba | 241 | MAX17055_DESIGNCAP_REG = 0x18, |
fneirab | 0:80c39eb8f3ba | 242 | MAX17055_AVGVCELL_REG = 0x19, |
fneirab | 0:80c39eb8f3ba | 243 | MAX17055_MAXMINVOLT_REG = 0x1B, |
fneirab | 0:80c39eb8f3ba | 244 | MAX17055_CONFIG_REG = 0x1D, |
fneirab | 0:80c39eb8f3ba | 245 | MAX17055_ICHGTERM_REG = 0x1E, |
fneirab | 0:80c39eb8f3ba | 246 | |
fneirab | 0:80c39eb8f3ba | 247 | MAX17055_VERSION_REG = 0x21, |
fneirab | 0:80c39eb8f3ba | 248 | MAX17055_QRTABLE10_REG = 0x22, |
fneirab | 0:80c39eb8f3ba | 249 | MAX17055_FULLCAPNOM_REG = 0x23, |
fneirab | 0:80c39eb8f3ba | 250 | MAX17055_LEARNCFG_REG = 0x28, |
fneirab | 0:80c39eb8f3ba | 251 | MAX17055_RELAXCFG_REG = 0x2A, |
fneirab | 0:80c39eb8f3ba | 252 | MAX17055_TGAIN_REG = 0x2C, |
fneirab | 0:80c39eb8f3ba | 253 | MAX17055_TOFF_REG = 0x2D, |
fneirab | 0:80c39eb8f3ba | 254 | |
fneirab | 0:80c39eb8f3ba | 255 | MAX17055_QRTABLE20_REG = 0x32, |
fneirab | 0:80c39eb8f3ba | 256 | MAX17055_RCOMP0_REG = 0x38, |
fneirab | 0:80c39eb8f3ba | 257 | MAX17055_TEMPCO_REG = 0x39, |
fneirab | 0:80c39eb8f3ba | 258 | MAX17055_VEMPTY_REG = 0x3A, |
fneirab | 0:80c39eb8f3ba | 259 | MAX17055_FSTAT_REG = 0x3D, |
fneirab | 0:80c39eb8f3ba | 260 | |
fneirab | 0:80c39eb8f3ba | 261 | MAX17055_QRTABLE30_REG = 0x42, |
fneirab | 0:80c39eb8f3ba | 262 | MAX17055_DQACC_REG = 0x45, |
fneirab | 0:80c39eb8f3ba | 263 | MAX17055_DPACC_REG = 0x46, |
fneirab | 0:80c39eb8f3ba | 264 | MAX17055_VFSOC0_REG = 0x48, |
fneirab | 0:80c39eb8f3ba | 265 | MAX17055_QH0_REG = 0x4C, |
fneirab | 0:80c39eb8f3ba | 266 | MAX17055_QH_REG = 0x4D, |
fneirab | 0:80c39eb8f3ba | 267 | |
fneirab | 0:80c39eb8f3ba | 268 | MAX17055_VFSOC0_QH0_LOCK_REG = 0x60, |
fneirab | 0:80c39eb8f3ba | 269 | MAX17055_LOCK1_REG = 0x62, |
fneirab | 0:80c39eb8f3ba | 270 | MAX17055_LOCK2_REG = 0x63, |
fneirab | 0:80c39eb8f3ba | 271 | |
fneirab | 0:80c39eb8f3ba | 272 | MAX17055_MODELDATA_START_REG = 0x80, |
fneirab | 0:80c39eb8f3ba | 273 | |
fneirab | 0:80c39eb8f3ba | 274 | MAX17055_IALRTTH_REG = 0xB4, |
fneirab | 0:80c39eb8f3ba | 275 | MAX17055_CURVE_REG = 0xB9, |
fneirab | 0:80c39eb8f3ba | 276 | MAX17055_HIBCFG_REG = 0xBA, |
fneirab | 0:80c39eb8f3ba | 277 | MAX17055_CONFIG2_REG = 0xBB, |
fneirab | 0:80c39eb8f3ba | 278 | |
fneirab | 0:80c39eb8f3ba | 279 | MAX17055_MODELCFG_REG = 0xDB, |
fneirab | 0:80c39eb8f3ba | 280 | |
fneirab | 0:80c39eb8f3ba | 281 | MAX17055_OCV_REG = 0xFB, |
fneirab | 0:80c39eb8f3ba | 282 | MAX17055_VFSOC_REG = 0xFF, |
fneirab | 0:80c39eb8f3ba | 283 | } ; |
fneirab | 0:80c39eb8f3ba | 284 | |
fneirab | 4:a4d6ae2182c2 | 285 | |
fneirab | 4:a4d6ae2182c2 | 286 | |
fneirab | 4:a4d6ae2182c2 | 287 | |
fneirab | 0:80c39eb8f3ba | 288 | /** |
fneirab | 0:80c39eb8f3ba | 289 | * @brief max17055 Constructor |
fneirab | 0:80c39eb8f3ba | 290 | * @details max17055 Constructor with battery and i2c as parameters |
fneirab | 0:80c39eb8f3ba | 291 | */ |
fneirab | 0:80c39eb8f3ba | 292 | MAX17055(I2C &i2c); |
fneirab | 0:80c39eb8f3ba | 293 | |
fneirab | 0:80c39eb8f3ba | 294 | /** |
fneirab | 0:80c39eb8f3ba | 295 | * @brief Fuel Gauge Destructor |
fneirab | 0:80c39eb8f3ba | 296 | */ |
fneirab | 0:80c39eb8f3ba | 297 | ~MAX17055(); |
fneirab | 4:a4d6ae2182c2 | 298 | |
fneirab | 5:a18a189588dc | 299 | //////////////////////////////////////////////////////////////////////////// |
fneirab | 5:a18a189588dc | 300 | |
fneirab | 5:a18a189588dc | 301 | /** |
fneirab | 5:a18a189588dc | 302 | * \brief Poll Flag clear |
fneirab | 5:a18a189588dc | 303 | * \par Details |
fneirab | 5:a18a189588dc | 304 | * This function clears status flags for the MAX17055 |
fneirab | 5:a18a189588dc | 305 | * |
fneirab | 5:a18a189588dc | 306 | * \param[in] reg_addr - register address |
fneirab | 5:a18a189588dc | 307 | * \param[in] mask - register address |
fneirab | 5:a18a189588dc | 308 | * \param[in] timeout - register data |
fneirab | 5:a18a189588dc | 309 | * |
fneirab | 5:a18a189588dc | 310 | * \retval 1 on success |
fneirab | 5:a18a189588dc | 311 | * -1 on Failure |
fneirab | 5:a18a189588dc | 312 | */ |
fneirab | 5:a18a189588dc | 313 | |
fneirab | 5:a18a189588dc | 314 | int max17055_poll_flag_clear(Registers_e reg_addr, int mask, int timeout); |
fneirab | 5:a18a189588dc | 315 | |
fneirab | 4:a4d6ae2182c2 | 316 | |
fneirab | 2:ff7db397b70f | 317 | /** |
fneirab | 2:ff7db397b70f | 318 | * \brief Write and Verify a MAX17055 register |
fneirab | 2:ff7db397b70f | 319 | * \par Details |
fneirab | 2:ff7db397b70f | 320 | * This function wites and verifies if the writing process was successful |
fneirab | 2:ff7db397b70f | 321 | * |
fneirab | 2:ff7db397b70f | 322 | * \param[in] reg_addr - register address |
fneirab | 4:a4d6ae2182c2 | 323 | * \param[out] reg_data - the variable that contains the data to write |
fneirab | 5:a18a189588dc | 324 | * to the register address |
fneirab | 2:ff7db397b70f | 325 | * |
fneirab | 4:a4d6ae2182c2 | 326 | * \retval 1 on success |
fneirab | 2:ff7db397b70f | 327 | * -1 if write errors |
fneirab | 2:ff7db397b70f | 328 | * -2 if read errors |
fneirab | 2:ff7db397b70f | 329 | * -3 if data curruption |
fneirab | 4:a4d6ae2182c2 | 330 | * |
fneirab | 2:ff7db397b70f | 331 | */ |
fneirab | 4:a4d6ae2182c2 | 332 | |
fneirab | 4:a4d6ae2182c2 | 333 | |
fneirab | 2:ff7db397b70f | 334 | int write_and_verify_reg(Registers_e reg_addr, uint16_t reg_data); |
fneirab | 4:a4d6ae2182c2 | 335 | |
fneirab | 4:a4d6ae2182c2 | 336 | |
fneirab | 3:f77a8345b0e3 | 337 | /////////////////////////////////////////////////////////////////////////// |
fneirab | 4:a4d6ae2182c2 | 338 | |
fneirab | 2:ff7db397b70f | 339 | /** |
fneirab | 2:ff7db397b70f | 340 | * \brief Initialise Function for MAX17055 |
fneirab | 2:ff7db397b70f | 341 | * \par Details |
fneirab | 2:ff7db397b70f | 342 | * This function intitializes the MAX17055 |
fneirab | 2:ff7db397b70f | 343 | * |
fneirab | 4:a4d6ae2182c2 | 344 | * \retval 1 on success |
fneirab | 2:ff7db397b70f | 345 | * -1 if errors exist |
fneirab | 2:ff7db397b70f | 346 | */ |
fneirab | 4:a4d6ae2182c2 | 347 | |
fneirab | 4:a4d6ae2182c2 | 348 | |
fneirab | 5:a18a189588dc | 349 | int init(struct max17055_platform_data *pri); |
fneirab | 4:a4d6ae2182c2 | 350 | |
fneirab | 4:a4d6ae2182c2 | 351 | |
fneirab | 3:f77a8345b0e3 | 352 | //////////////////////////////////////////////////////////////////////////// |
fneirab | 0:80c39eb8f3ba | 353 | |
fneirab | 3:f77a8345b0e3 | 354 | /** |
fneirab | 2:ff7db397b70f | 355 | * \brief Get Internal Temperature Function for MAX17055 |
fneirab | 2:ff7db397b70f | 356 | * \par Details |
fneirab | 2:ff7db397b70f | 357 | * This function sends a request to access the internal |
fneirab | 2:ff7db397b70f | 358 | * of the MAX17055 |
fneirab | 2:ff7db397b70f | 359 | * |
fneirab | 2:ff7db397b70f | 360 | * \param[out] *temp - pointer? or Reference? to the volue of the temperature |
fneirab | 4:a4d6ae2182c2 | 361 | * \retval 1 on success |
fneirab | 2:ff7db397b70f | 362 | * 0 on success |
fneirab | 2:ff7db397b70f | 363 | * -1 if errors exist |
fneirab | 2:ff7db397b70f | 364 | */ |
fneirab | 4:a4d6ae2182c2 | 365 | |
fneirab | 4:a4d6ae2182c2 | 366 | |
fneirab | 2:ff7db397b70f | 367 | int get_temperature(int *temp); |
fneirab | 4:a4d6ae2182c2 | 368 | |
fneirab | 4:a4d6ae2182c2 | 369 | |
fneirab | 4:a4d6ae2182c2 | 370 | //////////////////////////////////////////////////////////////////////////// |
fneirab | 4:a4d6ae2182c2 | 371 | |
fneirab | 3:f77a8345b0e3 | 372 | /** |
fneirab | 3:f77a8345b0e3 | 373 | * \brief Forced Exit Hibernate Mode Function for MAX17055 |
fneirab | 3:f77a8345b0e3 | 374 | * \par Details |
fneirab | 4:a4d6ae2182c2 | 375 | * This function executes a force exit from hibernate mode. |
fneirab | 3:f77a8345b0e3 | 376 | * |
fneirab | 3:f77a8345b0e3 | 377 | * \retval returns HibCFG original value before forced Exit Hybernate mode |
fneirab | 3:f77a8345b0e3 | 378 | * |
fneirab | 3:f77a8345b0e3 | 379 | */ |
fneirab | 4:a4d6ae2182c2 | 380 | |
fneirab | 4:a4d6ae2182c2 | 381 | |
fneirab | 3:f77a8345b0e3 | 382 | uint16_t forcedExitHyberMode(); |
fneirab | 3:f77a8345b0e3 | 383 | |
fneirab | 4:a4d6ae2182c2 | 384 | |
fneirab | 2:ff7db397b70f | 385 | |
fneirab | 2:ff7db397b70f | 386 | protected: |
fneirab | 0:80c39eb8f3ba | 387 | /** |
fneirab | 0:80c39eb8f3ba | 388 | * @brief Write Register |
fneirab | 0:80c39eb8f3ba | 389 | * @details Writes data to max17055 Register |
fneirab | 0:80c39eb8f3ba | 390 | * |
fneirab | 0:80c39eb8f3ba | 391 | * @parameters reg_addr Registers to write |
fneirab | 0:80c39eb8f3ba | 392 | * reg_data Data to write |
fneirab | 0:80c39eb8f3ba | 393 | */ |
fneirab | 0:80c39eb8f3ba | 394 | int writeReg(const Registers_e reg_addr, uint16_t reg_data); |
fneirab | 0:80c39eb8f3ba | 395 | |
fneirab | 0:80c39eb8f3ba | 396 | /** |
fneirab | 0:80c39eb8f3ba | 397 | * @brief Read Register |
fneirab | 0:80c39eb8f3ba | 398 | * @details Reads data from max17055 register |
fneirab | 0:80c39eb8f3ba | 399 | * |
fneirab | 0:80c39eb8f3ba | 400 | * @parameters reg_addr Register to read |
fneirab | 0:80c39eb8f3ba | 401 | */ |
fneirab | 1:a031f0c6a71e | 402 | int32_t readReg(Registers_e reg_addr, uint16_t &value); |
fneirab | 4:a4d6ae2182c2 | 403 | |
fneirab | 2:ff7db397b70f | 404 | |
fneirab | 0:80c39eb8f3ba | 405 | |
fneirab | 2:ff7db397b70f | 406 | |
fneirab | 0:80c39eb8f3ba | 407 | |
fneirab | 0:80c39eb8f3ba | 408 | private: |
fneirab | 0:80c39eb8f3ba | 409 | |
fneirab | 0:80c39eb8f3ba | 410 | I2C &m_i2cBus; // I2C object |
fneirab | 0:80c39eb8f3ba | 411 | |
fneirab | 0:80c39eb8f3ba | 412 | }; |
fneirab | 0:80c39eb8f3ba | 413 | |
fneirab | 0:80c39eb8f3ba | 414 | #endif /* _MAX17055_H_ */ |