MAX14690 Library
Dependents: MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld max32630fthr max4146x_comp ... more
Fork of MAX14690 by
Diff: MAX14720.h
- Revision:
- 3:cdd88a3d3d24
- Parent:
- 2:5bcfe7e294b6
- Child:
- 4:2e4837c3b6e1
--- a/MAX14720.h Wed Sep 28 19:52:29 2016 +0000 +++ b/MAX14720.h Tue Oct 04 22:26:50 2016 +0000 @@ -31,8 +31,8 @@ ******************************************************************************* */ -#ifndef PMIC_H_ -#define PMIC_H_ +#ifndef _MAX14720_H_ +#define _MAX14720_H_ #include "mbed.h" @@ -71,334 +71,103 @@ #define MAX14720_NO_ERROR 0 #define MAX14720_ERROR -1 +#define MAX14720_BOOST_MIN_MV 2500 +#define MAX14720_BOOST_MAX_MV 5000 +#define MAX14720_BOOST_STEP_MV 100 + class MAX14720 { public: typedef enum { // I2C Register Addresses - CHIP_ID = 0x00, - CHIP_REV = 0x01, - BOOST_C_DIV = 0x03, - BOOST_I_SET = 0x04, - BOOST_V_SET = 0x05, - BOOST_CFG = 0x06, - BUCK_V_SET = 0x07, - BUCK_CFG = 0x08, - BUCK_I_SET = 0x09, - LDOV_SET = 0x0A, - LDO_CFG = 0x0B, - SWITCH_CFG = 0x0C, - BAT_TIME = 0x0D, - BAT_CFG = 0x0E, - BAT_BCV = 0x0F, - BAT_OCV = 0x10, - BAT_LCV = 0x11, - MON_CFG = 0X19, - BOOT_CFG = 0x1A, - PIN_STAT = 0x1B, - BBB_EXTRA = 0x1C, - HAND_SHK = 0x1D, - UVLO_CFG = 0x1E, - PWR_OFF = 0x1F, - OTP_MAP_0 = 0x20, - OTP_MAP_1 = 0x21, - OTP_MAP_2 = 0x22, - OTP_MAP_3 = 0x23, - OTP_MAP_4 = 0x24, - OTP_MAP_5 = 0x25, - OTP_MAP_6 = 0x26, - OTP_MAP_7 = 0x27, - OTP_MAP_8 = 0x28, - OTP_MAP_9 = 0x29, - OTP_MAP_A = 0x2A, - OTP_MAP_b = 0x2B, - } MAX14720_REG_map_t; - - /// @brief ChipId Register (0x00) - typedef union ChipId_ { - char all; - } max14720_ChipId; - - /// @brief ChipRev Register (0x01) - typedef union ChipRev_ { - char all; - } max14720_ChipRev; - - /// @brief BoostCDiv Register (0x03) - typedef union BoostCDiv_ { - char all; - struct { - char ClkDivSet : 7; - char ClkDivEn : 1; - } bit; - } max14720_BoostCDiv; - - /// @brief BoostISet Register (0x04) - typedef union BoostISet_ { - char all; - struct { - char BoostISet : 3; - } bit; - } max14720_BoostISet; - - /// @brief BoostVSet Register (0x05) - typedef union BoostVSet_ { - char all; - struct { - char BoostVSet : 5; - } bit; - } max14720_BoostVSet; - - /// @brief BoostCfg Register (0x06) - typedef union BoostCfg_ { - char all; - struct { - char BoostInd : 1; - char BoostEMI : 1; - char reserved : 1; - char BoostEn : 2; - char BoostSeq : 3; - } bit; - } max14720_BoostCfg; - - /// @brief BuckVSet Register (0x07) - typedef union BuckVSet_ { - char all; - struct { - char BuckVSet : 6; - } bit; - } max14720_BuckVSet; - - /// @brief BuckCfg Register (0x08) - typedef union BuckCfg_ { - char all; - struct { - char BuckFst : 1; - char BuckMd : 2; - char BoostEn : 2; - char BuckSeq : 3; - } bit; - } max14720_BuckCfg; - - /// @brief BuckISet Register (0x09) - typedef union BuckISet_ { - char all; - struct { - char BuckInteg : 1; - char BuckMinOT : 1; - char BuckHysOff : 1; - char BuckInd : 1; - char BuckCfg : 1; - char BuckISet : 3; - } bit; - } max14720_BuckISet; - - /// @brief LDOVSet Register (0x0A) - typedef union LDOVSet_ { - char all; - struct { - char LDOVSet : 5; - } bit; - } max14720_LDOVSet; - - /// @brief LDOCfg Register (0x0B) - typedef union LDOCfg_ { - char all; - struct { - char LDOMode : 1; - char LDOEn : 2; - char LDO_ActDSC : 1; - char LDO_PasDSC : 1; - char LDOSeq : 3; - } bit; - } max14720_LDOCfg; + REG_CHIP_ID = 0x00, + REG_CHIP_REV = 0x01, + REG_BOOST_CDIV = 0x03, + REG_BOOST_ISET = 0x04, + REG_BOOST_VSET = 0x05, + REG_BOOST_CFG = 0x06, + REG_BUCK_VSET = 0x07, + REG_BUCK_CFG = 0x08, + REG_BUCK_ISET = 0x09, + REG_LDO_VSET = 0x0A, + REG_LDO_CFG = 0x0B, + REG_SWITCH_CFG = 0x0C, + REG_BAT_TIME = 0x0D, + REG_BAT_CFG = 0x0E, + REG_BAT_BCV = 0x0F, + REG_BAT_OCV = 0x10, + REG_BAT_LCV = 0x11, + REG_MON_CFG = 0x19, + REG_BOOT_CFG = 0x1A, + REG_PIN_STAT = 0x1B, + REG_BBB_EXTRA = 0x1C, + REG_HANDSHK = 0x1D, + REG_UVLO_CFG = 0x1E, + REG_PWR_OFF = 0x1F, + REG_OTP_MAP_0 = 0x20, + REG_OTP_MAP_1 = 0x21, + REG_OTP_MAP_2 = 0x22, + REG_OTP_MAP_3 = 0x23, + REG_OTP_MAP_4 = 0x24, + REG_OTP_MAP_5 = 0x25, + REG_OTP_MAP_6 = 0x26, + REG_OTP_MAP_7 = 0x27, + REG_OTP_MAP_8 = 0x28, + REG_OTP_MAP_9 = 0x29, + REG_OTP_MAP_A = 0x2A, + REG_OTP_MAP_B = 0x2B, + } registers_t; - /// @brief SwitchCfg Register (0x0C) - typedef union SwitchCfg_ { - char all; - struct { - char SWSoftStart : 1; - char SWEn : 2; - char reserved : 2; - char SWSeq : 3; - } bit; - } max14720_SwitchCfg; - - /// @brief BatTime Register (0x0D) - typedef union BatTime_ { - char all; - struct { - char LCVTm : 2; - char OCVTm : 2; - char BCVTm : 2; - } bit; - } max14720_BatTime; - - /// @brief BatCfg Register (0x0E) - typedef union BatCfg_ { - char all; - struct { - char BatImpCur : 3; - char LcvDly2Skip : 1; - char reserved : 2; - char BIMAbort : 1; - char BIA : 1; - } bit; - } max14720_BatCfg; - - /// @brief BatV Register (0x0F) - typedef union BatBCV_ { - char all; - } max14720_BatBCV; - - /// @brief BatOCV Register (0x10) - typedef union BatOCV_ { - char all; - } max14720_BatOCV; - - /// @brief BatLCV Register (0x11) - typedef union BatLCV_ { - char all; - } max14720_BatLCV; - - /// @brief MONCfg Register (0x19) - typedef union MONCfg_ { - char all; - struct { - char MONCtr : 3; - char MONHiZ : 1; - char reserved : 3; - char MONEn : 1; - } bit; - } max14720_MONCfg; - - /// @brief BootCfg Register (0x1A) - typedef union BootCfg_ { - char all; - struct { - char BootDly : 2; - char PFNPUDCfg : 1; - char SftRstCfg : 1; - char PwrRstCfg : 4; - } bit; - } max14720_BootCfg; - - /// @brief PinStat Register (0x1B) - typedef union PinStat_ { - char all; - struct { - char RST_LEN : 1; - char MPC_BEN : 1; - char KOUT_HVEN : 1; - char KIN_SWEN : 1; - } bit; - } max14720_PinStat; - - /// @brief BBBExtra Register (0x1C) - typedef union BBBExtra_ { - char all; - struct { - char BuckFScl : 1; - char BuckActDsc : 1; - char BuckPasDsc : 1; - char reserved : 2; - char Boost_ActDsc : 1; - char BoostPasDsc : 1; - char Boost_HysOff : 1; - } bit; - } max14720_BBBExtra; - - /// @brief HandShk Register (0x1D) - typedef union HandShk_ { - char all; - struct { - char StayOn : 1; - char reserved : 5; - char GlbPasDsc : 1; - char StartOff : 1; - } bit; - } max14720_HandShk; - - /// @brief UVLOCfg Register (0x1E) - typedef union UVLOCfg_ { - char all; - struct { - char LDO_UVLOsel : 1; - char BBBUVLOsel : 1; - } bit; - } max14720_UVLOCfg; - - /// @brief PWRCFG Register (0x1F) - typedef union PWROFF_ { - char all; - } max14720_PWROFF; - - /// All of the possible BoostVSet values typedef enum { - BoostVSet_25, - BoostVSet_26, - BoostVSet_27, - BoostVSet_28, - BoostVSet_29, - BoostVSet_30, - BoostVSet_31, - BoostVSet_32, - BoostVSet_33, - BoostVSet_34, - BoostVSet_35, - BoostVSet_36, - BoostVSet_37, - BoostVSet_38, - BoostVSet_39, - BoostVSet_40, - BoostVSet_41, - BoostVSet_42, - BoostVSet_43, - BoostVSet_44, - BoostVSet_45, - BoostVSet_46, - BoostVSet_47, - BoostVSet_48, - BoostVSet_49, - BoostVSet_50, - } BoostVSet_Values; + BOOST_ISET_MIN, + BOOST_ISET_50mA, + BOOST_ISET_100mA, + BOOST_ISET_150mA, + BOOST_ISET_200mA, + BOOST_ISET_250mA, + BOOST_ISET_300mA, + BOOST_ISET_350mA, + } boostISet_t; typedef enum { - BoostEn_Disable, - BoostEn_Enable, - BoostEn_Enable_MPC_High, - } BoostEn_Values; - - typedef enum { - BoostISet_0, - BoostISet_50mA, - BoostISet_100mA, - BoostISet_150mA, - BoostISet_200mA, - BoostISet_250mA, - BoostISet_300mA, - BoostISet_350mA, - } BoostISet_Values; + BOOST_DISABLED, + BOOST_ENABLED, + BOOST_EN_MPC, + } boostEn_t; + + typedef enum { + BUCK_BURST, + BUCK_FPWM, + BUCK_MPC_FPWM, + } buckMd_t; typedef enum { - BoostSeq_Disabled, - BoostSeq_Reserved, - BoostSeq_Enabled_0, - BoostSeq_Enabled_25, - BoostSeq_Enabled_50, - BoostSeq_Reserved2, - BoostSeq_Controlled_HVEN, - BoostSeq_Controlled_BoostEn, - } BoostSeq_Values; + BUCK_ISET_50mA, + BUCK_ISET_100mA, + BUCK_ISET_150mA, + BUCK_ISET_200mA, + BUCK_ISET_250mA, + BUCK_ISET_300mA, + BUCK_ISET_350mA, + BUCK_ISET_400mA, + } buckISet_t; typedef enum { - BoostEMI_Active, - BoostEMI_Disabled, - } BoostEMI_Values; + MON_PULLDOWN = 0x00, + MON_HI_Z = 0x08, + MON_SWIN = 0x80, + MON_SWOUT = 0x81, + MON_BIN = 0x82, + MON_BOUT = 0x83, + MON_HVIN = 0x84, + MON_HVOUT = 0x85, + MON_LIN = 0x86, + MON_LOUT = 0x87, + } monCfg_t; typedef enum { - BoostInd_3_3, - BoostInd_4_7, - } BoostInd_Values; + LIN_UVLO, + BIN_UVLO, + } uvloIn_t; /** * MAX14720 constructor. @@ -423,34 +192,46 @@ ~MAX14720(); /** - * Enable or disable Boost + * Initialize MAX14720 */ - int boostEn(BoostEn_Values value); + int init(); /** * Set the Boost Output Voltage from 2.5V to 5V with 100mV increments */ - int boostVSet(BoostVSet_Values value); - /** - * Read the Boost Output Voltage + int boostSetVoltage(int mV); + /** + * Enable or disable Boost */ - int readBoostVSet(BoostVSet_Values *value); - /** - * Set the Buck-Boost Peak Current-Limit + int boostSetMode(boostEn_t mode); + /** + * Configure Monitor Multiplexer */ - int boostISet(BoostISet_Values value); - /** - * Read the Buck-Boost Peak Current-Limit + int monSet(monCfg_t monCfg); + /** + * Turn off all supplies and go to shelf mode */ - int readBoostISet(BoostISet_Values *value); + int shutdown(); /** * Write a device register */ - int writeReg(MAX14720_REG_map_t reg, char value); + int writeReg(registers_t reg, char value); /** * Read a device register */ - int readReg(MAX14720_REG_map_t reg, char *value); + int readReg(registers_t reg, char *value); + + bool clkDivEn; + int clkDivSet; + boostISet_t boostISet; + int boostMillivolts; + boostEn_t boostEn; + bool boostEMI, boostInd, boostHysOff, boostPasDsc, boostActDsc; + buckMd_t buckMd; + bool buckFst; + buckISet_t buckISet; + bool buckCfg, buckInd, buckHysOff, buckMinOT, buckInteg, buckPasDsc, buckActDsc, buckFScl; + private: /// I2C pointer I2C *i2c;