Mode1 Optical Validation

Dependencies:   max32630fthr

Committer:
phonemacro
Date:
Wed Jun 01 18:42:12 2022 +0000
Revision:
66:d4989829a23d
Parent:
5:7f5a012747a5
updated xtalk

Who changed what in which revision?

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