Maxim Integrated / MAX77650

Dependents:   MAX32620FTHR_Pmic MAX32620FTHR_Pmic_Boot MAX32620FTHR_GPS_Tracker

Fork of MAX77650 by Jesse Marroquin

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX77650.cpp Source File

MAX77650.cpp

00001 
00002 /*******************************************************************************
00003  * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a
00006  * copy of this software and associated documentation files (the "Software"),
00007  * to deal in the Software without restriction, including without limitation
00008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00009  * and/or sell copies of the Software, and to permit persons to whom the
00010  * Software is furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included
00013  * in all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00019  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00021  * OTHER DEALINGS IN THE SOFTWARE.
00022  *
00023  * Except as contained in this notice, the name of Maxim Integrated
00024  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00025  * Products, Inc. Branding Policy.
00026  *
00027  * The mere transfer of this software does not imply any licenses
00028  * of trade secrets, proprietary technology, copyrights, patents,
00029  * trademarks, maskwork rights, or any other form of intellectual
00030  * property whatsoever. Maxim Integrated Products, Inc. retains all
00031  * ownership rights.
00032  *******************************************************************************
00033  */
00034 
00035 #include "MAX77650.h"
00036 
00037 #define SBB2_TV_MIN_MV 800
00038 #define SBB2_TV_MAX_MV 3950
00039 #define SBB2_TV_LSB_MV 50
00040 
00041 //******************************************************************************
00042 MAX77650::MAX77650(I2C &i2c, PinName pwrHldPin, int addr) :
00043     i2c(i2c)
00044 {
00045     devAddr = addr;
00046     pwrHld = new DigitalOut(pwrHldPin, 1);
00047 }
00048 
00049 //******************************************************************************
00050 MAX77650::~MAX77650()
00051 {
00052     delete pwrHld;
00053 }
00054 
00055 //******************************************************************************
00056 int MAX77650::readReg(reg_t reg, char *val)
00057 {
00058     char wbuf[] = { reg };
00059 
00060     if (!(i2c.write(devAddr, wbuf, sizeof(wbuf), true))) {
00061         if (!(i2c.read(devAddr, val, 1))) {
00062             return MAX77650_NO_ERROR;
00063         }
00064     }
00065 
00066     return MAX77650_ERROR;
00067 }
00068 
00069 //******************************************************************************
00070 int MAX77650::writeReg(reg_t reg, char val)
00071 {
00072     char wbuf[] = { reg, val };
00073 
00074     if (!(i2c.write(devAddr, wbuf, sizeof(wbuf)))) {
00075         return MAX77650_NO_ERROR;
00076     }
00077 
00078     return MAX77650_ERROR;
00079 }
00080 
00081 //******************************************************************************
00082 int MAX77650::writeReg(const char *buf, int len)
00083 {
00084     if (!(i2c.write(devAddr, buf, len))) {
00085         return MAX77650_NO_ERROR;
00086     }
00087 
00088     return MAX77650_ERROR;
00089 }
00090 
00091 //******************************************************************************
00092 int MAX77650::cid(void) {
00093     char rbuf[1];
00094 
00095     if (readReg(CID, rbuf)) {
00096         return MAX77650_ERROR;
00097     }
00098 
00099     return *rbuf;
00100 }
00101 
00102 //******************************************************************************
00103 int MAX77650::enableLDO(void)
00104 {
00105     char ade_flag[1];
00106 
00107     if (readReg(CNFG_LDO_B, ade_flag)) {
00108         return MAX77650_ERROR;
00109     }
00110 
00111     *ade_flag &= 0x08;
00112 
00113     return writeReg(CNFG_LDO_B, *ade_flag | 0x06);
00114 }
00115 
00116 //******************************************************************************
00117 int MAX77650::disableLDO(void)
00118 {
00119     char ade_flag[1];
00120 
00121     if (readReg(CNFG_LDO_B, ade_flag)) {
00122         return MAX77650_ERROR;
00123     }
00124 
00125     *ade_flag &= 0x08;
00126 
00127     return writeReg(CNFG_LDO_B, *ade_flag | 0x04);
00128 }
00129 
00130 //******************************************************************************
00131 int MAX77650::setSBB2VoltageMV(uint32_t tv_mv)
00132 {
00133     uint32_t tv_code;
00134     char ip_code[1];
00135 
00136     if ((tv_mv > SBB2_TV_MAX_MV) || (tv_mv < SBB2_TV_MIN_MV) || (tv_mv % SBB2_TV_LSB_MV)) {
00137         return MAX77650_ERROR;
00138     }
00139 
00140     tv_code = (tv_mv - SBB2_TV_MIN_MV) / SBB2_TV_LSB_MV;
00141 
00142     if (readReg(CNFG_SBB2_A, ip_code)) {
00143         return MAX77650_ERROR;
00144     }
00145 
00146     *ip_code &= 0xC0;
00147 
00148     return writeReg(CNFG_SBB2_A, tv_code | *ip_code);
00149 }
00150 
00151 //******************************************************************************
00152 int MAX77650::setSBB2Voltage(float tv_v)
00153 {
00154     return setSBB2VoltageMV(tv_v * 1000);
00155 }
00156 
00157 //******************************************************************************
00158 void MAX77650::assertPowerHold(void)
00159 {
00160     pwrHld->write(1);
00161 }
00162 
00163 //******************************************************************************
00164 void MAX77650::deassertPowerHold(void)
00165 {
00166     pwrHld->write(0);
00167 }