no-OS
Classes | Macros | Enumerations | Functions
ltc3337.h File Reference

Header file for the LTC3337 Driver. More...

#include <stdint.h>
#include "no_os_util.h"
#include "no_os_i2c.h"
Include dependency graph for ltc3337.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ltc3337_dev
 
struct  ltc3337_init_param
 
struct  charge_count_t
 

Macros

#define LTC3337_I2C_ADDR   0x64
 
#define LTC3337_MAX_TEMP_C   159
 
#define LTC3337_MIN_TEMP_C   -41
 
#define LTC3337_MAX_PRESCALE   15
 
#define LTC3337_OVERFLOW_ALARM_MAX   0xFF
 
#define LTC3337_REG_A   0x01
 
#define LTC3337_RA_PRESCALE_MSK   NO_OS_GENMASK(3, 0)
 
#define LTC3337_RA_CLEAR_INT   NO_OS_BIT(4)
 
#define LTC3337_RA_CNT_CHK   NO_OS_BIT(5)
 
#define LTC3337_RA_SHTDN   NO_OS_BIT(6)
 
#define LTC3337_RA_ADC_CONV   NO_OS_BIT(7)
 
#define LTC3337_RA_ALARM_LVL_MSK   NO_OS_GENMASK(15, 8)
 
#define LTC3337_REG_B   0x02
 
#define LTC3337_REG_C   0x03
 
#define LTC3337_RC_OVERFLOW   NO_OS_BIT(0)
 
#define LTC3337_RC_ALARM_TRIP   NO_OS_BIT(1)
 
#define LTC3337_RC_ALARM_MIN   NO_OS_BIT(2)
 
#define LTC3337_RC_ALARM_MAX   NO_OS_BIT(3)
 
#define LTC3337_RC_ADC_READY   NO_OS_BIT(4)
 
#define LTC3337_RC_IPK_PIN_MSK   NO_OS_GENMASK(7, 5)
 
#define LTC3337_RC_DIE_TEMP_MSK   NO_OS_GENMASK(15, 8)
 
#define LTC3337_REG_D   0x04
 
#define LTC3337_REG_E   0x05
 
#define LTC3337_REG_F   0x06
 
#define LTC3337_REG_G   0x07
 
#define LTC3337_BATV_MSK   NO_OS_GENMASK(11, 0)
 
#define LTC3337_REG_H   0x08
 
#define LTC3337_RH_HOT_ALARM_MSK   NO_OS_GENMASK(15, 8)
 
#define LTC3337_RH_COLD_ALARM_MSK   NO_OS_GENMASK(7, 0)
 
#define LTC3337_VLSB_UV   1465
 
#define LTC3337_TLSB_MC   784
 
#define LTC3337_TEMP_MIN_C   -41
 
#define LTC3337_NUM_IPEAKS   8
 
#define LTC3337_NANO_AMP   1000000000
 
#define LTC3337_CALC_SCALE   10000
 
#define LTC3337_CALC_TO_WHOLE   (LTC3337_NANO_AMP / LTC3337_CALC_SCALE)
 
#define LTC3337_UV_TO_MV_SCALE   1000
 
#define LTC3337_MC_TO_C_SCALE   1000
 

Enumerations

enum  ltc3337_voltage_src_t {
  BAT_IN_IPEAK_ON,
  BAT_IN_IPEAK_OFF,
  BAT_OUT_IPEAK_ON,
  BAT_OUT_IPEAK_OFF
}
 

Functions

int ltc3337_init (struct ltc3337_dev **dev, struct ltc3337_init_param *init_param)
 
int ltc3337_remove (struct ltc3337_dev *dev)
 
int ltc3337_set_prescaler (struct ltc3337_dev *dev, uint8_t prescale)
 
int ltc3337_set_temperature_alarms_c (struct ltc3337_dev *dev, int16_t hot_alarm, int16_t cold_alarm)
 
int ltc3337_set_counter_shutdown (struct ltc3337_dev *dev, uint8_t shutdown_en)
 
int ltc3337_set_counter_alarm (struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
 
int ltc3337_set_accumulated_charge (struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
 
int ltc3337_get_accumulated_charge (struct ltc3337_dev *dev, struct charge_count_t *value, uint16_t *raw_value)
 
int ltc3337_get_voltage_mv (struct ltc3337_dev *dev, enum ltc3337_voltage_src_t source, uint32_t *value)
 
int ltc3337_get_temperature_c (struct ltc3337_dev *dev, int16_t *value)
 
int ltc3337_get_and_clear_interrupts (struct ltc3337_dev *dev, uint16_t *int_field, int16_t *temp_c)
 
int ltc3337_calculate_charge_register (struct ltc3337_dev *dev, struct charge_count_t *charge_a, uint16_t *reg_value)
 

Detailed Description

Header file for the LTC3337 Driver.

Author
Brent Kowal (brent.nosp@m..kow.nosp@m.al@an.nosp@m.alog.nosp@m..com)

Copyright 2023(c) Analog Devices, Inc.

All rights reserved.

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

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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.

Macro Definition Documentation

◆ LTC3337_BATV_MSK

#define LTC3337_BATV_MSK   NO_OS_GENMASK(11, 0)

◆ LTC3337_CALC_SCALE

#define LTC3337_CALC_SCALE   10000

◆ LTC3337_CALC_TO_WHOLE

#define LTC3337_CALC_TO_WHOLE   (LTC3337_NANO_AMP / LTC3337_CALC_SCALE)

◆ LTC3337_I2C_ADDR

#define LTC3337_I2C_ADDR   0x64

◆ LTC3337_MAX_PRESCALE

#define LTC3337_MAX_PRESCALE   15

◆ LTC3337_MAX_TEMP_C

#define LTC3337_MAX_TEMP_C   159

◆ LTC3337_MC_TO_C_SCALE

#define LTC3337_MC_TO_C_SCALE   1000

◆ LTC3337_MIN_TEMP_C

#define LTC3337_MIN_TEMP_C   -41

◆ LTC3337_NANO_AMP

#define LTC3337_NANO_AMP   1000000000

◆ LTC3337_NUM_IPEAKS

#define LTC3337_NUM_IPEAKS   8

◆ LTC3337_OVERFLOW_ALARM_MAX

#define LTC3337_OVERFLOW_ALARM_MAX   0xFF

◆ LTC3337_RA_ADC_CONV

#define LTC3337_RA_ADC_CONV   NO_OS_BIT(7)

◆ LTC3337_RA_ALARM_LVL_MSK

#define LTC3337_RA_ALARM_LVL_MSK   NO_OS_GENMASK(15, 8)

◆ LTC3337_RA_CLEAR_INT

#define LTC3337_RA_CLEAR_INT   NO_OS_BIT(4)

◆ LTC3337_RA_CNT_CHK

#define LTC3337_RA_CNT_CHK   NO_OS_BIT(5)

◆ LTC3337_RA_PRESCALE_MSK

#define LTC3337_RA_PRESCALE_MSK   NO_OS_GENMASK(3, 0)

◆ LTC3337_RA_SHTDN

#define LTC3337_RA_SHTDN   NO_OS_BIT(6)

◆ LTC3337_RC_ADC_READY

#define LTC3337_RC_ADC_READY   NO_OS_BIT(4)

◆ LTC3337_RC_ALARM_MAX

#define LTC3337_RC_ALARM_MAX   NO_OS_BIT(3)

◆ LTC3337_RC_ALARM_MIN

#define LTC3337_RC_ALARM_MIN   NO_OS_BIT(2)

◆ LTC3337_RC_ALARM_TRIP

#define LTC3337_RC_ALARM_TRIP   NO_OS_BIT(1)

◆ LTC3337_RC_DIE_TEMP_MSK

#define LTC3337_RC_DIE_TEMP_MSK   NO_OS_GENMASK(15, 8)

◆ LTC3337_RC_IPK_PIN_MSK

#define LTC3337_RC_IPK_PIN_MSK   NO_OS_GENMASK(7, 5)

◆ LTC3337_RC_OVERFLOW

#define LTC3337_RC_OVERFLOW   NO_OS_BIT(0)

◆ LTC3337_REG_A

#define LTC3337_REG_A   0x01

◆ LTC3337_REG_B

#define LTC3337_REG_B   0x02

◆ LTC3337_REG_C

#define LTC3337_REG_C   0x03

◆ LTC3337_REG_D

#define LTC3337_REG_D   0x04

◆ LTC3337_REG_E

#define LTC3337_REG_E   0x05

◆ LTC3337_REG_F

#define LTC3337_REG_F   0x06

◆ LTC3337_REG_G

#define LTC3337_REG_G   0x07

◆ LTC3337_REG_H

#define LTC3337_REG_H   0x08

◆ LTC3337_RH_COLD_ALARM_MSK

#define LTC3337_RH_COLD_ALARM_MSK   NO_OS_GENMASK(7, 0)

◆ LTC3337_RH_HOT_ALARM_MSK

#define LTC3337_RH_HOT_ALARM_MSK   NO_OS_GENMASK(15, 8)

◆ LTC3337_TEMP_MIN_C

#define LTC3337_TEMP_MIN_C   -41

◆ LTC3337_TLSB_MC

#define LTC3337_TLSB_MC   784

◆ LTC3337_UV_TO_MV_SCALE

#define LTC3337_UV_TO_MV_SCALE   1000

◆ LTC3337_VLSB_UV

#define LTC3337_VLSB_UV   1465

Enumeration Type Documentation

◆ ltc3337_voltage_src_t

Enumeration of sources for reading voltage

Enumerator
BAT_IN_IPEAK_ON 
BAT_IN_IPEAK_OFF 
BAT_OUT_IPEAK_ON 
BAT_OUT_IPEAK_OFF 

Function Documentation

◆ ltc3337_calculate_charge_register()

int ltc3337_calculate_charge_register ( struct ltc3337_dev dev,
struct charge_count_t charge_a,
uint16_t *  reg_value 
)

Gets a register value equivalent of the provided charge in A/nA-hrs to be used in configuring the charge alarms, and resetting the charge register. This function does not access the device over the bus, but utilizes the latched prescaled and IPK values to perform the calculation

Parameters
dev- Device to utilize configuration from
charge_a- Pointer to the charge values in A/nA-hrs
reg_value- Pointer to store the output register value
Returns
0 on success, Non-0 on error

◆ ltc3337_get_accumulated_charge()

int ltc3337_get_accumulated_charge ( struct ltc3337_dev dev,
struct charge_count_t value,
uint16_t *  raw_value 
)

Gets the current value of the accumulated charge register. This function can return the raw value and/or the calculated value based on the prescaler and IPK settings of dev.

Parameters
dev- Device to read from
value- Pointer to calculated storage location, or NULL
raw_value- Pointer to raw storage location, or NULL
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_get_and_clear_interrupts()

int ltc3337_get_and_clear_interrupts ( struct ltc3337_dev dev,
uint16_t *  int_field,
int16_t *  temp_c 
)

Reads and clears the interrupt status of the chip. Since the die temp is also provided in the interrupt register, temperature is optionally provided as well. This allows a user to poll interrupt status and not accidentally clear interrupts by reading temperature inbetween interrupt polls. Use the LTC3337_RC_ macros to determine status of each interrupt in int_field

Parameters
dev- Device to read from
int_field- Interrupt status bits
temp_c- Location to store temperature (or NULL)
Returns
0 on success, Non-0 on error

◆ ltc3337_get_temperature_c()

int ltc3337_get_temperature_c ( struct ltc3337_dev dev,
int16_t *  value 
)

Gets the current die temperature

Parameters
dev- Device to read from
value- Location to store calculated value, in Deg C
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_get_voltage_mv()

int ltc3337_get_voltage_mv ( struct ltc3337_dev dev,
enum ltc3337_voltage_src_t  source,
uint32_t *  value 
)

Gets the current value of the requested voltage monitor in mV.

Parameters
dev- Device to read from
source- Which voltage source to read
value- Location to store calcualted value, in mV
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_init()

int ltc3337_init ( struct ltc3337_dev **  device,
struct ltc3337_init_param init_param 
)

Initializes the driver instance. Assigns the I2C bus and reads the IPK pins. The prescaler is set to the user value, and the accumulated charge alarm is defaulted to maximum 0xFF

Parameters
device- Pointer to the device instance
init_param- Initialization parameters
Returns
0 on success, Non-0 on error
Here is the caller graph for this function:

◆ ltc3337_remove()

int ltc3337_remove ( struct ltc3337_dev dev)

Uninitializes the device instance and frees up any allocated memory

Parameters
dev- Device to remove
Returns
0 on success, non-0 on error
Here is the caller graph for this function:

◆ ltc3337_set_accumulated_charge()

int ltc3337_set_accumulated_charge ( struct ltc3337_dev dev,
uint16_t  reg_value,
uint8_t  round_up 
)

Sets the level for the coulomb counter accumulated charge register. The input value is the raw register value, and can be calculated using LTC3337_CalculateChargeRegister or manually by hand. IMPORTANT: Only the upper 8-bits of the value are utilized. Use the roundUp flag to have the driver optionally round up to the next valid bit

Parameters
dev- Device to configure
reg_value- Register value, as if all 16-bits were utilized
round_up- 1 -Have the driver round up to next usable alarm bit
Returns
0 on success, Non-0 on error

◆ ltc3337_set_counter_alarm()

int ltc3337_set_counter_alarm ( struct ltc3337_dev dev,
uint16_t  counter_reg_val,
uint8_t  round_up 
)

Sets the alarm level for the coulomb counter alarm. The input value is the raw register value, and can be calculated using LTC3337_CalculateChargeRegister or manually by hand. IMPORTANT: Only the upper 8-bits of the value are utilized. Use the roundUp flag to have the driver optionally round up to the next valid bit

Parameters
dev- Device to configure
counter_reg_val- Register value, as if all 16-bits were utilized
round_up- 1 -Have the driver round up to next usable alarm bit
Returns
0 on success, Non-0 on error

◆ ltc3337_set_counter_shutdown()

int ltc3337_set_counter_shutdown ( struct ltc3337_dev dev,
uint8_t  shutdown_en 
)

Sets the state of the coulomb counter shutdown function

Parameters
dev- Device to configure
shutdown_en- 1 - Enable shutdown, 0 - Coulomb counter running
Returns
0 on success, Non-0 on error

◆ ltc3337_set_prescaler()

int ltc3337_set_prescaler ( struct ltc3337_dev dev,
uint8_t  prescale 
)

Sets the prescaler value of the device. IMPORTANT: Changing the prescaler does not affect the value of the accumulated charge register. If the prescaler is set sometime following the initial runtime setup, after charge has been accumulated, the acccumulated charge register should be set according to the current value shifted by the difference in original and current prescaler. This driver does not automatically perform that action. IMPORTANT: Changing the prescaler does not alter the configuration of alarm. That may need to be changed if configured prior to the prescaler

Parameters
dev- Pointer to the device instance
prescale- Prescaler value
Returns
0 on success, Non-0 on error

◆ ltc3337_set_temperature_alarms_c()

int ltc3337_set_temperature_alarms_c ( struct ltc3337_dev dev,
int16_t  hot_alarm,
int16_t  cold_alarm 
)

Set the alarm thresholds for hot and cold temperatures

Parameters
dev- Device to configure
hot_alarm- Hot alarm threshold, in Degrees C
cold_alarm- Cold alarm threshold, in Degrees C
Returns
0 on success, Non-0 on error