MAX77816 Library. The MAX77816 is a high-current, high-efficiency buck-boost regulator targeting single-cell Li-ion battery powered applications. Please find more detail things on the website: https://www.maximintegrated.com/en/products/power/switching-regulators/MAX77816.html

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max77816.cpp Source File

max77816.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2018 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 "max77816.h"
00034  
00035 /***** Definitions *****/
00036 #define I2C_ADDR            (0x18<<1)
00037  
00038 //******************************************************************************
00039 MAX77816::MAX77816(PinName sda, PinName scl)
00040 {
00041     i2c_ = new I2C(sda, scl);
00042     i2c_owner = true;
00043  
00044     i2c_->frequency(400000);
00045 }
00046  
00047 //******************************************************************************
00048 MAX77816::MAX77816(I2C *i2c) :
00049     i2c_(i2c)
00050 {
00051     i2c_owner = false;
00052 }
00053  
00054 //******************************************************************************
00055 MAX77816::~MAX77816()
00056 {
00057     if(i2c_owner) {
00058         delete i2c_;
00059     }
00060 }
00061  
00062 //******************************************************************************
00063 int32_t MAX77816::init()
00064 { 
00065     return 0;
00066 }
00067  
00068 //******************************************************************************
00069 int32_t MAX77816::writeReg(MAX77816::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 MAX77816::readReg(MAX77816::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 
00101 //*****************************************************************************
00102 int32_t MAX77816::readBlock(MAX77816::registers_t startReg, MAX77816::registers_t stopReg, uint8_t *data)
00103 {
00104     int32_t rtnVal = -1;
00105     int32_t numBytes = ((stopReg - startReg) + 1);
00106     char packet[] = {static_cast<char>(startReg)};
00107     
00108     if(i2c_->write(I2C_ADDR, packet, 1) == 0)
00109     {
00110         rtnVal = i2c_->read(I2C_ADDR | 0x01, reinterpret_cast<char *>(data), numBytes);
00111     }
00112     
00113     return rtnVal;
00114 }
00115 
00116 
00117 //*****************************************************************************
00118 int32_t MAX77816::writeBlock(MAX77816::registers_t startReg, MAX77816::registers_t stopReg, const uint8_t *data)
00119 {
00120     int32_t numBytes = ((stopReg - startReg) + 1);
00121     char packet[numBytes + 1];
00122     
00123     packet[0] = static_cast<char>(startReg);
00124     
00125     memcpy(packet + 1, data, numBytes);
00126     
00127     return i2c_->write(I2C_ADDR, packet, sizeof(packet));
00128 }
00129 
00130 
00131 //*****************************************************************************
00132 int32_t MAX77816::getVersion()
00133 {
00134     int32_t rData;
00135     
00136     rData = readReg(REG_0);
00137     if(rData< 0)
00138         return rData;
00139         
00140     return ((rData >> 4) & 0x7);
00141 }
00142 
00143 
00144 //*****************************************************************************
00145 int32_t MAX77816::getChipRevision()
00146 {
00147     int32_t rData;
00148     
00149     rData = readReg(REG_0);
00150     if(rData< 0)
00151         return rData;
00152         
00153     return ((rData >> 0) & 0xf);
00154 }
00155 
00156 //*****************************************************************************
00157 int32_t MAX77816::getStatus()
00158 {
00159     int32_t rData;
00160     
00161     rData = readReg(REG_1);
00162     if(rData< 0)
00163         return rData;
00164         
00165     return ((rData >> 0) & 0xf);
00166 }
00167 
00168 //*****************************************************************************
00169 int32_t MAX77816::setVout(uint8_t reg_data)
00170 {
00171     int32_t rData;
00172     
00173     rData = writeReg(REG_4, (reg_data & 0x7f));
00174     return rData;
00175 }
00176 
00177 //*****************************************************************************
00178 int32_t MAX77816::setVoutH(uint8_t reg_data)
00179 {
00180     int32_t rData;
00181     
00182     rData = writeReg(REG_5, (reg_data & 0x7f));
00183     return rData;
00184 }
00185 
00186 //*****************************************************************************
00187 int32_t MAX77816::setIntMask(uint8_t reg_data)
00188 {
00189     int32_t rData;
00190     
00191     rData = writeReg(REG_6, (reg_data & 0x7f));
00192     return rData;
00193 }
00194 
00195 int32_t MAX77816::setIntMask()
00196 {
00197     int32_t rData;
00198     
00199     rData = readReg(REG_6);
00200     if(rData< 0)
00201         return rData;
00202         
00203     return ((rData >> 0) & 0xf);
00204 }
00205 //*****************************************************************************
00206 int32_t MAX77816::getInt()
00207 {
00208     int32_t rData;
00209     
00210     rData = readReg(REG_7);
00211     if(rData< 0)
00212         return rData;
00213         
00214     return ((rData >> 0) & 0xf);
00215 }