MAX77650 Driver
Dependents: MAX32620FTHR_Pmic MAX32620FTHR_Pmic_Boot MAX32620FTHR_GPS_Tracker
Fork of MAX77650 by
Revision 0:d29ae4cd4af7, committed 2018-04-24
- Comitter:
- jessexm
- Date:
- Tue Apr 24 20:09:13 2018 +0000
- Commit message:
- Initial commit
Changed in this revision
MAX77650.cpp | Show annotated file Show diff for this revision Revisions of this file |
MAX77650.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d29ae4cd4af7 MAX77650.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX77650.cpp Tue Apr 24 20:09:13 2018 +0000 @@ -0,0 +1,167 @@ + +/******************************************************************************* + * Copyright (C) 2018 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. + ******************************************************************************* + */ + +#include "MAX77650.h" + +#define SBB2_TV_MIN_MV 800 +#define SBB2_TV_MAX_MV 3950 +#define SBB2_TV_LSB_MV 50 + +//****************************************************************************** +MAX77650::MAX77650(I2C &i2c, PinName pwrHldPin, int addr) : + i2c(i2c) +{ + devAddr = addr; + pwrHld = new DigitalOut(pwrHldPin, 1); +} + +//****************************************************************************** +MAX77650::~MAX77650() +{ + delete pwrHld; +} + +//****************************************************************************** +int MAX77650::readReg(reg_t reg, char *val) +{ + char wbuf[] = { reg }; + + if (!(i2c.write(devAddr, wbuf, sizeof(wbuf), true))) { + if (!(i2c.read(devAddr, val, 1))) { + return MAX77650_NO_ERROR; + } + } + + return MAX77650_ERROR; +} + +//****************************************************************************** +int MAX77650::writeReg(reg_t reg, char val) +{ + char wbuf[] = { reg, val }; + + if (!(i2c.write(devAddr, wbuf, sizeof(wbuf)))) { + return MAX77650_NO_ERROR; + } + + return MAX77650_ERROR; +} + +//****************************************************************************** +int MAX77650::writeReg(const char *buf, int len) +{ + if (!(i2c.write(devAddr, buf, len))) { + return MAX77650_NO_ERROR; + } + + return MAX77650_ERROR; +} + +//****************************************************************************** +int MAX77650::cid(void) { + char rbuf[1]; + + if (readReg(CID, rbuf)) { + return MAX77650_ERROR; + } + + return *rbuf; +} + +//****************************************************************************** +int MAX77650::enableLDO(void) +{ + char ade_flag[1]; + + if (readReg(CNFG_LDO_B, ade_flag)) { + return MAX77650_ERROR; + } + + *ade_flag &= 0x08; + + return writeReg(CNFG_LDO_B, *ade_flag | 0x06); +} + +//****************************************************************************** +int MAX77650::disableLDO(void) +{ + char ade_flag[1]; + + if (readReg(CNFG_LDO_B, ade_flag)) { + return MAX77650_ERROR; + } + + *ade_flag &= 0x08; + + return writeReg(CNFG_LDO_B, *ade_flag | 0x04); +} + +//****************************************************************************** +int MAX77650::setSBB2VoltageMV(uint32_t tv_mv) +{ + uint32_t tv_code; + char ip_code[1]; + + if ((tv_mv > SBB2_TV_MAX_MV) || (tv_mv < SBB2_TV_MIN_MV) || (tv_mv % SBB2_TV_LSB_MV)) { + return MAX77650_ERROR; + } + + tv_code = (tv_mv - SBB2_TV_MIN_MV) / SBB2_TV_LSB_MV; + + if (readReg(CNFG_SBB2_A, ip_code)) { + return MAX77650_ERROR; + } + + *ip_code &= 0xC0; + + return writeReg(CNFG_SBB2_A, tv_code | *ip_code); +} + +//****************************************************************************** +int MAX77650::setSBB2Voltage(float tv_v) +{ + return setSBB2VoltageMV(tv_v * 1000); +} + +//****************************************************************************** +void MAX77650::assertPowerHold(void) +{ + pwrHld->write(1); +} + +//****************************************************************************** +void MAX77650::deassertPowerHold(void) +{ + pwrHld->write(0); +}
diff -r 000000000000 -r d29ae4cd4af7 MAX77650.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX77650.h Tue Apr 24 20:09:13 2018 +0000 @@ -0,0 +1,264 @@ +/******************************************************************************* + * Copyright (C) 2018 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 _MAX77650_H_ +#define _MAX77650_H_ + +#include "mbed.h" + +#define MAX77650_NO_ERROR 0 +#define MAX77650_ERROR -1 + +#define MAX77650_I2C_ADDRESS 0x90 + +#define MAX77650_CID 0x78 + +/** + * @brief MAX77650 Ultra-Low Power PMIC with 3-Output SIMO and Charger + * + * @details The MAX77650/MAX77651 provide highly-integrated battery + * charging and power supply solutions for low-power wearable applications + * where size and efficiency are critical. + * <br>https://www.maximintegrated.com/en/products/power/battery-management/MAX77650.html + * + * @code + * #include "mbed.h" + * #include "MAX77650.h" + * + * // Configure LED to rotate colors + * static const char ledRotate[] = { + * MAX77650::CNFG_LED0_A, + * 0x44, 0x44, 0x44, + * 0x17, 0x37, 0x77, + * 0x01, + * }; + * + * I2C i2c2(I2C2_SDA, I2C2_SCL); + * + * MAX77650 max77650(i2c2); + * + * int main() + * { + * // Turn off Low-Dropout Linear Regulator + * max77650.disableLDO(); + * + * // Set SBB supply 2 at 3.3V + * max77650.setSBB2Voltage(3.3f); + * + * // Configure LED current sinks + * max77650.writeReg(ledRotate, sizeof(ledRotate)); + * + * while(1) ; + * + * } + * @endcode + */ + +class MAX77650 +{ +public: + + /** + * @brief Register Addresses + * @details Enumerated MAX77650 register addresses + */ + typedef enum { + CNFG_GLBL = 0x10, // Global Configuration + INT_GLBL = 0x00, // Interrupt Status + INTM_GLBL = 0x06, // Interrupt Mask + STAT_GLBL = 0x05, // Global Status + ERCFLAG = 0x04, // Flags + CNFG_GPIO = 0x12, // GPIO Configuration + CID = 0x11, // Chip Identification Code + INT_CHG = 0x01, // Charger Interrupt Status + INT_M_CHG = 0x07, // Charger Interrupt Mask + STAT_CHG_A = 0x02, // Charger Status A + STAT_CHG_B = 0x03, // Charger Status B + CNFG_CHG_A = 0x18, // Charger Configuration A + CNFG_CHG_B = 0x19, // Charger Configuration B + CNFG_CHG_C = 0x1A, // Charger Configuration C + CNFG_CHG_D = 0x1B, // Charger Configuration D + CNFG_CHG_E = 0x1C, // Charger Configuration E + CNFG_CHG_F = 0x1D, // Charger Configuration F + CNFG_CHG_G = 0x1E, // Charger Configuration G + CNFG_CHG_H = 0x1F, // Charger Configuration H + CNFG_CHG_I = 0x20, // Charger Configuration I + CNFG_LDO_A = 0x38, // LDO Configuration A + CNFG_LDO_B = 0x39, // LDO Configuration B + CNFG_SBB_TOP = 0x28, // SIMO Buck-Boost Configuration + CNFG_SBB0_A = 0x29, // SIMO Buck-Boost 0 Configuration A + CNFG_SBB0_B = 0x2A, // SIMO Buck-Boost 0 Configuration B + CNFG_SBB1_A = 0x2B, // SIMO Buck-Boost 1 Configuration A + CNFG_SBB1_B = 0x2C, // SIMO Buck-Boost 1 Configuration B + CNFG_SBB2_A = 0x2D, // SIMO Buck-Boost 2 Configuration A + CNFG_SBB2_B = 0x2E, // SIMO Buck-Boost 2 Configuration B + CNFG_LED0_A = 0x40, // LED 0 Configuration A + CNFG_LED0_B = 0x43, // LED 0 Configuration B + CNFG_LED1_A = 0x41, // LED 1 Configuration A + CNFG_LED1_B = 0x44, // LED 1 Configuration B + CNFG_LED2_A = 0x42, // LED 2 Configuration A + CNFG_LED2_B = 0x45, // LED 2 Configuration A + CNFG_LED_TOP = 0x46 // LED Configuration + } reg_t; + + /** + * @brief Global Configuration settings + * @details Enumerated global configuration settings + */ + typedef enum { + SBIA_LPM = 0x20, + SBIA_EN = 0x10, + NEN_PUSH = 0x00, + NEN_SLIDE = 0x08, + DBEN_100_US = 0x00, + DBEN_30_MS = 0x04, + SFT_OFF = 0x02, + SFT_CRST = 0x01, + } cnfg_gbl_t; + + /** + * @brief Interrupt Enable Flags + * @details Enumerated interrupt enable flags + */ + typedef enum { + DOD = 0x40, + TJAL_2 = 0x20, + TJAL_1 = 0x10, + NEN_RISE = 0x08, + NEN_FALL = 0x04, + GPI_RISE = 0x02, + GPI_FALL = 0x01, + } intm_glbl_t; + + /** + * MAX77650 constructor. + * + * @param i2c I2C object to use. + * @param pwrHldPin Pin power hold input is connected to. + * @param slaveAddress Slave Address of the device. + */ + MAX77650(I2C &i2c, PinName pwrHldPin = NC, int addr = MAX77650_I2C_ADDRESS); + + /** + * MAX77650 destructor. + */ + ~MAX77650(); + + /** + * @brief Read Register + * @details Reads from the specified register + * @param reg The register to be read + * @param val Pointer for where to store the data + * @returns 0 if no errors, -1 if error. + */ + int readReg(reg_t reg, char *val); + + /** + * @brief Write Register + * @details Writes the given value to the specified register. + * @param reg The register to be written + * @param val The data to be written + * @returns 0 if no errors, -1 if error. + */ + int writeReg(reg_t reg, char val); + + /** + * @brief Write Register + * @details Writes the given value(s) beginning with + * the register specified in the first buffer entry. + * @param buf The register and data to be written + * @param len The buffer length including starting register and data to be written + * @returns 0 if no errors, -1 if error. + */ + int writeReg(const char *buf, int len); + + /** + * @brief Read the CID + * @details Read and return Chip Identification Code register value + * @returns CID if no errors, -1 if error. + */ + int cid(void); + + /** + * @brief Enable LDO + * @details Enables LDO + * @returns 0 if no errors, -1 if error. + */ + int enableLDO(void); + + /** + * @brief Disable LDO + * @details Disables LDO + * @returns 0 if no errors, -1 if error. + */ + int disableLDO(void); + + /** + * @brief Set SBB 2 target voltage + * @details Select SBB 2 target output voltage. + * @param tv_mv The target voltage selection in milli-volts + * @returns 0 if no errors, -1 if error. + */ + int setSBB2VoltageMV(uint32_t tv_mv); + + /** + * @brief Set SBB 2 target voltage + * @details Select SBB 2 target output voltage. + * @param tv_v The target voltage selection in volts + * @returns 0 if no errors, -1 if error. + */ + int setSBB2Voltage(float tv_v); + + /** + * @brief Assert Power Hold input + * @details Asserts Power Hold input. + * @param pin The pin connected to Power Hold input + * @returns 0 if no errors, -1 if error. + */ + void assertPowerHold(void); + + /** + * @brief Deassert Power Hold input + * @details Deasserts Power Hold input. + * @param pin The pin connected to Power Hold input + * @returns 0 if no errors, -1 if error. + */ + void deassertPowerHold(void); + +private: + I2C &i2c; + int devAddr; + DigitalOut *pwrHld; +}; + +#endif