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:
5:a18a189588dc
Parent:
4:a4d6ae2182c2
Child:
6:5ced10109ebf
--- a/max17055.h	Wed Sep 27 17:10:18 2017 +0000
+++ b/max17055.h	Mon Oct 02 21:59:00 2017 +0000
@@ -1,7 +1,7 @@
 /******************************************************************//**
 * @file max17055.h
 *
-* @author Felipe Neira Maxim Integrated - TTS
+* @author Felipe Neira - Maxim Integrated - TTS
 *
 * @version 1.0
 *
@@ -54,7 +54,7 @@
 #define MAX17055_STATUS_BST             (1 << 3)
 #define MAX17055_STATUS_POR             (1 << 1)
 
-/* Model loading options */
+/// Model loading options
 #define MODEL_LOADING_OPTION1           1
 #define MODEL_LOADING_OPTION2           2
 #define MODEL_LOADING_OPTION3           3
@@ -97,55 +97,41 @@
  * @endcode
  */
 
+ /**
+    * @brief       Saved Fuel Gauge Parameters
+    * @details     Struct with saved fuel Gauge Parametrs
+    */
+
+struct saved_fuel_gauge_params_t{
+        int rcomp0;              /**< Explain */
+        int temp_co;             /**< Explain */
+        int full_cap_rep;        /**< Explain */
+        int cycles;              /**< Explain */
+        int full_cap_nom;        /**< Explain */
+     } ;
+
+   /**
+    * @brief       Saved Fuel Gauge Parameters
+    * @details     Struct with saved fuel Gauge Parametrs
+    */
 
 
-/******************************************************************//**
-* 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 {
+ struct max17055_platform_data{
         uint16_t designcap;/**< struct value 1 */
         uint16_t ichgterm; /**< struct value 2 */
         uint16_t vempty;   /**< struct value 3 */
-        int vcharge;
+        int vcharge;       /**< struct value 1 */
 
-        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 learncfg;  /**< struct value 1 */
+        uint16_t relaxcfg;  /**< struct value 1 */
+        uint16_t config;    /**< struct value 1 */
+        uint16_t config2;   /**< struct value 1 */
+        uint16_t fullsocthr;/**< struct value 1 */
+        uint16_t tgain;     /**< struct value 1 */
+        uint16_t toff;      /**< struct value 1 */
+        uint16_t curve;     /**< struct value 1 */
+        uint16_t rcomp0;    /**< struct value 1 */
+        uint16_t tempco;    /**< struct value 1 */ 
         uint16_t qrtable00;
         uint16_t qrtable10;
         uint16_t qrtable20;
@@ -157,34 +143,48 @@
         //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;
+        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 */
+     } ;
+
+
 
-    /*! \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;
+//! BATTERY Battery Parameters Class
+/*!
+ Generic API for battery parameters
+ */
+class BATTERY
+{
+
+public:
+
 
+     struct battery_cfg_t{
+        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
+     } ;
+    
+        
+   
 
 };
 
@@ -210,30 +210,33 @@
 //    ///# of bytes per LED channel
 //    static const uint8_t BYTES_PER_CH = 3;
 
+    struct BATTERY::battery_cfg_t batt_con;
+    struct max17055_platform_data design_data;
+    struct saved_fuel_gauge_params_t fuelGauge_params;
 
 
 
     /**
      * @brief       Register Addresses for the MAX17055
-     * @details     Enumerated max17055 (MAX17055 max17055)
+     * @details     Enumerated register addresses
      */
     enum Registers_e {
-        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,
+        MAX17055_STATUS_REG                 = 0x00, /**< 0x00 */
+        MAX17055_VALRTTH_REG                = 0x01, /**< 0x01 */
+        MAX17055_TALRTTH_REG                = 0x02, /**< 0x02 */
+        MAX17055_SALRTTH_REG                = 0x03, /**< 0x04 */
+        MAX17055_REPCAP_REG                 = 0x05, /**< 0x05 */ 
+        MAX17055_REPSOC_REG                 = 0x06, /**< 0x06 */
+        MAX17055_TEMP_REG                   = 0x08, /**< 0x07 */
+        MAX17055_VCELL_REG                  = 0x09, /**< 0x08 */
+        MAX17055_CURRENT_REG                = 0x0A, /**< 0x0A */ 
+        MAX17055_AVGCURRENT_REG             = 0x0B, /**< 0x0B */
+        MAX17055_REMCAP_REG                 = 0x0F, /**< 0x0F */
 
-        MAX17055_FULLCAPREP_REG             = 0x10,
-        MAX17055_TTE_REG                    = 0X11,
-        MAX17055_QRTABLE00_REG              = 0x12,
-        MAX17055_FULLSOCTHR_REG             = 0x13,
+        MAX17055_FULLCAPREP_REG             = 0x10, /**< 0x10 */
+        MAX17055_TTE_REG                    = 0X11, /**< 0x11 */
+        MAX17055_QRTABLE00_REG              = 0x12, /**< 0x12 */
+        MAX17055_FULLSOCTHR_REG             = 0x13, /**< 0x13 */
         MAX17055_CYCLES_REG                 = 0x17,
         MAX17055_DESIGNCAP_REG              = 0x18,
         MAX17055_AVGVCELL_REG               = 0x19,
@@ -293,6 +296,23 @@
      */
     ~MAX17055();
 
+    ////////////////////////////////////////////////////////////////////////////
+    
+    /**
+    * \brief        Poll Flag clear
+    * \par          Details
+    *               This function clears status flags for the MAX17055 
+    *
+    * \param[in]    reg_addr - register address
+    * \param[in]    mask - register address
+    * \param[in]    timeout - register data
+    *
+    * \retval       1 on success
+    *              -1 on Failure
+    */
+    
+    int max17055_poll_flag_clear(Registers_e reg_addr, int mask, int timeout);
+
 
     /**
     * \brief        Write and Verify a MAX17055 register
@@ -301,7 +321,7 @@
     *
     * \param[in]    reg_addr     - register address
     * \param[out]   reg_data     - the variable that contains the data to write
-    *                                to the register address
+    *                              to the register address
     *
     * \retval       1 on success
     *              -1 if write errors
@@ -326,7 +346,7 @@
     */
 
 
-    int init();
+    int init(struct max17055_platform_data *pri);
 
 
     ////////////////////////////////////////////////////////////////////////////