battman2 2.0.0.0
battman2.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 BATTMAN2_H
29#define BATTMAN2_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
53
74#define BATTMAN2_INT_GLBL0 0x00
75#define BATTMAN2_INT_GLBL1 0x04
76#define BATTMAN2_ERCFLAG 0x05
77#define BATTMAN2_STAT_GLBL 0x06
78#define BATTMAN2_INTM_GLBL1 0x08
79#define BATTMAN2_INTM_GLBL0 0x09
80#define BATTMAN2_CNFG_GLBL 0x10
81#define BATTMAN2_CNFG_GPIO0 0x11
82#define BATTMAN2_CNFG_GPIO1 0x12
83#define BATTMAN2_CNFG_GPIO2 0x13
84#define BATTMAN2_CID 0x14
85#define BATTMAN2_CNFG_WDT 0x17
86#define BATTMAN2_INT_CHG 0x01
87#define BATTMAN2_STAT_CHG_A 0x02
88#define BATTMAN2_STAT_CHG_B 0x03
89#define BATTMAN2_INT_M_CHG 0x07
90#define BATTMAN2_CNFG_CHG_A 0x20
91#define BATTMAN2_CNFG_CHG_B 0x21
92#define BATTMAN2_CNFG_CHG_C 0x22
93#define BATTMAN2_CNFG_CHG_D 0x23
94#define BATTMAN2_CNFG_CHG_E 0x24
95#define BATTMAN2_CNFG_CHG_F 0x25
96#define BATTMAN2_CNFG_CHG_G 0x26
97#define BATTMAN2_CNFG_CHG_H 0x27
98#define BATTMAN2_CNFG_CHG_I 0x28
99#define BATTMAN2_CNFG_SBB0_A 0x29
100#define BATTMAN2_CNFG_SBB0_B 0x2A
101#define BATTMAN2_CNFG_SBB1_A 0x2B
102#define BATTMAN2_CNFG_SBB1_B 0x2C
103#define BATTMAN2_CNFG_SBB2_A 0x2D
104#define BATTMAN2_CNFG_SBB2_B 0x2E
105#define BATTMAN2_CNFG_SBB_TOP 0x2F
106#define BATTMAN2_CNFG_LDO0_A 0x38
107#define BATTMAN2_CNFG_LDO0_B 0x39
108#define BATTMAN2_CNFG_LDO1_A 0x3A
109#define BATTMAN2_CNFG_LDO1_B 0x3B
110
111 // battman2_reg
112
133#define BATTMAN2_SEL_LED_RED 0x00
134#define BATTMAN2_SEL_LED_YELLOW 0x01
135#define BATTMAN2_SEL_LED_BLUE 0x02
136#define BATTMAN2_PIN_STATE_OFF 0x00
137#define BATTMAN2_PIN_STATE_ON 0x01
138
144#define BATTMAN2_SEL_ALT_GPIO_STANDARD 0x00
145#define BATTMAN2_SEL_ALT_GPIO_A_OUTPUT_SBB2 0x20
146#define BATTMAN2_DBEN_GPI_NO_DEBOUNCE 0x00
147#define BATTMAN2_DBEN_GPI_DEBOUNCE_30_ms 0x10
148#define BATTMAN2_DO_GPIO_LOGIC_LOW 0x00
149#define BATTMAN2_DO_GPIO_LOGIC_HIGH 0x08
150#define BATTMAN2_DRV_OPEN_DRAIN 0x00
151#define BATTMAN2_DRV_PUSH_PULL 0x04
152#define BATTMAN2_DI_GPIO_LOGIC_LOW 0x00
153#define BATTMAN2_DI_GPIO_LOGIC_HIGH 0x02
154#define BATTMAN2_DIR_OUTPUT 0x00
155#define BATTMAN2_DIR_INPUT 0x01
156
162#define BATTMAN2_THM_HOT_411_mV 0x00
163#define BATTMAN2_THM_HOT_367_mV 0x01
164#define BATTMAN2_THM_HOT_327_mV 0x02
165#define BATTMAN2_THM_HOT_291_mV 0x03
166#define BATTMAN2_THM_WARM_511_mV 0x00
167#define BATTMAN2_THM_WARM_459_mV 0x01
168#define BATTMAN2_THM_WARM_411_mV 0x02
169#define BATTMAN2_THM_WARM_367_mV 0x03
170#define BATTMAN2_THM_COOL_923_mV 0x00
171#define BATTMAN2_THM_COOL_867_mV 0x01
172#define BATTMAN2_THM_COOL_807_mV 0x02
173#define BATTMAN2_THM_COOL_747_mV 0x03
174#define BATTMAN2_THM_COLD_1024_mV 0x00
175#define BATTMAN2_THM_COLD_976_mV 0x01
176#define BATTMAN2_THM_COLD_923_mV 0x02
177#define BATTMAN2_THM_COLD_867_mV 0x03
178
184#define BATTMAN2_BIT_MASK_CHARGER_DISABLE 0xFE
185#define BATTMAN2_BIT_MASK_CHARGER_ENABLE 0x01
186#define BATTMAN2_SET_CHARGER_DISABLE 0x00
187#define BATTMAN2_SET_CHARGER_ENABLE 0x01
188
195#define BATTMAN2_I_PQ_10_PERCENTAGE 0x00
196#define BATTMAN2_I_PQ_20_PERCENTAGE 0x01
197
203#define BATTMAN2_I_TERM_5_PERCENTAGE 0x00
204#define BATTMAN2_I_TERM_7_5_PERCENTAGE 0x01
205#define BATTMAN2_I_TERM_10_PERCENTAGE 0x02
206#define BATTMAN2_I_TERM_15_PERCENTAGE 0x03
207
213#define BATTMAN2_T_TOPOFF_0_MIN 0x00
214#define BATTMAN2_T_TOPOFF_5_MIN 0x01
215#define BATTMAN2_T_TOPOFF_10_MIN 0x02
216#define BATTMAN2_T_TOPOFF_15_MIN 0x03
217#define BATTMAN2_T_TOPOFF_20_MIN 0x04
218#define BATTMAN2_T_TOPOFF_25_MIN 0x05
219#define BATTMAN2_T_TOPOFF_30_MIN 0x06
220#define BATTMAN2_T_TOPOFF_35_MIN 0x07
221
227#define BATTMAN2_TJ_REG_60_C 0x00
228#define BATTMAN2_TJ_REG_70_C 0x01
229#define BATTMAN2_TJ_REG_80_C 0x02
230#define BATTMAN2_TJ_REG_90_C 0x03
231#define BATTMAN2_TJ_REG_100_C 0x04
232
238#define BATTMAN2_T_FAST_CHG_TIMER_DISABLED 0x00
239#define BATTMAN2_T_FAST_CHG_TIMER_3_HOURS 0x01
240#define BATTMAN2_T_FAST_CHG_TIMER_5_HOURS 0x02
241#define BATTMAN2_T_FAST_CHG_TIMER_7_HOURS 0x03
242
248#define BATTMAN2_THM_EN_THERMISTOR_DISABLED 0x00
249#define BATTMAN2_THM_EN_THERMISTOR_ENABLED 0x01
250
256#define BATTMAN2_USBS_CHGIN_IS_NOT_SUSPENDED 0x00
257#define BATTMAN2_USBS_CHGIN_IS_SUSPENDED 0x01
258
264#define BATTMAN2_IMON_DISCHG_SCALE_8_2_mA 0x00
265#define BATTMAN2_IMON_DISCHG_SCALE_40_5_mA 0x01
266#define BATTMAN2_IMON_DISCHG_SCALE_72_3_mA 0x02
267#define BATTMAN2_IMON_DISCHG_SCALE_103_4_mA 0x03
268#define BATTMAN2_IMON_DISCHG_SCALE_134_1_mA 0x04
269#define BATTMAN2_IMON_DISCHG_SCALE_164_1_mA 0x05
270#define BATTMAN2_IMON_DISCHG_SCALE_193_7_mA 0x06
271#define BATTMAN2_IMON_DISCHG_SCALE_222_7_mA 0x07
272#define BATTMAN2_IMON_DISCHG_SCALE_251_2_mA 0x08
273#define BATTMAN2_IMON_DISCHG_SCALE_279_3_mA 0x09
274#define BATTMAN2_IMON_DISCHG_SCALE_300_mA 0x0A
275
281#define BATTMAN2_MUX_SEL_MULTIPLEXER_DISABLED 0x00
282#define BATTMAN2_MUX_SEL_CHGIN_VOLTAGE_MONITOR 0x01
283#define BATTMAN2_MUX_SEL_CHGIN_CURRENT_MONITOR 0x02
284#define BATTMAN2_MUX_SEL_BATT_VOLTAGE_MONITOR 0x03
285#define BATTMAN2_MUX_SEL_BATT_CHARGE_CURRENT_MONITOR 0x04
286#define BATTMAN2_MUX_SEL_BATT_DISCHARGE_CURRENT_NORMAL 0x05
287#define BATTMAN2_MUX_SEL_BATT_DISCHARGE_CURRENT_NULLING 0x06
288#define BATTMAN2_MUX_SEL_THM_VOLTAGE_MONITOR 0x07
289#define BATTMAN2_MUX_SEL_TBIAS_VOLTAGE_MONITOR 0x08
290#define BATTMAN2_MUX_SEL_AGND_VOLTAGE_MONITOR 0x09
291#define BATTMAN2_MUX_SEL_SYS_VOLTAGE_MONITOR 0x0A
292
298#define BATTMAN2_OP_MODE_BUCK_AND_BOOST 0x00
299#define BATTMAN2_OP_MODE_BUCK 0x01
300
306#define BATTMAN2_CURRENT_LIMIT_1000_mA 0x00
307#define BATTMAN2_CURRENT_LIMIT_750_mA 0x01
308#define BATTMAN2_CURRENT_LIMIT_500_mA 0x02
309#define BATTMAN2_CURRENT_LIMIT_333_mA 0x03
310
316#define BATTMAN2_ACTIVE_DISCHARGE_DISABLE 0x00
317#define BATTMAN2_ACTIVE_DISCHARGE_ENABLE 0x01
318
324#define BATTMAN2_ENABLE_CONTROL_FPS_SLOT_0 0x00
325#define BATTMAN2_ENABLE_CONTROL_FPS_SLOT_1 0x01
326#define BATTMAN2_ENABLE_CONTROL_FPS_SLOT_2 0x02
327#define BATTMAN2_ENABLE_CONTROL_FPS_SLOT_3 0x03
328#define BATTMAN2_ENABLE_CONTROL_OFF_IRRESPECTIVE_FPS 0x04
329#define BATTMAN2_ENABLE_CONTROL_ON_IRRESPECTIVE_FPS 0x06
330
336#define BATTMAN2_ICHGIN_LIM_95_mA 0x00
337#define BATTMAN2_ICHGIN_LIM_190_mA 0x01
338#define BATTMAN2_ICHGIN_LIM_285_mA 0x02
339#define BATTMAN2_ICHGIN_LIM_380_mA 0x03
340#define BATTMAN2_ICHGIN_LIM_475_mA 0x04
341
347#define BATTMAN2_DRV_SBB_FAST_TRANSITION_TIME 0x00
348#define BATTMAN2_DRV_SBB_TRANSITION_TIME_1 0x01
349#define BATTMAN2_DRV_SBB_TRANSITION_TIME_2 0x02
350#define BATTMAN2_DRV_SBB_TRANSITION_TIME_3 0x03
351
357#define BATTMAN2_SBB_CH_0 0x00
358#define BATTMAN2_SBB_CH_1 0x01
359#define BATTMAN2_SBB_CH_2 0x02
360
366#define BATTMAN2_SET_DEV_ADDR 0x48
367
368 // battman2_set
369
384#define BATTMAN2_CHG_DTLS_OFF 0x00
385#define BATTMAN2_CHG_DTLS_PREQUALIFICATION_MODE 0x01
386#define BATTMAN2_CHG_DTLS_FAST_CHARGE_CONSTANT_CURRENT 0x02
387#define BATTMAN2_CHG_DTLS_JEITA_MODIFIED_FAST_CHRG_CC 0x03
388#define BATTMAN2_CHG_DTLS_FAST_CHARGE_CONSTANT_VOLTAGE 0x04
389#define BATTMAN2_CHG_DTLS_JEITA_MODIFIED_FAST_CHRG_CV 0x05
390#define BATTMAN2_CHG_DTLS_TOP_OFF_MODE 0x06
391#define BATTMAN2_CHG_DTLS_JEITA_MODIFIED_TOP_OFF_MODE 0x07
392#define BATTMAN2_CHG_DTLS_DONE 0x08
393#define BATTMAN2_CHG_DTLS_JEITA_MODIFIED_DONE 0x09
394#define BATTMAN2_CHG_DTLS_PREQUALIFICATION_TIMER_FAULT 0x0A
395#define BATTMAN2_CHG_DTLS_FAST_CHARGE_TIMER_FAULT 0x0B
396#define BATTMAN2_CHG_DTLS_BATTERY_TEMPERATURE_FAULT 0x0C
397
402#define BATTMAN2_CHG_NO_CHARGING 0x00
403#define BATTMAN2_CHG_CHARGING 0x01
404
405 // battman2_chrg_status
406
421#define BATTMAN2_MAP_MIKROBUS( cfg, mikrobus ) \
422 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
423 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
424 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
425 cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
426
427 // battman2_map
428 // battman2
429
434typedef struct
435{
436 // Output pins
437 digital_out_t rst;
439 // Input pins
440 digital_in_t irq;
442 // Modules
443 i2c_master_t i2c;
445 // I2C slave address
448} battman2_t;
449
454typedef struct
455{
456 pin_name_t scl;
457 pin_name_t sda;
459 pin_name_t rst;
460 pin_name_t irq;
462 uint32_t i2c_speed;
463 uint8_t i2c_address;
466
471typedef enum
472{
474 BATTMAN2_ERROR = -1
475
477
482typedef struct
483{
484 uint8_t thm_hot;
485 uint8_t thm_warm;
486 uint8_t thm_cool;
487 uint8_t thm_cold;
490 uint8_t i_pq;
491 float chg_pq;
492 uint8_t i_term;
493 uint8_t t_topoff;
494 uint8_t tj_reg;
495 float vsys_reg;
496 float chg_cc;
497 uint8_t t_fast_chg;
499 uint8_t thm_en;
500 float chg_cv;
501 uint8_t usbs;
504 uint8_t mux_sel;
505
507
512typedef struct
513{
517 uint8_t tj_reg_stat;
518 uint8_t thm_dtls;
519 uint8_t chg_dtls;
520 uint8_t chgin_dtls;
521 uint8_t chg;
522 uint8_t time_sus;
523
525
530typedef struct
531{
533 uint8_t op_mode;
538 uint8_t drv_sbb;
539
541
546typedef struct
547{
549 uint8_t op_mode;
553
555
572
588
603
619err_t battman2_generic_write ( battman2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
620
636err_t battman2_generic_read ( battman2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
637
653
670err_t battman2_check_int_glbl ( battman2_t *ctx, uint8_t *int_glbl0, uint8_t *int_glbl1 );
671
687err_t battman2_check_faults_occurred ( battman2_t *ctx, uint8_t *faults );
688
704err_t battman2_check_stat ( battman2_t *ctx, uint8_t *stat );
705
706
728err_t battman2_set_gpio_output ( battman2_t *ctx, uint8_t gpio_sel, uint8_t led_state );
729
745err_t battman2_get_id ( battman2_t *ctx, uint8_t *cid );
746
764err_t battman2_set_charger_enable ( battman2_t *ctx, uint8_t en_chg );
765
782
799
816
836err_t battman2_set_sbb_config ( battman2_t *ctx, uint8_t sbb_sel, battman2_sbb_cnfg_t sbb_cfg );
837
857err_t battman2_get_sbb_config ( battman2_t *ctx, uint8_t sbb_sel, battman2_sbb_cnfg_t *sbb_cfg );
858
875
892
908
924
925#ifdef __cplusplus
926}
927#endif
928#endif // BATTMAN2_H
929
930 // battman2
931
932// ------------------------------------------------------------------------ END
battman2_return_value_t
BATT-MAN 2 Click return value data.
Definition battman2.h:472
@ BATTMAN2_OK
Definition battman2.h:473
@ BATTMAN2_ERROR
Definition battman2.h:474
err_t battman2_hw_reset(battman2_t *ctx)
BATT-MAN 2 hw reset function.
err_t battman2_generic_read(battman2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
BATT-MAN 2 I2C reading function.
err_t battman2_check_int_glbl(battman2_t *ctx, uint8_t *int_glbl0, uint8_t *int_glbl1)
BATT-MAN 2 check global interrupts function.
err_t battman2_get_ldo_config(battman2_t *ctx, battman2_ldo_cnfg_t *ldo_cfg)
BATT-MAN 2 get LDO configuration function.
err_t battman2_generic_write(battman2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
BATT-MAN 2 I2C writing function.
err_t battman2_set_gpio_output(battman2_t *ctx, uint8_t gpio_sel, uint8_t led_state)
BATT-MAN 2 set gpio output state function.
err_t battman2_set_sbb_config(battman2_t *ctx, uint8_t sbb_sel, battman2_sbb_cnfg_t sbb_cfg)
BATT-MAN 2 set SBB configuration function.
void battman2_led_intro(battman2_t *ctx)
BATT-MAN 2 LED intro function.
err_t battman2_default_cfg(battman2_t *ctx)
BATT-MAN 2 default configuration function.
uint8_t battman2_check_interrupt(battman2_t *ctx)
BATT-MAN 2 check interrupt function.
err_t battman2_set_charger_enable(battman2_t *ctx, uint8_t en_chg)
BATT-MAN 2 set charger enable function.
err_t battman2_set_ldo_config(battman2_t *ctx, battman2_ldo_cnfg_t ldo_cfg)
BATT-MAN 2 set LDO configuration function.
void battman2_cfg_setup(battman2_cfg_t *cfg)
BATT-MAN 2 configuration object setup function.
err_t battman2_check_stat(battman2_t *ctx, uint8_t *stat)
BATT-MAN 2 check states function.
err_t battman2_get_sbb_config(battman2_t *ctx, uint8_t sbb_sel, battman2_sbb_cnfg_t *sbb_cfg)
BATT-MAN 2 get SBB configuration function.
err_t battman2_check_faults_occurred(battman2_t *ctx, uint8_t *faults)
BATT-MAN 2 check faults occurred function.
err_t battman2_get_id(battman2_t *ctx, uint8_t *cid)
BATT-MAN 2 get device ID function.
err_t battman2_get_charger_cfg(battman2_t *ctx, battman2_chg_cnfg_t *chg_cnfg)
BATT-MAN 2 get charger configuration function.
err_t battman2_set_charger_cfg(battman2_t *ctx, battman2_chg_cnfg_t chg_cnfg)
BATT-MAN 2 set charger configuration function.
err_t battman2_get_chg_status(battman2_t *ctx, battman2_stat_chg_t *chg_stat)
BATT-MAN 2 get charger status function.
err_t battman2_init(battman2_t *ctx, battman2_cfg_t *cfg)
BATT-MAN 2 initialization function.
BATT-MAN 2 Click configuration object.
Definition battman2.h:455
uint32_t i2c_speed
Definition battman2.h:462
pin_name_t irq
Definition battman2.h:460
pin_name_t scl
Definition battman2.h:456
pin_name_t sda
Definition battman2.h:457
pin_name_t rst
Definition battman2.h:459
uint8_t i2c_address
Definition battman2.h:463
BATT-MAN 2 Click charger configuration object.
Definition battman2.h:483
uint8_t usbs
Definition battman2.h:501
float chg_cc
Definition battman2.h:496
uint8_t i_pq
Definition battman2.h:490
uint8_t imon_dischg_scale
Definition battman2.h:503
float vsys_reg
Definition battman2.h:495
float chg_cv
Definition battman2.h:500
uint8_t thm_cool
Definition battman2.h:486
uint8_t mux_sel
Definition battman2.h:504
uint8_t t_fast_chg
Definition battman2.h:497
float vchgin_min
Definition battman2.h:488
uint8_t thm_en
Definition battman2.h:499
uint8_t thm_hot
Definition battman2.h:484
uint8_t t_topoff
Definition battman2.h:493
uint8_t thm_warm
Definition battman2.h:485
uint8_t tj_reg
Definition battman2.h:494
uint8_t thm_cold
Definition battman2.h:487
float chg_cv_jeita
Definition battman2.h:502
float ichgin_lim
Definition battman2.h:489
float chg_cc_jeita
Definition battman2.h:498
float chg_pq
Definition battman2.h:491
uint8_t i_term
Definition battman2.h:492
BATT-MAN 2 Click LDO configuration object.
Definition battman2.h:547
uint8_t active_discharge_enable
Definition battman2.h:551
uint8_t enable_control
Definition battman2.h:552
uint8_t current_limit
Definition battman2.h:550
uint8_t op_mode
Definition battman2.h:549
float output_vtg
Definition battman2.h:548
BATT-MAN 2 Click Buck and boost configuration object.
Definition battman2.h:531
uint8_t active_discharge_enable
Definition battman2.h:535
uint8_t enable_control
Definition battman2.h:536
uint8_t drv_sbb
Definition battman2.h:538
uint8_t current_limit
Definition battman2.h:534
uint8_t ichgin_lim_def
Definition battman2.h:537
uint8_t op_mode
Definition battman2.h:533
float output_vtg
Definition battman2.h:532
BATT-MAN 2 Click charger status object.
Definition battman2.h:513
uint8_t vsys_min_stat
Definition battman2.h:516
uint8_t vchgin_min_stat
Definition battman2.h:514
uint8_t chg_dtls
Definition battman2.h:519
uint8_t tj_reg_stat
Definition battman2.h:517
uint8_t chgin_dtls
Definition battman2.h:520
uint8_t thm_dtls
Definition battman2.h:518
uint8_t ichgin_lim_stat
Definition battman2.h:515
uint8_t chg
Definition battman2.h:521
uint8_t time_sus
Definition battman2.h:522
BATT-MAN 2 Click context object.
Definition battman2.h:435
digital_in_t irq
Definition battman2.h:440
i2c_master_t i2c
Definition battman2.h:443
digital_out_t rst
Definition battman2.h:437
uint8_t slave_address
Definition battman2.h:446