Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAX20303_Wearable_PMIC_Activity_Tracker MAX20303_Wearable_PMIC_Activity_Tracker
MAX20303.h
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 #ifndef __MAX20303_H_ 00034 #define __MAX20303_H_ 00035 00036 #include "mbed.h" 00037 00038 #define MAX20303_SLAVE_ADDR (0x50 >> 1) 00039 #define MAX20303_SLAVE_WR_ADDR ((MAX20303_SLAVE_ADDR << 1)) 00040 #define MAX20303_SLAVE_RD_ADDR ((MAX20303_SLAVE_ADDR << 1) | 1) 00041 00042 00043 #define MAX20303_NO_ERROR 0 00044 #define MAX20303_ERROR -1 00045 00046 #define MAX20303_I2C_ADDR_FUEL_GAUGE 0x6c 00047 00048 #define MAX20303_LDO_MIN_MV 800 00049 #define MAX20303_LDO_MAX_MV 3600 00050 #define MAX20303_LDO_STEP_MV 100 00051 00052 #define MAX20303_OFF_COMMAND 0xB2 00053 00054 class MAX20303 00055 { 00056 00057 public: 00058 /** 00059 * @brief Register Addresses 00060 * @details Enumerated MAX20303 register addresses 00061 */ 00062 enum registers_t { 00063 REG_HARDWARE_ID = 0x00, ///< HardwareID Register 00064 REG_FIRMWARE_REV = 0x01, ///< FirmwareID Register 00065 // = 0x02, ///< 00066 REG_INT0 = 0x03, ///< Int0 Register 00067 REG_INT1 = 0x04, ///< Int1 Register 00068 REG_INT2 = 0x05, ///< Int2 Register 00069 REG_STATUS0 = 0x06, ///< Status Register 0 00070 REG_STATUS1 = 0x07, ///< Status Register 1 00071 REG_STATUS2 = 0x08, ///< Status Register 2 00072 REG_STATUS3 = 0x09, ///< Status Register 2 00073 // = 0x0A, ///< 00074 REG_SYSTEM_ERROR = 0x0B, ///< SystemError Register 00075 REG_INT_MASK0 = 0x0C, ///< IntMask0 Register 00076 REG_INT_MASK1 = 0x0D, ///< IntMask1 Register 00077 REG_INT_MASK2 = 0x0E, ///< IntMask1 Register 00078 REG_AP_DATOUT0 = 0x0F, ///< APDataOut0 Register 00079 REG_AP_DATOUT1 = 0x10, ///< APDataOut1 Register 00080 REG_AP_DATOUT2 = 0x11, ///< APDataOut2 Register 00081 REG_AP_DATOUT3 = 0x12, ///< APDataOut3 Register 00082 REG_AP_DATOUT4 = 0x13, ///< APDataOut4 Register 00083 REG_AP_DATOUT5 = 0x14, ///< APDataOut5 Register 00084 REG_AP_DATOUT6 = 0x15, ///< APDataOut6 Register 00085 REG_AP_CMDOUT = 0x17, ///< APCmdOut Register 00086 REG_AP_RESPONSE = 0x18, ///< APResponse Register 00087 REG_AP_DATAIN0 = 0x19, 00088 REG_AP_DATAIN1 = 0x1A, 00089 REG_AP_DATAIN2 = 0x1B, 00090 REG_AP_DATAIN3 = 0x1C, 00091 REG_AP_DATAIN4 = 0x1D, 00092 REG_AP_DATAIN5 = 0x1E, 00093 // = 0x1F, ///< 00094 REG_LDO_DIRECT = 0x20, 00095 REG_MPC_DIRECTWRITE = 0x21, 00096 REG_MPC_DIRECTRED = 0x22, 00097 00098 REG_LED_STEP_DIRECT = 0x2C, 00099 REG_LED0_DIRECT = 0x2D, 00100 REG_LED1_DIRECT = 0x2E, 00101 REG_LED2_DIRECT = 0x2F, 00102 00103 00104 REG_LDO1_CONFIG_WRITE = 0x40, 00105 REG_LDO1_CONFIG_READ = 0x41, 00106 REG_LDO2_CONFIG_WRITE = 0x42, 00107 REG_LDO2_CONFIG_READ = 0x43 00108 }; 00109 00110 /** 00111 * @brief Constructor using reference to I2C object 00112 * @param i2c - Reference to I2C object 00113 * @param slaveAddress - 7-bit I2C address 00114 */ 00115 MAX20303(I2C *i2c); 00116 00117 /** @brief Destructor */ 00118 ~MAX20303(void); 00119 00120 int led0on(char enable); 00121 int led1on(char enable); 00122 int led2on(char enable); 00123 int BoostEnable(void); 00124 int BuckBoostEnable(void); 00125 00126 /// @brief Enable the 1.8V output rail **/ 00127 int LDO1Config(void); 00128 int mv2bits(int mV); 00129 00130 /** @brief Power Off the board 00131 */ 00132 int PowerOffthePMIC(); 00133 00134 /** @brief Soft reset the PMIC 00135 */ 00136 int SoftResetthePMIC(); 00137 00138 /** @brief Hard reset the PMIC 00139 */ 00140 int HardResetthePMIC(); 00141 00142 /** @brief check if can communicate with max20303 00143 */ 00144 char CheckPMICHWID(); 00145 00146 private: 00147 00148 int writeReg(registers_t reg, uint8_t value); 00149 int readReg(registers_t reg, uint8_t &value); 00150 00151 int writeRegMulti(registers_t reg, uint8_t *value, uint8_t len); 00152 int readRegMulti(registers_t reg, uint8_t *value, uint8_t len); 00153 00154 /// I2C object 00155 I2C *m_i2c; 00156 00157 /// Device slave addresses 00158 uint8_t m_writeAddress, m_readAddress; 00159 00160 // Application Processor Interface Related Variables 00161 uint8_t i2cbuffer_[16]; 00162 uint8_t appdatainoutbuffer_[8]; 00163 uint8_t appcmdoutvalue_; 00164 00165 00166 /** @brief API Related Functions ***/ 00167 00168 /*** 00169 * @brief starts writing from ApResponse register 0x0F 00170 * check the datasheet to determine the value of dataoutlen 00171 */ 00172 int AppWrite(uint8_t dataoutlen); 00173 00174 /** @brief starts reading from ApResponse register 0x18 00175 * check the datasheet to determine the value of datainlen 00176 * the result values are written into i2cbuffer 00177 * 00178 */ 00179 int AppRead(uint8_t datainlen); 00180 }; 00181 00182 #endif /* __MAX20303_H_ */
Generated on Tue Jul 12 2022 20:12:47 by
1.7.2