Fork of MAX14690 library

Fork of MAX14690 by Greg Steiert

Committer:
switches
Date:
Tue Oct 04 22:26:50 2016 +0000
Revision:
3:cdd88a3d3d24
Parent:
2:5bcfe7e294b6
Child:
4:2e4837c3b6e1
Updated Library for Demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jbradshaw 0:0e40db4a2b3e 1 /*******************************************************************************
jbradshaw 0:0e40db4a2b3e 2 * Copyright (C) 2015 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 3:cdd88a3d3d24 34 #ifndef _MAX14720_H_
switches 3:cdd88a3d3d24 35 #define _MAX14720_H_
jbradshaw 0:0e40db4a2b3e 36
jbradshaw 0:0e40db4a2b3e 37 #include "mbed.h"
jbradshaw 0:0e40db4a2b3e 38
jbradshaw 1:f8919b0c2052 39 /**
jbradshaw 1:f8919b0c2052 40 * Example for the MAX14720 PMIC Driver
jbradshaw 1:f8919b0c2052 41 *
jbradshaw 1:f8919b0c2052 42 * @code
jbradshaw 1:f8919b0c2052 43 * #include <stdio.h>
jbradshaw 1:f8919b0c2052 44 * #include "mbed.h"
jbradshaw 1:f8919b0c2052 45 * #include "MAX14720.h"
jbradshaw 1:f8919b0c2052 46 *
jbradshaw 1:f8919b0c2052 47 * // I2C Master 2
jbradshaw 2:5bcfe7e294b6 48 * I2C i2c2(I2C2_SDA, I2C2_SCL);
jbradshaw 2:5bcfe7e294b6 49 *
jbradshaw 2:5bcfe7e294b6 50 * #define I2C_ADDR_PMIC (0x54)
jbradshaw 2:5bcfe7e294b6 51 * MAX14720 max14720(&i2c2,I2C_ADDR_PMIC);
jbradshaw 1:f8919b0c2052 52 *
jbradshaw 1:f8919b0c2052 53 * int main(void) {
jbradshaw 1:f8919b0c2052 54 * int result;
jbradshaw 1:f8919b0c2052 55 *
jbradshaw 1:f8919b0c2052 56 * // initialize BoostVSet on the MAX14720 PMIC to 4.5 Volts
jbradshaw 1:f8919b0c2052 57 * printf("Init MAX14720\n");
jbradshaw 1:f8919b0c2052 58 * result = max14720.boostEn(MAX14720::BoostEn_Disable);
jbradshaw 1:f8919b0c2052 59 * if (result == MAX14720_ERROR) printf("Error communicating with MAX14720");
jbradshaw 1:f8919b0c2052 60 * result = max14720.boostVSet(MAX14720::BoostVSet_45);
jbradshaw 1:f8919b0c2052 61 * if (result == MAX14720_ERROR) printf("Error communicating with MAX14720");
jbradshaw 1:f8919b0c2052 62 * result = max14720.boostEn(MAX14720::BoostEn_Enable);
jbradshaw 1:f8919b0c2052 63 * if (result == MAX14720_ERROR) printf("Error communicating with MAX14720");
jbradshaw 1:f8919b0c2052 64 *
jbradshaw 1:f8919b0c2052 65 * while (1) {
jbradshaw 1:f8919b0c2052 66 * }
jbradshaw 1:f8919b0c2052 67 * }
jbradshaw 1:f8919b0c2052 68 * @endcode
jbradshaw 1:f8919b0c2052 69 */
jbradshaw 1:f8919b0c2052 70
jbradshaw 0:0e40db4a2b3e 71 #define MAX14720_NO_ERROR 0
jbradshaw 0:0e40db4a2b3e 72 #define MAX14720_ERROR -1
jbradshaw 0:0e40db4a2b3e 73
switches 3:cdd88a3d3d24 74 #define MAX14720_BOOST_MIN_MV 2500
switches 3:cdd88a3d3d24 75 #define MAX14720_BOOST_MAX_MV 5000
switches 3:cdd88a3d3d24 76 #define MAX14720_BOOST_STEP_MV 100
switches 3:cdd88a3d3d24 77
jbradshaw 0:0e40db4a2b3e 78 class MAX14720
jbradshaw 0:0e40db4a2b3e 79 {
jbradshaw 0:0e40db4a2b3e 80 public:
jbradshaw 0:0e40db4a2b3e 81 typedef enum { // I2C Register Addresses
switches 3:cdd88a3d3d24 82 REG_CHIP_ID = 0x00,
switches 3:cdd88a3d3d24 83 REG_CHIP_REV = 0x01,
switches 3:cdd88a3d3d24 84 REG_BOOST_CDIV = 0x03,
switches 3:cdd88a3d3d24 85 REG_BOOST_ISET = 0x04,
switches 3:cdd88a3d3d24 86 REG_BOOST_VSET = 0x05,
switches 3:cdd88a3d3d24 87 REG_BOOST_CFG = 0x06,
switches 3:cdd88a3d3d24 88 REG_BUCK_VSET = 0x07,
switches 3:cdd88a3d3d24 89 REG_BUCK_CFG = 0x08,
switches 3:cdd88a3d3d24 90 REG_BUCK_ISET = 0x09,
switches 3:cdd88a3d3d24 91 REG_LDO_VSET = 0x0A,
switches 3:cdd88a3d3d24 92 REG_LDO_CFG = 0x0B,
switches 3:cdd88a3d3d24 93 REG_SWITCH_CFG = 0x0C,
switches 3:cdd88a3d3d24 94 REG_BAT_TIME = 0x0D,
switches 3:cdd88a3d3d24 95 REG_BAT_CFG = 0x0E,
switches 3:cdd88a3d3d24 96 REG_BAT_BCV = 0x0F,
switches 3:cdd88a3d3d24 97 REG_BAT_OCV = 0x10,
switches 3:cdd88a3d3d24 98 REG_BAT_LCV = 0x11,
switches 3:cdd88a3d3d24 99 REG_MON_CFG = 0x19,
switches 3:cdd88a3d3d24 100 REG_BOOT_CFG = 0x1A,
switches 3:cdd88a3d3d24 101 REG_PIN_STAT = 0x1B,
switches 3:cdd88a3d3d24 102 REG_BBB_EXTRA = 0x1C,
switches 3:cdd88a3d3d24 103 REG_HANDSHK = 0x1D,
switches 3:cdd88a3d3d24 104 REG_UVLO_CFG = 0x1E,
switches 3:cdd88a3d3d24 105 REG_PWR_OFF = 0x1F,
switches 3:cdd88a3d3d24 106 REG_OTP_MAP_0 = 0x20,
switches 3:cdd88a3d3d24 107 REG_OTP_MAP_1 = 0x21,
switches 3:cdd88a3d3d24 108 REG_OTP_MAP_2 = 0x22,
switches 3:cdd88a3d3d24 109 REG_OTP_MAP_3 = 0x23,
switches 3:cdd88a3d3d24 110 REG_OTP_MAP_4 = 0x24,
switches 3:cdd88a3d3d24 111 REG_OTP_MAP_5 = 0x25,
switches 3:cdd88a3d3d24 112 REG_OTP_MAP_6 = 0x26,
switches 3:cdd88a3d3d24 113 REG_OTP_MAP_7 = 0x27,
switches 3:cdd88a3d3d24 114 REG_OTP_MAP_8 = 0x28,
switches 3:cdd88a3d3d24 115 REG_OTP_MAP_9 = 0x29,
switches 3:cdd88a3d3d24 116 REG_OTP_MAP_A = 0x2A,
switches 3:cdd88a3d3d24 117 REG_OTP_MAP_B = 0x2B,
switches 3:cdd88a3d3d24 118 } registers_t;
jbradshaw 0:0e40db4a2b3e 119
jbradshaw 0:0e40db4a2b3e 120 typedef enum {
switches 3:cdd88a3d3d24 121 BOOST_ISET_MIN,
switches 3:cdd88a3d3d24 122 BOOST_ISET_50mA,
switches 3:cdd88a3d3d24 123 BOOST_ISET_100mA,
switches 3:cdd88a3d3d24 124 BOOST_ISET_150mA,
switches 3:cdd88a3d3d24 125 BOOST_ISET_200mA,
switches 3:cdd88a3d3d24 126 BOOST_ISET_250mA,
switches 3:cdd88a3d3d24 127 BOOST_ISET_300mA,
switches 3:cdd88a3d3d24 128 BOOST_ISET_350mA,
switches 3:cdd88a3d3d24 129 } boostISet_t;
jbradshaw 0:0e40db4a2b3e 130
jbradshaw 0:0e40db4a2b3e 131 typedef enum {
switches 3:cdd88a3d3d24 132 BOOST_DISABLED,
switches 3:cdd88a3d3d24 133 BOOST_ENABLED,
switches 3:cdd88a3d3d24 134 BOOST_EN_MPC,
switches 3:cdd88a3d3d24 135 } boostEn_t;
switches 3:cdd88a3d3d24 136
switches 3:cdd88a3d3d24 137 typedef enum {
switches 3:cdd88a3d3d24 138 BUCK_BURST,
switches 3:cdd88a3d3d24 139 BUCK_FPWM,
switches 3:cdd88a3d3d24 140 BUCK_MPC_FPWM,
switches 3:cdd88a3d3d24 141 } buckMd_t;
jbradshaw 0:0e40db4a2b3e 142
jbradshaw 0:0e40db4a2b3e 143 typedef enum {
switches 3:cdd88a3d3d24 144 BUCK_ISET_50mA,
switches 3:cdd88a3d3d24 145 BUCK_ISET_100mA,
switches 3:cdd88a3d3d24 146 BUCK_ISET_150mA,
switches 3:cdd88a3d3d24 147 BUCK_ISET_200mA,
switches 3:cdd88a3d3d24 148 BUCK_ISET_250mA,
switches 3:cdd88a3d3d24 149 BUCK_ISET_300mA,
switches 3:cdd88a3d3d24 150 BUCK_ISET_350mA,
switches 3:cdd88a3d3d24 151 BUCK_ISET_400mA,
switches 3:cdd88a3d3d24 152 } buckISet_t;
jbradshaw 0:0e40db4a2b3e 153
jbradshaw 0:0e40db4a2b3e 154 typedef enum {
switches 3:cdd88a3d3d24 155 MON_PULLDOWN = 0x00,
switches 3:cdd88a3d3d24 156 MON_HI_Z = 0x08,
switches 3:cdd88a3d3d24 157 MON_SWIN = 0x80,
switches 3:cdd88a3d3d24 158 MON_SWOUT = 0x81,
switches 3:cdd88a3d3d24 159 MON_BIN = 0x82,
switches 3:cdd88a3d3d24 160 MON_BOUT = 0x83,
switches 3:cdd88a3d3d24 161 MON_HVIN = 0x84,
switches 3:cdd88a3d3d24 162 MON_HVOUT = 0x85,
switches 3:cdd88a3d3d24 163 MON_LIN = 0x86,
switches 3:cdd88a3d3d24 164 MON_LOUT = 0x87,
switches 3:cdd88a3d3d24 165 } monCfg_t;
jbradshaw 0:0e40db4a2b3e 166
jbradshaw 0:0e40db4a2b3e 167 typedef enum {
switches 3:cdd88a3d3d24 168 LIN_UVLO,
switches 3:cdd88a3d3d24 169 BIN_UVLO,
switches 3:cdd88a3d3d24 170 } uvloIn_t;
jbradshaw 0:0e40db4a2b3e 171
jbradshaw 0:0e40db4a2b3e 172 /**
jbradshaw 0:0e40db4a2b3e 173 * MAX14720 constructor.
jbradshaw 0:0e40db4a2b3e 174 *
jbradshaw 0:0e40db4a2b3e 175 * @param sda mbed pin to use for SDA line of I2C interface.
jbradshaw 0:0e40db4a2b3e 176 * @param scl mbed pin to use for SCL line of I2C interface.
jbradshaw 0:0e40db4a2b3e 177 * @param slaveAddress Slave Address of the device.
jbradshaw 0:0e40db4a2b3e 178 */
jbradshaw 0:0e40db4a2b3e 179 MAX14720(PinName sda, PinName scl, int slaveAddress);
jbradshaw 0:0e40db4a2b3e 180
jbradshaw 0:0e40db4a2b3e 181 /**
jbradshaw 0:0e40db4a2b3e 182 * MAX14720 constructor.
jbradshaw 0:0e40db4a2b3e 183 *
jbradshaw 0:0e40db4a2b3e 184 * @param i2c I2C object to use.
jbradshaw 0:0e40db4a2b3e 185 * @param slaveAddress Slave Address of the device.
jbradshaw 0:0e40db4a2b3e 186 */
jbradshaw 0:0e40db4a2b3e 187 MAX14720(I2C *i2c, int slaveAddress);
jbradshaw 0:0e40db4a2b3e 188
jbradshaw 0:0e40db4a2b3e 189 /**
jbradshaw 0:0e40db4a2b3e 190 * MAX14720 destructor.
jbradshaw 0:0e40db4a2b3e 191 */
jbradshaw 0:0e40db4a2b3e 192 ~MAX14720();
jbradshaw 0:0e40db4a2b3e 193
jbradshaw 0:0e40db4a2b3e 194 /**
switches 3:cdd88a3d3d24 195 * Initialize MAX14720
jbradshaw 0:0e40db4a2b3e 196 */
switches 3:cdd88a3d3d24 197 int init();
jbradshaw 0:0e40db4a2b3e 198 /**
jbradshaw 0:0e40db4a2b3e 199 * Set the Boost Output Voltage from 2.5V to 5V with 100mV increments
jbradshaw 0:0e40db4a2b3e 200 */
switches 3:cdd88a3d3d24 201 int boostSetVoltage(int mV);
switches 3:cdd88a3d3d24 202 /**
switches 3:cdd88a3d3d24 203 * Enable or disable Boost
jbradshaw 0:0e40db4a2b3e 204 */
switches 3:cdd88a3d3d24 205 int boostSetMode(boostEn_t mode);
switches 3:cdd88a3d3d24 206 /**
switches 3:cdd88a3d3d24 207 * Configure Monitor Multiplexer
jbradshaw 0:0e40db4a2b3e 208 */
switches 3:cdd88a3d3d24 209 int monSet(monCfg_t monCfg);
switches 3:cdd88a3d3d24 210 /**
switches 3:cdd88a3d3d24 211 * Turn off all supplies and go to shelf mode
jbradshaw 0:0e40db4a2b3e 212 */
switches 3:cdd88a3d3d24 213 int shutdown();
jbradshaw 0:0e40db4a2b3e 214
jbradshaw 0:0e40db4a2b3e 215 /**
jbradshaw 0:0e40db4a2b3e 216 * Write a device register
jbradshaw 0:0e40db4a2b3e 217 */
switches 3:cdd88a3d3d24 218 int writeReg(registers_t reg, char value);
jbradshaw 0:0e40db4a2b3e 219 /**
jbradshaw 0:0e40db4a2b3e 220 * Read a device register
jbradshaw 0:0e40db4a2b3e 221 */
switches 3:cdd88a3d3d24 222 int readReg(registers_t reg, char *value);
switches 3:cdd88a3d3d24 223
switches 3:cdd88a3d3d24 224 bool clkDivEn;
switches 3:cdd88a3d3d24 225 int clkDivSet;
switches 3:cdd88a3d3d24 226 boostISet_t boostISet;
switches 3:cdd88a3d3d24 227 int boostMillivolts;
switches 3:cdd88a3d3d24 228 boostEn_t boostEn;
switches 3:cdd88a3d3d24 229 bool boostEMI, boostInd, boostHysOff, boostPasDsc, boostActDsc;
switches 3:cdd88a3d3d24 230 buckMd_t buckMd;
switches 3:cdd88a3d3d24 231 bool buckFst;
switches 3:cdd88a3d3d24 232 buckISet_t buckISet;
switches 3:cdd88a3d3d24 233 bool buckCfg, buckInd, buckHysOff, buckMinOT, buckInteg, buckPasDsc, buckActDsc, buckFScl;
switches 3:cdd88a3d3d24 234
jbradshaw 0:0e40db4a2b3e 235 private:
jbradshaw 0:0e40db4a2b3e 236 /// I2C pointer
jbradshaw 0:0e40db4a2b3e 237 I2C *i2c;
jbradshaw 0:0e40db4a2b3e 238 /// Is this object the owner of the I2C object
jbradshaw 0:0e40db4a2b3e 239 bool isOwner;
jbradshaw 0:0e40db4a2b3e 240 /// Device slave address
jbradshaw 0:0e40db4a2b3e 241 int slaveAddress;
jbradshaw 0:0e40db4a2b3e 242
jbradshaw 0:0e40db4a2b3e 243 };
jbradshaw 0:0e40db4a2b3e 244
jbradshaw 0:0e40db4a2b3e 245 #endif /* PMIC_H_ */