MAX14690 library

Fork of MAX14690 by Maxim Integrated

Revision:
10:32c7e2ab67aa
Parent:
9:8fb54367ceb5
Child:
11:022bcd2ea263
--- a/MAX14690.h	Thu Nov 10 16:06:11 2016 +0000
+++ b/MAX14690.h	Fri Nov 18 22:06:28 2016 +0000
@@ -39,9 +39,13 @@
 #define MAX14690_NO_ERROR   0
 #define MAX14690_ERROR      -1
 
-#define MAX14690_BOOST_MIN_MV 2500
-#define MAX14690_BOOST_MAX_MV 5000
-#define MAX14690_BOOST_STEP_MV 100
+#define MAX14690_I2C_ADDR 0x50
+
+#define MAX14690_LDO_MIN_MV 800
+#define MAX14690_LDO_MAX_MV 3600
+#define MAX14690_LDO_STEP_MV 100
+
+#define MAX14690_OFF_COMMAND 0xB2
 
 /**
  * @brief MAX14690 Power-Management Solution Driver
@@ -118,7 +122,7 @@
         REG_BUCK1_CFG = 0x0D,   ///< 
         REG_BUCK1_VSET = 0x0E,   ///< 
         REG_BUCK2_CFG = 0x0F,   ///< 
-        REG_BUCK2_ISET = 0x10,   ///< 
+        REG_BUCK2_VSET = 0x10,   ///< 
         REG_RSVD_11 = 0x11,   ///< 
         REG_LDO1_CFG = 0x12,   ///< 
         REG_LDO1_VSET = 0x13,   ///< 
@@ -137,8 +141,8 @@
     } registers_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Thermal Status
+     * @details Thermal status determined by thermistor
      */
     typedef enum  {
         THMSTAT_000,	///< T < T1
@@ -152,8 +156,8 @@
     } thermStat_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Charge Status
+     * @details Current operating mode of charger
      */
     typedef enum  {
         CHGSTAT_000,	///< Charger off
@@ -167,8 +171,8 @@
     } chgStat_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Input Current Limit
+     * @details CHGIN input current limit values
      */
     typedef enum  {
         ILIM_0mA,		///< 0mA
@@ -178,8 +182,8 @@
     } iLimCntl_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Recharge Threshold
+     * @details Battery recharge voltage threshold
      */
     typedef enum  {
         BAT_RECHG_70mV,		///< 70mV
@@ -189,8 +193,8 @@
     } batReChg_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Battery Regulation Voltage
+     * @details Battery regulation voltages set point
      */
     typedef enum  {
         BAT_REG_4050mV,		///< 4.05V
@@ -204,8 +208,8 @@
     } batReg_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Precharge Voltage
+     * @details Battery precharge voltage threshold
      */
     typedef enum  {
         VPCHG_2100mV,		///< 2.10V
@@ -219,8 +223,8 @@
     } vPChg_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Precharge Current
+     * @details Battery precharge current value
      */
     typedef enum  {
         IPCHG_5,		///< 5% of Ifchg
@@ -230,8 +234,8 @@
     } iPChg_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Done Current
+     * @details Charger done current where charging stops
      */
     typedef enum  {
         CHGDONE_5,		///< 5% of Ifchg
@@ -241,8 +245,8 @@
     } chgDone_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Maintain Charge Timer
+     * @details Timeout settings for maintain charge mode
      */
     typedef enum  {
         MTCHGTMR_0min,		///< 0 min
@@ -252,8 +256,8 @@
     } mtChgTmr_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Fast Charge Timer
+     * @details Timeout settings for fast charge mode
      */
     typedef enum  {
         FCHGTMR_75min,		///< 75 min
@@ -263,8 +267,8 @@
     } fChgTmr_t;
 
     /**
-     * @brief   
-     * @details 
+     * @brief   Precharge Timer
+     * @details Timeout settings for precharge mode
      */
     typedef enum  {
         PCHGTMR_30min,		///< 30 min
@@ -274,15 +278,27 @@
     } pChgTmr_t;
 
     /**
-     * @brief   Voltage Regulator Enable Mode
+     * @brief   LDO Enable Mode
      * @details Enumerated enable modes for voltage regulators
      */
     typedef enum {
-        VREG_DISABLED,	///< Regulator Disabled
-        VREG_ENABLED,	///< Regulator Enabled
-        VREG_EN_MPC0,	///< Regulator Enabled by MPC pin
-        VREG_EN_MPC1,	///< Regulator Enabled by MPC pin
-    } vRegEn_t;
+        LDO_DISABLED,	///< Disabled, Regulator Mode
+        SW_DISABLED,	///< Disabled, Switch Mode
+        LDO_ENABLED,	///< Enabled, Regulator Mode
+        SW_ENABLED,	///< Enabled, Switch Mode
+        LDO_EN_MPC0,	///< Regulator Enabled by MPC pin
+        SW_EN_MPC0,	///< Switch Enabled by MPC pin
+        LDO_EN_MPC1,	///< Regulator Enabled by MPC pin
+        SW_EN_MPC1,	///< Switch Enabled by MPC pin
+        LDO_DISABLED_DSC,	///< Regulator Disabled
+        SW_DISABLED_DSC,	///< Switch Disabled
+        LDO_ENABLED_DSC,	///< Regulator Enabled
+        SW_ENABLED_DSC,	///< Switch Enabled
+        LDO_EN_MPC0_DSC,	///< Regulator Enabled by MPC pin
+        SW_EN_MPC0_DSC,	///< Switch Enabled by MPC pin
+        LDO_EN_MPC1_DSC,	///< Regulator Enabled by MPC pin
+        SW_EN_MPC1_DSC,	///< Switch Enabled by MPC pin
+    } ldoMode_t;
 
     /**
      * @brief   Buck Operating Modes
@@ -296,101 +312,57 @@
     } buckMd_t;
 
     /**
-     * @brief   
-     * @details 
-     */
-    typedef enum  {
-        ,		///< 
-    } _t;
-
-    /**
-     * @brief   
-     * @details 
-     */
-    typedef enum  {
-        ,		///< 
-    } _t;
-
-    /**
-     * @brief   
-     * @details 
+     * @brief   Thermistor Configuration
+     * @details Enumerated thermistor operating modes
      */
-    typedef enum  {
-        ,		///< 
-    } _t;
-
-    /**
-     * @brief   Boost Peak Current Settings
-     * @details Enumerated peak current settings for boost regulator
-     */
-    typedef enum  {
-        BOOST_ISET_MIN,		///< Minimum On-Time
-        BOOST_ISET_50mA,	///< 50mA Peak Current
-        BOOST_ISET_100mA,	///< 100mA Peak Current
-        BOOST_ISET_150mA,	///< 150mA Peak Current
-        BOOST_ISET_200mA,	///< 200mA Peak Current
-        BOOST_ISET_250mA,	///< 250mA Peak Current
-        BOOST_ISET_300mA,	///< 300mA Peak Current
-        BOOST_ISET_350mA,	///< 350mA Peak Current
-    } boostISet_t;
-
-    /**
-     * @brief   Buck Peak Current Settings
-     * @details Enumerated peak current settings for buck regulator
-     */
-    typedef enum  {
-        BUCK_ISET_50mA,		///< 50mA Peak Current
-        BUCK_ISET_100mA,	///< 100mA Peak Current
-        BUCK_ISET_150mA,	///< 150mA Peak Current
-        BUCK_ISET_200mA,	///< 200mA Peak Current
-        BUCK_ISET_250mA,	///< 250mA Peak Current
-        BUCK_ISET_300mA,	///< 300mA Peak Current
-        BUCK_ISET_350mA,	///< 350mA Peak Current
-        BUCK_ISET_400mA,	///< 400mA Peak Current
-    } buckISet_t;
+    typedef enum {
+        THRM_DISABLED,		///< Thermistor monitoring disabled
+        THRM_ENABLED,		///< Basic thermistor monitoring 
+        THRM_RSVD,	///< reserved, do not use
+        THRM_JEITA,	///< JEITA thermistor monitoring
+    } thrmCfg_t;
 
     /**
      * @brief   Monitor Configurations
      * @details Enumerated configuration modes for monitor multiplexer
      */
     typedef enum {
-        MON_PULLDOWN = 0x00,	///< Pulled down by 100k Ohm
-        MON_HI_Z = 0x08,		///< High Impedance
-        MON_SWIN = 0x80,		///< SWIN Selected
-        MON_SWOUT = 0x81,		///< SWOUT Selected
-        MON_BIN = 0x82,			///< BIN Selected
-        MON_BOUT = 0x83,		///< BOUT Selected
-        MON_HVIN = 0x84,		///< HVIN Selected
-        MON_HVOUT = 0x85,		///< HVOUT Selected
-        MON_LIN = 0x86,			///< LIN Selected
-        MON_LOUT = 0x87,		///< LOUT Selected
+        MON_PULLDOWN = 0x0,	///< Pulled down by 100k Ohm
+        MON_BAT = 0x1,		///< BAT Selected
+        MON_SYS = 0x2,		///< SYS Selected
+        MON_BUCK1 = 0x3,	///< BUCK1 Selected
+        MON_BUCK2 = 0x4,	///< BUCK2 Selected
+        MON_LDO1 = 0x5,		///< LDO1 Selected
+        MON_LDO2 = 0x6,		///< LDO2 Selected
+        MON_LDO3 = 0x7,		///< LDO3nSelected
+        MON_HI_Z = 0x8,		///< High Impedance
     } monCfg_t;
 
     /**
-     * @brief   Under-Voltage Lock Out Input
-     * @details Enumerated input selection options for UVLO
+     * @brief   Monitor Divide Ratio
+     * @details Ratio settings for monitor divider
      */
-    typedef enum {
-        LIN_UVLO,	///< LIN used to determine UVLO condition
-        BIN_UVLO,	///< BIN used to determine UVLO condition
-    } uvloIn_t;
+    typedef enum  {
+        MON_DIV4,		///< 4:1 Monitor Ratio
+        MON_DIV3,		///< 3:1 Monitor Ratio
+        MON_DIV2,		///< 2:1 Monitor Ratio
+        MON_DIV1,		///< 1:1 Monitor Ratio
+    } monRatio_t;
 
     /**
     	* MAX14690 constructor.
     	*
     	* @param sda mbed pin to use for SDA line of I2C interface.
     	* @param scl mbed pin to use for SCL line of I2C interface.
-    	* @param slaveAddress Slave Address of the device.
     	*/
-    MAX14690(PinName sda, PinName scl, int slaveAddress);
+    MAX14690(PinName sda, PinName scl);
 
     /**
     	* MAX14690 constructor.
     	*
     	* @param i2c I2C object to use.
-    	* @param slaveAddress Slave Address of the device.
     	*/
-    MAX14690(I2C *i2c, int slaveAddress);
+    MAX14690(I2C *i2c);
 
     /**
     	* MAX14690 destructor.
@@ -403,33 +375,55 @@
      *  Settings are stored in public variables.
      *  The variables are pre-loaded with the most common configuation.
      *  Assign new values to the public variables before calling init.
-     *  This will update all the settings including the boost voltage 
-     *  from boostMillivolts and the boost enable mode from boostEn.
+     *  This will update all the settings including the LDO voltages 
+     *  and modes.
      * @returns 0 if no errors, -1 if error.
     */
     int init();
 
     /**
-     * @brief   Set the Boost Voltage
+     * @brief   Set the LDO Voltage
      * @details Sets the voltage for the boost regulator.
      *  The voltage is specified in millivolts.
      *  The MAX14690 cannot update the voltage when enabled.
-     *  This function checks the local boostEn variable and if the
+     *  This function checks the local ldoMode variable and if the
      *  regualtor is enabled it will send the disable command before
-     *  sending the new voltage and re-enable the boost regulator after
+     *  sending the new voltage and re-enable the LDO after
      *  the new voltage is written.
      * @param   mV voltage for boost regualtor in millivolts
      * @returns 0 if no errors, -1 if error.
     */
-    int boostSetVoltage(int mV);
+    int ldo2SetVoltage(int mV);
+
+    /**
+     * @brief   Set LDO Enable Mode
+     * @details Sets the enable mode for the LDO/SW
+     * @param   mode The enable mode for the LDO/SW
+     * @returns 0 if no errors, -1 if error.
+    */
+    int ldo2SetMode(ldoMode_t mode);
 
     /**
-     * @brief   Set Boost Enable Mode
-     * @details Sets the enable mode for the boost regulator
-     * @param   mode The enable mode for the boost regulator
+     * @brief   Set the LDO Voltage
+     * @details Sets the voltage for the boost regulator.
+     *  The voltage is specified in millivolts.
+     *  The MAX14690 cannot update the voltage when enabled.
+     *  This function checks the local ldoMode variable and if the
+     *  regualtor is enabled it will send the disable command before
+     *  sending the new voltage and re-enable the LDO after
+     *  the new voltage is written.
+     * @param   mV voltage for boost regualtor in millivolts
      * @returns 0 if no errors, -1 if error.
     */
-    int boostSetMode(boostEn_t mode);
+    int ldo3SetVoltage(int mV);
+
+    /**
+     * @brief   Set LDO Enable Mode
+     * @details Sets the enable mode for the LDO/SW
+     * @param   mode The enable mode for the LDO/SW
+     * @returns 0 if no errors, -1 if error.
+    */
+    int ldo3SetMode(ldoMode_t mode);
 
     /**
      * @brief   Configure Mon Pin
@@ -437,7 +431,7 @@
      * @param   monCfg The configuration mode for the monitor pin
      * @returns 0 if no errors, -1 if error.
     */
-    int monSet(monCfg_t monCfg);
+    int monSet(monCfg_t monCfg, monRatio_t monRatio);
 
     /**
      * @brief   Shutdown
@@ -448,6 +442,16 @@
     int shutdown();
 
     /**
+     * @brief   Reset settings to default values
+     * @details Resets all local variables to the default value.
+     *  Note: this only resets the local variables and has no effect 
+     *  on the part until they are applied by another functions such as
+     *  init();
+     * @returns 0 if no errors, -1 if error.
+    */
+	void resetToDefaults();
+
+    /**
      * @brief   Write Register
      * @details Writes the given value to the specified register.  
      *  Note, this function provides direct access to the registers
@@ -471,56 +475,107 @@
     */
     int readReg(registers_t reg, char *value);
 
-    /// Boost Clock Divider Enable: default 0 - Disabled, 1 - Enabled
-    bool clkDivEn;
-    /// Boost Clock Divider Setting: default 0, The clock is divided by this value +10 when enabled
-    int clkDivSet;
-    /// Boost Peak Current Setting: default BOOST_ISET_100mA
-    boostISet_t boostISet;
-    /// Boost Voltage in millivolts: default 3300
-    int boostMillivolts;
-    /// Boost Enable Mode: default BOOST_DISABLED
-    boostEn_t boostEn;
-    /// Boost EMI Setting: default 0 - EMI damping active (lower noise), 1 - Damping disabled (more efficient)
-    bool boostEMI;
-	/// Boost Inductor Setting: default 0 - 4.7uH, 1 - 3.3uH
-    bool boostInd;
-	/// Boost Hysteresis Off: default 0 - Hysteresis enabled (more efficient), 1 - Hysteresis off (lower voltage ripple)
-    bool boostHysOff;
-	/// Boost Passive Discharge: default 0 - Disabled, 1 - Enabled when boost disabled 
-    bool boostPasDsc;
-	/// Boost Active Discharge: default 0 - Disabled, 1 - Enabled when boost disabled 
-    bool boostActDsc;
-	/// Buck Operating Mode: default BUCK_BURST 
-    buckMd_t buckMd;
-	/// Buck Fast Start: default 0 - Normal startup current limit, 1 - Double startup current for fast start 
-    bool buckFst;
-	/// Buck Peak Current Setting: default BUCK_ISET_300mA
-    buckISet_t buckISet;
-    /// Buck Configuration: default 0 - For burst mode, 1 - For FPWM mode
-    bool buckCfg;
-	/// Buck Inductor Setting: default 0 - 2.2uH, 1 - 4.7uH
-    bool buckInd;
-	/// Buck Hysteresis Off: default 0 - Hysteresis enabled (more efficient), 1 - Hysteresis off (lower voltage ripple)
-    bool buckHysOff;
-	/// Buck Minimum On Time: default 1 - Disable deglitch delay (lower voltage ripple), 0 - Enable deglitch dealy (more efficient)
-    bool buckMinOT;
-	/// Buck Integrate: default 1 - Better load regulation at higher current (recommended for output capacitance >6uF), 0 - More stable operation with smaller output capacitor
-    bool buckInteg;
-	/// Buck Passive Discharge: default 0 - Disabled, 1 - Enabled when buck disabled  
-    bool buckPasDsc;
-	/// Buck Active Discharge: default 0 - Disabled, 1 - Enabled when buck disabled 
-    bool buckActDsc;
-	/// Buck Fet Scaling: default 0 - Full buck FET after soft start (more efficient for larger loads), 1 - Reduced buck FET while active (lower quiescent current for light loads)
-    bool buckFScl;
+    /// Thermal Status Change Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermStatus;
+    /// Charger Status Change Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnChgStatus;
+    /// Input Limit Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnILim;
+    /// USB Over Voltage Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnUSBOVP;
+    /// USB OK Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnUSBOK;
+    /// Charger Thermal Shutdown Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnChgThmSD;
+    /// Thermal Regulation Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermReg;
+    /// Charger Timeout Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnChgTimeOut;
+    /// Buck1 Thermal Error Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermBuck1;
+    /// Buck2 Thermal Error Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermBuck2;
+    /// LDO1 Thermal Error Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermLDO1;
+    /// LDO2 Thermal Error Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermLDO2;
+    /// LDO3 Thermal Error Interrupt Enable: default 0 - Disabled, 1 - Enabled
+    bool intEnThermLDO3;
+    /// CHGIN Input Current Limit Setting: default 500mA
+    iLimCntl_t iLimCntl;
+    /// Charger Auto Stop: default 1 - move to Charge Done when charging complete, 0 - remain in Maintain Charge mode
+    bool chgAutoStp;
+    /// Charger Auto Restart: default 1 - restart charging when Vbat drops below threshold, 0 - stay in Charge Done until charging disabled 
+    bool chgAutoReSta;
+    /// Charger Battery Recharge Threshold: default -120mV
+    batReChg_t batReChg;
+    /// Charger Battery Regulation Voltage: default 4.20V
+    batReg_t batReg;
+    /// Charger Enable: default 1 - Enabled, 0 - Disabled
+    bool chgEn;
+    /// Charger Precharge Voltage Threshold: default 3.00V
+    vPChg_t vPChg;
+    /// Charger Precharge Current Setting: default 10% of fast charge current
+    iPChg_t iPChg;
+    /// Charger Done Threshold, stop charging when charge current drops to this level: default 10% of fast charge current
+    chgDone_t chgDone;
+    /// Maintain Charge Timer, time to wait after reaching done current before disabling charger: default 0 min
+    mtChgTmr_t mtChgTmr;
+    /// Fast Charge Timer, timeout for fast charge duration: default 300 min
+    fChgTmr_t fChgTmr;
+    /// Precharge Timer, timeout for precharge duration: default 60 min
+    pChgTmr_t pChgTmr;
+    /// Buck 1 Mode Select: default Burst mode
+    buckMd_t buck1Md;
+    /// Buck 1 Inductor Select: default 0 - 2.2uH, 1 - 4.7uH
+    bool buck1Ind;
+    /// Buck 2 Mode Select: default BUCK_BURST
+    buckMd_t buck2Md;
+    /// Buck 2 Inductor Select: default 0 - 2.2uH, 1 - 4.7uH
+    bool buck2Ind;
+    /// LDO 2 Mode Select: default LDO_DISABLED
+    ldoMode_t ldo2Mode;
+    /// LDO 2 Voltage in millivolts: default 3200
+    int ldo2Millivolts;
+    /// LDO 3 Mode Select: default LDO_DISABLED
+    ldoMode_t ldo3Mode;
+    /// LDO 3 Voltage in millivolts: default 3000
+    int ldo3Millivolts;
+    /// Thermistor Configuration: default THRM_ENABLED
+    thrmCfg_t thrmCfg;
+    /// Monitor Multiplexer Divider Ratio Select: default MON_DIV4
+    monRatio_t monRatio;
+    /// Monitor Multiplexer Configuration: default MON_PULLDOWN
+    monCfg_t monCfg;
+    /// Buck 2 Active Discharge: default 0 - discharge only during hard reset, 1 - discharge when regulator is disabled
+    bool buck2ActDsc;
+    /// Buck 2 Force FET Scaling: default 0 - full FET for better active efficiency, 1 - reduced FET for lower quiescent current
+    bool buck2FFET;
+    /// Buck 1 Active Discharge: default 0 - discharge only during hard reset, 1 - discharge when regulator is disabled
+    bool buck1ActDsc;
+    /// Buck 1 Force FET Scaling: default 0 - full FET for better active efficiency, 1 - reduced FET for lower quiescent current
+    bool buck1FFET;
+    /// PFN pin resistor enable: default 1 - internal pullup/pulldown enabled, 0 - internal pullup/pulldown disabled 
+    bool pfnResEna;
+    /// Stay On Handshake: default 1 - remain on, 0 - turn off if not set within 5s of power-on 
+    bool stayOn;
 
 private:
     /// I2C pointer
     I2C *i2c;
     /// Is this object the owner of the I2C object
     bool isOwner;
-    /// Device slave address
-    int slaveAddress;
+
+    /**
+     * @brief   Converts mV to register bits
+     * @details Converts integer representing the desired voltage 
+     *  in millivolts to the coresponding 8 bit register value.
+     *  This will check to ensure the voltage is within the allowed 
+     *  range and return an error (-1) if it is out of range.
+     * @param   mV voltage for LDO regulator in millivolts
+     * @returns 8 bit register value if no errors, -1 if error.
+    */    
+    int mv2bits(int mV);
 };
 
 #endif /* _MAX14690_H_ */