39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
73#define BATTMON2_REG_STATUS 0x00
74#define BATTMON2_REG_V_ALRT_TH 0x01
75#define BATTMON2_REG_T_ALRT_TH 0x02
76#define BATTMON2_REG_S_ALRT_TH 0x03
77#define BATTMON2_REG_AT_RATE 0x04
78#define BATTMON2_REG_REP_CAP 0x05
79#define BATTMON2_REG_REP_SOC 0x06
80#define BATTMON2_REG_AGE 0x07
81#define BATTMON2_REG_TEMP 0x08
82#define BATTMON2_REG_V_CELL 0x09
83#define BATTMON2_REG_CURRENT 0x0A
84#define BATTMON2_REG_AVG_CURRENT 0x0B
85#define BATTMON2_REG_Q_RESIDUAL 0x0C
86#define BATTMON2_REG_MIX_SOC 0x0D
87#define BATTMON2_REG_AV_SOC 0x0E
88#define BATTMON2_REG_MIX_CAP 0x0F
89#define BATTMON2_REG_FULL_CAP_REP 0x10
90#define BATTMON2_REG_TTE 0x11
91#define BATTMON2_REG_QR_TABLE_00 0x12
92#define BATTMON2_REG_FULL_SOC_THR 0x13
93#define BATTMON2_REG_R_CELL 0x14
94#define BATTMON2_REG_AVG_TA 0x16
95#define BATTMON2_REG_CYCLES 0x17
96#define BATTMON2_REG_DESIGN_CAP 0x18
97#define BATTMON2_REG_AVG_V_CELL 0x19
98#define BATTMON2_REG_MAX_MIN_TEMP 0x1A
99#define BATTMON2_REG_MAX_MIN_VOLT 0x1B
100#define BATTMON2_REG_MAX_MIN_CURR 0x1C
101#define BATTMON2_REG_CONFIG 0x1D
102#define BATTMON2_REG_I_CHG_TERM 0x1E
103#define BATTMON2_REG_AV_CAP 0x1F
104#define BATTMON2_REG_TTF 0x20
105#define BATTMON2_REG_DEV_NAME 0x21
106#define BATTMON2_REG_QR_TABLE_10 0x22
107#define BATTMON2_REG_FULL_CAP_NOM 0x23
108#define BATTMON2_REG_AIN 0x27
109#define BATTMON2_REG_LEARN_CFG 0x28
110#define BATTMON2_REG_FILTER_CFG 0x29
111#define BATTMON2_REG_RELAX_CFG 0x2A
112#define BATTMON2_REG_MISC_CFG 0x2B
113#define BATTMON2_REG_T_GAIN 0x2C
114#define BATTMON2_REG_T_OFF 0x2D
115#define BATTMON2_REG_C_GAIN 0x2E
116#define BATTMON2_REG_C_OFF 0x2F
117#define BATTMON2_REG_QR_TABLE_20 0x32
118#define BATTMON2_REG_DIE_TEMP 0x34
119#define BATTMON2_REG_FULL_CAP 0x35
120#define BATTMON2_REG_R_COMP_0 0x38
121#define BATTMON2_REG_TEMP_CO 0x39
122#define BATTMON2_REG_V_EMPTY 0x3A
123#define BATTMON2_REG_F_STAT 0x3D
124#define BATTMON2_REG_TIMER 0x3E
125#define BATTMON2_REG_SHDN_TIMER 0x3F
126#define BATTMON2_REG_QR_TABLE_30 0x42
127#define BATTMON2_REG_R_GAIN 0x43
128#define BATTMON2_REG_DQ_ACC 0x45
129#define BATTMON2_REG_DP_ACC 0x46
130#define BATTMON2_REG_CONVG_CFG 0x49
131#define BATTMON2_REG_V_F_REM_CAP 0x4A
132#define BATTMON2_REG_QH 0x4D
133#define BATTMON2_REG_SOFT_WAKEUP 0x60
134#define BATTMON2_REG_STATUS_2 0xB0
135#define BATTMON2_REG_POWER 0xB1
136#define BATTMON2_REG_ID_USER_MEM_2 0xB2
137#define BATTMON2_REG_AVG_POWER 0xB3
138#define BATTMON2_REG_I_ALRT_TH 0xB4
139#define BATTMON2_REG_TTF_CFG 0xB5
140#define BATTMON2_REG_C_V_MIX_CAP 0xB6
141#define BATTMON2_REG_C_V_HALF_TIME 0xB7
142#define BATTMON2_REG_C_G_TEMP_CO 0xB8
143#define BATTMON2_REG_CURVE 0xB9
144#define BATTMON2_REG_HIB_CFG 0xBA
145#define BATTMON2_REG_CONFIG_2 0xBB
146#define BATTMON2_REG_V_RIPPLE 0xBC
147#define BATTMON2_REG_RIPPLE_CFG 0xBD
148#define BATTMON2_REG_TIMER_H 0xBE
149#define BATTMON2_REG_R_SENSE_USER_MEM_3 0xD0
150#define BATTMON2_REG_SC_OCV_LIM 0xD1
151#define BATTMON2_REG_V_GAIN 0xD2
152#define BATTMON2_REG_SOC_HOLD 0xD3
153#define BATTMON2_REG_MAX_PEAK_POWER 0xD4
154#define BATTMON2_REG_SUS_PEAK_POWER 0xD5
155#define BATTMON2_REG_PACK_RESISTANCE 0xD6
156#define BATTMON2_REG_SYS_RESISTANCE 0xD7
157#define BATTMON2_REG_MIN_SYS_VOLTAGE 0xD8
158#define BATTMON2_REG_MPP_CURRENT 0xD9
159#define BATTMON2_REG_SPP_CURRENT 0xDA
160#define BATTMON2_REG_MODEL_CFG 0xDB
161#define BATTMON2_REG_AT_Q_RESIDUAL 0xDC
162#define BATTMON2_REG_AT_TTE 0xDD
163#define BATTMON2_REG_AT_AV_SOC 0xDE
164#define BATTMON2_REG_AT_AV_CAP 0xDF
182#define BATTMON2_CAPACITY_RESOLUTION 0.5
183#define BATTMON2_PERCENTAGE_RESOLUTION ( 1.0 / 256.0 )
184#define BATTMON2_VOLTAGE_RESOLUTION ( 1.25 / 16.0 )
185#define BATTMON2_CURRENT_RESOLUTION 0.15625
186#define BATTMON2_TEMPERATURE_RESOLUTION ( 1.0 / 256.0 )
187#define BATTMON2_TIME_RESOLUTION 5.625
193#define BATTMON2_DEVICE_ID 0x4039
200#define BATTMON2_SET_DEV_ADDR 0x36
218#define BATTMON2_MAP_MIKROBUS( cfg, mikrobus ) \
219 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
220 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
221 cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
battmon2_return_value_t
BATT-MON 2 Click return value data.
Definition battmon2.h:264
@ BATTMON2_OK
Definition battmon2.h:265
@ BATTMON2_ERROR
Definition battmon2.h:266
err_t battmon2_generic_read(battmon2_t *ctx, uint8_t reg, uint16_t *rx_buf, uint8_t rx_len)
BATT-MON 2 I2C reading function.
void battmon2_cfg_setup(battmon2_cfg_t *cfg)
BATT-MON 2 configuration object setup function.
err_t battmon2_get_battery_percentage(battmon2_t *ctx, float *percentage)
BATT-MON 2 get battery percentage function.
err_t battmon2_get_battery_voltage(battmon2_t *ctx, float *voltage)
BATT-MON 2 get battery voltage function.
err_t battmon2_get_die_temperature(battmon2_t *ctx, float *temperature)
BATT-MON 2 get die temperature function.
err_t battmon2_get_battery_current(battmon2_t *ctx, float *current)
BATT-MON 2 get battery current function.
err_t battmon2_get_battery_capacity(battmon2_t *ctx, float *capacity)
BATT-MON 2 get battery capacity function.
uint8_t battmon2_get_alert_pin(battmon2_t *ctx)
BATT-MON 2 get alert pin function.
err_t battmon2_generic_write(battmon2_t *ctx, uint8_t reg, uint16_t *tx_buf, uint8_t tx_len)
BATT-MON 2 I2C writing function.
err_t battmon2_write_register(battmon2_t *ctx, uint8_t reg, uint16_t data_in)
BATT-MON 2 write register function.
err_t battmon2_read_register(battmon2_t *ctx, uint8_t reg, uint16_t *data_out)
BATT-MON 2 read register function.
err_t battmon2_check_communication(battmon2_t *ctx)
BATT-MON 2 check communication function.
err_t battmon2_get_battery_ttf(battmon2_t *ctx, uint32_t *time_to_full)
BATT-MON 2 get battery ttf function.
err_t battmon2_get_battery_tte(battmon2_t *ctx, uint32_t *time_to_empty)
BATT-MON 2 get battery tte function.
err_t battmon2_init(battmon2_t *ctx, battmon2_cfg_t *cfg)
BATT-MON 2 initialization function.
BATT-MON 2 Click configuration object.
Definition battmon2.h:248
pin_name_t alert
Definition battmon2.h:252
uint32_t i2c_speed
Definition battmon2.h:254
pin_name_t scl
Definition battmon2.h:249
pin_name_t sda
Definition battmon2.h:250
uint8_t i2c_address
Definition battmon2.h:255
BATT-MON 2 Click context object.
Definition battmon2.h:231
digital_in_t alert
Definition battmon2.h:233
i2c_master_t i2c
Definition battmon2.h:236
uint8_t slave_address
Definition battmon2.h:239