TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
wwwarunraj
Date:
Sun Apr 19 11:19:57 2020 +0000
Revision:
4:291477e8690d
Parent:
1:f60eafbf009a
19/04

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /*******************************************************************************
gmehmet 1:f60eafbf009a 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
gmehmet 1:f60eafbf009a 3 *
gmehmet 1:f60eafbf009a 4 * Permission is hereby granted, free of charge, to any person obtaining a
gmehmet 1:f60eafbf009a 5 * copy of this software and associated documentation files (the "Software"),
gmehmet 1:f60eafbf009a 6 * to deal in the Software without restriction, including without limitation
gmehmet 1:f60eafbf009a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gmehmet 1:f60eafbf009a 8 * and/or sell copies of the Software, and to permit persons to whom the
gmehmet 1:f60eafbf009a 9 * Software is furnished to do so, subject to the following conditions:
gmehmet 1:f60eafbf009a 10 *
gmehmet 1:f60eafbf009a 11 * The above copyright notice and this permission notice shall be included
gmehmet 1:f60eafbf009a 12 * in all copies or substantial portions of the Software.
gmehmet 1:f60eafbf009a 13 *
gmehmet 1:f60eafbf009a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 1:f60eafbf009a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 1:f60eafbf009a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 1:f60eafbf009a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 1:f60eafbf009a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 1:f60eafbf009a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 1:f60eafbf009a 20 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 1:f60eafbf009a 21 *
gmehmet 1:f60eafbf009a 22 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 1:f60eafbf009a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 1:f60eafbf009a 24 * Products, Inc. Branding Policy.
gmehmet 1:f60eafbf009a 25 *
gmehmet 1:f60eafbf009a 26 * The mere transfer of this software does not imply any licenses
gmehmet 1:f60eafbf009a 27 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 1:f60eafbf009a 28 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 1:f60eafbf009a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 1:f60eafbf009a 30 * ownership rights.
gmehmet 1:f60eafbf009a 31 *******************************************************************************
gmehmet 1:f60eafbf009a 32 */
gmehmet 1:f60eafbf009a 33 #ifndef __MAX20303_H_
gmehmet 1:f60eafbf009a 34 #define __MAX20303_H_
gmehmet 1:f60eafbf009a 35
gmehmet 1:f60eafbf009a 36 #include "mbed.h"
gmehmet 1:f60eafbf009a 37
gmehmet 1:f60eafbf009a 38 #define MAX20303_SLAVE_ADDR (0x50 >> 1)
gmehmet 1:f60eafbf009a 39 #define MAX20303_SLAVE_WR_ADDR ((MAX20303_SLAVE_ADDR << 1))
gmehmet 1:f60eafbf009a 40 #define MAX20303_SLAVE_RD_ADDR ((MAX20303_SLAVE_ADDR << 1) | 1)
gmehmet 1:f60eafbf009a 41
gmehmet 1:f60eafbf009a 42
gmehmet 1:f60eafbf009a 43 #define MAX20303_NO_ERROR 0
gmehmet 1:f60eafbf009a 44 #define MAX20303_ERROR -1
gmehmet 1:f60eafbf009a 45
gmehmet 1:f60eafbf009a 46 #define MAX20303_I2C_ADDR_FUEL_GAUGE 0x6C
gmehmet 1:f60eafbf009a 47
gmehmet 1:f60eafbf009a 48 #define MAX20303_LDO_MIN_MV 800
gmehmet 1:f60eafbf009a 49 #define MAX20303_LDO_MAX_MV 3600
gmehmet 1:f60eafbf009a 50 #define MAX20303_LDO_STEP_MV 100
gmehmet 1:f60eafbf009a 51
gmehmet 1:f60eafbf009a 52 #define MAX20303_OFF_COMMAND 0xB2
gmehmet 1:f60eafbf009a 53
gmehmet 1:f60eafbf009a 54 class MAX20303
gmehmet 1:f60eafbf009a 55 {
gmehmet 1:f60eafbf009a 56
gmehmet 1:f60eafbf009a 57 public:
gmehmet 1:f60eafbf009a 58 /**
gmehmet 1:f60eafbf009a 59 * @brief Register Addresses
gmehmet 1:f60eafbf009a 60 * @details Enumerated MAX20303 register addresses
gmehmet 1:f60eafbf009a 61 */
gmehmet 1:f60eafbf009a 62 enum registers_t {
gmehmet 1:f60eafbf009a 63 REG_HARDWARE_ID = 0x00, ///< HardwareID Register
gmehmet 1:f60eafbf009a 64 REG_FIRMWARE_REV = 0x01, ///< FirmwareID Register
gmehmet 1:f60eafbf009a 65 // = 0x02, ///<
gmehmet 1:f60eafbf009a 66 REG_INT0 = 0x03, ///< Int0 Register
gmehmet 1:f60eafbf009a 67 REG_INT1 = 0x04, ///< Int1 Register
gmehmet 1:f60eafbf009a 68 REG_INT2 = 0x05, ///< Int2 Register
gmehmet 1:f60eafbf009a 69 REG_STATUS0 = 0x06, ///< Status Register 0
gmehmet 1:f60eafbf009a 70 REG_STATUS1 = 0x07, ///< Status Register 1
gmehmet 1:f60eafbf009a 71 REG_STATUS2 = 0x08, ///< Status Register 2
gmehmet 1:f60eafbf009a 72 REG_STATUS3 = 0x09, ///< Status Register 2
gmehmet 1:f60eafbf009a 73 // = 0x0A, ///<
gmehmet 1:f60eafbf009a 74 REG_SYSTEM_ERROR = 0x0B, ///< SystemError Register
gmehmet 1:f60eafbf009a 75 REG_INT_MASK0 = 0x0C, ///< IntMask0 Register
gmehmet 1:f60eafbf009a 76 REG_INT_MASK1 = 0x0D, ///< IntMask1 Register
gmehmet 1:f60eafbf009a 77 REG_INT_MASK2 = 0x0E, ///< IntMask1 Register
gmehmet 1:f60eafbf009a 78 REG_AP_DATOUT0 = 0x0F, ///< APDataOut0 Register
gmehmet 1:f60eafbf009a 79 REG_AP_DATOUT1 = 0x10, ///< APDataOut1 Register
gmehmet 1:f60eafbf009a 80 REG_AP_DATOUT2 = 0x11, ///< APDataOut2 Register
gmehmet 1:f60eafbf009a 81 REG_AP_DATOUT3 = 0x12, ///< APDataOut3 Register
gmehmet 1:f60eafbf009a 82 REG_AP_DATOUT4 = 0x13, ///< APDataOut4 Register
gmehmet 1:f60eafbf009a 83 REG_AP_DATOUT5 = 0x14, ///< APDataOut5 Register
gmehmet 1:f60eafbf009a 84 REG_AP_DATOUT6 = 0x15, ///< APDataOut6 Register
gmehmet 1:f60eafbf009a 85 REG_AP_CMDOUT = 0x17, ///< APCmdOut Register
gmehmet 1:f60eafbf009a 86 REG_AP_RESPONSE = 0x18, ///< APResponse Register
gmehmet 1:f60eafbf009a 87 REG_AP_DATAIN0 = 0x19,
gmehmet 1:f60eafbf009a 88 REG_AP_DATAIN1 = 0x1A,
gmehmet 1:f60eafbf009a 89 REG_AP_DATAIN2 = 0x1B,
gmehmet 1:f60eafbf009a 90 REG_AP_DATAIN3 = 0x1C,
gmehmet 1:f60eafbf009a 91 REG_AP_DATAIN4 = 0x1D,
gmehmet 1:f60eafbf009a 92 REG_AP_DATAIN5 = 0x1E,
gmehmet 1:f60eafbf009a 93 // = 0x1F, ///<
gmehmet 1:f60eafbf009a 94 REG_LDO_DIRECT = 0x20,
gmehmet 1:f60eafbf009a 95 REG_MPC_DIRECTWRITE = 0x21,
gmehmet 1:f60eafbf009a 96 REG_MPC_DIRECTRED = 0x22,
gmehmet 1:f60eafbf009a 97
gmehmet 1:f60eafbf009a 98 REG_LED_STEP_DIRECT = 0x2C,
gmehmet 1:f60eafbf009a 99 REG_LED0_DIRECT = 0x2D,
gmehmet 1:f60eafbf009a 100 REG_LED1_DIRECT = 0x2E,
gmehmet 1:f60eafbf009a 101 REG_LED2_DIRECT = 0x2F,
gmehmet 1:f60eafbf009a 102
gmehmet 1:f60eafbf009a 103
gmehmet 1:f60eafbf009a 104 REG_LDO1_CONFIG_WRITE = 0x40,
gmehmet 1:f60eafbf009a 105 REG_LDO1_CONFIG_READ = 0x41,
gmehmet 1:f60eafbf009a 106 REG_LDO2_CONFIG_WRITE = 0x42,
gmehmet 1:f60eafbf009a 107 REG_LDO2_CONFIG_READ = 0x43
gmehmet 1:f60eafbf009a 108
gmehmet 1:f60eafbf009a 109 /*
gmehmet 1:f60eafbf009a 110 REG_CHG_TMR = 0x0C, ///< Charger Timers
gmehmet 1:f60eafbf009a 111 REG_BUCK1_CFG = 0x0D, ///< Buck 1 Configuration
gmehmet 1:f60eafbf009a 112 REG_BUCK1_VSET = 0x0E, ///< Buck 1 Voltage Setting
gmehmet 1:f60eafbf009a 113 REG_BUCK2_CFG = 0x0F, ///< Buck 2 Configuration
gmehmet 1:f60eafbf009a 114 REG_BUCK2_VSET = 0x10, ///< Buck 2 Voltage Setting
gmehmet 1:f60eafbf009a 115 REG_RSVD_11 = 0x11, ///< Reserved 0x11
gmehmet 1:f60eafbf009a 116 REG_LDO1_CFG = 0x12, ///< LDO 1 Configuration
gmehmet 1:f60eafbf009a 117 REG_LDO1_VSET = 0x13, ///< LDO 1 Voltage Setting
gmehmet 1:f60eafbf009a 118 REG_LDO2_CFG = 0x14, ///< LDO 2 Configuration
gmehmet 1:f60eafbf009a 119 REG_LDO2_VSET = 0x15, ///< LDO 2 Voltage Setting
gmehmet 1:f60eafbf009a 120 REG_LDO3_CFG = 0x16, ///< LDO 3 Configuration
gmehmet 1:f60eafbf009a 121 REG_LDO3_VSET = 0x17, ///< LDO 3 Voltage Setting
gmehmet 1:f60eafbf009a 122 REG_THRM_CFG = 0x18, ///< Thermistor Configuration
gmehmet 1:f60eafbf009a 123 REG_MON_CFG = 0x19, ///< Monitor Multiplexer Configuration
gmehmet 1:f60eafbf009a 124 REG_BOOT_CFG = 0x1A, ///< Boot Configuration
gmehmet 1:f60eafbf009a 125 REG_PIN_STATUS = 0x1B, ///< Pin Status
gmehmet 1:f60eafbf009a 126 REG_BUCK_EXTRA = 0x1C, ///< Additional Buck Settings
gmehmet 1:f60eafbf009a 127 REG_PWR_CFG = 0x1D, ///< Power Configuration
gmehmet 1:f60eafbf009a 128 REG_NULL = 0x1E, ///< Reserved 0x1E
gmehmet 1:f60eafbf009a 129 REG_PWR_OFF = 0x1F, ///< Power Off Register
gmehmet 1:f60eafbf009a 130 */
gmehmet 1:f60eafbf009a 131 };
gmehmet 1:f60eafbf009a 132
gmehmet 1:f60eafbf009a 133 /**
gmehmet 1:f60eafbf009a 134 * @brief Constructor using reference to I2C object
gmehmet 1:f60eafbf009a 135 * @param i2c - Reference to I2C object
gmehmet 1:f60eafbf009a 136 * @param slaveAddress - 7-bit I2C address
gmehmet 1:f60eafbf009a 137 */
gmehmet 1:f60eafbf009a 138 MAX20303(I2C *i2c);
gmehmet 1:f60eafbf009a 139
gmehmet 1:f60eafbf009a 140 /** @brief Destructor */
gmehmet 1:f60eafbf009a 141 ~MAX20303(void);
gmehmet 1:f60eafbf009a 142
gmehmet 1:f60eafbf009a 143 int led0on(char enable);
gmehmet 1:f60eafbf009a 144 int led1on(char enable);
gmehmet 1:f60eafbf009a 145 int led2on(char enable);
gmehmet 1:f60eafbf009a 146 int BoostEnable(void);
gmehmet 1:f60eafbf009a 147 int BuckBoostEnable(void);
gmehmet 1:f60eafbf009a 148
gmehmet 1:f60eafbf009a 149 /// @brief Enable the 1.8V output rail **/
gmehmet 1:f60eafbf009a 150 int LDO1Config(void);
gmehmet 1:f60eafbf009a 151
gmehmet 1:f60eafbf009a 152 /// @brief Enable the 3V output rail **/
gmehmet 1:f60eafbf009a 153 int LDO2Config(void);
gmehmet 1:f60eafbf009a 154
gmehmet 1:f60eafbf009a 155
gmehmet 1:f60eafbf009a 156 int mv2bits(int mV);
gmehmet 1:f60eafbf009a 157
gmehmet 1:f60eafbf009a 158 /** @brief Power Off the board
gmehmet 1:f60eafbf009a 159 */
gmehmet 1:f60eafbf009a 160 int PowerOffthePMIC();
gmehmet 1:f60eafbf009a 161
gmehmet 1:f60eafbf009a 162 /** @brief Power Off the board with 30ms delay
gmehmet 1:f60eafbf009a 163 */
gmehmet 1:f60eafbf009a 164 int PowerOffDelaythePMIC();
gmehmet 1:f60eafbf009a 165
gmehmet 1:f60eafbf009a 166 /** @brief Soft reset the PMIC
gmehmet 1:f60eafbf009a 167 */
gmehmet 1:f60eafbf009a 168 int SoftResetthePMIC();
gmehmet 1:f60eafbf009a 169
gmehmet 1:f60eafbf009a 170 /** @brief Hard reset the PMIC
gmehmet 1:f60eafbf009a 171 */
gmehmet 1:f60eafbf009a 172 int HardResetthePMIC();
gmehmet 1:f60eafbf009a 173
gmehmet 1:f60eafbf009a 174 /** @brief check if can communicate with max20303
gmehmet 1:f60eafbf009a 175 */
gmehmet 1:f60eafbf009a 176 char CheckPMICHWID();
gmehmet 1:f60eafbf009a 177
gmehmet 1:f60eafbf009a 178 /** @brief CheckPMICStatusRegisters
gmehmet 1:f60eafbf009a 179 */
gmehmet 1:f60eafbf009a 180 int CheckPMICStatusRegisters(unsigned char buf_results[5]);
gmehmet 1:f60eafbf009a 181
gmehmet 1:f60eafbf009a 182 int Max20303_BatteryGauge(unsigned char *batterylevel);
gmehmet 1:f60eafbf009a 183
gmehmet 1:f60eafbf009a 184 // check if the battery is connected.
gmehmet 1:f60eafbf009a 185 // Warning: that function has 1000ms delay
gmehmet 1:f60eafbf009a 186 char Max20303_IsBattery_Connected();
gmehmet 1:f60eafbf009a 187
gmehmet 1:f60eafbf009a 188 private:
gmehmet 1:f60eafbf009a 189
gmehmet 1:f60eafbf009a 190 int writeReg(registers_t reg, uint8_t value);
gmehmet 1:f60eafbf009a 191 int readReg(registers_t reg, uint8_t &value);
gmehmet 1:f60eafbf009a 192
gmehmet 1:f60eafbf009a 193 int writeRegMulti(registers_t reg, uint8_t *value, uint8_t len);
gmehmet 1:f60eafbf009a 194 int readRegMulti(registers_t reg, uint8_t *value, uint8_t len);
gmehmet 1:f60eafbf009a 195
gmehmet 1:f60eafbf009a 196 /// I2C object
gmehmet 1:f60eafbf009a 197 I2C *m_i2c;
gmehmet 1:f60eafbf009a 198
gmehmet 1:f60eafbf009a 199 /// Device slave addresses
gmehmet 1:f60eafbf009a 200 uint8_t m_writeAddress, m_readAddress;
gmehmet 1:f60eafbf009a 201
gmehmet 1:f60eafbf009a 202 // Application Processor Interface Related Variables
gmehmet 1:f60eafbf009a 203 uint8_t i2cbuffer_[16];
gmehmet 1:f60eafbf009a 204 uint8_t appdatainoutbuffer_[8];
gmehmet 1:f60eafbf009a 205 uint8_t appcmdoutvalue_;
gmehmet 1:f60eafbf009a 206
gmehmet 1:f60eafbf009a 207 // check if the battery is connected
gmehmet 1:f60eafbf009a 208 char m_battery_is_connected;
gmehmet 1:f60eafbf009a 209
gmehmet 1:f60eafbf009a 210 /** @brief API Related Functions ***/
gmehmet 1:f60eafbf009a 211
gmehmet 1:f60eafbf009a 212 /***
gmehmet 1:f60eafbf009a 213 * @brief starts writing from ApResponse register 0x0F
gmehmet 1:f60eafbf009a 214 * check the datasheet to determine the value of dataoutlen
gmehmet 1:f60eafbf009a 215 */
gmehmet 1:f60eafbf009a 216 int AppWrite(uint8_t dataoutlen);
gmehmet 1:f60eafbf009a 217
gmehmet 1:f60eafbf009a 218 /** @brief starts reading from ApResponse register 0x18
gmehmet 1:f60eafbf009a 219 * check the datasheet to determine the value of datainlen
gmehmet 1:f60eafbf009a 220 * the result values are written into i2cbuffer
gmehmet 1:f60eafbf009a 221 *
gmehmet 1:f60eafbf009a 222 */
gmehmet 1:f60eafbf009a 223 int AppRead(uint8_t datainlen);
gmehmet 1:f60eafbf009a 224 };
gmehmet 1:f60eafbf009a 225
gmehmet 1:f60eafbf009a 226 #endif /* __MAX20303_H_ */