Fork of MAX14690 library
Fork of MAX14690 by
MAX14690.cpp@13:dff55b34fe1f, 2016-12-06 (annotated)
- Committer:
- j3
- Date:
- Tue Dec 06 19:52:05 2016 +0000
- Revision:
- 13:dff55b34fe1f
- Parent:
- 10:32c7e2ab67aa
Added readAllReg member fx
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 | 10:32c7e2ab67aa | 37 | MAX14690::MAX14690(PinName sda, PinName scl) |
jbradshaw | 0:0e40db4a2b3e | 38 | { |
switches | 3:cdd88a3d3d24 | 39 | i2c = new I2C(sda,scl); |
switches | 3:cdd88a3d3d24 | 40 | isOwner = true; |
switches | 10:32c7e2ab67aa | 41 | resetToDefaults(); |
jbradshaw | 0:0e40db4a2b3e | 42 | } |
jbradshaw | 0:0e40db4a2b3e | 43 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 44 | MAX14690::MAX14690(I2C *i2c) |
jbradshaw | 0:0e40db4a2b3e | 45 | { |
switches | 3:cdd88a3d3d24 | 46 | this->i2c = i2c; |
switches | 3:cdd88a3d3d24 | 47 | isOwner = false; |
switches | 10:32c7e2ab67aa | 48 | resetToDefaults(); |
jbradshaw | 0:0e40db4a2b3e | 49 | } |
jessexm | 8:2c3f2da51c5d | 50 | |
jbradshaw | 0:0e40db4a2b3e | 51 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 52 | MAX14690::~MAX14690() |
jbradshaw | 0:0e40db4a2b3e | 53 | { |
switches | 3:cdd88a3d3d24 | 54 | if (isOwner == true) { |
switches | 3:cdd88a3d3d24 | 55 | delete i2c; |
switches | 3:cdd88a3d3d24 | 56 | } |
switches | 3:cdd88a3d3d24 | 57 | } |
switches | 3:cdd88a3d3d24 | 58 | |
switches | 3:cdd88a3d3d24 | 59 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 60 | void MAX14690::resetToDefaults() |
switches | 3:cdd88a3d3d24 | 61 | { |
switches | 10:32c7e2ab67aa | 62 | intEnThermStatus = false; |
switches | 10:32c7e2ab67aa | 63 | intEnChgStatus = false; |
switches | 10:32c7e2ab67aa | 64 | intEnILim = false; |
switches | 10:32c7e2ab67aa | 65 | intEnUSBOVP = false; |
switches | 10:32c7e2ab67aa | 66 | intEnUSBOK = false; |
switches | 10:32c7e2ab67aa | 67 | intEnChgThmSD = false; |
switches | 10:32c7e2ab67aa | 68 | intEnThermReg = false; |
switches | 10:32c7e2ab67aa | 69 | intEnChgTimeOut = false; |
switches | 10:32c7e2ab67aa | 70 | intEnThermBuck1 = false; |
switches | 10:32c7e2ab67aa | 71 | intEnThermBuck2 = false; |
switches | 10:32c7e2ab67aa | 72 | intEnThermLDO1 = false; |
switches | 10:32c7e2ab67aa | 73 | intEnThermLDO2 = false; |
switches | 10:32c7e2ab67aa | 74 | intEnThermLDO3 = false; |
switches | 10:32c7e2ab67aa | 75 | iLimCntl = ILIM_500mA; |
switches | 10:32c7e2ab67aa | 76 | chgAutoStp = true; |
switches | 10:32c7e2ab67aa | 77 | chgAutoReSta = true; |
switches | 10:32c7e2ab67aa | 78 | batReChg = BAT_RECHG_120mV; |
switches | 10:32c7e2ab67aa | 79 | batReg = BAT_REG_4200mV; |
switches | 10:32c7e2ab67aa | 80 | chgEn = true; |
switches | 10:32c7e2ab67aa | 81 | vPChg = VPCHG_3000mV; |
switches | 10:32c7e2ab67aa | 82 | iPChg = IPCHG_10; |
switches | 10:32c7e2ab67aa | 83 | chgDone = CHGDONE_10; |
switches | 10:32c7e2ab67aa | 84 | mtChgTmr = MTCHGTMR_0min; |
switches | 10:32c7e2ab67aa | 85 | fChgTmr = FCHGTMR_300min; |
switches | 10:32c7e2ab67aa | 86 | pChgTmr = PCHGTMR_60min; |
switches | 10:32c7e2ab67aa | 87 | buck1Md = BUCK_BURST; |
switches | 10:32c7e2ab67aa | 88 | buck1Ind = 0; |
switches | 10:32c7e2ab67aa | 89 | buck2Md = BUCK_BURST; |
switches | 10:32c7e2ab67aa | 90 | buck2Ind = 0; |
switches | 10:32c7e2ab67aa | 91 | ldo2Mode = LDO_DISABLED; |
switches | 10:32c7e2ab67aa | 92 | ldo2Millivolts = 3200; |
switches | 10:32c7e2ab67aa | 93 | ldo3Mode = LDO_DISABLED; |
switches | 10:32c7e2ab67aa | 94 | ldo3Millivolts = 3000; |
switches | 10:32c7e2ab67aa | 95 | thrmCfg = THRM_ENABLED; |
switches | 10:32c7e2ab67aa | 96 | monRatio = MON_DIV4; |
switches | 10:32c7e2ab67aa | 97 | monCfg = MON_PULLDOWN; |
switches | 10:32c7e2ab67aa | 98 | buck2ActDsc = false; |
switches | 10:32c7e2ab67aa | 99 | buck2FFET = false; |
switches | 10:32c7e2ab67aa | 100 | buck1ActDsc = false; |
switches | 10:32c7e2ab67aa | 101 | buck1FFET = false; |
switches | 10:32c7e2ab67aa | 102 | pfnResEna = true; |
switches | 10:32c7e2ab67aa | 103 | stayOn = true; |
jbradshaw | 0:0e40db4a2b3e | 104 | } |
jbradshaw | 0:0e40db4a2b3e | 105 | |
jbradshaw | 0:0e40db4a2b3e | 106 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 107 | int MAX14690::ldo2SetMode(ldoMode_t mode) |
switches | 3:cdd88a3d3d24 | 108 | { |
switches | 10:32c7e2ab67aa | 109 | ldo2Mode = mode; |
switches | 10:32c7e2ab67aa | 110 | return writeReg(REG_LDO2_CFG, mode); |
switches | 10:32c7e2ab67aa | 111 | } |
switches | 10:32c7e2ab67aa | 112 | |
switches | 10:32c7e2ab67aa | 113 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 114 | int MAX14690::ldo2SetVoltage(int mV) |
switches | 10:32c7e2ab67aa | 115 | { |
switches | 10:32c7e2ab67aa | 116 | int regBits = mv2bits(mV); |
switches | 3:cdd88a3d3d24 | 117 | char data; |
jessexm | 8:2c3f2da51c5d | 118 | |
switches | 10:32c7e2ab67aa | 119 | if (regBits < 0) { |
switches | 10:32c7e2ab67aa | 120 | return MAX14690_ERROR; |
switches | 3:cdd88a3d3d24 | 121 | } else { |
switches | 10:32c7e2ab67aa | 122 | data = regBits; |
switches | 3:cdd88a3d3d24 | 123 | } |
jessexm | 8:2c3f2da51c5d | 124 | |
switches | 10:32c7e2ab67aa | 125 | if (ldo2Mode == LDO_ENABLED) { |
switches | 10:32c7e2ab67aa | 126 | if (writeReg(REG_LDO2_CFG, LDO_DISABLED) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 127 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 128 | } |
switches | 3:cdd88a3d3d24 | 129 | } |
jessexm | 8:2c3f2da51c5d | 130 | |
switches | 10:32c7e2ab67aa | 131 | if (writeReg(REG_LDO2_VSET, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 132 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 133 | } |
jessexm | 8:2c3f2da51c5d | 134 | |
switches | 10:32c7e2ab67aa | 135 | if (ldo2Mode == LDO_ENABLED) { |
switches | 10:32c7e2ab67aa | 136 | if (writeReg(REG_LDO2_CFG, LDO_ENABLED) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 137 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 138 | } |
switches | 10:32c7e2ab67aa | 139 | } |
switches | 10:32c7e2ab67aa | 140 | |
switches | 10:32c7e2ab67aa | 141 | return MAX14690_NO_ERROR; |
switches | 10:32c7e2ab67aa | 142 | } |
switches | 10:32c7e2ab67aa | 143 | |
switches | 10:32c7e2ab67aa | 144 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 145 | int MAX14690::ldo3SetMode(ldoMode_t mode) |
switches | 10:32c7e2ab67aa | 146 | { |
switches | 10:32c7e2ab67aa | 147 | ldo3Mode = mode; |
switches | 10:32c7e2ab67aa | 148 | return writeReg(REG_LDO3_CFG, mode); |
switches | 10:32c7e2ab67aa | 149 | } |
switches | 10:32c7e2ab67aa | 150 | |
switches | 10:32c7e2ab67aa | 151 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 152 | int MAX14690::ldo3SetVoltage(int mV) |
switches | 10:32c7e2ab67aa | 153 | { |
switches | 10:32c7e2ab67aa | 154 | int regBits = mv2bits(mV); |
switches | 10:32c7e2ab67aa | 155 | char data; |
switches | 10:32c7e2ab67aa | 156 | |
switches | 10:32c7e2ab67aa | 157 | if (regBits < 0) { |
switches | 10:32c7e2ab67aa | 158 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 159 | } else { |
switches | 10:32c7e2ab67aa | 160 | data = regBits; |
switches | 10:32c7e2ab67aa | 161 | } |
switches | 10:32c7e2ab67aa | 162 | |
switches | 10:32c7e2ab67aa | 163 | if (ldo3Mode == LDO_ENABLED) { |
switches | 10:32c7e2ab67aa | 164 | if (writeReg(REG_LDO3_CFG, LDO_DISABLED) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 165 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 166 | } |
switches | 10:32c7e2ab67aa | 167 | } |
switches | 10:32c7e2ab67aa | 168 | |
switches | 10:32c7e2ab67aa | 169 | if (writeReg(REG_LDO3_VSET, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 170 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 171 | } |
switches | 10:32c7e2ab67aa | 172 | |
switches | 10:32c7e2ab67aa | 173 | if (ldo3Mode == LDO_ENABLED) { |
switches | 10:32c7e2ab67aa | 174 | if (writeReg(REG_LDO3_CFG, LDO_ENABLED) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 175 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 176 | } |
switches | 3:cdd88a3d3d24 | 177 | } |
jessexm | 8:2c3f2da51c5d | 178 | |
switches | 9:8fb54367ceb5 | 179 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 180 | } |
jbradshaw | 0:0e40db4a2b3e | 181 | |
jbradshaw | 0:0e40db4a2b3e | 182 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 183 | int MAX14690::init() |
switches | 3:cdd88a3d3d24 | 184 | { |
switches | 10:32c7e2ab67aa | 185 | int regBits; |
switches | 3:cdd88a3d3d24 | 186 | char data; |
jessexm | 8:2c3f2da51c5d | 187 | |
switches | 10:32c7e2ab67aa | 188 | // Configure buck regulators |
switches | 10:32c7e2ab67aa | 189 | data = (buck1Md << 1) | |
switches | 10:32c7e2ab67aa | 190 | (buck1Ind); |
switches | 10:32c7e2ab67aa | 191 | if (writeReg(REG_BUCK1_CFG, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 192 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 193 | } |
switches | 10:32c7e2ab67aa | 194 | data = (buck2Md << 1) | |
switches | 10:32c7e2ab67aa | 195 | (buck2Ind); |
switches | 10:32c7e2ab67aa | 196 | if (writeReg(REG_BUCK2_CFG, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 197 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 198 | } |
switches | 10:32c7e2ab67aa | 199 | data = (buck2ActDsc << 5) | |
switches | 10:32c7e2ab67aa | 200 | (buck2FFET << 4) | |
switches | 10:32c7e2ab67aa | 201 | (buck1ActDsc << 1) | |
switches | 10:32c7e2ab67aa | 202 | (buck1FFET); |
switches | 10:32c7e2ab67aa | 203 | if (writeReg(REG_BUCK_EXTRA, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 204 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 205 | } |
jessexm | 8:2c3f2da51c5d | 206 | |
switches | 10:32c7e2ab67aa | 207 | // Configure Charger |
switches | 10:32c7e2ab67aa | 208 | data = (iLimCntl); |
switches | 10:32c7e2ab67aa | 209 | if (writeReg(REG_I_LIM_CNTL, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 210 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 211 | } |
switches | 10:32c7e2ab67aa | 212 | data = (vPChg << 4) | |
switches | 10:32c7e2ab67aa | 213 | (iPChg << 2) | |
switches | 10:32c7e2ab67aa | 214 | (chgDone); |
switches | 10:32c7e2ab67aa | 215 | if (writeReg(REG_CHG_CNTL_B, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 216 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 217 | } |
switches | 10:32c7e2ab67aa | 218 | data = (mtChgTmr << 4) | |
switches | 10:32c7e2ab67aa | 219 | (fChgTmr << 2) | |
switches | 10:32c7e2ab67aa | 220 | (pChgTmr); |
switches | 10:32c7e2ab67aa | 221 | if (writeReg(REG_CHG_TMR, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 222 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 223 | } |
switches | 10:32c7e2ab67aa | 224 | data = (thrmCfg); |
switches | 10:32c7e2ab67aa | 225 | if (writeReg(REG_THRM_CFG, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 226 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 227 | } |
switches | 10:32c7e2ab67aa | 228 | // Set enable bit after setting other charger bits |
switches | 10:32c7e2ab67aa | 229 | data = (chgAutoStp << 7) | |
switches | 10:32c7e2ab67aa | 230 | (chgAutoReSta << 6) | |
switches | 10:32c7e2ab67aa | 231 | (batReChg << 4) | |
switches | 10:32c7e2ab67aa | 232 | (batReg << 1) | |
switches | 10:32c7e2ab67aa | 233 | (chgEn); |
switches | 10:32c7e2ab67aa | 234 | if (writeReg(REG_CHG_CNTL_A, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 235 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 236 | } |
jessexm | 8:2c3f2da51c5d | 237 | |
switches | 10:32c7e2ab67aa | 238 | // Configure monitor multiplexer |
switches | 10:32c7e2ab67aa | 239 | data = (monRatio << 4) | |
switches | 10:32c7e2ab67aa | 240 | (monCfg); |
switches | 10:32c7e2ab67aa | 241 | if (writeReg(REG_MON_CFG, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 242 | return MAX14690_ERROR; |
switches | 3:cdd88a3d3d24 | 243 | } |
jessexm | 8:2c3f2da51c5d | 244 | |
switches | 10:32c7e2ab67aa | 245 | // Configure and enable LDOs |
switches | 10:32c7e2ab67aa | 246 | regBits = mv2bits(ldo2Millivolts); |
switches | 10:32c7e2ab67aa | 247 | if (regBits < 0) { |
switches | 10:32c7e2ab67aa | 248 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 249 | } else { |
switches | 10:32c7e2ab67aa | 250 | data = regBits; |
switches | 10:32c7e2ab67aa | 251 | } |
switches | 10:32c7e2ab67aa | 252 | if (writeReg(REG_LDO2_VSET, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 253 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 254 | } |
switches | 10:32c7e2ab67aa | 255 | data = (ldo2Mode); |
switches | 10:32c7e2ab67aa | 256 | if (writeReg(REG_LDO2_CFG, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 257 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 258 | } |
switches | 10:32c7e2ab67aa | 259 | regBits = mv2bits(ldo3Millivolts); |
switches | 10:32c7e2ab67aa | 260 | if (regBits < 0) { |
switches | 10:32c7e2ab67aa | 261 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 262 | } else { |
switches | 10:32c7e2ab67aa | 263 | data = regBits; |
switches | 10:32c7e2ab67aa | 264 | } |
switches | 10:32c7e2ab67aa | 265 | if (writeReg(REG_LDO3_VSET, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 266 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 267 | } |
switches | 10:32c7e2ab67aa | 268 | data = (ldo3Mode); |
switches | 10:32c7e2ab67aa | 269 | if (writeReg(REG_LDO3_CFG, data) != MAX14690_NO_ERROR) { |
switches | 10:32c7e2ab67aa | 270 | return MAX14690_ERROR; |
switches | 10:32c7e2ab67aa | 271 | } |
switches | 10:32c7e2ab67aa | 272 | |
switches | 10:32c7e2ab67aa | 273 | // Set stayOn bit after other registers to confirm successful boot. |
switches | 10:32c7e2ab67aa | 274 | data = (pfnResEna << 7) | |
switches | 10:32c7e2ab67aa | 275 | (stayOn); |
switches | 10:32c7e2ab67aa | 276 | if (writeReg(REG_PWR_CFG, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 277 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 278 | } |
jessexm | 8:2c3f2da51c5d | 279 | |
switches | 10:32c7e2ab67aa | 280 | // Unmask Interrupts Last |
switches | 10:32c7e2ab67aa | 281 | data = (intEnThermStatus << 7) | |
switches | 10:32c7e2ab67aa | 282 | (intEnChgStatus << 6) | |
switches | 10:32c7e2ab67aa | 283 | (intEnILim << 5) | |
switches | 10:32c7e2ab67aa | 284 | (intEnUSBOVP << 4) | |
switches | 10:32c7e2ab67aa | 285 | (intEnUSBOK << 3) | |
switches | 10:32c7e2ab67aa | 286 | (intEnChgThmSD << 2) | |
switches | 10:32c7e2ab67aa | 287 | (intEnThermReg << 1) | |
switches | 10:32c7e2ab67aa | 288 | (intEnChgTimeOut); |
switches | 10:32c7e2ab67aa | 289 | if (writeReg(REG_INT_MASK_A, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 290 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 291 | } |
switches | 10:32c7e2ab67aa | 292 | data = (intEnThermBuck1 << 4) | |
switches | 10:32c7e2ab67aa | 293 | (intEnThermBuck2 << 3) | |
switches | 10:32c7e2ab67aa | 294 | (intEnThermLDO1 << 2) | |
switches | 10:32c7e2ab67aa | 295 | (intEnThermLDO2 << 1) | |
switches | 10:32c7e2ab67aa | 296 | (intEnThermLDO3); |
switches | 10:32c7e2ab67aa | 297 | if (writeReg(REG_INT_MASK_B, data) != MAX14690_NO_ERROR) { |
switches | 9:8fb54367ceb5 | 298 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 299 | } |
switches | 10:32c7e2ab67aa | 300 | |
switches | 9:8fb54367ceb5 | 301 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 302 | } |
jbradshaw | 0:0e40db4a2b3e | 303 | |
jbradshaw | 0:0e40db4a2b3e | 304 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 305 | int MAX14690::monSet(monCfg_t newMonCfg, monRatio_t newMonRatio) |
switches | 3:cdd88a3d3d24 | 306 | { |
switches | 10:32c7e2ab67aa | 307 | char data = (newMonRatio << 4) | (newMonCfg); |
switches | 10:32c7e2ab67aa | 308 | monCfg = newMonCfg; |
switches | 10:32c7e2ab67aa | 309 | monRatio = newMonRatio; |
switches | 10:32c7e2ab67aa | 310 | return writeReg(REG_MON_CFG, data); |
jbradshaw | 0:0e40db4a2b3e | 311 | } |
jbradshaw | 0:0e40db4a2b3e | 312 | |
jbradshaw | 0:0e40db4a2b3e | 313 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 314 | int MAX14690::shutdown() |
switches | 3:cdd88a3d3d24 | 315 | { |
jessexm | 8:2c3f2da51c5d | 316 | return writeReg(REG_PWR_OFF, 0xB2); |
jbradshaw | 0:0e40db4a2b3e | 317 | } |
jbradshaw | 0:0e40db4a2b3e | 318 | |
switches | 3:cdd88a3d3d24 | 319 | |
jbradshaw | 0:0e40db4a2b3e | 320 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 321 | int MAX14690::writeReg(registers_t reg, char value) |
jbradshaw | 0:0e40db4a2b3e | 322 | { |
jbradshaw | 0:0e40db4a2b3e | 323 | char cmdData[2] = { (char)reg, value }; |
jessexm | 8:2c3f2da51c5d | 324 | |
switches | 10:32c7e2ab67aa | 325 | if (i2c->write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) { |
switches | 9:8fb54367ceb5 | 326 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 327 | } |
jessexm | 8:2c3f2da51c5d | 328 | |
switches | 9:8fb54367ceb5 | 329 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 330 | } |
jbradshaw | 0:0e40db4a2b3e | 331 | |
jbradshaw | 0:0e40db4a2b3e | 332 | //****************************************************************************** |
switches | 9:8fb54367ceb5 | 333 | int MAX14690::readReg(registers_t reg, char *value) |
jbradshaw | 0:0e40db4a2b3e | 334 | { |
jbradshaw | 0:0e40db4a2b3e | 335 | char cmdData[1] = { (char)reg }; |
switches | 3:cdd88a3d3d24 | 336 | |
switches | 10:32c7e2ab67aa | 337 | if (i2c->write(MAX14690_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) { |
switches | 9:8fb54367ceb5 | 338 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 339 | } |
jessexm | 8:2c3f2da51c5d | 340 | |
switches | 10:32c7e2ab67aa | 341 | if (i2c->read(MAX14690_I2C_ADDR, value, 1) != 0) { |
switches | 9:8fb54367ceb5 | 342 | return MAX14690_ERROR; |
jessexm | 8:2c3f2da51c5d | 343 | } |
jessexm | 8:2c3f2da51c5d | 344 | |
switches | 9:8fb54367ceb5 | 345 | return MAX14690_NO_ERROR; |
jbradshaw | 0:0e40db4a2b3e | 346 | } |
switches | 10:32c7e2ab67aa | 347 | |
switches | 10:32c7e2ab67aa | 348 | //****************************************************************************** |
j3 | 13:dff55b34fe1f | 349 | int MAX14690::readAllReg(char *data, size_t len) |
j3 | 13:dff55b34fe1f | 350 | { |
j3 | 13:dff55b34fe1f | 351 | int rtnVal = MAX14690_ERROR; |
j3 | 13:dff55b34fe1f | 352 | char writeData[] = {0}; |
j3 | 13:dff55b34fe1f | 353 | |
j3 | 13:dff55b34fe1f | 354 | if(len >= 32) |
j3 | 13:dff55b34fe1f | 355 | { |
j3 | 13:dff55b34fe1f | 356 | if(i2c->write(MAX14690_I2C_ADDR, writeData, sizeof(writeData)) == 0) |
j3 | 13:dff55b34fe1f | 357 | { |
j3 | 13:dff55b34fe1f | 358 | rtnVal = i2c->read(MAX14690_I2C_ADDR, data, len); |
j3 | 13:dff55b34fe1f | 359 | } |
j3 | 13:dff55b34fe1f | 360 | } |
j3 | 13:dff55b34fe1f | 361 | |
j3 | 13:dff55b34fe1f | 362 | return rtnVal; |
j3 | 13:dff55b34fe1f | 363 | } |
j3 | 13:dff55b34fe1f | 364 | |
j3 | 13:dff55b34fe1f | 365 | //****************************************************************************** |
switches | 10:32c7e2ab67aa | 366 | int MAX14690::mv2bits(int mV) |
switches | 10:32c7e2ab67aa | 367 | { |
switches | 10:32c7e2ab67aa | 368 | int regBits; |
switches | 10:32c7e2ab67aa | 369 | |
switches | 10:32c7e2ab67aa | 370 | if ((MAX14690_LDO_MIN_MV <= mV) && (mV <= MAX14690_LDO_MAX_MV)) { |
switches | 10:32c7e2ab67aa | 371 | regBits = (mV - MAX14690_LDO_MIN_MV) / MAX14690_LDO_STEP_MV; |
switches | 10:32c7e2ab67aa | 372 | } else { |
switches | 10:32c7e2ab67aa | 373 | return -1; |
switches | 10:32c7e2ab67aa | 374 | } |
switches | 10:32c7e2ab67aa | 375 | |
switches | 10:32c7e2ab67aa | 376 | return regBits; |
switches | 10:32c7e2ab67aa | 377 | } |