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 Maxim Integrated

Revision:
0:80c39eb8f3ba
Child:
1:a031f0c6a71e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max17055.h	Thu Sep 21 00:53:05 2017 +0000
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Maxim Integrated
+ * Products, Inc. shall not be used except as stated in the Maxim Integrated
+ * Products, Inc. Branding Policy.
+ *
+ * The mere transfer of this software does not imply any licenses
+ * of trade secrets, proprietary technology, copyrights, patents,
+ * trademarks, maskwork rights, or any other form of intellectual
+ * property whatsoever. Maxim Integrated Products, Inc. retains all
+ * ownership rights.
+ ********************************************************************************/
+
+#ifndef __MAX17055_H_
+#define __MAX17055_H_
+
+// Include
+#include "mbed.h"
+
+
+/**
+ * @brief Library for the MAX17055\n
+ * The MAX17055 is a low 7μA operating current fuel gauge
+ * which implements Maxim ModelGauge™ m5 EZ algorithm.
+ * ModelGauge m5 EZ makes fuel gauge implementation easy
+ * by eliminating battery characterization requirements
+ * and simplifying host software interaction.
+ * The ModelGauge m5 EZ robust algorithm provides tolerance against
+ * battery diversity for most lithium batteries and applications.
+ * Communication is through an SPI-compatible interface.
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "MAX170155.h"
+ *
+ *
+ * // Hardware serial port
+ * Serial serial(USBTX, USBRX);
+ *
+ * //SPI communications
+ * I2C i2c(SCL, SDA);
+ *
+ * //Fuel Gauge
+ * MAX17055 max17055(i2C, Sutff );//To be completed
+ *
+ *
+ * int main(void)
+ * {
+ *     CODE CODE
+ *      while(true)
+ *      {
+ *          CODE CODE
+ *      }
+ * }
+ * @endcode
+ */
+
+
+// Battery struct for all the parameters
+/******************************************************/
+// NOTE:: I PERSONALL THINK BATTERY SHOULD BE A CLASS JUST SO THAT WE CAN KEEP ALL THE PARAMETERS
+// AS PRIVATE AND PROVIDE USERS WITH CLASS FUNCTIOS TO MODIFY THE PRIVATE VALUE INSIDE
+/*****************************************************/
+typedef struct {
+    int capacity;  //!< The rated capacity in mAh of the battery
+    int voltageMax;  //!< The maximum voltage in mV that should be used for charging
+    int voltageNom;  //!< The normal voltage in mV of the battery near mid charge
+    int voltageMin;  //!< The minimum voltage in mV that the battery should be discharged
+    int temperatureMax;  //!< The maximum temperature in degrees C where charging is allowed
+    int temperatureMin;  //!< The minimum temperature in degrees C where charging is allowed
+    int currentCharge;  //!< The current as a percentage of capicity used for charging
+    int currentTerm;  //!< The current as a percentage of capacity to stop charging
+    int currentPre;  //!< The current as a percentage of capacity for pre-charging
+} battery_cfg_t;
+
+
+//From Linux driver
+typedef struct {
+    uint16_t designcap;
+    uint16_t ichgterm;
+    uint16_t vempty;
+    int vcharge;
+
+    uint16_t learncfg;
+    uint16_t relaxcfg;
+    uint16_t config;
+    uint16_t config2;
+    uint16_t fullsocthr;
+    uint16_t tgain;
+    uint16_t toff;
+    uint16_t curve;
+    uint16_t rcomp0;
+    uint16_t tempco;
+    uint16_t qrtable00;
+    uint16_t qrtable10;
+    uint16_t qrtable20;
+    uint16_t qrtable30;
+
+    uint16_t dpacc;
+    uint16_t modelcfg;
+
+    //uint16_t model_data[MAX17055_TABLE_SIZE];
+    int (*get_charging_status)(void);
+    int model_option;
+
+    /*
+     * rsense in miliOhms.
+     * default 10 (if rsense = 0) as it is the recommended value by
+     * the datasheet although it can be changed by board designers.
+     */
+    unsigned int rsense;
+    int volt_min;   /* in mV */
+    int volt_max;   /* in mV */
+    int temp_min;   /* in DegreC */
+    int temp_max;   /* in DegreeC */
+    int soc_max;    /* in percent */
+    int soc_min;    /* in percent */
+    int curr_max;   /* in mA */
+    int curr_min;   /* in mA */
+} max17055_platform_data;
+
+typedef struct {
+    int rcomp0;
+    int temp_co;
+    int full_cap_rep;
+    int cycles;
+    int full_cap_nom;
+} saved_fuel_gauge_params_t;
+
+/// Battery Fuel Gauge Class (MAX17055)
+/** Generic API for a battery fuel gauge
+ */
+class MAX17055
+{
+
+public:
+
+    ///7-bit slave address
+    static const uint8_t I2C_ADRS   = 0x36;  //Slave address 0x6C or 0x36 for 7 MSbit Addres
+    ///8-bit write address
+    static const uint8_t I2C_W_ADRS = 0x6C;
+    ///8-bit read address
+    static const uint8_t I2C_R_ADRS = 0x6D;
+    /////Max # Bytes in FIFO
+//    static const uint16_t MAX_FIFO_BYTES = 288;
+//    ///# of bytes per LED channel
+//    static const uint8_t BYTES_PER_CH = 3;
+
+
+
+
+    /**
+     * @brief       Register Addresses
+     * @details     Enumerated max17055 (MAX17055 max17055)
+     */
+    enum Registers_e {
+        MAX17055_STATUS_REG                 = 0x00,
+        MAX17055_VALRTTH_REG                = 0x01,
+        MAX17055_TALRTTH_REG                = 0x02,
+        MAX17055_SALRTTH_REG                = 0x03,
+        MAX17055_REPCAP_REG                 = 0x05,
+        MAX17055_REPSOC_REG                 = 0x06,
+        MAX17055_TEMP_REG                   = 0x08,
+        MAX17055_VCELL_REG                  = 0x09,
+        MAX17055_CURRENT_REG                = 0x0A,
+        MAX17055_AVGCURRENT_REG             = 0x0B,
+        MAX17055_REMCAP_REG                 = 0x0F,
+
+        MAX17055_FULLCAPREP_REG             = 0x10,
+        MAX17055_TTE_REG                    = 0X11,
+        MAX17055_QRTABLE00_REG              = 0x12,
+        MAX17055_FULLSOCTHR_REG             = 0x13,
+        MAX17055_CYCLES_REG                 = 0x17,
+        MAX17055_DESIGNCAP_REG              = 0x18,
+        MAX17055_AVGVCELL_REG               = 0x19,
+        MAX17055_MAXMINVOLT_REG             = 0x1B,
+        MAX17055_CONFIG_REG                 = 0x1D,
+        MAX17055_ICHGTERM_REG               = 0x1E,
+
+        MAX17055_VERSION_REG                = 0x21,
+        MAX17055_QRTABLE10_REG              = 0x22,
+        MAX17055_FULLCAPNOM_REG             = 0x23,
+        MAX17055_LEARNCFG_REG               = 0x28,
+        MAX17055_RELAXCFG_REG               = 0x2A,
+        MAX17055_TGAIN_REG                  = 0x2C,
+        MAX17055_TOFF_REG                   = 0x2D,
+
+        MAX17055_QRTABLE20_REG              = 0x32,
+        MAX17055_RCOMP0_REG                 = 0x38,
+        MAX17055_TEMPCO_REG                 = 0x39,
+        MAX17055_VEMPTY_REG                 = 0x3A,
+        MAX17055_FSTAT_REG                  = 0x3D,
+
+        MAX17055_QRTABLE30_REG              = 0x42,
+        MAX17055_DQACC_REG                  = 0x45,
+        MAX17055_DPACC_REG                  = 0x46,
+        MAX17055_VFSOC0_REG                 = 0x48,
+        MAX17055_QH0_REG                    = 0x4C,
+        MAX17055_QH_REG                     = 0x4D,
+
+        MAX17055_VFSOC0_QH0_LOCK_REG        = 0x60,
+        MAX17055_LOCK1_REG                  = 0x62,
+        MAX17055_LOCK2_REG                  = 0x63,
+
+        MAX17055_MODELDATA_START_REG        = 0x80,
+
+        MAX17055_IALRTTH_REG                = 0xB4,
+        MAX17055_CURVE_REG                  = 0xB9,
+        MAX17055_HIBCFG_REG                 = 0xBA,
+        MAX17055_CONFIG2_REG                = 0xBB,
+
+        MAX17055_MODELCFG_REG               = 0xDB,
+
+        MAX17055_OCV_REG                    = 0xFB,
+        MAX17055_VFSOC_REG                  = 0xFF,
+    } ;
+
+    /**
+     * @brief       max17055 Constructor
+     * @details     max17055 Constructor with battery and i2c as parameters
+     */
+    MAX17055(I2C &i2c);
+
+    /**
+     * @brief       Fuel Gauge Destructor
+     */
+    ~MAX17055();
+    
+    
+
+protected:
+    /**
+     * @brief       Write Register
+     * @details     Writes data to max17055 Register
+     *
+     * @parameters  reg_addr Registers to write
+     *              reg_data Data to write
+     */
+    int writeReg(const Registers_e reg_addr, uint16_t reg_data);
+
+    /**
+     * @brief       Read Register
+     * @details     Reads data from max17055 register
+     *
+     * @parameters  reg_addr Register to read
+     */
+    int32_t readReg(Registers_e reg_addr, uint8_t &value);
+
+   
+
+private:
+
+    I2C &m_i2cBus;                          // I2C object
+
+};
+
+//extern saved_fuel_gauge_params_t default_param;
+
+#endif /* _MAX17055_H_ */