charger25 2.1.0.0
charger25.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef CHARGER25_H
29#define CHARGER25_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define CHARGER25_REG_MINIMAL_SYSTEM_VOLTAGE 0x00
74#define CHARGER25_REG_CHARGE_VOLTAGE_LIMIT 0x01
75#define CHARGER25_REG_CHARGE_CURRENT_LIMIT 0x03
76#define CHARGER25_REG_INPUT_VOLTAGE_LIMIT 0x05
77#define CHARGER25_REG_INPUT_CURRENT_LIMIT 0x06
78#define CHARGER25_REG_PRECHARGE_CONTROL 0x08
79#define CHARGER25_REG_TERMINATION_CONTROL 0x09
80#define CHARGER25_REG_RECHARGE_CONTROL 0x0A
81#define CHARGER25_REG_VOTG_REGULATION 0x0B
82#define CHARGER25_REG_IOTG_REGULATION 0x0D
83#define CHARGER25_REG_TIMER_CONTROL 0x0E
84#define CHARGER25_REG_CHARGER_CONTROL_0 0x0F
85#define CHARGER25_REG_CHARGER_CONTROL_1 0x10
86#define CHARGER25_REG_CHARGER_CONTROL_2 0x11
87#define CHARGER25_REG_CHARGER_CONTROL_3 0x12
88#define CHARGER25_REG_CHARGER_CONTROL_4 0x13
89#define CHARGER25_REG_CHARGER_CONTROL_5 0x14
90#define CHARGER25_REG_RESERVED 0x15
91#define CHARGER25_REG_TEMPERATURE_CONTROL 0x16
92#define CHARGER25_REG_NTC_CONTROL_0 0x17
93#define CHARGER25_REG_NTC_CONTROL_1 0x18
94#define CHARGER25_REG_ICO_CURRENT_LIMIT 0x19
95#define CHARGER25_REG_CHARGER_STATUS_0 0x1B
96#define CHARGER25_REG_CHARGER_STATUS_1 0x1C
97#define CHARGER25_REG_CHARGER_STATUS_2 0x1D
98#define CHARGER25_REG_CHARGER_STATUS_3 0x1E
99#define CHARGER25_REG_CHARGER_STATUS_4 0x1F
100#define CHARGER25_REG_FAULT_STATUS_0 0x20
101#define CHARGER25_REG_FAULT_STATUS_1 0x21
102#define CHARGER25_REG_CHARGER_FLAG_0 0x22
103#define CHARGER25_REG_CHARGER_FLAG_1 0x23
104#define CHARGER25_REG_CHARGER_FLAG_2 0x24
105#define CHARGER25_REG_CHARGER_FLAG_3 0x25
106#define CHARGER25_REG_FAULT_FLAG_0 0x26
107#define CHARGER25_REG_FAULT_FLAG_1 0x27
108#define CHARGER25_REG_CHARGER_MASK_0 0x28
109#define CHARGER25_REG_CHARGER_MASK_1 0x29
110#define CHARGER25_REG_CHARGER_MASK_2 0x2A
111#define CHARGER25_REG_CHARGER_MASK_3 0x2B
112#define CHARGER25_REG_FAULT_MASK_0 0x2C
113#define CHARGER25_REG_FAULT_MASK_1 0x2D
114#define CHARGER25_REG_ADC_CONTROL 0x2E
115#define CHARGER25_REG_ADC_FUNCTION_DISABLE_0 0x2F
116#define CHARGER25_REG_ADC_FUNCTION_DISABLE_1 0x30
117#define CHARGER25_REG_IBUS_ADC 0x31
118#define CHARGER25_REG_IBAT_ADC 0x33
119#define CHARGER25_REG_VBUS_ADC 0x35
120#define CHARGER25_REG_VAC1_ADC 0x37
121#define CHARGER25_REG_VAC2_ADC 0x39
122#define CHARGER25_REG_VBAT_ADC 0x3B
123#define CHARGER25_REG_VSYS_ADC 0x3D
124#define CHARGER25_REG_TS_ADC 0x3F
125#define CHARGER25_REG_TDIE_ADC 0x41
126#define CHARGER25_REG_D_P_ADC 0x43
127#define CHARGER25_REG_D_M_ADC 0x45
128#define CHARGER25_REG_DPDM_DRIVER 0x47
129#define CHARGER25_REG_PART_INFORMATION 0x48
130
131 // charger25_reg
132
147#define CHARGER25_SOFT_RESET 0x40
148
153#define CHARGER25_VSYS_MIN_BIT_MASK 0x3F
154#define CHARGER25_VSYS_MIN_STEP_SIZE 250
155#define CHARGER25_VSYS_MIN_FIXED_OFFSET 2500
156
161#define CHARGER25_VTG_LIM_MSB_BIT_MASK 0x07
162#define CHARGER25_VTG_CONV_V_MV 10
163#define CHARGER25_VTG_CELL_COUNT_DIV 3
164#define CHARGER25_VTG_CELL_SEL_1 1
165#define CHARGER25_VTG_CELL_SEL_2 2
166#define CHARGER25_VTG_CELL_SEL_3 3
167#define CHARGER25_VTG_CELL_SEL_4 4
168#define CHARGER25_VTG_CELL_COUNT_MIN 1
169#define CHARGER25_VTG_CELL_COUNT_MAX 4
170#define CHARGER25_VTG_CELL_COUNT_MUL 7
171
176#define CHARGER25_CURR_LIM_MSB_BIT_MASK 0x01
177#define CHARGER25_CURR_CONV_A_MA 10
178
183#define CHARGER25_INPUT_VTG_CONV_V_MV 100
184
189#define CHARGER25_SET_ADC_FUNC_ENABLE 0x00
190#define CHARGER25_SET_ADC_FUNC_DISABLE 0x01
191#define CHARGER25_SET_ADC_CTRL_DISABLE 0x00
192#define CHARGER25_SET_ADC_CTRL_ENABLE 0x01
193
198#define CHARGER25_SET_ADC_RATE_CONT_CNV 0x00
199#define CHARGER25_SET_ADC_ONES_HOT_CNV 0x01
200#define CHARGER25_SET_ADC_SAMPLE_15_BIT 0x00
201#define CHARGER25_SET_ADC_SAMPLE_14_BIT 0x01
202#define CHARGER25_SET_ADC_SAMPLE_13_BIT 0x02
203#define CHARGER25_SET_ADC_SAMPLE_12_BIT 0x03
204
209#define CHARGER25_SET_ADC_AVG_SINGLE_VAL 0x00
210#define CHARGER25_SET_ADC_AVG_RUN_AVG 0x01
211#define CHARGER25_SET_ADC_AVG_INIT_EXI_VAL 0x00
212#define CHARGER25_SET_ADC_AVG_INIT_ADC_CNV 0x01
213
218#define CHARGER25_CH_STAT_NOT_CHARGING 0x00
219#define CHARGER25_CH_STAT_TRICKLE_CHARGE 0x01
220#define CHARGER25_CH_STAT_PRE_CHARGE 0x02
221#define CHARGER25_CH_STAT_FAST_CHARGE 0x03
222#define CHARGER25_CH_STAT_TAPER_CHARGE 0x04
223#define CHARGER25_CH_STAT_TIMER_ACT_CHARGING 0x06
224#define CHARGER25_CH_STAT_CHARGE_TERMIN_DONE 0x07
225
230#define CHARGER25_STATE_PIN_QON_LOW 0x00
231#define CHARGER25_STATE_PIN_QON_HIGH 0x01
232
238#define CHARGER25_DEVICE_ADDRESS 0x6B
239
240 // charger25_set
241
256#define CHARGER25_MAP_MIKROBUS( cfg, mikrobus ) \
257 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
258 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
259 cfg.qon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
260 cfg.ce = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
261 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
262
263 // charger25_map
264 // charger25
265
270typedef struct
271{
272 // Output pins
273 digital_out_t qon;
274 digital_out_t ce;
276 // Input pins
277 digital_in_t int_pin;
279 // Modules
280 i2c_master_t i2c;
282 // I2C slave address
286
291typedef struct
292{
293 pin_name_t scl;
294 pin_name_t sda;
296 pin_name_t qon;
297 pin_name_t ce;
298 pin_name_t int_pin;
300 uint32_t i2c_speed;
301 uint8_t i2c_address;
304
309typedef struct
310{
311 uint8_t iindpm_stat;
312 uint8_t vindpm_stat;
313 uint8_t wd_stat;
314 uint8_t poorsrc_stat;
315 uint8_t pg_stat;
319 uint8_t chg_stat;
320 uint8_t vbus_stat;
321 uint8_t bc1_2_done;
322 uint8_t ico_stat;
323 uint8_t treg_stat;
324 uint8_t dpdm_stat;
326 uint8_t acrb2_stat;
327 uint8_t acrb1_stat;
329 uint8_t vsys_stat;
330 uint8_t chg_tmr_stat;
334 uint8_t ts_cold_stat;
335 uint8_t ts_cool_stat;
336 uint8_t ts_warm_stat;
337 uint8_t ts_hot_stat;
340
345typedef struct
346{
347 uint8_t adc_en;
348 uint8_t adc_rate;
349 uint8_t adc_sample;
350 uint8_t adc_avg;
351 uint8_t adc_avg_init;
354
359typedef struct
360{
361 uint8_t ibus_adc_dis;
362 uint8_t ibat_adc_dis;
363 uint8_t vbus_adc_dis;
364 uint8_t vbat_adc_dis;
365 uint8_t vsys_adc_dis;
366 uint8_t ts_adc_dis;
367 uint8_t tdie_adc_dis;
368 uint8_t dp_adc_dis;
369 uint8_t dm_adc_dis;
370 uint8_t vac2_adc_dis;
371 uint8_t vac1_adc_dis;
374
385
386
387
404
419
433
448err_t charger25_generic_write ( charger25_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
449
464err_t charger25_generic_read ( charger25_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
465
479void charger25_set_qon_pin ( charger25_t *ctx, uint8_t state );
480
493
506
520
535
550err_t charger25_get_vbat ( charger25_t *ctx, uint16_t *vbat );
551
566err_t charger25_get_vsys_min ( charger25_t *ctx, uint16_t *vsys_min );
567
584
601
616err_t charger25_get_vbat_lim ( charger25_t *ctx, uint16_t *vtg_lim );
617
636err_t charger25_set_vbat_lim ( charger25_t *ctx, uint16_t vtg_lim );
637
656err_t charger25_get_cell_count ( charger25_t *ctx, uint8_t *cell_count );
657
676err_t charger25_set_cell_count ( charger25_t *ctx, uint8_t cell_count );
677
692err_t charger25_get_current_limit ( charger25_t *ctx, uint16_t *current_lim );
693
708err_t charger25_set_current_limit ( charger25_t *ctx, uint16_t current_lim );
709
724err_t charger25_get_input_vtg_limit ( charger25_t *ctx, uint16_t *input_vtg_limit );
725
740err_t charger25_set_input_vtg_limit ( charger25_t *ctx, uint16_t input_vtg_limit );
741
756err_t charger25_get_input_curr_limit ( charger25_t *ctx, uint16_t *input_curr_limit );
757
772err_t charger25_set_input_curr_limit ( charger25_t *ctx, uint16_t input_curr_limit );
773
790
791#ifdef __cplusplus
792}
793#endif
794#endif // CHARGER25_H
795
796 // charger25
797
798// ------------------------------------------------------------------------ END
charger25_return_value_t
Charger 25 Click return value data.
Definition charger25.h:380
@ CHARGER25_ERROR
Definition charger25.h:382
@ CHARGER25_OK
Definition charger25.h:381
void charger25_set_qon_pin(charger25_t *ctx, uint8_t state)
Charger 25 set QON pin state function.
err_t charger25_get_vsys_min(charger25_t *ctx, uint16_t *vsys_min)
Charger 25 get VSYS function.
err_t charger25_set_input_curr_limit(charger25_t *ctx, uint16_t input_curr_limit)
Charger 25 set input current limit function.
err_t charger25_set_cell_count(charger25_t *ctx, uint8_t cell_count)
Charger 25 set battery cell count function.
err_t charger25_get_input_curr_limit(charger25_t *ctx, uint16_t *input_curr_limit)
Charger 25 get input current limit function.
void charger25_disable(charger25_t *ctx)
Charger 25 charge disable function.
err_t charger25_init(charger25_t *ctx, charger25_cfg_t *cfg)
Charger 25 initialization function.
void charger25_enable(charger25_t *ctx)
Charger 25 charge enable function.
err_t charger25_generic_read(charger25_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Charger 25 I2C reading function.
err_t charger25_get_input_vtg_limit(charger25_t *ctx, uint16_t *input_vtg_limit)
Charger 25 get input voltage limit function.
err_t charger25_get_vbat_lim(charger25_t *ctx, uint16_t *vtg_lim)
Charger 25 get battery voltage limit function.
err_t charger25_default_cfg(charger25_t *ctx)
Charger 25 default configuration function.
uint8_t charger25_get_interrupt(charger25_t *ctx)
Charger 25 get interrupt function.
err_t charger25_set_adc_function(charger25_t *ctx, charger25_adc_func_t adc_func)
Charger 25 set ADC function function.
err_t charger25_get_vbat(charger25_t *ctx, uint16_t *vbat)
Charger 25 get VBAT function.
void charger25_cfg_setup(charger25_cfg_t *cfg)
Charger 25 configuration object setup function.
err_t charger25_get_current_limit(charger25_t *ctx, uint16_t *current_lim)
Charger 25 get charge current limit function.
err_t charger25_generic_write(charger25_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Charger 25 I2C writing function.
err_t charger25_set_vbat_lim(charger25_t *ctx, uint16_t vtg_lim)
Charger 25 set battery voltage limit function.
err_t charger25_set_current_limit(charger25_t *ctx, uint16_t current_lim)
Charger 25 set charge current limit function.
err_t charger25_get_cell_count(charger25_t *ctx, uint8_t *cell_count)
Charger 25 get battery cell count function.
err_t charger25_sw_reset(charger25_t *ctx)
Charger 25 software reset function.
err_t charger25_set_input_vtg_limit(charger25_t *ctx, uint16_t input_vtg_limit)
Charger 25 set input voltage limit function.
err_t charger25_get_status(charger25_t *ctx, charger25_status_t *status)
Charger 25 get charging status function.
err_t charger25_set_adc_control(charger25_t *ctx, charger25_adc_ctrl_t adc_ctrl)
Charger 25 set ADC control function.
Charger 25 Click ADC control object.
Definition charger25.h:346
uint8_t adc_avg
Definition charger25.h:350
uint8_t adc_avg_init
Definition charger25.h:351
uint8_t adc_rate
Definition charger25.h:348
uint8_t adc_en
Definition charger25.h:347
uint8_t adc_sample
Definition charger25.h:349
Charger 25 Click ADC function object.
Definition charger25.h:360
uint8_t ibus_adc_dis
Definition charger25.h:361
uint8_t dp_adc_dis
Definition charger25.h:368
uint8_t vbus_adc_dis
Definition charger25.h:363
uint8_t dm_adc_dis
Definition charger25.h:369
uint8_t vbat_adc_dis
Definition charger25.h:364
uint8_t ibat_adc_dis
Definition charger25.h:362
uint8_t ts_adc_dis
Definition charger25.h:366
uint8_t vac2_adc_dis
Definition charger25.h:370
uint8_t tdie_adc_dis
Definition charger25.h:367
uint8_t vsys_adc_dis
Definition charger25.h:365
uint8_t vac1_adc_dis
Definition charger25.h:371
Charger 25 Click configuration object.
Definition charger25.h:292
uint32_t i2c_speed
Definition charger25.h:300
pin_name_t ce
Definition charger25.h:297
pin_name_t scl
Definition charger25.h:293
pin_name_t int_pin
Definition charger25.h:298
pin_name_t qon
Definition charger25.h:296
pin_name_t sda
Definition charger25.h:294
uint8_t i2c_address
Definition charger25.h:301
Charger 25 Click status object.
Definition charger25.h:310
uint8_t treg_stat
Definition charger25.h:323
uint8_t acrb1_stat
Definition charger25.h:327
uint8_t dpdm_stat
Definition charger25.h:324
uint8_t vbus_present_stat
Definition charger25.h:318
uint8_t ts_cold_stat
Definition charger25.h:334
uint8_t chg_tmr_stat
Definition charger25.h:330
uint8_t bc1_2_done
Definition charger25.h:321
uint8_t acrb2_stat
Definition charger25.h:326
uint8_t vsys_stat
Definition charger25.h:329
uint8_t prechg_tmr_stat
Definition charger25.h:332
uint8_t vbus_stat
Definition charger25.h:320
uint8_t vbat_present_stat
Definition charger25.h:325
uint8_t ts_hot_stat
Definition charger25.h:337
uint8_t iindpm_stat
Definition charger25.h:311
uint8_t vbatotg_low_stat
Definition charger25.h:333
uint8_t wd_stat
Definition charger25.h:313
uint8_t vindpm_stat
Definition charger25.h:312
uint8_t ts_cool_stat
Definition charger25.h:335
uint8_t ac2_present_stat
Definition charger25.h:316
uint8_t ico_stat
Definition charger25.h:322
uint8_t pg_stat
Definition charger25.h:315
uint8_t adc_done_stat
Definition charger25.h:328
uint8_t trichg_tmr_stat
Definition charger25.h:331
uint8_t ac1_present_stat
Definition charger25.h:317
uint8_t poorsrc_stat
Definition charger25.h:314
uint8_t chg_stat
Definition charger25.h:319
uint8_t ts_warm_stat
Definition charger25.h:336
Charger 25 Click context object.
Definition charger25.h:271
digital_in_t int_pin
Definition charger25.h:277
i2c_master_t i2c
Definition charger25.h:280
digital_out_t qon
Definition charger25.h:273
uint8_t slave_address
Definition charger25.h:283
digital_out_t ce
Definition charger25.h:274