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"
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
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
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
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
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
195#define BATTMAN2_I_PQ_10_PERCENTAGE 0x00
196#define BATTMAN2_I_PQ_20_PERCENTAGE 0x01
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
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
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
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
248#define BATTMAN2_THM_EN_THERMISTOR_DISABLED 0x00
249#define BATTMAN2_THM_EN_THERMISTOR_ENABLED 0x01
256#define BATTMAN2_USBS_CHGIN_IS_NOT_SUSPENDED 0x00
257#define BATTMAN2_USBS_CHGIN_IS_SUSPENDED 0x01
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
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
298#define BATTMAN2_OP_MODE_BUCK_AND_BOOST 0x00
299#define BATTMAN2_OP_MODE_BUCK 0x01
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
316#define BATTMAN2_ACTIVE_DISCHARGE_DISABLE 0x00
317#define BATTMAN2_ACTIVE_DISCHARGE_ENABLE 0x01
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
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
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
357#define BATTMAN2_SBB_CH_0 0x00
358#define BATTMAN2_SBB_CH_1 0x01
359#define BATTMAN2_SBB_CH_2 0x02
366#define BATTMAN2_SET_DEV_ADDR 0x48
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
402#define BATTMAN2_CHG_NO_CHARGING 0x00
403#define BATTMAN2_CHG_CHARGING 0x01
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 )
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