no-OS
|
Header file for the LTC3337 Driver. More...
Go to the source code of this file.
Classes | |
struct | ltc3337_dev |
struct | ltc3337_init_param |
struct | charge_count_t |
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) |
Header file for the LTC3337 Driver.
Copyright 2023(c) Analog Devices, Inc.
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, INC. “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 ANALOG DEVICES, INC. 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.
#define LTC3337_BATV_MSK NO_OS_GENMASK(11, 0) |
#define LTC3337_CALC_SCALE 10000 |
#define LTC3337_CALC_TO_WHOLE (LTC3337_NANO_AMP / LTC3337_CALC_SCALE) |
#define LTC3337_I2C_ADDR 0x64 |
#define LTC3337_MAX_PRESCALE 15 |
#define LTC3337_MAX_TEMP_C 159 |
#define LTC3337_MC_TO_C_SCALE 1000 |
#define LTC3337_MIN_TEMP_C -41 |
#define LTC3337_NANO_AMP 1000000000 |
#define LTC3337_NUM_IPEAKS 8 |
#define LTC3337_OVERFLOW_ALARM_MAX 0xFF |
#define LTC3337_RA_ADC_CONV NO_OS_BIT(7) |
#define LTC3337_RA_ALARM_LVL_MSK NO_OS_GENMASK(15, 8) |
#define LTC3337_RA_CLEAR_INT NO_OS_BIT(4) |
#define LTC3337_RA_CNT_CHK NO_OS_BIT(5) |
#define LTC3337_RA_PRESCALE_MSK NO_OS_GENMASK(3, 0) |
#define LTC3337_RA_SHTDN NO_OS_BIT(6) |
#define LTC3337_RC_ADC_READY NO_OS_BIT(4) |
#define LTC3337_RC_ALARM_MAX NO_OS_BIT(3) |
#define LTC3337_RC_ALARM_MIN NO_OS_BIT(2) |
#define LTC3337_RC_ALARM_TRIP NO_OS_BIT(1) |
#define LTC3337_RC_DIE_TEMP_MSK NO_OS_GENMASK(15, 8) |
#define LTC3337_RC_IPK_PIN_MSK NO_OS_GENMASK(7, 5) |
#define LTC3337_RC_OVERFLOW NO_OS_BIT(0) |
#define LTC3337_REG_A 0x01 |
#define LTC3337_REG_B 0x02 |
#define LTC3337_REG_C 0x03 |
#define LTC3337_REG_D 0x04 |
#define LTC3337_REG_E 0x05 |
#define LTC3337_REG_F 0x06 |
#define LTC3337_REG_G 0x07 |
#define LTC3337_REG_H 0x08 |
#define LTC3337_RH_COLD_ALARM_MSK NO_OS_GENMASK(7, 0) |
#define LTC3337_RH_HOT_ALARM_MSK NO_OS_GENMASK(15, 8) |
#define LTC3337_TEMP_MIN_C -41 |
#define LTC3337_TLSB_MC 784 |
#define LTC3337_UV_TO_MV_SCALE 1000 |
#define LTC3337_VLSB_UV 1465 |
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
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 |
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.
dev | - Device to read from |
value | - Pointer to calculated storage location, or NULL |
raw_value | - Pointer to raw storage location, or NULL |
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
dev | - Device to read from |
int_field | - Interrupt status bits |
temp_c | - Location to store temperature (or NULL) |
int ltc3337_get_temperature_c | ( | struct ltc3337_dev * | dev, |
int16_t * | value | ||
) |
Gets the current die temperature
dev | - Device to read from |
value | - Location to store calculated value, in Deg C |
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.
dev | - Device to read from |
source | - Which voltage source to read |
value | - Location to store calcualted value, in mV |
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
device | - Pointer to the device instance |
init_param | - Initialization parameters |
int ltc3337_remove | ( | struct ltc3337_dev * | dev | ) |
Uninitializes the device instance and frees up any allocated memory
dev | - Device to remove |
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
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 |
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
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 |
int ltc3337_set_counter_shutdown | ( | struct ltc3337_dev * | dev, |
uint8_t | shutdown_en | ||
) |
Sets the state of the coulomb counter shutdown function
dev | - Device to configure |
shutdown_en | - 1 - Enable shutdown, 0 - Coulomb counter running |
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
dev | - Pointer to the device instance |
prescale | - Prescaler value |
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
dev | - Device to configure |
hot_alarm | - Hot alarm threshold, in Degrees C |
cold_alarm | - Cold alarm threshold, in Degrees C |