Library for MAX77756. The MAX77756 is a synchronous 500mA step-down DC-DC converter with integrated dual-input power multiplexer(MUX).
max77756.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2017 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 #include "max77756.h" 00034 00035 /***** Definitions *****/ 00036 #define I2C_ADDR (0x1E<<1) 00037 00038 //****************************************************************************** 00039 MAX77756::MAX77756(PinName sda, PinName scl) 00040 { 00041 i2c_ = new I2C(sda, scl); 00042 i2c_owner = true; 00043 00044 i2c_->frequency(400000); 00045 } 00046 00047 //****************************************************************************** 00048 MAX77756::MAX77756(I2C *i2c) : 00049 i2c_(i2c) 00050 { 00051 i2c_owner = false; 00052 } 00053 00054 //****************************************************************************** 00055 MAX77756::~MAX77756() 00056 { 00057 if(i2c_owner) { 00058 delete i2c_; 00059 } 00060 } 00061 00062 //****************************************************************************** 00063 int32_t MAX77756::init() 00064 { 00065 return 0; 00066 } 00067 00068 //****************************************************************************** 00069 int32_t MAX77756::writeReg(MAX77756::registers_t reg_addr, char reg_data) 00070 { 00071 char data[2]; 00072 00073 data[0] = reg_addr; 00074 data[1] = reg_data; 00075 if (i2c_->write(I2C_ADDR, data, 2) != 0) { 00076 return -1; 00077 } 00078 00079 return 0; 00080 } 00081 00082 //****************************************************************************** 00083 int32_t MAX77756::readReg(MAX77756::registers_t reg_addr) 00084 { 00085 char data; 00086 00087 data = reg_addr; 00088 if (i2c_->write(I2C_ADDR, &data, 1, true) != 0) { 00089 return -1; 00090 } 00091 00092 if (i2c_->read(I2C_ADDR | 0x01, &data, 1) != 0) { 00093 return -1; 00094 } 00095 00096 return (0x0 + data); 00097 } 00098 00099 //****************************************************************************** 00100 int32_t MAX77756::outEnable(MAX77756::Enable_t enable) 00101 { 00102 int32_t data; 00103 00104 data = readReg(REG_CONFIGA); 00105 if (data < 0) { 00106 return -1; 00107 } 00108 00109 data &= (~0x01); 00110 data |= (enable & 0x01); 00111 00112 data = writeReg(REG_CONFIGA, data & 0xff); 00113 if (data < 0) { 00114 return -1; 00115 } 00116 00117 return 0; 00118 } 00119 00120 //****************************************************************************** 00121 int32_t MAX77756::setVout(uint32_t outVoltage) 00122 { 00123 int32_t data; 00124 uint32_t bitVolt; 00125 00126 if (outVoltage < 1500 || outVoltage > 7500) { 00127 return -1; 00128 } 00129 00130 bitVolt = (uint32_t)((outVoltage -1500)/50); 00131 data = writeReg(REG_CONFIGB, bitVolt & 0xff); 00132 if (data < 0) { 00133 return -1; 00134 } 00135 00136 return 0; 00137 } 00138 00139 //****************************************************************************** 00140 int32_t MAX77756::config( MAX77756::SpreadSpectrum_t sspectrum, 00141 MAX77756::SoftStart_t sstart, 00142 MAX77756::PeakCurrent_t ipeak, 00143 MAX77756::EnableLogic_t enlogic) 00144 { 00145 int32_t data; 00146 int32_t config = 0; 00147 00148 data = readReg(REG_CONFIGA); 00149 if (data < 0) { 00150 return -1; 00151 } 00152 00153 data &= (~0xF2); 00154 config = (sspectrum << 7) | (sstart << 6) | (ipeak << 4) | (enlogic <<1); 00155 data |= ( config & 0xF2); 00156 00157 data = writeReg(REG_CONFIGA, data & 0xff); 00158 if (data < 0) { 00159 return -1; 00160 } 00161 00162 return 0; 00163 } 00164 00165
Generated on Tue Jul 26 2022 05:13:05 by 1.7.2