Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld max32630fthr max4146x_comp ... more
Fork of MAX14690 by
Revision 10:32c7e2ab67aa, committed 2016-11-18
- Comitter:
- switches
- Date:
- Fri Nov 18 22:06:28 2016 +0000
- Parent:
- 9:8fb54367ceb5
- Child:
- 11:022bcd2ea263
- Commit message:
- New library for MAX14690N
Changed in this revision
MAX14690.cpp | Show annotated file Show diff for this revision Revisions of this file |
MAX14690.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAX14690.cpp Thu Nov 10 16:06:11 2016 +0000 +++ b/MAX14690.cpp Fri Nov 18 22:06:28 2016 +0000 @@ -34,60 +34,18 @@ #include "MAX14690.h" //****************************************************************************** -MAX14690::MAX14690(PinName sda, PinName scl, int slaveAddress) : - slaveAddress(slaveAddress) +MAX14690::MAX14690(PinName sda, PinName scl) { i2c = new I2C(sda,scl); isOwner = true; - clkDivEn = false; - clkDivSet = 0; - boostISet = BOOST_ISET_100mA; - boostMillivolts = 3300; - boostEn = BOOST_DISABLED; - boostEMI = false; - boostInd = false; - boostHysOff = false; - boostPasDsc = false; - boostActDsc = false; - buckMd = BUCK_BURST; - buckFst = false; - buckISet = BUCK_ISET_300mA; - buckCfg = false; - buckInd = false; - buckHysOff = true; - buckMinOT = true; - buckInteg = true; - buckPasDsc = false; - buckActDsc = false; - buckFScl = false; + resetToDefaults(); } //****************************************************************************** -MAX14690::MAX14690(I2C *i2c, int slaveAddress) : - slaveAddress(slaveAddress) +MAX14690::MAX14690(I2C *i2c) { this->i2c = i2c; isOwner = false; - clkDivEn = false; - clkDivSet = 0; - boostISet = BOOST_ISET_100mA; - boostMillivolts = 3300; - boostEn = BOOST_DISABLED; - boostEMI = false; - boostInd = false; - boostHysOff = false; - boostPasDsc = false; - boostActDsc = false; - buckMd = BUCK_BURST; - buckFst = false; - buckISet = BUCK_ISET_300mA; - buckCfg = false; - buckInd = false; - buckHysOff = true; - buckMinOT = true; - buckInteg = true; - buckPasDsc = false; - buckActDsc = false; - buckFScl = false; + resetToDefaults(); } //****************************************************************************** @@ -99,40 +57,121 @@ } //****************************************************************************** -int MAX14690::boostSetMode(boostEn_t mode) +void MAX14690::resetToDefaults() { - char data; - - boostEn = mode; - data = (boostEn << 3) | (boostEMI << 1) | (boostInd); - return writeReg(REG_BOOST_CFG, data); + intEnThermStatus = false; + intEnChgStatus = false; + intEnILim = false; + intEnUSBOVP = false; + intEnUSBOK = false; + intEnChgThmSD = false; + intEnThermReg = false; + intEnChgTimeOut = false; + intEnThermBuck1 = false; + intEnThermBuck2 = false; + intEnThermLDO1 = false; + intEnThermLDO2 = false; + intEnThermLDO3 = false; + iLimCntl = ILIM_500mA; + chgAutoStp = true; + chgAutoReSta = true; + batReChg = BAT_RECHG_120mV; + batReg = BAT_REG_4200mV; + chgEn = true; + vPChg = VPCHG_3000mV; + iPChg = IPCHG_10; + chgDone = CHGDONE_10; + mtChgTmr = MTCHGTMR_0min; + fChgTmr = FCHGTMR_300min; + pChgTmr = PCHGTMR_60min; + buck1Md = BUCK_BURST; + buck1Ind = 0; + buck2Md = BUCK_BURST; + buck2Ind = 0; + ldo2Mode = LDO_DISABLED; + ldo2Millivolts = 3200; + ldo3Mode = LDO_DISABLED; + ldo3Millivolts = 3000; + thrmCfg = THRM_ENABLED; + monRatio = MON_DIV4; + monCfg = MON_PULLDOWN; + buck2ActDsc = false; + buck2FFET = false; + buck1ActDsc = false; + buck1FFET = false; + pfnResEna = true; + stayOn = true; } //****************************************************************************** -int MAX14690::boostSetVoltage(int mV) +int MAX14690::ldo2SetMode(ldoMode_t mode) { + ldo2Mode = mode; + return writeReg(REG_LDO2_CFG, mode); +} + +//****************************************************************************** +int MAX14690::ldo2SetVoltage(int mV) +{ + int regBits = mv2bits(mV); char data; - if ((MAX14690_BOOST_MIN_MV <= mV) && (mV <= MAX14690_BOOST_MAX_MV)) { - boostMillivolts = mV; - data = (mV - MAX14690_BOOST_MIN_MV) / MAX14690_BOOST_STEP_MV; + if (regBits < 0) { + return MAX14690_ERROR; } else { - return MAX14690_ERROR; + data = regBits; } - if (boostEn == BOOST_ENABLED) { - if (writeReg(REG_BOOST_CFG, 0x00) != MAX14690_NO_ERROR) { + if (ldo2Mode == LDO_ENABLED) { + if (writeReg(REG_LDO2_CFG, LDO_DISABLED) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } } - if (writeReg(REG_BOOST_VSET, data) != MAX14690_NO_ERROR) { + if (writeReg(REG_LDO2_VSET, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - if (boostEn == BOOST_ENABLED) { - data = (boostEn << 3) | (boostEMI << 1) | (boostInd); - if (writeReg(REG_BOOST_CFG, data) != MAX14690_NO_ERROR) { + if (ldo2Mode == LDO_ENABLED) { + if (writeReg(REG_LDO2_CFG, LDO_ENABLED) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + } + + return MAX14690_NO_ERROR; +} + +//****************************************************************************** +int MAX14690::ldo3SetMode(ldoMode_t mode) +{ + ldo3Mode = mode; + return writeReg(REG_LDO3_CFG, mode); +} + +//****************************************************************************** +int MAX14690::ldo3SetVoltage(int mV) +{ + int regBits = mv2bits(mV); + char data; + + if (regBits < 0) { + return MAX14690_ERROR; + } else { + data = regBits; + } + + if (ldo3Mode == LDO_ENABLED) { + if (writeReg(REG_LDO3_CFG, LDO_DISABLED) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + } + + if (writeReg(REG_LDO3_VSET, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + + if (ldo3Mode == LDO_ENABLED) { + if (writeReg(REG_LDO3_CFG, LDO_ENABLED) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } } @@ -143,52 +182,132 @@ //****************************************************************************** int MAX14690::init() { + int regBits; char data; - data = (clkDivEn << 7) | (clkDivSet); - if (writeReg(REG_BOOST_CDIV, data) != MAX14690_NO_ERROR) { + // Configure buck regulators + data = (buck1Md << 1) | + (buck1Ind); + if (writeReg(REG_BUCK1_CFG, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (buck2Md << 1) | + (buck2Ind); + if (writeReg(REG_BUCK2_CFG, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (buck2ActDsc << 5) | + (buck2FFET << 4) | + (buck1ActDsc << 1) | + (buck1FFET); + if (writeReg(REG_BUCK_EXTRA, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - data = (boostISet); - if (writeReg(REG_BOOST_ISET, data) != MAX14690_NO_ERROR) { + // Configure Charger + data = (iLimCntl); + if (writeReg(REG_I_LIM_CNTL, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (vPChg << 4) | + (iPChg << 2) | + (chgDone); + if (writeReg(REG_CHG_CNTL_B, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (mtChgTmr << 4) | + (fChgTmr << 2) | + (pChgTmr); + if (writeReg(REG_CHG_TMR, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (thrmCfg); + if (writeReg(REG_THRM_CFG, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + // Set enable bit after setting other charger bits + data = (chgAutoStp << 7) | + (chgAutoReSta << 6) | + (batReChg << 4) | + (batReg << 1) | + (chgEn); + if (writeReg(REG_CHG_CNTL_A, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - if ((MAX14690_BOOST_MIN_MV <= boostMillivolts) && - (boostMillivolts <= MAX14690_BOOST_MAX_MV)) { - data = (boostMillivolts - MAX14690_BOOST_MIN_MV) / MAX14690_BOOST_STEP_MV; - if (writeReg(REG_BOOST_VSET, data) != MAX14690_NO_ERROR) { - return MAX14690_ERROR; - } - } else { + // Configure monitor multiplexer + data = (monRatio << 4) | + (monCfg); + if (writeReg(REG_MON_CFG, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - data = (buckMd << 1) | (buckFst); - if (writeReg(REG_BUCK_CFG, data) != MAX14690_NO_ERROR) { + // Configure and enable LDOs + regBits = mv2bits(ldo2Millivolts); + if (regBits < 0) { + return MAX14690_ERROR; + } else { + data = regBits; + } + if (writeReg(REG_LDO2_VSET, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (ldo2Mode); + if (writeReg(REG_LDO2_CFG, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + regBits = mv2bits(ldo3Millivolts); + if (regBits < 0) { + return MAX14690_ERROR; + } else { + data = regBits; + } + if (writeReg(REG_LDO3_VSET, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + data = (ldo3Mode); + if (writeReg(REG_LDO3_CFG, data) != MAX14690_NO_ERROR) { + return MAX14690_ERROR; + } + + // Set stayOn bit after other registers to confirm successful boot. + data = (pfnResEna << 7) | + (stayOn); + if (writeReg(REG_PWR_CFG, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) | - (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl); - if (writeReg(REG_BBB_EXTRA, data) != MAX14690_NO_ERROR) { + // Unmask Interrupts Last + data = (intEnThermStatus << 7) | + (intEnChgStatus << 6) | + (intEnILim << 5) | + (intEnUSBOVP << 4) | + (intEnUSBOK << 3) | + (intEnChgThmSD << 2) | + (intEnThermReg << 1) | + (intEnChgTimeOut); + if (writeReg(REG_INT_MASK_A, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - - // Write Boost Enable Register Last - data = (boostEn << 3) | (boostEMI << 1) | (boostInd); - if (writeReg(REG_BOOST_CFG, data) != MAX14690_NO_ERROR) { + data = (intEnThermBuck1 << 4) | + (intEnThermBuck2 << 3) | + (intEnThermLDO1 << 2) | + (intEnThermLDO2 << 1) | + (intEnThermLDO3); + if (writeReg(REG_INT_MASK_B, data) != MAX14690_NO_ERROR) { return MAX14690_ERROR; } - + return MAX14690_NO_ERROR; } //****************************************************************************** -int MAX14690::monSet(monCfg_t monCfg) +int MAX14690::monSet(monCfg_t newMonCfg, monRatio_t newMonRatio) { - return writeReg(REG_MON_CFG, monCfg); + char data = (newMonRatio << 4) | (newMonCfg); + monCfg = newMonCfg; + monRatio = newMonRatio; + return writeReg(REG_MON_CFG, data); } //****************************************************************************** @@ -203,7 +322,7 @@ { char cmdData[2] = { (char)reg, value }; - if (i2c->write(slaveAddress, cmdData, sizeof(cmdData)) != 0) { + if (i2c->write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) { return MAX14690_ERROR; } @@ -215,13 +334,27 @@ { char cmdData[1] = { (char)reg }; - if (i2c->write(slaveAddress, cmdData, sizeof(cmdData)) != 0) { + if (i2c->write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) { return MAX14690_ERROR; } - if (i2c->read(slaveAddress, value, 1) != 0) { + if (i2c->read(MAX14690_I2C_ADDR, value, 1) != 0) { return MAX14690_ERROR; } return MAX14690_NO_ERROR; } + +//****************************************************************************** +int MAX14690::mv2bits(int mV) +{ + int regBits; + + if ((MAX14690_LDO_MIN_MV <= mV) && (mV <= MAX14690_LDO_MAX_MV)) { + regBits = (mV - MAX14690_LDO_MIN_MV) / MAX14690_LDO_STEP_MV; + } else { + return -1; + } + + return regBits; +}
--- 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_ */