42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
67#define CHARGER8_M5REG_STATUS 0x00
68#define CHARGER8_M5REG_VALRTTH 0x01
69#define CHARGER8_M5REG_TALRTTH 0x02
70#define CHARGER8_M5REG_SALRTTH 0x03
71#define CHARGER8_M5REG_ATRATE 0x04
72#define CHARGER8_M5REG_REP_CAP 0x05
73#define CHARGER8_M5REG_REP_SOC 0x06
74#define CHARGER8_M5REG_AGE 0x07
75#define CHARGER8_M5REG_TEMPERATURE 0x08
76#define CHARGER8_M5REG_VCELL 0x09
77#define CHARGER8_M5REG_CURRENT 0x0A
78#define CHARGER8_M5REG_AVE_CURRENT 0x0B
79#define CHARGER8_M5REG_QRESIDUAL 0x0C
80#define CHARGER8_M5REG_MIX_SOC 0x0D
81#define CHARGER8_M5REG_AV_SOC 0x0E
82#define CHARGER8_M5REG_MIX_CAP 0x0F
83#define CHARGER8_M5REG_FULL_CAP 0x10
84#define CHARGER8_M5REG_TIME_TO_EMPTY 0x11
85#define CHARGER8_M5REG_QRTABLE00 0x12
86#define CHARGER8_M5REG_FULL_SOC_THR 0x13
87#define CHARGER8_M5REG_RCALL 0x14
88#define CHARGER8_M5REG_RFAST 0x15
89#define CHARGER8_M5REG_AVG_TA 0x16
90#define CHARGER8_M5REG_BATTERY_CYCLES 0x17
91#define CHARGER8_M5REG_DESIGN_CAP 0x18
92#define CHARGER8_M5REG_AVG_VCALL 0x19
93#define CHARGER8_M5REG_MAX_MIN_TEMP 0x1A
94#define CHARGER8_M5REG_MAX_MIN_VOLT 0x1B
95#define CHARGER8_M5REG_MAX_MIN_CURRENT 0x1C
96#define CHARGER8_M5REG_CONFIG 0x1D
97#define CHARGER8_M5REG_ICHGTERM 0x1E
98#define CHARGER8_M5REG_AV_CAP 0x1F
99#define CHARGER8_M5REG_TIME_TO_FULL 0x20
100#define CHARGER8_M5REG_DEVICE_NAME 0x21
101#define CHARGER8_M5REG_QRTABLE10 0x22
102#define CHARGER8_M5REG_FULL_CAP_NOM 0x23
103#define CHARGER8_M5REG_AIN0 0x27
104#define CHARGER8_M5REG_LEARN_CFG 0x28
105#define CHARGER8_M5REG_FILTER_CFG 0x29
106#define CHARGER8_M5REG_RELAX_CFG 0x2A
107#define CHARGER8_M5REG_MISC_CFG 0x2B
108#define CHARGER8_M5REG_T_GAIN 0x2C
109#define CHARGER8_M5REG_T_OFF 0x2D
110#define CHARGER8_M5REG_C_GAIN 0x2E
111#define CHARGER8_M5REG_C_OFF 0x2F
112#define CHARGER8_M5REG_QRTABLE20 0x32
113#define CHARGER8_M5REG_FULL_CAP_REP 0x35
114#define CHARGER8_M5REG_IAVG_EMPTY 0x36
115#define CHARGER8_M5REG_RCOMP0 0x38
116#define CHARGER8_M5REG_TEMPCO 0x39
117#define CHARGER8_M5REG_V_EMPTY 0x3A
118#define CHARGER8_M5REG_FSTAT 0x3D
119#define CHARGER8_M5REG_TIMER 0x3E
120#define CHARGER8_M5REG_SHDN_TIMER 0x3F
121#define CHARGER8_M5REG_QRTABLE30 0x42
122#define CHARGER8_M5REG_DQACC 0x45
123#define CHARGER8_M5REG_DPACC 0x46
124#define CHARGER8_M5REG_VF_REM_CAP 0x4A
125#define CHARGER8_M5REG_QH 0x4D
126#define CHARGER8_M5REG_STATUS_2 0xB0
127#define CHARGER8_M5REG_IALRTTH 0xB4
128#define CHARGER8_M5REG_VSHDN_CFG 0xB8
129#define CHARGER8_M5REG_AGE_FORECAST 0xB9
130#define CHARGER8_M5REG_HIB_CFG 0xBA
131#define CHARGER8_M5REG_CONFIG_2 0xBB
132#define CHARGER8_M5REG_VRIPPLE 0xBC
133#define CHARGER8_M5REG_PACK_CFG 0xBD
134#define CHARGER8_M5REG_TIMER_H 0xBE
135#define CHARGER8_M5REG_AVG_CELL_4 0xD1
136#define CHARGER8_M5REG_AVG_CELL_3 0xD2
137#define CHARGER8_M5REG_AVG_CELL_2 0xD3
138#define CHARGER8_M5REG_AVG_CELL_1 0xD4
139#define CHARGER8_M5REG_CELL_4 0xD5
140#define CHARGER8_M5REG_CELL_3 0xD6
141#define CHARGER8_M5REG_CELL_2 0xD7
142#define CHARGER8_M5REG_CELL_1 0xD8
143#define CHARGER8_M5REG_CELL_X 0xD9
144#define CHARGER8_M5REG_BATTERY_VOLTAGE 0xDA
145#define CHARGER8_M5REG_ATQ_RESIDUAL 0xDC
146#define CHARGER8_M5REG_AT_TTE 0xDD
147#define CHARGER8_M5REG_ATAV_SOC 0xDE
148#define CHARGER8_M5REG_ATAV_CAP 0xDF
155#define CHARGER8_NVREG_X_TABLE0 0x80
156#define CHARGER8_NVREG_X_TABLE1 0x81
157#define CHARGER8_NVREG_X_TABLE2 0x82
158#define CHARGER8_NVREG_X_TABLE3 0x83
159#define CHARGER8_NVREG_X_TABLE4 0x84
160#define CHARGER8_NVREG_X_TABLE5 0x85
161#define CHARGER8_NVREG_X_TABLE6 0x86
162#define CHARGER8_NVREG_X_TABLE7 0x87
163#define CHARGER8_NVREG_X_TABLE8 0x88
164#define CHARGER8_NVREG_X_TABLE9 0x89
165#define CHARGER8_NVREG_X_TABLE10 0x8A
166#define CHARGER8_NVREG_X_TABLE11 0x8B
167#define CHARGER8_NVREG_USER_18C 0x8C
168#define CHARGER8_NVREG_USER_18D 0x8D
169#define CHARGER8_NVREG_ODSCTH 0x8E
170#define CHARGER8_NVREG_ODSCCFG 0x8F
171#define CHARGER8_NVREG_OCV_TABLE0 0x90
172#define CHARGER8_NVREG_OCV_TABLE1 0x91
173#define CHARGER8_NVREG_OCV_TABLE2 0x92
174#define CHARGER8_NVREG_OCV_TABLE3 0x93
175#define CHARGER8_NVREG_OCV_TABLE4 0x94
176#define CHARGER8_NVREG_OCV_TABLE5 0x95
177#define CHARGER8_NVREG_OCV_TABLE6 0x96
178#define CHARGER8_NVREG_OCV_TABLE7 0x97
179#define CHARGER8_NVREG_OCV_TABLE8 0x98
180#define CHARGER8_NVREG_OCV_TABLE9 0x99
181#define CHARGER8_NVREG_OCV_TABLE10 0x9A
182#define CHARGER8_NVREG_OCV_TABLE11 0x9B
183#define CHARGER8_NVREG_ICHG_TERM 0x9C
184#define CHARGER8_NVREG_FILTER_CFG 0x9D
185#define CHARGER8_NVREG_V_EMPTY 0x9E
186#define CHARGER8_NVREG_LEARN_CFG 0x9F
187#define CHARGER8_NVREG_QR_TABLE00 0xA0
188#define CHARGER8_NVREG_QR_TABLE10 0xA1
189#define CHARGER8_NVREG_QR_TABLE20 0xA2
190#define CHARGER8_NVREG_QR_TABLE30 0xA3
191#define CHARGER8_NVREG_CYCLES 0xA4
192#define CHARGER8_NVREG_FULL_CAP_NOM 0xA5
193#define CHARGER8_NVREG_R_COMP_0 0xA6
194#define CHARGER8_NVREG_TEMP_CO 0xA7
195#define CHARGER8_NVREG_IAVG_EMPTY 0xA8
196#define CHARGER8_NVREG_FULL_CAP_REP 0xA9
197#define CHARGER8_NVREG_VOLT_TEMP 0xAA
198#define CHARGER8_NVREG_MIN_MAX_CURRENT 0xAB
199#define CHARGER8_NVREG_MIN_MAX_VOLT 0xAC
200#define CHARGER8_NVREG_MIN_MAX_TEMP 0xAD
201#define CHARGER8_NVREG_SOC 0xAE
202#define CHARGER8_NVREG_TIMER_H 0xAF
203#define CHARGER8_NVREG_CONFIG 0xB0
204#define CHARGER8_NVREG_RIPPLE_CFG 0xB1
205#define CHARGER8_NVREG_MISC_CFG 0xB2
206#define CHARGER8_NVREG_DESIGN_CFG 0xB3
207#define CHARGER8_NVREG_HIB_CFG 0xB4
208#define CHARGER8_NVREG_PACK_CFG 0xB5
209#define CHARGER8_NVREG_RELAX_CFG 0xB6
210#define CHARGER8_NVREG_CONVG_CFG 0xB7
211#define CHARGER8_NVREG_NV_CONFIG_0 0xB8
212#define CHARGER8_NVREG_NV_CONFIG_1 0xB9
213#define CHARGER8_NVREG_NV_CONFIG_2 0xBA
214#define CHARGER8_NVREG_SBS_CFG 0xBB
215#define CHARGER8_NVREG_ROM_ID_0 0xBC
216#define CHARGER8_NVREG_ROM_ID_1 0xBD
217#define CHARGER8_NVREG_ROM_ID_2 0xBE
218#define CHARGER8_NVREG_ROM_ID_3 0xBF
219#define CHARGER8_NVREG_V_ALRT_TH 0xC0
220#define CHARGER8_NVREG_T_ALRT_TH 0xC1
221#define CHARGER8_NVREG_S_ALRT_TH 0xC2
222#define CHARGER8_NVREG_I_ALRT_TH 0xC3
223#define CHARGER8_NVREG_USER_1C4 0xC4
224#define CHARGER8_NVREG_USER_1C5 0xC5
225#define CHARGER8_NVREG_FULL_SOC_THR 0xC6
226#define CHARGER8_NVREG_TTF_CFG 0xC7
227#define CHARGER8_NVREG_C_GAIN 0xC8
228#define CHARGER8_NVREG_T_CURVE 0xC9
229#define CHARGER8_NVREG_T_GAIN 0xCA
230#define CHARGER8_NVREG_T_OFF 0xCB
231#define CHARGER8_NVREG_MANIFCTURE_NAME_0 0xCC
232#define CHARGER8_NVREG_MANIFCTURE_NAME_1 0xCD
233#define CHARGER8_NVREG_MANIFCTURE_NAME_2 0xCE
234#define CHARGER8_NVREG_R_SENSE 0xCF
235#define CHARGER8_NVREG_USER_1D0 0xD0
236#define CHARGER8_NVREG_USER_1D1 0xD1
237#define CHARGER8_NVREG_AGE_FC_CFG 0xD2
238#define CHARGER8_NVREG_DESIGN_VOLTAGE 0xD3
239#define CHARGER8_NVREG_USER_1D4 0xD4
240#define CHARGER8_NVREG_R_FAST_V_SHDN 0xD5
241#define CHARGER8_NVREG_MANIFACTURE_DATE 0xD6
242#define CHARGER8_NVREG_FIRST_USED 0xD7
243#define CHARGER8_NVREG_SERIAL_NUMBER_0 0xD8
244#define CHARGER8_NVREG_SERIAL_NUMBER_1 0xD9
245#define CHARGER8_NVREG_SERIAL_NUMBER_2 0xDA
246#define CHARGER8_NVREG_DEVICE_NUMBER_0 0xDB
247#define CHARGER8_NVREG_DEVICE_NUMBER_1 0xDC
248#define CHARGER8_NVREG_DEVICE_NUMBER_2 0xDD
249#define CHARGER8_NVREG_DEVICE_NUMBER_3 0xDE
250#define CHARGER8_NVREG_DEVICE_NUMBER_4 0xDF
257#define CHARGER8_COMMAND 0x60
258#define CHARGER8_CMD_COPY_NV_BLOCK_MSB 0xE9
259#define CHARGER8_CMD_NV_RECALL_MSB 0xE0
260#define CHARGER8_CMD_NV_RECALL_LSB 0x01
267#define CHARGER8_CHARGER_ENABLE 0x00
268#define CHARGER8_CHARGER_DISABLE 0x01
275#define CHARGER8_ALERT_ENABLE 0x01
276#define CHARGER8_ALERT_DISABLE 0x00
282#define CHARGER8_USB_SUSPAND_MODE_ENABLE 0x01
283#define CHARGER8_USB_SUSPAND_MODE_DISABLE 0x00
290#define CHARGER8_DEVICE_SLAVE_ADDRESS 0x36
291#define CHARGER8_DEVICE_NV_SLAVE_ADDRESS 0x0B
298#define CHARGER8_MAP_MIKROBUS( cfg, mikrobus ) \
299 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
300 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
301 cfg.dok = MIKROBUS( mikrobus, MIKROBUS_AN ); \
302 cfg.alt = MIKROBUS( mikrobus, MIKROBUS_RST ); \
303 cfg.us = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
304 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT );
311#define CHARGER8_RETVAL uint8_t
313#define CHARGER8_OK 0x00
314#define CHARGER8_INIT_ERROR 0xFF
#define CHARGER8_RETVAL
Definition charger8.h:311
void charger8_set_max_battery_capacity(charger8_t *ctx, uint16_t capacity)
Function for set Max battery capacity in [mAh].
CHARGER8_RETVAL charger8_init(charger8_t *ctx, charger8_cfg_t *cfg)
Initialization function.
uint8_t charger8_get_fault_output(charger8_t *ctx)
Function for reads FAULT pin state.
void charger8_enable(charger8_t *ctx, uint8_t enable)
Functions for enable or disable device.
uint16_t charger8_generic_read(charger8_t *ctx, uint8_t reg)
Generic read function.
void charger8_reset(charger8_t *ctx)
General reset procedure.
uint16_t charger8_get_status(charger8_t *ctx)
Function for reads the Status register.
void charger8_default_cfg(charger8_t *ctx)
Click Default Configuration function.
void charger8_generic_write(charger8_t *ctx, uint8_t reg, uint16_t data_wr)
Generic write function.
float charger8_get_time_to_empty(charger8_t *ctx)
Function for reads the Time to Empty data.
void charger8_set_alert(charger8_t *ctx, uint8_t state)
Function for set Alert pin state.
uint8_t charger8_get_soc(charger8_t *ctx)
Function for reads the percentage of the battery charge.
float charger8_get_time_to_full(charger8_t *ctx)
Function for reads the Time to Full data.
float charger8_get_voltage(charger8_t *ctx)
Functions for reading the voltage of the battery.
float charger8_get_temperature(charger8_t *ctx)
Functions for read Temperature of the chip.
void charger8_cfg_setup(charger8_cfg_t *cfg)
Config Object Initialization function.
float charger8_get_current(charger8_t *ctx)
Functions for reading the current charging battery.
uint16_t charger8_get_capacity(charger8_t *ctx)
Function for reads the current capacity of the battery.
void charger8_set_usb_suspend(charger8_t *ctx, uint8_t mode)
Function for set USB Suspand pin.
uint8_t charger8_get_dc_power_ok(charger8_t *ctx)
Function for reads DC power pin state.
Click configuration structure definition.
Definition charger8.h:356
pin_name_t alt
Definition charger8.h:365
uint32_t i2c_speed
Definition charger8.h:372
pin_name_t us
Definition charger8.h:367
pin_name_t dok
Definition charger8.h:364
uint8_t i2c_nv_address
Definition charger8.h:374
pin_name_t flt
Definition charger8.h:368
pin_name_t scl
Definition charger8.h:359
pin_name_t en
Definition charger8.h:366
pin_name_t sda
Definition charger8.h:360
uint8_t i2c_address
Definition charger8.h:373
Click ctx object definition.
Definition charger8.h:328
digital_in_t flt
Definition charger8.h:338
i2c_master_t i2c
Definition charger8.h:342
digital_out_t alt
Definition charger8.h:332
digital_out_t us
Definition charger8.h:334
digital_out_t en
Definition charger8.h:333
uint8_t slave_address
Definition charger8.h:346
digital_out_t dok
Definition charger8.h:331
uint16_t max_bat_capacity
Definition charger8.h:348
uint8_t nv_slave_address
Definition charger8.h:347