![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is a mbed 5.2 Release
Fork of mbed-os-test by
Embed:
(wiki syntax)
Show/hide line numbers
MAX14720.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 00034 #include "MAX14720.h" 00035 00036 //****************************************************************************** 00037 MAX14720::MAX14720(PinName sda, PinName scl, int slaveAddress) : 00038 slaveAddress(slaveAddress) { 00039 i2c = new I2C(sda, scl); 00040 isOwner = true; 00041 clkDivEn = false; 00042 clkDivSet = 0; 00043 boostISet = BOOST_ISET_100mA; 00044 boostMillivolts = 3300; 00045 boostEn = BOOST_DISABLED; 00046 boostEMI = false; 00047 boostInd = false; 00048 boostHysOff = false; 00049 boostPasDsc = false; 00050 boostActDsc = false; 00051 buckMd = BUCK_BURST; 00052 buckFst = false; 00053 buckISet = BUCK_ISET_300mA; 00054 buckCfg = false; 00055 buckInd = false; 00056 buckHysOff = true; 00057 buckMinOT = true; 00058 buckInteg = true; 00059 buckPasDsc = false; 00060 buckActDsc = false; 00061 buckFScl = false; 00062 } 00063 //****************************************************************************** 00064 MAX14720::MAX14720(I2C *i2c, int slaveAddress) : slaveAddress(slaveAddress) { 00065 this->i2c = i2c; 00066 isOwner = false; 00067 clkDivEn = false; 00068 clkDivSet = 0; 00069 boostISet = BOOST_ISET_100mA; 00070 boostMillivolts = 3300; 00071 boostEn = BOOST_DISABLED; 00072 boostEMI = false; 00073 boostInd = false; 00074 boostHysOff = false; 00075 boostPasDsc = false; 00076 boostActDsc = false; 00077 buckMd = BUCK_BURST; 00078 buckFst = false; 00079 buckISet = BUCK_ISET_300mA; 00080 buckCfg = false; 00081 buckInd = false; 00082 buckHysOff = true; 00083 buckMinOT = true; 00084 buckInteg = true; 00085 buckPasDsc = false; 00086 buckActDsc = false; 00087 buckFScl = false; 00088 } 00089 //****************************************************************************** 00090 MAX14720::~MAX14720() { 00091 if (isOwner == true) { 00092 delete i2c; 00093 } 00094 } 00095 00096 //****************************************************************************** 00097 int MAX14720::boostSetMode(boostEn_t mode) { 00098 int result; 00099 char data; 00100 boostEn = mode; 00101 data = (boostEn << 3) | (boostEMI << 1) | (boostInd); 00102 result = writeReg(REG_BOOST_CFG, data); 00103 if (result == MAX14720_ERROR) return result; 00104 return 0; 00105 } 00106 00107 //****************************************************************************** 00108 int MAX14720::boostSetVoltage(int mV) { 00109 int result; 00110 char data; 00111 if ((MAX14720_BOOST_MIN_MV <= mV) && (mV <= MAX14720_BOOST_MAX_MV)) { 00112 boostMillivolts = mV; 00113 data = (mV - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV; 00114 } else { 00115 return MAX14720_ERROR; 00116 } 00117 if (boostEn == BOOST_ENABLED) { 00118 result = writeReg(REG_BOOST_CFG, 0x00); 00119 } 00120 if (result == MAX14720_ERROR) return result; 00121 result = writeReg(REG_BOOST_VSET, data); 00122 if (result == MAX14720_ERROR) return result; 00123 if (boostEn == BOOST_ENABLED) { 00124 data = (boostEn << 3) | (boostEMI << 1) | (boostInd); 00125 result = writeReg(REG_BOOST_CFG, data); 00126 } 00127 if (result == MAX14720_ERROR) return result; 00128 return 0; 00129 } 00130 00131 //****************************************************************************** 00132 int MAX14720::init() { 00133 int result; 00134 char data; 00135 data = (clkDivEn << 7) | (clkDivSet); 00136 result = writeReg(REG_BOOST_CDIV, data); 00137 if (result == MAX14720_ERROR) return result; 00138 data = (boostISet); 00139 result = writeReg(REG_BOOST_ISET, data); 00140 if (result == MAX14720_ERROR)return result; 00141 if ((MAX14720_BOOST_MIN_MV <= boostMillivolts) && 00142 (boostMillivolts <= MAX14720_BOOST_MAX_MV)) { 00143 data = (boostMillivolts - MAX14720_BOOST_MIN_MV) / MAX14720_BOOST_STEP_MV; 00144 } else { 00145 return MAX14720_ERROR; 00146 } 00147 result = writeReg(REG_BOOST_VSET, data); 00148 if (result == MAX14720_ERROR) return result; 00149 data = (buckMd << 1) | (buckFst); 00150 result = writeReg(REG_BUCK_CFG, data); 00151 if (result == MAX14720_ERROR) return result; 00152 data = (boostHysOff << 7) | (boostPasDsc << 6) | (boostActDsc << 5) | 00153 (buckPasDsc << 2) | (buckActDsc << 1) | (buckFScl); 00154 result = writeReg(REG_BBB_EXTRA, data); 00155 if (result == MAX14720_ERROR) return result; 00156 // Write Boost Enable Register Last 00157 data = (boostEn << 3) | (boostEMI << 1) | (boostInd); 00158 result = writeReg(REG_BOOST_CFG, data); 00159 if (result == MAX14720_ERROR) return result; 00160 return 0; 00161 } 00162 00163 //****************************************************************************** 00164 int MAX14720::monSet(monCfg_t monCfg) { 00165 int result; 00166 result = writeReg(REG_MON_CFG, monCfg); 00167 if (result == MAX14720_ERROR) return result; 00168 return 0; 00169 } 00170 00171 //****************************************************************************** 00172 int MAX14720::shutdown() { 00173 int result; 00174 result = writeReg(REG_PWR_OFF, 0xB2); 00175 if (result == MAX14720_ERROR) return result; 00176 return 0; 00177 } 00178 00179 //****************************************************************************** 00180 int MAX14720::writeReg(registers_t reg, char value) { 00181 int result; 00182 char cmdData[2] = {(char)reg, value}; 00183 result = i2c->write(slaveAddress, cmdData, 2); 00184 if (result != 0) return MAX14720_ERROR; 00185 return MAX14720_NO_ERROR; 00186 } 00187 00188 //****************************************************************************** 00189 int MAX14720::readReg(registers_t reg, char *value) { 00190 int result; 00191 char cmdData[1] = {(char)reg}; 00192 00193 result = i2c->write(slaveAddress, cmdData, 1); 00194 if (result != 0) return MAX14720_ERROR; 00195 result = i2c->read(slaveAddress, value, 1); 00196 if (result != 0) return MAX14720_ERROR; 00197 return MAX14720_NO_ERROR; 00198 }
Generated on Wed Jul 13 2022 17:00:35 by
![doxygen](doxygen.png)