no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ltc3337.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __LTC3337_H__
34#define __LTC3337_H__
35
36#include <stdint.h>
37#include "no_os_util.h"
38#include "no_os_i2c.h"
39
40#define LTC3337_I2C_ADDR 0x64 // b1100100[r/w] 0xC8, 0xC9
41
42#define LTC3337_MAX_TEMP_C 159 //Maximum temperature for alarms
43#define LTC3337_MIN_TEMP_C -41 //Minimum temperature for alarms
44#define LTC3337_MAX_PRESCALE 15 //Maximum prescaler value
45
46#define LTC3337_OVERFLOW_ALARM_MAX 0xFF //Max value for overflow alarm
47
48#define LTC3337_REG_A 0x01 //Prescaler Select, IRQ Clear, Shutdown, Alarm Thresh
49
50#define LTC3337_RA_PRESCALE_MSK NO_OS_GENMASK(3, 0)
51#define LTC3337_RA_CLEAR_INT NO_OS_BIT(4)
52#define LTC3337_RA_CNT_CHK NO_OS_BIT(5)
53#define LTC3337_RA_SHTDN NO_OS_BIT(6)
54#define LTC3337_RA_ADC_CONV NO_OS_BIT(7)
55#define LTC3337_RA_ALARM_LVL_MSK NO_OS_GENMASK(15, 8)
56
57#define LTC3337_REG_B 0x02 //Accumulated Charge
58
59#define LTC3337_REG_C 0x03 //Status, Temperature
60//Use the following definitions for derterming interrupt status
61#define LTC3337_RC_OVERFLOW NO_OS_BIT(0)
62#define LTC3337_RC_ALARM_TRIP NO_OS_BIT(1)
63#define LTC3337_RC_ALARM_MIN NO_OS_BIT(2)
64#define LTC3337_RC_ALARM_MAX NO_OS_BIT(3)
65#define LTC3337_RC_ADC_READY NO_OS_BIT(4)
66#define LTC3337_RC_IPK_PIN_MSK NO_OS_GENMASK(7, 5)
67#define LTC3337_RC_DIE_TEMP_MSK NO_OS_GENMASK(15, 8)
68
69#define LTC3337_REG_D 0x04 //BAT_IN V, Ipeak On
70#define LTC3337_REG_E 0x05 //BAT_IN V, Ipeak Off
71#define LTC3337_REG_F 0x06 //BAT_OUT V, Ipeak On
72#define LTC3337_REG_G 0x07 //BAT_OUT V, Ipeak Off
73#define LTC3337_BATV_MSK NO_OS_GENMASK(11, 0)
74
75#define LTC3337_REG_H 0x08 //Temp Alarm Config
76#define LTC3337_RH_HOT_ALARM_MSK NO_OS_GENMASK(15, 8)
77#define LTC3337_RH_COLD_ALARM_MSK NO_OS_GENMASK(7, 0)
78
79#define LTC3337_VLSB_UV 1465 //1.465 mV = 1465 uV
80#define LTC3337_TLSB_MC 784 //0.784 Deg C = 784 mC
81#define LTC3337_TEMP_MIN_C -41
82
83#define LTC3337_NUM_IPEAKS 8 //3-bit iPeak Input
84
85//Scale values used in integer match to calulate A/nA-hrs from counters
86#define LTC3337_NANO_AMP 1000000000
87#define LTC3337_CALC_SCALE 10000
88#define LTC3337_CALC_TO_WHOLE (LTC3337_NANO_AMP / LTC3337_CALC_SCALE)
89
90//Scale value for converting uV to mV
91#define LTC3337_UV_TO_MV_SCALE 1000
92
93//Scale Value for converting mC to Deg C
94#define LTC3337_MC_TO_C_SCALE 1000
95
102 struct no_os_i2c_desc *i2c_desc; //I2C device
103 uint8_t ipeak_latched; //iPeak value read at init
104 uint16_t latched_reg_a; //Latched Register A value
105};
106
111 struct no_os_i2c_init_param i2c_init; //I2C Configuration
112 uint8_t prescale; //Initial device prescaler value
113};
114
119 uint32_t a_hr; //A-hrs
120 uint32_t na_hr; //nA-hrs
121};
122
132
133/* Initializes the device instance */
134int ltc3337_init(struct ltc3337_dev** dev,
136
137/* Removes the device instance */
138int ltc3337_remove(struct ltc3337_dev* dev);
139
140/* Sets the device prescaler value */
141int ltc3337_set_prescaler(struct ltc3337_dev* dev, uint8_t prescale);
142
143/* Sets the temperature alarms, in Deg C */
144int ltc3337_set_temperature_alarms_c(struct ltc3337_dev* dev, int16_t hot_alarm,
145 int16_t cold_alarm);
146
147/* Enabled / Disables the Coulomb counter shutdown */
148int ltc3337_set_counter_shutdown(struct ltc3337_dev* dev, uint8_t shutdown_en);
149
150/* Sets the couloumb counter alarm threshold */
151int ltc3337_set_counter_alarm(struct ltc3337_dev* dev, uint16_t reg_value,
152 uint8_t round_up);
153
154/* Manually sets the accumulated charge register */
155int ltc3337_set_accumulated_charge(struct ltc3337_dev* dev, uint16_t reg_value,
156 uint8_t round_up);
157
158/* Gets the current value of the accumulated charge register */
160 struct charge_count_t* value,
161 uint16_t* raw_value);
162
163/* Reads the specified voltage source, in millivolts */
164int ltc3337_get_voltage_mv(struct ltc3337_dev* dev,
165 enum ltc3337_voltage_src_t source,
166 uint32_t* value);
167
168/* Gets the current die temperature, in Deg C */
169int ltc3337_get_temperature_c(struct ltc3337_dev* dev, int16_t* value);
170
171/* Gets the device interrupt status, and clears interrupts */
173 uint16_t* int_field,
174 int16_t* temp_c);
175
176/* Calculates a charge register value based on A-Hr units */
178 struct charge_count_t* charge_a,
179 uint16_t* reg_value);
180
181#endif
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int ltc3337_init(struct ltc3337_dev **dev, struct ltc3337_init_param *init_param)
Definition ltc3337.c:86
ltc3337_voltage_src_t
Definition ltc3337.h:126
@ BAT_OUT_IPEAK_OFF
Definition ltc3337.h:130
@ BAT_OUT_IPEAK_ON
Definition ltc3337.h:129
@ BAT_IN_IPEAK_ON
Definition ltc3337.h:127
@ BAT_IN_IPEAK_OFF
Definition ltc3337.h:128
int ltc3337_remove(struct ltc3337_dev *dev)
Definition ltc3337.c:132
int ltc3337_set_temperature_alarms_c(struct ltc3337_dev *dev, int16_t hot_alarm, int16_t cold_alarm)
Definition ltc3337.c:299
int ltc3337_set_counter_alarm(struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
Definition ltc3337.c:363
int ltc3337_get_and_clear_interrupts(struct ltc3337_dev *dev, uint16_t *int_field, int16_t *temp_c)
Definition ltc3337.c:441
int ltc3337_set_prescaler(struct ltc3337_dev *dev, uint8_t prescale)
Definition ltc3337.c:271
int ltc3337_set_counter_shutdown(struct ltc3337_dev *dev, uint8_t shutdown_en)
Definition ltc3337.c:327
int ltc3337_set_accumulated_charge(struct ltc3337_dev *dev, uint16_t reg_value, uint8_t round_up)
Definition ltc3337.c:407
int ltc3337_get_voltage_mv(struct ltc3337_dev *dev, enum ltc3337_voltage_src_t source, uint32_t *value)
Definition ltc3337.c:153
int ltc3337_calculate_charge_register(struct ltc3337_dev *dev, struct charge_count_t *charge_a, uint16_t *reg_value)
Definition ltc3337.c:479
int ltc3337_get_temperature_c(struct ltc3337_dev *dev, int16_t *value)
Definition ltc3337.c:199
int ltc3337_get_accumulated_charge(struct ltc3337_dev *dev, struct charge_count_t *value, uint16_t *raw_value)
Definition ltc3337.c:227
Header file of I2C Interface.
Header file of utility functions.
Definition ltc3337.h:118
uint32_t a_hr
Definition ltc3337.h:119
uint32_t na_hr
Definition ltc3337.h:120
Definition ltc3337.h:101
struct no_os_i2c_desc * i2c_desc
Definition ltc3337.h:102
uint16_t latched_reg_a
Definition ltc3337.h:104
uint8_t ipeak_latched
Definition ltc3337.h:103
Definition ltc3337.h:110
uint8_t prescale
Definition ltc3337.h:112
struct no_os_i2c_init_param i2c_init
Definition ltc3337.h:111
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52