MAX14690 library

Fork of MAX14690 by Maxim Integrated

Committer:
switches
Date:
Tue Oct 04 22:26:50 2016 +0000
Revision:
3:cdd88a3d3d24
Parent:
0:0e40db4a2b3e
Child:
7:2e9f6e70b34f
Updated Library for Demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jbradshaw 0:0e40db4a2b3e 1 /*******************************************************************************
jbradshaw 0:0e40db4a2b3e 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
jbradshaw 0:0e40db4a2b3e 3 *
jbradshaw 0:0e40db4a2b3e 4 * Permission is hereby granted, free of charge, to any person obtaining a
jbradshaw 0:0e40db4a2b3e 5 * copy of this software and associated documentation files (the "Software"),
jbradshaw 0:0e40db4a2b3e 6 * to deal in the Software without restriction, including without limitation
jbradshaw 0:0e40db4a2b3e 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
jbradshaw 0:0e40db4a2b3e 8 * and/or sell copies of the Software, and to permit persons to whom the
jbradshaw 0:0e40db4a2b3e 9 * Software is furnished to do so, subject to the following conditions:
jbradshaw 0:0e40db4a2b3e 10 *
jbradshaw 0:0e40db4a2b3e 11 * The above copyright notice and this permission notice shall be included
jbradshaw 0:0e40db4a2b3e 12 * in all copies or substantial portions of the Software.
jbradshaw 0:0e40db4a2b3e 13 *
jbradshaw 0:0e40db4a2b3e 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
jbradshaw 0:0e40db4a2b3e 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
jbradshaw 0:0e40db4a2b3e 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
jbradshaw 0:0e40db4a2b3e 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
jbradshaw 0:0e40db4a2b3e 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
jbradshaw 0:0e40db4a2b3e 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
jbradshaw 0:0e40db4a2b3e 20 * OTHER DEALINGS IN THE SOFTWARE.
jbradshaw 0:0e40db4a2b3e 21 *
jbradshaw 0:0e40db4a2b3e 22 * Except as contained in this notice, the name of Maxim Integrated
jbradshaw 0:0e40db4a2b3e 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
jbradshaw 0:0e40db4a2b3e 24 * Products, Inc. Branding Policy.
jbradshaw 0:0e40db4a2b3e 25 *
jbradshaw 0:0e40db4a2b3e 26 * The mere transfer of this software does not imply any licenses
jbradshaw 0:0e40db4a2b3e 27 * of trade secrets, proprietary technology, copyrights, patents,
jbradshaw 0:0e40db4a2b3e 28 * trademarks, maskwork rights, or any other form of intellectual
jbradshaw 0:0e40db4a2b3e 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
jbradshaw 0:0e40db4a2b3e 30 * ownership rights.
jbradshaw 0:0e40db4a2b3e 31 *******************************************************************************
jbradshaw 0:0e40db4a2b3e 32 */
jbradshaw 0:0e40db4a2b3e 33
jbradshaw 0:0e40db4a2b3e 34 #include "MAX14720.h"
jbradshaw 0:0e40db4a2b3e 35
jbradshaw 0:0e40db4a2b3e 36 //******************************************************************************
jbradshaw 0:0e40db4a2b3e 37 MAX14720::MAX14720(PinName sda, PinName scl, int slaveAddress) :
switches 3:cdd88a3d3d24 38 slaveAddress(slaveAddress)
jbradshaw 0:0e40db4a2b3e 39 {
switches 3:cdd88a3d3d24 40 i2c = new I2C(sda,scl);
switches 3:cdd88a3d3d24 41 isOwner = true;
switches 3:cdd88a3d3d24 42 clkDivEn = false;
switches 3:cdd88a3d3d24 43 clkDivSet = 0;
switches 3:cdd88a3d3d24 44 boostISet = BOOST_ISET_100mA;
switches 3:cdd88a3d3d24 45 boostMillivolts = 3300;
switches 3:cdd88a3d3d24 46 boostEn = BOOST_DISABLED;
switches 3:cdd88a3d3d24 47 boostEMI = false;
switches 3:cdd88a3d3d24 48 boostInd = false;
switches 3:cdd88a3d3d24 49 boostHysOff = false;
switches 3:cdd88a3d3d24 50 boostPasDsc = false;
switches 3:cdd88a3d3d24 51 boostActDsc = false;
switches 3:cdd88a3d3d24 52 buckMd = BUCK_BURST;
switches 3:cdd88a3d3d24 53 buckFst = false;
switches 3:cdd88a3d3d24 54 buckISet = BUCK_ISET_300mA;
switches 3:cdd88a3d3d24 55 buckCfg = false;
switches 3:cdd88a3d3d24 56 buckInd = false;
switches 3:cdd88a3d3d24 57 buckHysOff = true;
switches 3:cdd88a3d3d24 58 buckMinOT = true;
switches 3:cdd88a3d3d24 59 buckInteg = true;
switches 3:cdd88a3d3d24 60 buckPasDsc = false;
switches 3:cdd88a3d3d24 61 buckActDsc = false;
switches 3:cdd88a3d3d24 62 buckFScl = false;
jbradshaw 0:0e40db4a2b3e 63 }
jbradshaw 0:0e40db4a2b3e 64 //******************************************************************************
jbradshaw 0:0e40db4a2b3e 65 MAX14720::MAX14720(I2C *i2c, int slaveAddress) :
switches 3:cdd88a3d3d24 66 slaveAddress(slaveAddress)
jbradshaw 0:0e40db4a2b3e 67 {
switches 3:cdd88a3d3d24 68 this->i2c = i2c;
switches 3:cdd88a3d3d24 69 isOwner = false;
switches 3:cdd88a3d3d24 70 clkDivEn = false;
switches 3:cdd88a3d3d24 71 clkDivSet = 0;
switches 3:cdd88a3d3d24 72 boostISet = BOOST_ISET_100mA;
switches 3:cdd88a3d3d24 73 boostMillivolts = 3300;
switches 3:cdd88a3d3d24 74 boostEn = BOOST_DISABLED;
switches 3:cdd88a3d3d24 75 boostEMI = false;
switches 3:cdd88a3d3d24 76 boostInd = false;
switches 3:cdd88a3d3d24 77 boostHysOff = false;
switches 3:cdd88a3d3d24 78 boostPasDsc = false;
switches 3:cdd88a3d3d24 79 boostActDsc = false;
switches 3:cdd88a3d3d24 80 buckMd = BUCK_BURST;
switches 3:cdd88a3d3d24 81 buckFst = false;
switches 3:cdd88a3d3d24 82 buckISet = BUCK_ISET_300mA;
switches 3:cdd88a3d3d24 83 buckCfg = false;
switches 3:cdd88a3d3d24 84 buckInd = false;
switches 3:cdd88a3d3d24 85 buckHysOff = true;
switches 3:cdd88a3d3d24 86 buckMinOT = true;
switches 3:cdd88a3d3d24 87 buckInteg = true;
switches 3:cdd88a3d3d24 88 buckPasDsc = false;
switches 3:cdd88a3d3d24 89 buckActDsc = false;
switches 3:cdd88a3d3d24 90 buckFScl = false;
jbradshaw 0:0e40db4a2b3e 91 }
jbradshaw 0:0e40db4a2b3e 92 //******************************************************************************
jbradshaw 0:0e40db4a2b3e 93 MAX14720::~MAX14720()
jbradshaw 0:0e40db4a2b3e 94 {
switches 3:cdd88a3d3d24 95 if (isOwner == true) {
switches 3:cdd88a3d3d24 96 delete i2c;
switches 3:cdd88a3d3d24 97 }
switches 3:cdd88a3d3d24 98 }
switches 3:cdd88a3d3d24 99
switches 3:cdd88a3d3d24 100 //******************************************************************************
switches 3:cdd88a3d3d24 101 int MAX14720::boostSetMode(boostEn_t mode)
switches 3:cdd88a3d3d24 102 {
switches 3:cdd88a3d3d24 103 int result;
switches 3:cdd88a3d3d24 104 char data;
switches 3:cdd88a3d3d24 105 boostEn = mode;
switches 3:cdd88a3d3d24 106 data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
switches 3:cdd88a3d3d24 107 result = writeReg(REG_BOOST_CFG, data);
switches 3:cdd88a3d3d24 108 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 109 return 0;
jbradshaw 0:0e40db4a2b3e 110 }
jbradshaw 0:0e40db4a2b3e 111
jbradshaw 0:0e40db4a2b3e 112 //******************************************************************************
switches 3:cdd88a3d3d24 113 int MAX14720::boostSetVoltage(int mV)
switches 3:cdd88a3d3d24 114 {
jbradshaw 0:0e40db4a2b3e 115 int result;
switches 3:cdd88a3d3d24 116 char data;
switches 3:cdd88a3d3d24 117 if ((MAX14720_BOOST_MIN_MV <= mV)&&(mV <= MAX14720_BOOST_MAX_MV)) {
switches 3:cdd88a3d3d24 118 boostMillivolts = mV;
switches 3:cdd88a3d3d24 119 data = (mV - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV;
switches 3:cdd88a3d3d24 120 } else {
switches 3:cdd88a3d3d24 121 return MAX14720_ERROR;
switches 3:cdd88a3d3d24 122 }
switches 3:cdd88a3d3d24 123 if (boostEn == BOOST_ENABLED) {
switches 3:cdd88a3d3d24 124 result = writeReg(REG_BOOST_CFG, 0x00);
switches 3:cdd88a3d3d24 125 }
jbradshaw 0:0e40db4a2b3e 126 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 127 result = writeReg(REG_BOOST_VSET, data);
jbradshaw 0:0e40db4a2b3e 128 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 129 if (boostEn == BOOST_ENABLED) {
switches 3:cdd88a3d3d24 130 data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
switches 3:cdd88a3d3d24 131 result = writeReg(REG_BOOST_CFG, data);
switches 3:cdd88a3d3d24 132 }
switches 3:cdd88a3d3d24 133 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 134 return 0;
jbradshaw 0:0e40db4a2b3e 135 }
jbradshaw 0:0e40db4a2b3e 136
jbradshaw 0:0e40db4a2b3e 137 //******************************************************************************
switches 3:cdd88a3d3d24 138 int MAX14720::init()
switches 3:cdd88a3d3d24 139 {
jbradshaw 0:0e40db4a2b3e 140 int result;
switches 3:cdd88a3d3d24 141 char data;
switches 3:cdd88a3d3d24 142 data = (clkDivEn << 7) | (clkDivSet);
switches 3:cdd88a3d3d24 143 result = writeReg(REG_BOOST_CDIV, data);
switches 3:cdd88a3d3d24 144 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 145 data = (boostISet);
switches 3:cdd88a3d3d24 146 result = writeReg(REG_BOOST_ISET, data);
switches 3:cdd88a3d3d24 147 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 148 if ((MAX14720_BOOST_MIN_MV <= boostMillivolts)&&(boostMillivolts <= MAX14720_BOOST_MAX_MV)) {
switches 3:cdd88a3d3d24 149 data = (boostMillivolts - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV;
switches 3:cdd88a3d3d24 150 } else {
switches 3:cdd88a3d3d24 151 return MAX14720_ERROR;
switches 3:cdd88a3d3d24 152 }
switches 3:cdd88a3d3d24 153 result = writeReg(REG_BOOST_VSET, data);
switches 3:cdd88a3d3d24 154 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 155 data = (buckMd << 1) | (buckFst);
switches 3:cdd88a3d3d24 156 result = writeReg(REG_BUCK_CFG, data);
switches 3:cdd88a3d3d24 157 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 158 data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) | (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl);
switches 3:cdd88a3d3d24 159 result = writeReg(REG_BBB_EXTRA, data);
switches 3:cdd88a3d3d24 160 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 161 // Write Boost Enable Register Last
switches 3:cdd88a3d3d24 162 data = (boostEn << 3) | (boostEMI << 1) | (boostInd);
switches 3:cdd88a3d3d24 163 result = writeReg(REG_BOOST_CFG, data);
switches 3:cdd88a3d3d24 164 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 165 return 0;
jbradshaw 0:0e40db4a2b3e 166 }
jbradshaw 0:0e40db4a2b3e 167
jbradshaw 0:0e40db4a2b3e 168 //******************************************************************************
switches 3:cdd88a3d3d24 169 int MAX14720::monSet(monCfg_t monCfg)
switches 3:cdd88a3d3d24 170 {
jbradshaw 0:0e40db4a2b3e 171 int result;
switches 3:cdd88a3d3d24 172 result = writeReg(REG_MON_CFG, monCfg);
switches 3:cdd88a3d3d24 173 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 174 return 0;
jbradshaw 0:0e40db4a2b3e 175 }
jbradshaw 0:0e40db4a2b3e 176
jbradshaw 0:0e40db4a2b3e 177 //******************************************************************************
switches 3:cdd88a3d3d24 178 int MAX14720::shutdown()
switches 3:cdd88a3d3d24 179 {
jbradshaw 0:0e40db4a2b3e 180 int result;
switches 3:cdd88a3d3d24 181 result = writeReg(REG_PWR_OFF, 0xB2);
jbradshaw 0:0e40db4a2b3e 182 if (result == MAX14720_ERROR) return result;
switches 3:cdd88a3d3d24 183 return 0;
jbradshaw 0:0e40db4a2b3e 184 }
jbradshaw 0:0e40db4a2b3e 185
switches 3:cdd88a3d3d24 186
jbradshaw 0:0e40db4a2b3e 187 //******************************************************************************
switches 3:cdd88a3d3d24 188 int MAX14720::writeReg(registers_t reg, char value)
jbradshaw 0:0e40db4a2b3e 189 {
jbradshaw 0:0e40db4a2b3e 190 int result;
jbradshaw 0:0e40db4a2b3e 191 char cmdData[2] = { (char)reg, value };
jbradshaw 0:0e40db4a2b3e 192 result = i2c->write(slaveAddress, cmdData, 2);
jbradshaw 0:0e40db4a2b3e 193 if (result != 0) return MAX14720_ERROR;
jbradshaw 0:0e40db4a2b3e 194 return MAX14720_NO_ERROR;
jbradshaw 0:0e40db4a2b3e 195 }
jbradshaw 0:0e40db4a2b3e 196
jbradshaw 0:0e40db4a2b3e 197 //******************************************************************************
switches 3:cdd88a3d3d24 198 int MAX14720::readReg(registers_t reg, char *value)
jbradshaw 0:0e40db4a2b3e 199 {
jbradshaw 0:0e40db4a2b3e 200 int result;
jbradshaw 0:0e40db4a2b3e 201 char cmdData[1] = { (char)reg };
switches 3:cdd88a3d3d24 202
jbradshaw 0:0e40db4a2b3e 203 result = i2c->write(slaveAddress, cmdData, 1);
jbradshaw 0:0e40db4a2b3e 204 if (result != 0) return MAX14720_ERROR;
jbradshaw 0:0e40db4a2b3e 205 result = i2c->read(slaveAddress, value, 1);
jbradshaw 0:0e40db4a2b3e 206 if (result != 0) return MAX14720_ERROR;
jbradshaw 0:0e40db4a2b3e 207 return MAX14720_NO_ERROR;
jbradshaw 0:0e40db4a2b3e 208 }
jbradshaw 0:0e40db4a2b3e 209
jbradshaw 0:0e40db4a2b3e 210
jbradshaw 0:0e40db4a2b3e 211
jbradshaw 0:0e40db4a2b3e 212
jbradshaw 0:0e40db4a2b3e 213
jbradshaw 0:0e40db4a2b3e 214
jbradshaw 0:0e40db4a2b3e 215