LTC4155 - Dual Input Power Manager/ 3.5A Li-Ion Battery Charger with I2C Control and USB OTG

Features

  • High Efficiency Charger Capable of 3.5A Charge Current
  • Monolithic Switching Regulator Makes Optimal Use of Limited Power and Thermal Budget
  • Dual Input Overvoltage Protection Controller
  • Priority Multiplexing for Multiple Inputs
  • I2C/SMBus Control and Status Feedback
  • NTC Thermistor ADC for Temperature Dependent Charge Algorithms (JEITA)
  • Instant-On Operation with Low Battery
  • Battery Ideal Diode Controller for Power Management
  • USB On-The-Go Power Delivery to the USB Port
  • Full Featured Li-Ion/Polymer Battery Charger with Four Float Voltage Settings
  • 28-Lead 4mm × 5mm QFN Package
Designed for Automotive and Transportation Applications
AEC-Q100 data available for specific packages


Typical Application

LTC4155 Typical Application
LTC4155 Typical Application

Description

The LTC®4155 is a 15 watt I2C controlled power manager with PowerPath™ instant-on operation, high efficiency switching battery charging and USB compatibility. The LTC4155 seamlessly manages power distribution from two 5V sources, such as a USB port and a wall adapter, to a single-cell rechargeable Lithium-Ion/Polymer battery and a system load.

The LTC4155’s switching battery charger automatically limits its input current for USB compatibility, or may draw up to 3A from a high power wall adapter. The high efficiency step-down switching charger is designed to provide maximum power to the application and reduced heat in high power density applications.

I2C adjustability of input current, charge current, battery float voltage, charge termination, and many other parameters allows maximum flexibility. I2C status reporting of key system and charge parameters facilitates intelligent control decisions. USB On-The-Go support provides 5V power back to the USB port without any additional components. A dual-input, priority multiplexing, overvoltage protection circuit guards the LTC4155 from high voltage damage on the VBUS pin.

The LTC4155 is available in the low profile 28-lead 4mm × 5mm × 0.75mm QFN surface mount package.

Packaging

For complete and up to date package information and drawings, please refer to our packaging page

Part Number Package Code Temp Package
Drawing
RoHS
LTC4155EUFD#PBF 4x5 QFN-28 UFD E 05-08-1712 Yes
LTC4155EUFD#TRPBF 4x5 QFN-28 UFD E 05-08-1712 Yes
LTC4155IUFD#PBF 4x5 QFN-28 UFD I 05-08-1712 Yes
LTC4155IUFD#TRPBF 4x5 QFN-28 UFD I 05-08-1712 Yes


LTC4155 Package Drawing

Order Info

  • Part numbers ending in PBF are lead free. Solder plated terminal finish (SnPb) versions are non-standard and special terms and conditions and pricing applies if available. Please contact LTC marketing for information.
  • Part numbers containing TR or TRM are shipped in tape and reel or 500 unit mini tape and reel, respectively
  • Please refer to our general ordering information or the product datasheet for more details

Package Variations and Pricing

Part Number Package Temp Price
(1-99)
Price
(1k)*
RoHS
LTC4155EUFD#PBF 4x5 QFN-28 E $4.22 $2.95 Yes
LTC4155EUFD#TRPBF 4x5 QFN-28 E $3.01 Yes
LTC4155IUFD#PBF 4x5 QFN-28 I $4.64 $3.25 Yes
LTC4155IUFD#TRPBF 4x5 QFN-28 I $3.31 Yes
Buy NowRequest Samples
* The USA list pricing shown is for BUDGETARY USE ONLY, shown in United States dollars (FOB USA per unit for the stated volume), and is subject to change. International prices may differ due to local duties, taxes, fees and exchange rates. For volume-specific price or delivery quotes, please contact your local Linear Technology sales office or authorized distributor.

Demo Boards

Linear Technology offers many demo boards free of charge to qualified customers. Contact your local sales office or distributor to inquire about a demo board. Certain demo boards are also available for sale via credit card on this website. Demo boards are for evaluation purposes only. It remains the customer’s responsibility to verify proper and reliable operation in the actual end application.

Part Number Description Price Documentation
DC1674A-A LTC4155EUFD Demo Board I VIN = 4.35V to 5.5V, Dual Input Li-Ion Charger with USB OTG, VOUT = 4.5V, VBATT = 4.05V to 4.2V @ 3.5A; DC590B Demo Board required $150.00
Buy Now

Companion Boards

Part Number Description Price Documentation
DC590B Isolated USB Serial Controller for Linear Technology QuikEval-Compatible Demo Boards $50.00
Buy Now
Click here to view our complete list of demo boards

Designed for Automotive and Transportation Appications

AEC-Q100 data is available for these specific part numbers. Please contact your local sales representative for more information regarding reliability reports or to inquire about parts that are not included. For more information, view our Automotive and Transportation page

Part Number Package Temp Price
(1-99)
Price
(1k)*
RoHS
LTC4155IUFD#PBF 4x5 QFN-28 I $4.64 $3.25 Yes
LTC4155IUFD#TRPBF 4x5 QFN-28 I $3.31 Yes
Buy NowRequest Samples
* The USA list pricing shown is for BUDGETARY USE ONLY, shown in United States dollars (FOB USA per unit for the stated volume), and is subject to change. International prices may differ due to local duties, taxes, fees and exchange rates. For volume-specific price or delivery quotes, please contact your local Linear Technology sales office or authorized distributor.

Applications

  • Tablet PCs
  • Ultra Mobile PCs
  • Video Media Players
  • Digital Cameras, GPS, PDAs
  • Smart Phones
  • Portable Medical Devices

Product Notifications

Please login to your MyLinear account for notifications of datasheet updates, new document releases and LTspice model announcements for your favorite products. If you do not have a MyLinear account you may Sign Up Now.

Forgot your password? Click here.
Need help? Email mylinear@linear.com with questions and comments.

Design Tools

Linduino

Linduino is an Arduino compatible platform for developing and distributing firmware libraries and code for SPI and I²C-compatible integrated circuits. The Linduino One board interfaces to more than 300 QuikEval demonstration cards, supporting a variety of product types including analog-to-digital converters (ADCs)digital-to-analog converters (DACs)power monitors, and more. Firmware libraries for individual devices are written in C and designed to be portable to a wide variety of processors and microcontrollers. Each library has a demonstration program that can be uploaded to the Linduino One platform to allow the circuit and software to be quickly and easily verified.

Click here for more information on Linduino

Code

Linduino is Linear Technology's Arduino compatible system for developing and distributing firmware libraries and example code for Linear Technology’s integrated circuits. The code below can be downloaded or copied and pasted into your project. Please visit the Linduino Home Page for demo board, manual and setup information.

This part is Code Supported: There is example code available for this part. The code below may rely on other drivers available in the full library.

Download LTC4155 - DC1674A.ino

/*!
LTC4155: Dual-Input Power Manager / 3.5A Li-Ion Battery Charger with I²C Control and USB OTG

@verbatim
The LTC®4155 is a 15 watt I²C controlled power manager with PowerPath™ instant-
on operation, high efficiency switching battery charging and USB compatibility.
The LTC4155 seamlessly manages power distribution from two 5V sources, such as a
USB port and a wall adapter, to a single-cell rechargeable Lithium-Ion/Polymer
battery and a system load.
@endverbatim

http://www.linear.com/product/LTC4155

http://www.linear.com/product/LTC4155#demoboards

REVISION HISTORY
$Revision: 4641 $
$Date: 2016-01-29 14:38:11 -0800 (Fri, 29 Jan 2016) $

Copyright (c) 2016, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1.  Redistributions  of source code must retain the above copyright notice, this
    list  of conditions and the following disclaimer.

2.  Redistributions  in  binary  form must reproduce the above copyright notice,
    this  list of conditions and  the following disclaimer in the  documentation
    and/or other materials provided with the distribution.

THIS  SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY  EXPRESS  OR  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES   OF  MERCHANTABILITY  AND  FITNESS  FOR  A  PARTICULAR  PURPOSE  ARE
DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY  DIRECT,  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING,  BUT  NOT  LIMITED  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS  OF  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
(INCLUDING  NEGLIGENCE  OR  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The  views and conclusions contained in the software and documentation are those
of  the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However,  the Linduino is only possible because of the Arduino team's commitment
to   the   open-source   community.   Please,  visit  http://www.arduino.cc  and
http://store.arduino.cc  ,  and  consider  a  purchase that will help fund their
ongoing work.

Generated on: 2016-01-19
*/



/*! @file
 *  @ingroup LTC4155
 *  @brief Arduino Example
 *
 *  This is an example sketch to demonstrate use of the API with the Linduino.
 *  In addition to the sketch, the following files are required::
 *    LTC4155.c
 *    LTC4155.h
 *    LTC4155_reg_defs.h
 */

#include "LTC4155.h"
#include <Arduino.h>
#include "Linduino.h"

#include "UserInterface.h"
#include "LT_I2CBus.h"
#include "LT_SMBusNoPec.h"

static LT_SMBus *smbus = new LT_SMBusNoPec();

int read_register(uint8_t addr,uint8_t command_code, uint8_t *data, port_configuration_t *port_configuration);
int write_register(uint8_t addr,uint8_t command_code, uint8_t data, port_configuration_t *port_configuration);

LTC4155_chip_cfg_t cfg =
{
  LTC4155_ADDR_09, //.addr (7-bit)
  read_register, //.read_register
  write_register, //.write_register
  0 //.port_configuration not used
};


LTC4155 chip;
uint8_t data;

void setup()
{
  Serial.begin(115200);         //! Initialize the serial port to the PC
  while (!Serial);              //! Wait for serial port to be opened in the case of Leonardo USB Serial
  Serial.println(F("Initializing LTC4155"));
  chip = LTC4155_init(&cfg);
}

void loop()
{
  /* the API functions can be used to read and write individual bit fields within a command code */
  Serial.println(F("Press any key to arm ship-and-store mode."));
  while (Serial.available() == 0);
  while (Serial.available() > 0)
    Serial.read();
  LTC4155_write_register(chip, LTC4155_ARM_SHIPMODE, LTC4155_ARM_SHIPMODE_PRESET_ARM);
  Serial.println(F("Ship-and-store mode armed.\n"));

  Serial.println(F("Press any key to disarm ship-and-store mode."));
  while (Serial.available() == 0);
  while (Serial.available() > 0)
    Serial.read();
  LTC4155_read_register(chip, LTC4155_REG6, &data);
  LTC4155_write_register(chip, LTC4155_REG6, data); // Write to register 6 to clear ship-mode without changing its contents.
  Serial.println(F("Ship-and-store mode disarmed.\n"));
}

/*! read_register function wraps C++ method LT_SMBus::readByte and places the returned data in *data.*/
int read_register(uint8_t addr, uint8_t command_code, uint8_t *data, port_configuration_t *port_configuration)
{
  //virtual uint8_t LT_SMBus::readByte(uint8_t address,uint8_t command);
  *data = smbus->readByte(addr, command_code);
  return 0;
}

/*! write_register function wraps C++ method LT_SMBus::writeByte.*/
int write_register(uint8_t addr, uint8_t command_code, uint8_t data, port_configuration_t *port_configuration)
{
  //virtual void LT_SMBus::writeByte(uint8_t address,uint8_t command,uint8_t data);
  smbus->writeByte(addr, command_code, data);
  return 0;
}

Download LTC4155 - Linduino Header File

/*!
LTC4155: Dual-Input Power Manager / 3.5A Li-Ion Battery Charger with I²C Control and USB OTG

@verbatim
The LTC®4155 is a 15 watt I²C controlled power manager with PowerPath™ instant-
on operation, high efficiency switching battery charging and USB compatibility.
The LTC4155 seamlessly manages power distribution from two 5V sources, such as a
USB port and a wall adapter, to a single-cell rechargeable Lithium-Ion/Polymer
battery and a system load.
@endverbatim

http://www.linear.com/product/LTC4155

http://www.linear.com/product/LTC4155#demoboards

REVISION HISTORY
$Revision: 4623 $
$Date: 2016-01-26 12:29:50 -0800 (Tue, 26 Jan 2016) $

Copyright (c) 2016, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1.  Redistributions  of source code must retain the above copyright notice, this
    list  of conditions and the following disclaimer.

2.  Redistributions  in  binary  form must reproduce the above copyright notice,
    this  list of conditions and  the following disclaimer in the  documentation
    and/or other materials provided with the distribution.

THIS  SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY  EXPRESS  OR  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES   OF  MERCHANTABILITY  AND  FITNESS  FOR  A  PARTICULAR  PURPOSE  ARE
DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY  DIRECT,  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING,  BUT  NOT  LIMITED  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS  OF  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
(INCLUDING  NEGLIGENCE  OR  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The  views and conclusions contained in the software and documentation are those
of  the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However,  the Linduino is only possible because of the Arduino team's commitment
to   the   open-source   community.   Please,  visit  http://www.arduino.cc  and
http://store.arduino.cc  ,  and  consider  a  purchase that will help fund their
ongoing work.

Generated on: 2016-01-19
*/


/*! @file
 *  @ingroup LTC4155
 *  @brief LTC4155 communication library core header file defining
 *  prototypes, data structures and constants used by LTC4155.c
 *
 *  Functions  matching  the  prototypes  of  @ref  smbus_write_register and @ref
 *  smbus_read_register  must  be  provided  to this API. They will implement the
 *  SMBus  read  and write transactions on your hardware. If the register size of
 *  the  LTC4155  is 8 bits, functions should be provided that implement SMBus
 *  read  byte and write byte. If the register size of the LTC4155 is 16 bits,
 *  functions  should  be provided that implement SMBus read word and write word.
 *  smbus_read_register  needs  to  store the value read from the LTC4155 into
 *  the  variable  data.  Both  functions  should return 0 on success and a non-0
 *  error  code  on  failure.  The  API functions will return your error codes on
 *  failure and a 0 on success.
 */

#ifndef LTC4155_H_
#define LTC4155_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "LTC4155_reg_defs.h"
#include "LTC4155_formats.h"
#include <stdint.h>
#include <stddef.h>

  // Type declarations
  /*! Hardware port information. Modify as needed for local hardware
  requirements. Available to user supplied read and write functions. */
  typedef struct
  {
    int file_descriptor; //!< Linux SMBus file handle
  } port_configuration_t;
  /*! Prototype of user supplied SMBus write_byte or write_word function. Should return 0 on success and a non-0 error code on failure. */
  typedef int (*smbus_write_register)(uint8_t addr, //!< Target IC's SMBus address
                                      uint8_t command_code, //!< Command code to be written to
                                      uint8_t data, //!< Data to be written
                                      port_configuration_t *port_configuration //!< Pointer to a user supplied port_configuration struct
                                     );
  /*! Prototype of user supplied SMBus read_byte or read_word function. Should return 0 on success and a non-0 error code on failure. */
  typedef int (*smbus_read_register)(uint8_t addr, //!< Target IC's SMBus address
                                     uint8_t command_code, //!< command code to be read from
                                     uint8_t *data, //!< Pointer to data destination
                                     port_configuration_t *port_configuration //!< Pointer to a user supplied port_configuration struct
                                    );
  typedef void *LTC4155;
  /*! Information required to access hardware SMBus port */
  typedef struct
  {
    uint8_t addr; //!< Target IC's SMBus address
    smbus_read_register read_register; //!< Pointer to a user supplied smbus_read_register function
    smbus_write_register write_register; //!< Pointer to a user supplied smbus_write_register function
    port_configuration_t *port_configuration; //!< Pointer to a user supplied port_configuration struct
  } LTC4155_chip_cfg_t;

  // function declarations
  /*! Returns a pointer to a LTC4155 structure used by LTC4155_write_register and LTC4155_read_register */
  LTC4155 LTC4155_init(LTC4155_chip_cfg_t *cfg //!< Information required to access hardware SMBus port
                      );
  /*! Function to modify a bit field within a register while preserving the unaddressed bit fields */
  int LTC4155_write_register(LTC4155 chip_handle, //!< Struct returned by LTC4155_init
                             uint16_t registerinfo, //!< Bit field name from LTC4155_regdefs.h
                             uint8_t data //!< Data to be written
                            );
  /*! Retrieves a bit field data into *data. Right shifts the addressed portion down to the 0 position */
  int LTC4155_read_register(LTC4155 chip_handle, //!< Struct returned by LTC4155_init
                            uint16_t registerinfo, //!< Register name from LTC4155_regdefs.h
                            uint8_t *data //!< Pointer to the data destination
                           );
  /*! Multiple LTC4155 use.
    Multiple LTC4155s can be used with this API. Each one must be initialized.
    The LTC4155_init requires some memory for each LTC4155. This memory can
    be  statically  allocated  by  defining  MAX_NUM_LTC4155_INSTANCES  to the
    number of LTC4155s required. Alternatively it can be dynamically allocated
    by  defining  LTC4155_USE_MALLOC.  The  default  is  to not use malloc and
    statically allocate one LTC4155.
  */
#ifndef MAX_NUM_LTC4155_INSTANCES
#define MAX_NUM_LTC4155_INSTANCES 1
#endif
#ifdef __cplusplus
}
#endif
#endif /* LTC4155_H_ */

Download LTC4155 - Linduino.CPP File

/*!
LTC4155: Dual-Input Power Manager / 3.5A Li-Ion Battery Charger with I²C Control and USB OTG

@verbatim
The LTC®4155 is a 15 watt I²C controlled power manager with PowerPath™ instant-
on operation, high efficiency switching battery charging and USB compatibility.
The LTC4155 seamlessly manages power distribution from two 5V sources, such as a
USB port and a wall adapter, to a single-cell rechargeable Lithium-Ion/Polymer
battery and a system load.
@endverbatim

http://www.linear.com/product/LTC4155

http://www.linear.com/product/LTC4155#demoboards

REVISION HISTORY
$Revision: 4623 $
$Date: 2016-01-26 12:29:50 -0800 (Tue, 26 Jan 2016) $

Copyright (c) 2016, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1.  Redistributions  of source code must retain the above copyright notice, this
    list  of conditions and the following disclaimer.

2.  Redistributions  in  binary  form must reproduce the above copyright notice,
    this  list of conditions and  the following disclaimer in the  documentation
    and/or other materials provided with the distribution.

THIS  SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY  EXPRESS  OR  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES   OF  MERCHANTABILITY  AND  FITNESS  FOR  A  PARTICULAR  PURPOSE  ARE
DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY  DIRECT,  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING,  BUT  NOT  LIMITED  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS  OF  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
(INCLUDING  NEGLIGENCE  OR  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The  views and conclusions contained in the software and documentation are those
of  the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However,  the Linduino is only possible because of the Arduino team's commitment
to   the   open-source   community.   Please,  visit  http://www.arduino.cc  and
http://store.arduino.cc  ,  and  consider  a  purchase that will help fund their
ongoing work.

Generated on: 2016-01-19
*/


//! @defgroup LTC4155 LTC4155: Dual-Input Power Manager / 3.5A Li-Ion Battery Charger with I²C Control and USB OTG

/*! @file
 *  @ingroup LTC4155
 *  @brief LTC4155 lightweight, hardware ambiguous, embeddable C Communication
 *  Library.
 *
 * Communication  is  bit-field based as well as whole-register based. This library
 * automatically masks and right-justifies bit fields to  ease programmer workload.
 *
 * This C library provides a header file with the complete definitions of registers
 * and  bit  fields  within  those  registers, and routines to read and write those
 * registers and individual bit-fields.
 *
 * Outside  of  the  Linduino  environment,  this  library  can  be  built with any
 * standard  C  compiler  and  can  be  used with different I2C/SMBus communication
 * hardware  simply  by  swapping  out  the  pointers  to appropriate user-supplied
 * functions   *@ref   smbus_write_register   and   *@ref  smbus_read_register.  An
 * example  is  provided  using  the  i2c-tools  Linux kernel driver which has been
 * tested  on  the  BeagleBone  Black  Linux  single board computer. It can also be
 * readily  adapted  to  common  microcontrollers  with  minimal  memory  impact on
 * embedded systems.
 *
 * A higher level hardware ambiguous Python communication library is also available.
 *
 * Please   visit   http://www.linear.com/product/LTC4155#code  or  contact  the
 * factory at 408-432-1900 or www.linear.com for further information.
 */

#include "LTC4155.h"

#ifndef LTC4155_USE_MALLOC
int LTC4155_instances = 0;
LTC4155_chip_cfg_t LTC4155_chip_array[MAX_NUM_LTC4155_INSTANCES];
#endif


//private function
LTC4155 LTC4155_alloc(void)
{
  //! this function "allocates" a LTC4155_chip structure.
  //! It may or may not use malloc.
#ifdef LTC4155_USE_MALLOC
  return malloc(sizeof(LTC4155_chip_cfg_t));
#else
  if (LTC4155_instances < MAX_NUM_LTC4155_INSTANCES)
  {
    return &LTC4155_chip_array[LTC4155_instances++];
  }
  else
  {
    return 0;
  }
#endif
}

LTC4155 LTC4155_init(LTC4155_chip_cfg_t *cfg)
{
  LTC4155_chip_cfg_t *chip = LTC4155_alloc();
  if (chip == NULL) return NULL;
  chip->addr = cfg->addr;
  chip->write_register = cfg->write_register;
  chip->read_register = cfg->read_register;
  chip->port_configuration = cfg->port_configuration;
  return (LTC4155) chip;
}

static inline uint8_t get_size(uint16_t registerinfo)
{
  return ((registerinfo >> 8) & 0x0F) + 1;
}
static inline uint8_t get_subaddr(uint16_t registerinfo)
{
  return (registerinfo) & 0xFF;
}
static inline uint8_t get_offset(uint16_t registerinfo)
{
  return (registerinfo >> 12) & 0x0F;
}
static inline uint8_t get_mask(uint16_t registerinfo)
{
  uint8_t mask = 1 << get_offset(registerinfo);
  uint8_t size = get_size(registerinfo);
  uint8_t i;
  for (i=0; i<size-1; i++)
  {
    mask |= mask << 1;
  }
  return mask;
}

int LTC4155_write_register(LTC4155 chip_handle, uint16_t registerinfo, uint8_t data)
{
  LTC4155_chip_cfg_t *chip = (LTC4155_chip_cfg_t *) chip_handle;
  int failure;
  uint8_t command_code = get_subaddr(registerinfo);
  if (get_size(registerinfo) != 8)
  {
    uint8_t offset = get_offset(registerinfo);
    uint16_t mask = get_mask(registerinfo);
    uint8_t read_data;
    failure = chip->read_register(chip->addr,command_code,&read_data,chip->port_configuration);
    if (failure) return failure;
    data = (read_data & ~mask) | (data << offset);
  }
  return chip->write_register(chip->addr,command_code,data,chip->port_configuration);
}

int LTC4155_read_register(LTC4155 chip_handle, uint16_t registerinfo, uint8_t *data)
{
  LTC4155_chip_cfg_t *chip = (LTC4155_chip_cfg_t *) chip_handle;
  int result;
  uint8_t command_code = get_subaddr(registerinfo);
  uint8_t offset = get_offset(registerinfo);
  uint16_t mask = get_mask(registerinfo);
  result = chip->read_register(chip->addr,command_code,data,chip->port_configuration);
  *data &= mask;
  *data = *data >> offset;
  return result;
}

Technical Support