MAX14690 Library

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld max32630fthr max4146x_comp ... more

Fork of MAX14690 by Greg Steiert

MAX14720.h

Committer:
switches
Date:
2016-10-04
Revision:
3:cdd88a3d3d24
Parent:
2:5bcfe7e294b6
Child:
4:2e4837c3b6e1

File content as of revision 3:cdd88a3d3d24:

/*******************************************************************************
 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated
 * Products, Inc. shall not be used except as stated in the Maxim Integrated
 * Products, Inc. Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products, Inc. retains all
 * ownership rights.
 *******************************************************************************
 */

#ifndef _MAX14720_H_
#define _MAX14720_H_

#include "mbed.h"

/**
 * Example for the MAX14720 PMIC Driver
 *
 * @code
 * #include <stdio.h>
 * #include "mbed.h"
 * #include "MAX14720.h"
 *
 *  // I2C Master 2
 * I2C i2c2(I2C2_SDA, I2C2_SCL);
 *
 * #define  I2C_ADDR_PMIC   (0x54)                 
 * MAX14720 max14720(&i2c2,I2C_ADDR_PMIC);
 *
 * int main(void) {
 *     int result;
 * 
 *	   // initialize BoostVSet on the MAX14720 PMIC to 4.5 Volts
 *     printf("Init MAX14720\n");
 *     result = max14720.boostEn(MAX14720::BoostEn_Disable);
 *     if (result == MAX14720_ERROR) printf("Error communicating with MAX14720");
 *     result = max14720.boostVSet(MAX14720::BoostVSet_45);
 *     if (result == MAX14720_ERROR) printf("Error communicating with MAX14720");
 *     result = max14720.boostEn(MAX14720::BoostEn_Enable);
 *     if (result == MAX14720_ERROR) printf("Error communicating with MAX14720");
 * 
 *	   while (1) {
 *     }
 * }
 * @endcode
 */

#define MAX14720_NO_ERROR   0
#define MAX14720_ERROR      -1

#define MAX14720_BOOST_MIN_MV 2500
#define MAX14720_BOOST_MAX_MV 5000
#define MAX14720_BOOST_STEP_MV 100

class MAX14720
{
public:
    typedef enum {  // I2C Register Addresses
        REG_CHIP_ID = 0x00,
        REG_CHIP_REV = 0x01,
        REG_BOOST_CDIV = 0x03,
        REG_BOOST_ISET = 0x04,
        REG_BOOST_VSET = 0x05,
        REG_BOOST_CFG = 0x06,
        REG_BUCK_VSET = 0x07,
        REG_BUCK_CFG = 0x08,
        REG_BUCK_ISET = 0x09,
        REG_LDO_VSET = 0x0A,
        REG_LDO_CFG = 0x0B,
        REG_SWITCH_CFG = 0x0C,
        REG_BAT_TIME = 0x0D,
        REG_BAT_CFG = 0x0E,
        REG_BAT_BCV = 0x0F,
        REG_BAT_OCV = 0x10,
        REG_BAT_LCV = 0x11,
        REG_MON_CFG = 0x19,
        REG_BOOT_CFG = 0x1A,
        REG_PIN_STAT = 0x1B,
        REG_BBB_EXTRA = 0x1C,
        REG_HANDSHK = 0x1D,
        REG_UVLO_CFG = 0x1E,
        REG_PWR_OFF = 0x1F,
        REG_OTP_MAP_0 = 0x20,
        REG_OTP_MAP_1 = 0x21,
        REG_OTP_MAP_2 = 0x22,
        REG_OTP_MAP_3 = 0x23,
        REG_OTP_MAP_4 = 0x24,
        REG_OTP_MAP_5 = 0x25,
        REG_OTP_MAP_6 = 0x26,
        REG_OTP_MAP_7 = 0x27,
        REG_OTP_MAP_8 = 0x28,
        REG_OTP_MAP_9 = 0x29,
        REG_OTP_MAP_A = 0x2A,
        REG_OTP_MAP_B = 0x2B,
    } registers_t;

	typedef enum  {
		BOOST_ISET_MIN,
		BOOST_ISET_50mA,
		BOOST_ISET_100mA,
		BOOST_ISET_150mA,
		BOOST_ISET_200mA,
		BOOST_ISET_250mA,
		BOOST_ISET_300mA,
		BOOST_ISET_350mA,
	} boostISet_t;

	typedef enum {
		BOOST_DISABLED,
		BOOST_ENABLED,
		BOOST_EN_MPC,
	} boostEn_t;
	
	typedef enum {
		BUCK_BURST,
		BUCK_FPWM,
		BUCK_MPC_FPWM,
	} buckMd_t;

	typedef enum  {
		BUCK_ISET_50mA,
		BUCK_ISET_100mA,
		BUCK_ISET_150mA,
		BUCK_ISET_200mA,
		BUCK_ISET_250mA,
		BUCK_ISET_300mA,
		BUCK_ISET_350mA,
		BUCK_ISET_400mA,
	} buckISet_t;

	typedef enum {
        MON_PULLDOWN = 0x00,		
        MON_HI_Z = 0x08,
        MON_SWIN = 0x80,
        MON_SWOUT = 0x81,
        MON_BIN = 0x82,
        MON_BOUT = 0x83,
        MON_HVIN = 0x84,
        MON_HVOUT = 0x85,
        MON_LIN = 0x86,
        MON_LOUT = 0x87,        		
	} monCfg_t;

	typedef enum {
		LIN_UVLO,
		BIN_UVLO,			
	} uvloIn_t;

	/**
		* MAX14720 constructor.
		*
		* @param sda mbed pin to use for SDA line of I2C interface.
		* @param scl mbed pin to use for SCL line of I2C interface.
		* @param slaveAddress Slave Address of the device.
		*/
	MAX14720(PinName sda, PinName scl, int slaveAddress);

	/**
		* MAX14720 constructor.
		*
		* @param i2c I2C object to use.
		* @param slaveAddress Slave Address of the device.
		*/
	MAX14720(I2C *i2c, int slaveAddress);

	/**
		* MAX14720 destructor.
		*/
	~MAX14720();

	/** 
	* Initialize MAX14720
	*/
	int init();
	/**
	* Set the Boost Output Voltage from 2.5V to 5V with 100mV increments
	*/
	int boostSetVoltage(int mV);
	/** 
	* Enable or disable Boost
	*/
	int boostSetMode(boostEn_t mode);
	/** 
	* Configure Monitor Multiplexer
	*/
	int monSet(monCfg_t monCfg);
	/** 
	* Turn off all supplies and go to shelf mode
	*/
	int shutdown();

	/**
	* Write a device register
	*/
	int writeReg(registers_t reg, char value);
	/**
	* Read a device register
	*/
	int readReg(registers_t reg, char *value);

	bool clkDivEn;
	int clkDivSet;
	boostISet_t boostISet;
	int boostMillivolts;
	boostEn_t boostEn;
	bool boostEMI, boostInd, boostHysOff, boostPasDsc, boostActDsc;
	buckMd_t buckMd;
	bool buckFst;
	buckISet_t buckISet;
	bool buckCfg, buckInd, buckHysOff, buckMinOT, buckInteg, buckPasDsc, buckActDsc, buckFScl;

private:
	/// I2C pointer
	I2C *i2c;
	/// Is this object the owner of the I2C object
	bool isOwner;
	/// Device slave address
	int slaveAddress;
      
};

#endif /* PMIC_H_ */