MAX77816 Library. The MAX77816 is a high-current, high-efficiency buck-boost regulator targeting single-cell Li-ion battery powered applications. Please find more detail things on the website: https://www.maximintegrated.com/en/products/power/switching-regulators/MAX77816.html
Revision 0:c39030c3a7cf, committed 2018-03-20
- Comitter:
- daniel_gs_jeong
- Date:
- Tue Mar 20 12:29:51 2018 +0000
- Child:
- 1:7182e55f5f59
- Commit message:
- MAX77816 Library. The MAX77816 is a high-current, high-efficiency; buck-boost regulator targeting single-cell Li-ion battery powered; applications.
Changed in this revision
max77816.cpp | Show annotated file Show diff for this revision Revisions of this file |
max77816.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max77816.cpp Tue Mar 20 12:29:51 2018 +0000 @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (C) 2017 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 "max77816.h" + +/***** Definitions *****/ +#define I2C_ADDR (0x18<<1) + +//****************************************************************************** +MAX77816::MAX77816(PinName sda, PinName scl) +{ + i2c_ = new I2C(sda, scl); + i2c_owner = true; + + i2c_->frequency(400000); +} + +//****************************************************************************** +MAX77816::MAX77816(I2C *i2c) : + i2c_(i2c) +{ + i2c_owner = false; +} + +//****************************************************************************** +MAX77816::~MAX77816() +{ + if(i2c_owner) { + delete i2c_; + } +} + +//****************************************************************************** +int32_t MAX77816::init() +{ + return 0; +} + +//****************************************************************************** +int32_t MAX77816::writeReg(MAX77816::registers_t reg_addr, char reg_data) +{ + char data[2]; + + data[0] = reg_addr; + data[1] = reg_data; + if (i2c_->write(I2C_ADDR, data, 2) != 0) { + return -1; + } + + return 0; +} + +//****************************************************************************** +int32_t MAX77816::readReg(MAX77816::registers_t reg_addr) +{ + char data; + + data = reg_addr; + if (i2c_->write(I2C_ADDR, &data, 1, true) != 0) { + return -1; + } + + if (i2c_->read(I2C_ADDR | 0x01, &data, 1) != 0) { + return -1; + } + + return (0x0 + data); +} + + + +//***************************************************************************** +int32_t MAX77816::readBlock(MAX77816::registers_t startReg, MAX77816::registers_t stopReg, uint8_t *data) +{ + int32_t rtnVal = -1; + int32_t numBytes = ((stopReg - startReg) + 1); + char packet[] = {static_cast<char>(startReg)}; + + if(i2c_->write(I2C_ADDR, packet, 1) == 0) + { + rtnVal = i2c_->read(I2C_ADDR | 0x01, reinterpret_cast<char *>(data), numBytes); + } + + return rtnVal; +} + + +//***************************************************************************** +int32_t MAX77816::writeBlock(MAX77816::registers_t startReg, MAX77816::registers_t stopReg, const uint8_t *data) +{ + int32_t numBytes = ((stopReg - startReg) + 1); + char packet[numBytes + 1]; + + packet[0] = static_cast<char>(startReg); + + memcpy(packet + 1, data, numBytes); + + return i2c_->write(I2C_ADDR, packet, sizeof(packet)); +} + + +//***************************************************************************** +int32_t MAX77816::getVersion() +{ + int32_t rData; + + rData = readReg(REG_0); + if(rData< 0) + return rData; + + return ((rData >> 4) & 0x7); +} + + +//***************************************************************************** +int32_t MAX77816::getChipRevision() +{ + int32_t rData; + + rData = readReg(REG_0); + if(rData< 0) + return rData; + + return ((rData >> 0) & 0xf); +} + +//***************************************************************************** +int32_t MAX77816::getStatus() +{ + int32_t rData; + + rData = readReg(REG_1); + if(rData< 0) + return rData; + + return ((rData >> 0) & 0xf); +} + +//***************************************************************************** +int32_t MAX77816::setVout(uint8_t reg_data) +{ + int32_t rData; + + rData = writeReg(REG_4, (reg_data & 0x7f)); + return rData; +} + +//***************************************************************************** +int32_t MAX77816::setVoutH(uint8_t reg_data) +{ + int32_t rData; + + rData = writeReg(REG_5, (reg_data & 0x7f)); + return rData; +} + +//***************************************************************************** +int32_t MAX77816::setIntMask(uint8_t reg_data) +{ + int32_t rData; + + rData = writeReg(REG_6, (reg_data & 0x7f)); + return rData; +} + +int32_t MAX77816::setIntMask() +{ + int32_t rData; + + rData = readReg(REG_6); + if(rData< 0) + return rData; + + return ((rData >> 0) & 0xf); +} +//***************************************************************************** +int32_t MAX77816::getInt() +{ + int32_t rData; + + rData = readReg(REG_7); + if(rData< 0) + return rData; + + return ((rData >> 0) & 0xf); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max77816.h Tue Mar 20 12:29:51 2018 +0000 @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (C) 2017 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 _MAX77816_H_ +#define _MAX77816_H_ + +#include "mbed.h" + +class MAX77816 +{ + +public: + + /** + * @brief Register Addresses + * @details Enumerated MAX77816 register addresses + */ + typedef enum { + REG_0, + REG_1, + REG_2, + REG_3, + REG_4, + REG_5, + REG_6, + REG_7 + } registers_t; + + + /** + * MAX77816 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. + */ + MAX77816(PinName sda, PinName scl); + + /** + * MAX77816 constructor. + * + * @param i2c I2C object to use. + */ + MAX77816(I2C *i2c); + + /** + * MAX44000 destructor. + */ + ~MAX77816(); + + /** + * @brief Initialize MAX77816 + */ + int32_t init(); + + /** + * @brief Write Register + * @details Writes data to MAX77816 register + * + * @param reg_addr Register to write + * @param reg_data Data to write + * @returns 0 if no errors, -1 if error. + */ + int32_t writeReg(MAX77816::registers_t reg_addr, char reg_data); + + /** + * @brief Read Register + * @details Reads data from MAX77816 register + * + * @param reg_addr Register to read + * @returns data if no errors, -1 if error. + */ + int32_t readReg(MAX77816::registers_t reg_addr); + + + int32_t writeBlock(MAX77816::registers_t startReg, MAX77816::registers_t stopReg, const uint8_t *data); + int32_t readBlock(MAX77816::registers_t startReg, MAX77816::registers_t stopReg, uint8_t *data); + + int32_t getVersion(); + int32_t getChipRevision(); + int32_t getStatus(); + int32_t setVout(uint8_t reg_data); + int32_t setVoutH(uint8_t reg_data); + int32_t setIntMask(uint8_t reg_data); + int32_t setIntMask(); + int32_t getInt(); + +private: + + I2C *i2c_; + bool i2c_owner; + +}; + +#endif /* _MAX77816_H_ */ + \ No newline at end of file