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.
Fork of MAX14690 by
Diff: MAX14720.cpp
- Revision:
- 3:cdd88a3d3d24
- Parent:
- 0:0e40db4a2b3e
- Child:
- 7:2e9f6e70b34f
--- a/MAX14720.cpp Wed Sep 28 19:52:29 2016 +0000
+++ b/MAX14720.cpp Tue Oct 04 22:26:50 2016 +0000
@@ -35,87 +35,157 @@
//******************************************************************************
MAX14720::MAX14720(PinName sda, PinName scl, int slaveAddress) :
- slaveAddress(slaveAddress)
+ slaveAddress(slaveAddress)
{
- i2c = new I2C(sda,scl);
- isOwner = true;
+ 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;
}
//******************************************************************************
MAX14720::MAX14720(I2C *i2c, int slaveAddress) :
- slaveAddress(slaveAddress)
+ slaveAddress(slaveAddress)
{
- this->i2c = i2c;
- isOwner = false;
+ 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;
}
//******************************************************************************
MAX14720::~MAX14720()
{
- if (isOwner == true) {
- delete i2c;
- }
+ if (isOwner == true) {
+ delete i2c;
+ }
+}
+
+//******************************************************************************
+int MAX14720::boostSetMode(boostEn_t mode)
+{
+ int result;
+ char data;
+ boostEn = mode;
+ data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
+ result = writeReg(REG_BOOST_CFG, data);
+ if (result == MAX14720_ERROR) return result;
+ return 0;
}
//******************************************************************************
-int MAX14720::boostEn(BoostEn_Values value) {
+int MAX14720::boostSetVoltage(int mV)
+{
int result;
- max14720_BoostCfg val;
-
- // read modify write BoostEn to desired state
- result = readReg(BOOST_CFG, &val.all);
- val.bit.BoostEn = (char)value;
- result = writeReg(BOOST_CFG, val.all);
+ char data;
+ if ((MAX14720_BOOST_MIN_MV <= mV)&&(mV <= MAX14720_BOOST_MAX_MV)) {
+ boostMillivolts = mV;
+ data = (mV - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV;
+ } else {
+ return MAX14720_ERROR;
+ }
+ if (boostEn == BOOST_ENABLED) {
+ result = writeReg(REG_BOOST_CFG, 0x00);
+ }
if (result == MAX14720_ERROR) return result;
- return 0;
-}
-
-//******************************************************************************
-int MAX14720::boostVSet(BoostVSet_Values value) {
- int result;
- max14720_BoostVSet val;
-
- // read modify write boostVSet to desired state
- result = readReg(BOOST_V_SET, &val.all);
- val.bit.BoostVSet = (char)value;
- result = writeReg(BOOST_V_SET, val.all);
+ result = writeReg(REG_BOOST_VSET, data);
if (result == MAX14720_ERROR) return result;
- return 0;
+ if (boostEn == BOOST_ENABLED) {
+ data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
+ result = writeReg(REG_BOOST_CFG, data);
+ }
+ if (result == MAX14720_ERROR) return result;
+ return 0;
}
//******************************************************************************
-int MAX14720::readBoostVSet(BoostVSet_Values *value) {
+int MAX14720::init()
+{
int result;
- char val;
-
- result = readReg(BOOST_V_SET,&val);
- *value = (BoostVSet_Values)val;
- return result;
+ char data;
+ data = (clkDivEn << 7) | (clkDivSet);
+ result = writeReg(REG_BOOST_CDIV, data);
+ if (result == MAX14720_ERROR) return result;
+ data = (boostISet);
+ result = writeReg(REG_BOOST_ISET, data);
+ if (result == MAX14720_ERROR) return result;
+ if ((MAX14720_BOOST_MIN_MV <= boostMillivolts)&&(boostMillivolts <= MAX14720_BOOST_MAX_MV)) {
+ data = (boostMillivolts - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV;
+ } else {
+ return MAX14720_ERROR;
+ }
+ result = writeReg(REG_BOOST_VSET, data);
+ if (result == MAX14720_ERROR) return result;
+ data = (buckMd << 1) | (buckFst);
+ result = writeReg(REG_BUCK_CFG, data);
+ if (result == MAX14720_ERROR) return result;
+ data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) | (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl);
+ result = writeReg(REG_BBB_EXTRA, data);
+ if (result == MAX14720_ERROR) return result;
+ // Write Boost Enable Register Last
+ data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
+ result = writeReg(REG_BOOST_CFG, data);
+ if (result == MAX14720_ERROR) return result;
+ return 0;
}
//******************************************************************************
-int MAX14720::readBoostISet(BoostISet_Values *value) {
+int MAX14720::monSet(monCfg_t monCfg)
+{
int result;
- char val;
-
- result = readReg(BOOST_V_SET,&val);
- *value = (BoostISet_Values)val;
- return result;
+ result = writeReg(REG_MON_CFG, monCfg);
+ if (result == MAX14720_ERROR) return result;
+ return 0;
}
//******************************************************************************
-int MAX14720::boostISet(BoostISet_Values value) {
+int MAX14720::shutdown()
+{
int result;
- max14720_BoostISet val;
-
- // read modify write boostVSet to desired state
- result = readReg(BOOST_I_SET, &val.all);
- val.bit.BoostISet = (char)value;
- result = writeReg(BOOST_I_SET, val.all);
+ result = writeReg(REG_PWR_OFF, 0xB2);
if (result == MAX14720_ERROR) return result;
- return 0;
+ return 0;
}
+
//******************************************************************************
-int MAX14720::writeReg(MAX14720_REG_map_t reg, char value)
+int MAX14720::writeReg(registers_t reg, char value)
{
int result;
char cmdData[2] = { (char)reg, value };
@@ -125,11 +195,11 @@
}
//******************************************************************************
-int MAX14720::readReg(MAX14720_REG_map_t reg, char *value)
+int MAX14720::readReg(registers_t reg, char *value)
{
int result;
char cmdData[1] = { (char)reg };
-
+
result = i2c->write(slaveAddress, cmdData, 1);
if (result != 0) return MAX14720_ERROR;
result = i2c->read(slaveAddress, value, 1);
