Maxim Integrated / MAX14720

Dependents:   HSP_PMIC_Demo HSP_SpO2 HSP_ECG HSP_ECG_LeadOFF_Detection

Fork of MAX14720 by Greg Steiert

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX14720.h Source File

MAX14720.h

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 #ifndef _MAX14720_H_
00035 #define _MAX14720_H_
00036 
00037 #include "mbed.h"
00038 
00039 #define MAX14720_NO_ERROR   0
00040 #define MAX14720_ERROR      -1
00041 
00042 #define MAX14720_BOOST_MIN_MV 2500
00043 #define MAX14720_BOOST_MAX_MV 5000
00044 #define MAX14720_BOOST_STEP_MV 100
00045 
00046 /**
00047  * @brief MAX14720 Power-Management Solution Driver
00048  *
00049  * @details The MAX14720/MAX14750 are compact power-management solutions for
00050  * space-constrained, battery-powered applications where size and efficiency are
00051  * critical. Both devices integrate a power switch, a linear regulator, a buck
00052  * regulator, and a buck-boost regulator.
00053  * <br>https://www.maximintegrated.com/en/products/power/battery-management/MAX14720.html
00054  *
00055  * @code
00056  * #include "mbed.h"
00057  * #include "MAX14720.h"
00058  *
00059  * // I2C Master 2
00060  * I2C i2c2(I2C2_SDA, I2C2_SCL);
00061  *
00062  * #define  I2C_ADDR_PMIC   (0x54)
00063  * MAX14720 max14720(&i2c2, I2C_ADDR_PMIC);
00064  *
00065  * DigitalOut led(LED1, 0);
00066  * InterruptIn button(SW1);
00067  *
00068  * void turnOff()
00069  * {
00070  *     max14720.shutdown();
00071  * }
00072  *
00073  * int main()
00074  * {
00075  *     button.fall(&turnOff);
00076  *
00077  *     max14720.boostEn = MAX14720::BOOST_ENABLED;
00078  *     if (max14720.init() == MAX14720_ERROR) {
00079  *         printf("Error initializing MAX14720");
00080  *     }
00081  *
00082  *     wait(1);
00083  *
00084  *     while(1) {
00085  *         max14720.boostSetMode(MAX14720::BOOST_DISABLED);
00086  *         max14720.boostEn = MAX14720::BOOST_ENABLED;
00087  *         wait(0.5);
00088  *         max14720.boostSetVoltage(2500);
00089  *         wait(0.5);
00090  *         max14720.boostSetVoltage(5000);
00091  *         wait(0.5);
00092  *     }
00093  * }
00094  * @endcode
00095  */
00096 class MAX14720
00097 {
00098 public:
00099 
00100     /**
00101      * @brief   Register Addresses
00102      * @details Enumerated MAX14720 register addresses
00103      */
00104     typedef enum {
00105         REG_CHIP_ID = 0x00,     ///< Chip ID
00106         REG_CHIP_REV = 0x01,    ///< Chip Revision
00107         REG_BOOST_CDIV = 0x03,  ///< Boost Clock Divider
00108         REG_BOOST_ISET = 0x04,  ///< Boost Peak Current
00109         REG_BOOST_VSET = 0x05,  ///< Boost Voltage Setting
00110         REG_BOOST_CFG = 0x06,   ///< Boost Configuration
00111         REG_BUCK_VSET = 0x07,   ///< Buck Voltage Setting
00112         REG_BUCK_CFG = 0x08,    ///< Buck Configuration
00113         REG_BUCK_ISET = 0x09,   ///< Buck Peak Current and Settings
00114         REG_LDO_VSET = 0x0A,    ///< LDO Voltage Setting
00115         REG_LDO_CFG = 0x0B,     ///< LDO Configuration
00116         REG_SWITCH_CFG = 0x0C,  ///< Switch Configuration
00117         REG_BAT_TIME = 0x0D,    ///< Battery Impedance Timing
00118         REG_BAT_CFG = 0x0E,     ///< Battery Impedance Configuration
00119         REG_BAT_BCV = 0x0F,     ///< Battery Cell Voltage
00120         REG_BAT_OCV = 0x10,     ///< Open Cell Voltage
00121         REG_BAT_LCV = 0x11,     ///< Loaded Cell Voltage
00122         REG_MON_CFG = 0x19,     ///< Monitor Multiplexer Configuration
00123         REG_BOOT_CFG = 0x1A,    ///< Boot Configuration
00124         REG_PIN_STAT = 0x1B,    ///< Pin Status
00125         REG_BBB_EXTRA = 0x1C,   ///< Buck/Buck-Boost Extra
00126         REG_HANDSHK = 0x1D,     ///< Power-On Handshake
00127         REG_UVLO_CFG = 0x1E,    ///< Under-Voltage Lock Out
00128         REG_PWR_OFF = 0x1F,     ///< Power Off Command
00129     } registers_t;
00130 
00131     /**
00132      * @brief   Boost Peak Current Settings
00133      * @details Enumerated peak current settings for boost regulator
00134      */
00135     typedef enum  {
00136         BOOST_ISET_MIN,     ///< Minimum On-Time
00137         BOOST_ISET_50mA,    ///< 50mA Peak Current
00138         BOOST_ISET_100mA,   ///< 100mA Peak Current
00139         BOOST_ISET_150mA,   ///< 150mA Peak Current
00140         BOOST_ISET_200mA,   ///< 200mA Peak Current
00141         BOOST_ISET_250mA,   ///< 250mA Peak Current
00142         BOOST_ISET_300mA,   ///< 300mA Peak Current
00143         BOOST_ISET_350mA,   ///< 350mA Peak Current
00144     } boostISet_t;
00145 
00146     /**
00147      * @brief   Boost Enable Mode
00148      * @details Enumerated enable modes for boost regulator
00149      */
00150     typedef enum {
00151         BOOST_DISABLED, ///< Boost Disabled
00152         BOOST_ENABLED,  ///< Boost Enabled
00153         BOOST_EN_MPC,   ///< Boost Enabled by MPC pin
00154     } boostEn_t;
00155 
00156     /**
00157      * @brief   Buck Operating Modes
00158      * @details Enumerated operating modes for buck regulator
00159      */
00160     typedef enum {
00161         BUCK_BURST,     ///< Burst Mode Operation
00162         BUCK_FPWM,      ///< Forced PWM Operation
00163         BUCK_MPC_FPWM,  ///< MPC activated Forced PWM
00164     } buckMd_t;
00165 
00166     /**
00167      * @brief   Buck Peak Current Settings
00168      * @details Enumerated peak current settings for buck regulator
00169      */
00170     typedef enum  {
00171         BUCK_ISET_50mA,     ///< 50mA Peak Current
00172         BUCK_ISET_100mA,    ///< 100mA Peak Current
00173         BUCK_ISET_150mA,    ///< 150mA Peak Current
00174         BUCK_ISET_200mA,    ///< 200mA Peak Current
00175         BUCK_ISET_250mA,    ///< 250mA Peak Current
00176         BUCK_ISET_300mA,    ///< 300mA Peak Current
00177         BUCK_ISET_350mA,    ///< 350mA Peak Current
00178         BUCK_ISET_400mA,    ///< 400mA Peak Current
00179     } buckISet_t;
00180 
00181     /**
00182      * @brief   Monitor Configurations
00183      * @details Enumerated configuration modes for monitor multiplexer
00184      */
00185     typedef enum {
00186         MON_PULLDOWN = 0x00,    ///< Pulled down by 100k Ohm
00187         MON_HI_Z = 0x08,        ///< High Impedance
00188         MON_SWIN = 0x80,        ///< SWIN Selected
00189         MON_SWOUT = 0x81,       ///< SWOUT Selected
00190         MON_BIN = 0x82,         ///< BIN Selected
00191         MON_BOUT = 0x83,        ///< BOUT Selected
00192         MON_HVIN = 0x84,        ///< HVIN Selected
00193         MON_HVOUT = 0x85,       ///< HVOUT Selected
00194         MON_LIN = 0x86,         ///< LIN Selected
00195         MON_LOUT = 0x87,        ///< LOUT Selected
00196     } monCfg_t;
00197 
00198     /**
00199      * @brief   Under-Voltage Lock Out Input
00200      * @details Enumerated input selection options for UVLO
00201      */
00202     typedef enum {
00203         LIN_UVLO,   ///< LIN used to determine UVLO condition
00204         BIN_UVLO,   ///< BIN used to determine UVLO condition
00205     } uvloIn_t;
00206 
00207     /**
00208         * MAX14720 constructor.
00209         *
00210         * @param sda mbed pin to use for SDA line of I2C interface.
00211         * @param scl mbed pin to use for SCL line of I2C interface.
00212         * @param slaveAddress Slave Address of the device.
00213         */
00214     MAX14720(PinName sda, PinName scl, int slaveAddress);
00215 
00216     /**
00217         * MAX14720 constructor.
00218         *
00219         * @param i2c I2C object to use.
00220         * @param slaveAddress Slave Address of the device.
00221         */
00222     MAX14720(I2C *i2c, int slaveAddress);
00223 
00224     /**
00225         * MAX14720 destructor.
00226         */
00227     ~MAX14720();
00228 
00229     /**
00230      * @brief   Initialize MAX14720
00231      * @details Applies settings to MAX14720.
00232      *  Settings are stored in public variables.
00233      *  The variables are pre-loaded with the most common configuation.
00234      *  Assign new values to the public variables before calling init.
00235      *  This will update all the settings including the boost voltage 
00236      *  from boostMillivolts and the boost enable mode from boostEn.
00237      * @returns 0 if no errors, -1 if error.
00238     */
00239     int init();
00240 
00241     /**
00242      * @brief   Set the Boost Voltage
00243      * @details Sets the voltage for the boost regulator.
00244      *  The voltage is specified in millivolts.
00245      *  The MAX14720 cannot update the voltage when enabled.
00246      *  This function checks the local boostEn variable and if the
00247      *  regualtor is enabled it will send the disable command before
00248      *  sending the new voltage and re-enable the boost regulator after
00249      *  the new voltage is written.
00250      * @param   mV voltage for boost regualtor in millivolts
00251      * @returns 0 if no errors, -1 if error.
00252     */
00253     int boostSetVoltage(int mV);
00254 
00255     /**
00256      * @brief   Set Boost Enable Mode
00257      * @details Sets the enable mode for the boost regulator
00258      * @param   mode The enable mode for the boost regulator
00259      * @returns 0 if no errors, -1 if error.
00260     */
00261     int boostSetMode(boostEn_t mode);
00262 
00263     /**
00264      * @brief   Configure Mon Pin
00265      * @details Configures the operating mode of the monitor multiplexer
00266      * @param   monCfg The configuration mode for the monitor pin
00267      * @returns 0 if no errors, -1 if error.
00268     */
00269     int monSet(monCfg_t monCfg);
00270 
00271     /**
00272      * @brief   Shutdown
00273      * @details Sends the command to turn off all supplies and put the part
00274      *  in battery saving shelf mode.
00275      * @returns 0 if no errors, -1 if error.
00276     */
00277     int shutdown();
00278 
00279     /**
00280      * @brief   Write Register
00281      * @details Writes the given value to the specified register.  
00282      *  Note, this function provides direct access to the registers
00283      *  without any awareness or effect on the settings stored in 
00284      *  the public variables.  This is used by the other functions to
00285      *  set the values inside the MAX14720.  Calling this outside of the 
00286      *  other functions can break the synchronization of the variables
00287      *  to the state of the MAX14720.
00288      * @param   reg The register to be written
00289      * @param   value The data to be written
00290      * @returns 0 if no errors, -1 if error.
00291     */
00292     int writeReg(registers_t reg, char value);
00293 
00294     /**
00295      * @brief   Read Register
00296      * @details Reads from the specified register
00297      * @param   reg The register to be read
00298      * @param   value Pointer for where to store the data
00299      * @returns 0 if no errors, -1 if error.
00300     */
00301     int readReg(registers_t reg, char *value);
00302 
00303     /// Boost Clock Divider Enable: default 0 - Disabled, 1 - Enabled
00304     bool clkDivEn;
00305     /// Boost Clock Divider Setting: default 0, The clock is divided by this value +10 when enabled
00306     int clkDivSet;
00307     /// Boost Peak Current Setting: default BOOST_ISET_100mA
00308     boostISet_t boostISet;
00309     /// Boost Voltage in millivolts: default 3300
00310     int boostMillivolts;
00311     /// Boost Enable Mode: default BOOST_DISABLED
00312     boostEn_t boostEn;
00313     /// Boost EMI Setting: default 0 - EMI damping active (lower noise), 1 - Damping disabled (more efficient)
00314     bool boostEMI;
00315     /// Boost Inductor Setting: default 0 - 4.7uH, 1 - 3.3uH
00316     bool boostInd;
00317     /// Boost Hysteresis Off: default 0 - Hysteresis enabled (more efficient), 1 - Hysteresis off (lower voltage ripple)
00318     bool boostHysOff;
00319     /// Boost Passive Discharge: default 0 - Disabled, 1 - Enabled when boost disabled 
00320     bool boostPasDsc;
00321     /// Boost Active Discharge: default 0 - Disabled, 1 - Enabled when boost disabled 
00322     bool boostActDsc;
00323     /// Buck Operating Mode: default BUCK_BURST 
00324     buckMd_t buckMd;
00325     /// Buck Fast Start: default 0 - Normal startup current limit, 1 - Double startup current for fast start 
00326     bool buckFst;
00327     /// Buck Peak Current Setting: default BUCK_ISET_300mA
00328     buckISet_t buckISet;
00329     /// Buck Configuration: default 0 - For burst mode, 1 - For FPWM mode
00330     bool buckCfg;
00331     /// Buck Inductor Setting: default 0 - 2.2uH, 1 - 4.7uH
00332     bool buckInd;
00333     /// Buck Hysteresis Off: default 0 - Hysteresis enabled (more efficient), 1 - Hysteresis off (lower voltage ripple)
00334     bool buckHysOff;
00335     /// Buck Minimum On Time: default 1 - Disable deglitch delay (lower voltage ripple), 0 - Enable deglitch dealy (more efficient)
00336     bool buckMinOT;
00337     /// Buck Integrate: default 1 - Better load regulation at higher current (recommended for output capacitance >6uF), 0 - More stable operation with smaller output capacitor
00338     bool buckInteg;
00339     /// Buck Passive Discharge: default 0 - Disabled, 1 - Enabled when buck disabled  
00340     bool buckPasDsc;
00341     /// Buck Active Discharge: default 0 - Disabled, 1 - Enabled when buck disabled 
00342     bool buckActDsc;
00343     /// 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)
00344     bool buckFScl;
00345 
00346 private:
00347     /// I2C pointer
00348     I2C *i2c;
00349     /// Is this object the owner of the I2C object
00350     bool isOwner;
00351     /// Device slave address
00352     int slaveAddress;
00353 };
00354 
00355 #endif /* _MAX14720_H_ */