MAX14690 library
Fork of MAX14690 by
MAX14690.cpp@9:8fb54367ceb5, 2016-11-10 (annotated)
- Committer:
- switches
- Date:
- Thu Nov 10 16:06:11 2016 +0000
- Revision:
- 9:8fb54367ceb5
- Parent:
- MAX14720.cpp@8:2c3f2da51c5d
- Child:
- 10:32c7e2ab67aa
initial commit, work in progress
Who changed what in which revision?
User | Revision | Line number | New 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 | |
switches | 9:8fb54367ceb5 | 34 | #include "MAX14690.h" |
jbradshaw | 0:0e40db4a2b3e | 35 | |
jbradshaw | 0:0e40db4a2b3e | 36 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 37 | MAX14690::MAX14690(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 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 65 | MAX14690::MAX14690(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 | } |
jessexm | 8:2c3f2da51c5d | 92 | |
jbradshaw | 0:0e40db4a2b3e | 93 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 94 | MAX14690::~MAX14690() |
jbradshaw | 0:0e40db4a2b3e | 95 | { |
switches | 3:cdd88a3d3d24 | 96 | if (isOwner == true) { |
switches | 3:cdd88a3d3d24 | 97 | delete i2c; |
switches | 3:cdd88a3d3d24 | 98 | } |
switches | 3:cdd88a3d3d24 | 99 | } |
switches | 3:cdd88a3d3d24 | 100 | |
switches | 3:cdd88a3d3d24 | 101 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 102 | int MAX14690::boostSetMode(boostEn_t mode) |
switches | 3:cdd88a3d3d24 | 103 | { |
switches | 3:cdd88a3d3d24 | 104 | char data; |
jessexm | 8:2c3f2da51c5d | 105 | |
switches | 3:cdd88a3d3d24 | 106 | boostEn = mode; |
switches | 3:cdd88a3d3d24 | 107 | data = (boostEn << 3) | (boostEMI << 1) | (boostInd); |
jessexm | 8:2c3f2da51c5d | 108 | return writeReg(REG_BOOST_CFG, data); |
jbradshaw | 0:0e40db4a2b3e | 109 | } |
jbradshaw | 0:0e40db4a2b3e | 110 | |
jbradshaw | 0:0e40db4a2b3e | 111 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 112 | int MAX14690::boostSetVoltage(int mV) |
switches | 3:cdd88a3d3d24 | 113 | { |
switches | 3:cdd88a3d3d24 | 114 | char data; |
jessexm | 8:2c3f2da51c5d | 115 | |
switches | 9:8fb54367ceb5 | 116 | if ((MAX14690_BOOST_MIN_MV <= mV) && (mV <= MAX14690_BOOST_MAX_MV)) { |
switches | 3:cdd88a3d3d24 | 117 | boostMillivolts = mV; |
switches | 9:8fb54367ceb5 | 118 | data = (mV - MAX14690_BOOST_MIN_MV) / MAX14690_BOOST_STEP_MV; |
switches | 3:cdd88a3d3d24 | 119 | } else { |
switches | 9:8fb54367ceb5 | 120 | return MAX14690_ERROR; |
switches | 3:cdd88a3d3d24 | 121 | } |
jessexm | 8:2c3f2da51c5d | 122 | |
switches | 3:cdd88a3d3d24 | 123 | if (boostEn == BOOST_ENABLED) { |
switches | 9:8fb54367ceb5 | 124 | if (writeReg(REG_BOOST_CFG, 0x00) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 125 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 126 | } |
switches | 3:cdd88a3d3d24 | 127 | } |
jessexm | 8:2c3f2da51c5d | 128 | |
switches | 9:8fb54367ceb5 | 129 | if (writeReg(REG_BOOST_VSET, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 130 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 131 | } |
jessexm | 8:2c3f2da51c5d | 132 | |
switches | 3:cdd88a3d3d24 | 133 | if (boostEn == BOOST_ENABLED) { |
switches | 3:cdd88a3d3d24 | 134 | data = (boostEn << 3) | (boostEMI << 1) | (boostInd); |
switches | 9:8fb54367ceb5 | 135 | if (writeReg(REG_BOOST_CFG, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 136 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 137 | } |
switches | 3:cdd88a3d3d24 | 138 | } |
jessexm | 8:2c3f2da51c5d | 139 | |
switches | 9:8fb54367ceb5 | 140 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 141 | } |
jbradshaw | 0:0e40db4a2b3e | 142 | |
jbradshaw | 0:0e40db4a2b3e | 143 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 144 | int MAX14690::init() |
switches | 3:cdd88a3d3d24 | 145 | { |
switches | 3:cdd88a3d3d24 | 146 | char data; |
jessexm | 8:2c3f2da51c5d | 147 | |
switches | 3:cdd88a3d3d24 | 148 | data = (clkDivEn << 7) | (clkDivSet); |
switches | 9:8fb54367ceb5 | 149 | if (writeReg(REG_BOOST_CDIV, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 150 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 151 | } |
jessexm | 8:2c3f2da51c5d | 152 | |
switches | 3:cdd88a3d3d24 | 153 | data = (boostISet); |
switches | 9:8fb54367ceb5 | 154 | if (writeReg(REG_BOOST_ISET, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 155 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 156 | } |
jessexm | 8:2c3f2da51c5d | 157 | |
switches | 9:8fb54367ceb5 | 158 | if ((MAX14690_BOOST_MIN_MV <= boostMillivolts) && |
switches | 9:8fb54367ceb5 | 159 | (boostMillivolts <= MAX14690_BOOST_MAX_MV)) { |
switches | 9:8fb54367ceb5 | 160 | data = (boostMillivolts - MAX14690_BOOST_MIN_MV) / MAX14690_BOOST_STEP_MV; |
switches | 9:8fb54367ceb5 | 161 | if (writeReg(REG_BOOST_VSET, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 162 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 163 | } |
switches | 3:cdd88a3d3d24 | 164 | } else { |
switches | 9:8fb54367ceb5 | 165 | return MAX14690_ERROR; |
switches | 3:cdd88a3d3d24 | 166 | } |
jessexm | 8:2c3f2da51c5d | 167 | |
switches | 3:cdd88a3d3d24 | 168 | data = (buckMd << 1) | (buckFst); |
switches | 9:8fb54367ceb5 | 169 | if (writeReg(REG_BUCK_CFG, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 170 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 171 | } |
jessexm | 8:2c3f2da51c5d | 172 | |
jessexm | 8:2c3f2da51c5d | 173 | data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) | |
jessexm | 8:2c3f2da51c5d | 174 | (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl); |
switches | 9:8fb54367ceb5 | 175 | if (writeReg(REG_BBB_EXTRA, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 176 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 177 | } |
jessexm | 8:2c3f2da51c5d | 178 | |
switches | 3:cdd88a3d3d24 | 179 | // Write Boost Enable Register Last |
switches | 3:cdd88a3d3d24 | 180 | data = (boostEn << 3) | (boostEMI << 1) | (boostInd); |
switches | 9:8fb54367ceb5 | 181 | if (writeReg(REG_BOOST_CFG, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 182 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 183 | } |
jessexm | 8:2c3f2da51c5d | 184 | |
switches | 9:8fb54367ceb5 | 185 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 186 | } |
jbradshaw | 0:0e40db4a2b3e | 187 | |
jbradshaw | 0:0e40db4a2b3e | 188 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 189 | int MAX14690::monSet(monCfg_t monCfg) |
switches | 3:cdd88a3d3d24 | 190 | { |
jessexm | 8:2c3f2da51c5d | 191 | return writeReg(REG_MON_CFG, monCfg); |
jbradshaw | 0:0e40db4a2b3e | 192 | } |
jbradshaw | 0:0e40db4a2b3e | 193 | |
jbradshaw | 0:0e40db4a2b3e | 194 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 195 | int MAX14690::shutdown() |
switches | 3:cdd88a3d3d24 | 196 | { |
jessexm | 8:2c3f2da51c5d | 197 | return writeReg(REG_PWR_OFF, 0xB2); |
jbradshaw | 0:0e40db4a2b3e | 198 | } |
jbradshaw | 0:0e40db4a2b3e | 199 | |
switches | 3:cdd88a3d3d24 | 200 | |
jbradshaw | 0:0e40db4a2b3e | 201 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 202 | int MAX14690::writeReg(registers_t reg, char value) |
jbradshaw | 0:0e40db4a2b3e | 203 | { |
jbradshaw | 0:0e40db4a2b3e | 204 | char cmdData[2] = { (char)reg, value }; |
jessexm | 8:2c3f2da51c5d | 205 | |
jessexm | 8:2c3f2da51c5d | 206 | if (i2c->write(slaveAddress, cmdData, sizeof(cmdData)) != 0) { |
switches | 9:8fb54367ceb5 | 207 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 208 | } |
jessexm | 8:2c3f2da51c5d | 209 | |
switches | 9:8fb54367ceb5 | 210 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 211 | } |
jbradshaw | 0:0e40db4a2b3e | 212 | |
jbradshaw | 0:0e40db4a2b3e | 213 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 214 | int MAX14690::readReg(registers_t reg, char *value) |
jbradshaw | 0:0e40db4a2b3e | 215 | { |
jbradshaw | 0:0e40db4a2b3e | 216 | char cmdData[1] = { (char)reg }; |
switches | 3:cdd88a3d3d24 | 217 | |
jessexm | 8:2c3f2da51c5d | 218 | if (i2c->write(slaveAddress, cmdData, sizeof(cmdData)) != 0) { |
switches | 9:8fb54367ceb5 | 219 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 220 | } |
jessexm | 8:2c3f2da51c5d | 221 | |
jessexm | 8:2c3f2da51c5d | 222 | if (i2c->read(slaveAddress, value, 1) != 0) { |
switches | 9:8fb54367ceb5 | 223 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 224 | } |
jessexm | 8:2c3f2da51c5d | 225 | |
switches | 9:8fb54367ceb5 | 226 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 227 | } |