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:
4:a4d6ae2182c2
Parent:
3:f77a8345b0e3
Child:
5:a18a189588dc
--- a/max17055.h	Tue Sep 26 00:15:04 2017 +0000
+++ b/max17055.h	Wed Sep 27 17:10:18 2017 +0000
@@ -1,34 +1,48 @@
-/*******************************************************************************
- * 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.
- ********************************************************************************/
+/******************************************************************//**
+* @file max17055.h
+*
+* @author Felipe Neira Maxim Integrated - TTS
+*
+* @version 1.0
+*
+* Started: 11SEP17
+*
+* Updated:
+*
+* @brief Source file for MAX31855 class
+*
+********************************************************************************
+* Copyright (C) 2017 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_
@@ -40,6 +54,11 @@
 #define MAX17055_STATUS_BST             (1 << 3)
 #define MAX17055_STATUS_POR             (1 << 1)
 
+/* Model loading options */
+#define MODEL_LOADING_OPTION1           1
+#define MODEL_LOADING_OPTION2           2
+#define MODEL_LOADING_OPTION3           3
+
 
 /**
  * @brief Library for the MAX17055\n
@@ -79,78 +98,100 @@
  */
 
 
-// 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;
+
+/******************************************************************//**
+* BATTERY Class
+**********************************************************************/
+/// MAX17055 Battery Parameters Class
+/** Generic API for battery parameters
+ */
+class BATTERY
+{
+    public:
+    
+    /** \struct BATTERY::battery_cfg_t
+    * A description of the struct type
+    */
+    
+    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;
+    
+    
+    /**
+    * A description of the struct type
+    */
+
+    typedef struct {
+        uint16_t designcap;/**< struct value 1 */
+        uint16_t ichgterm; /**< struct value 2 */
+        uint16_t vempty;   /**< struct value 3 */
+        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;
+
+    /*! \struct BATTERY::saved_fuel_gauge_params_t
+    * A description of the struct type
+    */
+    typedef struct {
+        int rcomp0;
+        int temp_co;
+        int full_cap_rep;
+        int cycles;
+        int full_cap_nom;
+    } saved_fuel_gauge_params_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)
+/******************************************************************//**
+* MAX17055 Class
+**********************************************************************/
+/// MAX17055 Battery Fuel Gauge Class 
 /** Generic API for a battery fuel gauge
  */
 class MAX17055
@@ -173,19 +214,19 @@
 
 
     /**
-     * @brief       Register Addresses
+     * @brief       Register Addresses for the MAX17055
      * @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_STATUS_REG                 = 0x00, /**< enum value 1 */
+        MAX17055_VALRTTH_REG                = 0x01, /**< enum value 2 */
+        MAX17055_TALRTTH_REG                = 0x02, /**< enum value 3 */
+        MAX17055_SALRTTH_REG                = 0x03, /**< enum value 4 */
+        MAX17055_REPCAP_REG                 = 0x05, /**< enum value 5 */ 
+        MAX17055_REPSOC_REG                 = 0x06, /**< enum value 6 */
+        MAX17055_TEMP_REG                   = 0x08, /**< enum value 7 */
+        MAX17055_VCELL_REG                  = 0x09, /**< enum value 8 */
+        MAX17055_CURRENT_REG                = 0x0A, /**< enum value 9 */ 
         MAX17055_AVGCURRENT_REG             = 0x0B,
         MAX17055_REMCAP_REG                 = 0x0F,
 
@@ -238,6 +279,9 @@
         MAX17055_VFSOC_REG                  = 0xFF,
     } ;
 
+   
+
+
     /**
      * @brief       max17055 Constructor
      * @details     max17055 Constructor with battery and i2c as parameters
@@ -248,43 +292,43 @@
      * @brief       Fuel Gauge Destructor
      */
     ~MAX17055();
-    
-    
+
+
     /**
     * \brief        Write and Verify a MAX17055 register
     * \par          Details
     *               This function wites and verifies if the writing process was successful
     *
     * \param[in]    reg_addr     - register address
-    * \param[out]   reg_data     - the variable that contains the data to write 
+    * \param[out]   reg_data     - the variable that contains the data to write
     *                                to the register address
     *
-    * \retval       1 on success 
+    * \retval       1 on success
     *              -1 if write errors
     *              -2 if read errors
     *              -3 if data curruption
-    * 
+    *
     */
-    
-    
+
+
     int write_and_verify_reg(Registers_e reg_addr, uint16_t reg_data);
-    
-    
+
+
     ///////////////////////////////////////////////////////////////////////////
-    
+
     /**
     * \brief        Initialise Function for MAX17055
     * \par          Details
     *               This function intitializes the MAX17055
     *
-    * \retval       1 on success 
+    * \retval       1 on success
     *              -1 if errors exist
     */
-    
-    
+
+
     int init();
-    
-    
+
+
     ////////////////////////////////////////////////////////////////////////////
 
     /**
@@ -294,30 +338,30 @@
     *               of the MAX17055
     *
     * \param[out]   *temp     - pointer? or Reference? to the volue of the temperature
-    * \retval       1 on success 
+    * \retval       1 on success
     *               0 on success
     *              -1 if errors exist
     */
-    
-    
+
+
     int get_temperature(int *temp);
-    
-    
-    ////////////////////////////////////////////////////////////////////////////////
-    
+
+
+    ////////////////////////////////////////////////////////////////////////////
+
     /**
     * \brief        Forced Exit Hibernate Mode Function for MAX17055
     * \par          Details
-    *               This function executes a force exit from hibernate mode. 
+    *               This function executes a force exit from hibernate mode.
     *
     * \retval       returns HibCFG original value before forced Exit Hybernate mode
     *
     */
-        
-        
+
+
     uint16_t forcedExitHyberMode();
 
-       
+
 
 protected:
     /**
@@ -336,7 +380,7 @@
      * @parameters  reg_addr Register to read
      */
     int32_t readReg(Registers_e reg_addr, uint16_t &value);
-    
+
 
 
 
@@ -347,6 +391,4 @@
 
 };
 
-//extern saved_fuel_gauge_params_t default_param;
-
 #endif /* _MAX17055_H_ */