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 BATTMAN3_REG_MANUFACTURE_AND_MODEL_ID 0x00
74#define BATTMAN3_REG_SILICON_REVSION 0x01
75#define BATTMAN3_REG_CHARGER_VBUS_ILIM 0x02
76#define BATTMAN3_REG_CHARGER_TERMINATION_SETTING 0x03
77#define BATTMAN3_REG_CHARGER_CURRENT_SETTING 0x04
78#define BATTMAN3_REG_CHARGER_VOLTAGE_THRESHOLD 0x05
79#define BATTMAN3_REG_CHARGER_TIMER_SETTING 0x06
80#define BATTMAN3_REG_CHARGER_FUNCTION_SETTING1 0x07
81#define BATTMAN3_REG_CHARGER_STATUS1 0x08
82#define BATTMAN3_REG_CHARGER_STATUS2 0x09
83#define BATTMAN3_REG_CHARGER_FAULT 0x0A
84#define BATTMAN3_REG_BATTERY_SHORT 0x0B
85#define BATTMAN3_REG_BATTERY_THERMISTOR_CONTROL 0x0C
86#define BATTMAN3_REG_V_SOC_0 0x0D
87#define BATTMAN3_REG_V_SOC_5 0x0E
88#define BATTMAN3_REG_V_SOC_11 0x0F
89#define BATTMAN3_REG_V_SOC_19 0x10
90#define BATTMAN3_REG_V_SOC_28 0x11
91#define BATTMAN3_REG_V_SOC_41 0x12
92#define BATTMAN3_REG_V_SOC_55 0x13
93#define BATTMAN3_REG_V_SOC_69 0x14
94#define BATTMAN3_REG_V_SOC_84 0x15
95#define BATTMAN3_REG_V_SOC_100 0x16
96#define BATTMAN3_REG_FILTER_SETTING1 0x17
97#define BATTMAN3_REG_FILTER_SETTING2 0x18
98#define BATTMAN3_REG_RBAT_0 0x19
99#define BATTMAN3_REG_RBAT_10 0x1A
100#define BATTMAN3_REG_RBAT_20 0x1B
101#define BATTMAN3_REG_RBAT_30 0x1C
102#define BATTMAN3_REG_RBAT_40 0x1D
103#define BATTMAN3_REG_RBAT_60 0x1E
104#define BATTMAN3_REG_K_RBAT_CHARGE 0x1F
105#define BATTMAN3_REG_BAT_TEMP 0x20
106#define BATTMAN3_REG_BAT_SOC 0x21
107#define BATTMAN3_REG_VBAT_READ_H 0x22
108#define BATTMAN3_REG_VBAT_READ_L 0x23
109#define BATTMAN3_REG_FUEL_GAUGE_MODE 0x24
110#define BATTMAN3_REG_SOC_RESET 0x25
111#define BATTMAN3_REG_BST_LED_CTRL 0x26
112#define BATTMAN3_REG_BST_CFG 0x27
113#define BATTMAN3_REG_IBL_SET 0x28
114#define BATTMAN3_REG_ILED2_SET 0x29
115#define BATTMAN3_REG_ILED3_SET 0x2A
116#define BATTMAN3_REG_ILED4_SET 0x2B
117#define BATTMAN3_REG_ILED5_SET 0x2C
118#define BATTMAN3_REG_BL_FR 0x2D
119#define BATTMAN3_REG_LED3_BLINK 0x2E
120#define BATTMAN3_REG_LED4_BLINK 0x2F
121#define BATTMAN3_REG_LED5_BLINK 0x30
122#define BATTMAN3_REG_LED_STATUS 0x31
123#define BATTMAN3_REG_LDO_CTRL 0x32
124#define BATTMAN3_REG_LDO_CFG 0x33
125#define BATTMAN3_REG_VID_LDO12 0x34
126#define BATTMAN3_REG_VID_LDO3 0x35
127#define BATTMAN3_REG_PGOOD_STATUS 0x36
128#define BATTMAN3_REG_PGOOD_MASK 0x37
129#define BATTMAN3_REG_CHARGER_INTERRUPT_ENABLE 0x38
130#define BATTMAN3_REG_CHARGER_INTERRUPT_FLAG 0x39
131#define BATTMAN3_REG_BOOST_LDO_INTERRUPT_ENABLE 0x3A
132#define BATTMAN3_REG_BOOST_LDO_INTERRUPT_FLAG 0x3B
133#define BATTMAN3_REG_DEFAULT_SET 0x3C
134#define BATTMAN3_REG_NTC47K_SET 0x3D
154#define BATTMAN3_CHARGE_STATUS1_OFF 0x0
155#define BATTMAN3_CHARGE_STATUS1_TRICLE_CHARGE 0x1
156#define BATTMAN3_CHARGE_STATUS1_FAST_CHARGE_CC 0x2
157#define BATTMAN3_CHARGE_STATUS1_FAST_CHARGE_CV 0x3
158#define BATTMAN3_CHARGE_STATUS1_CHARGE_COMPLETE 0x4
159#define BATTMAN3_CHARGE_STATUS1_SUSPEND 0x5
160#define BATTMAN3_CHARGE_STATUS1_TIMER_EXPIRED 0x6
161#define BATTMAN3_CHARGE_STATUS1_BATTERY_DETECTION 0x7
162#define BATTMAN3_CHARGE_STATUS2_BATTERY_MONITOR_OFF 0x0
163#define BATTMAN3_CHARGE_STATUS2_NO_BATTERY 0x1
164#define BATTMAN3_CHARGE_STATUS2_VBSNS_LESSTHEN_VTRK 0x2
165#define BATTMAN3_CHARGE_STATUS2_VBSNS_MIDDLE_VRK_VWEAK 0x3
166#define BATTMAN3_CHARGE_STATUS2_VBSNS_MORETHEN_VWEAK 0x4
172#define BATTMAN3_ENABLE 0x1
173#define BATTMAN3_DISABLE 0x0
180#define BATTMAN3_SET_DEV_ADDR 0x44
198#define BATTMAN3_MAP_MIKROBUS( cfg, mikrobus ) \
199 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
200 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
201 cfg.pgood = MIKROBUS( mikrobus, MIKROBUS_CS ); \
202 cfg.bok = MIKROBUS( mikrobus, MIKROBUS_RST ); \
203 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
battman3_vtrk_dead_t
BATT-MAN 3 Click dead battery voltage.
Definition battman3.h:298
@ BATTMAN3_VTRK_DEAD_2p6V
Definition battman3.h:301
@ BATTMAN3_VTRK_DEAD_3p3V
Definition battman3.h:302
@ BATTMAN3_VTRK_DEAD_2p4V
Definition battman3.h:299
@ BATTMAN3_VTRK_DEAD_2p5V
Definition battman3.h:300
battman3_return_value_t
BATT-MAN 3 Click return value data.
Definition battman3.h:250
@ BATTMAN3_ERROR
Definition battman3.h:252
@ BATTMAN3_OK
Definition battman3.h:251
battman3_ldo_t
BATT-MAN 3 Click LDO.
Definition battman3.h:286
@ BATTMAN3_LDO3
Definition battman3.h:289
@ BATTMAN3_LDO2
Definition battman3.h:288
@ BATTMAN3_LDO1
Definition battman3.h:287
battman3_ldo_vout_t
BATT-MAN 3 Click LDO voltage output.
Definition battman3.h:261
@ BATTMAN3_LDO_3p00V
Definition battman3.h:266
@ BATTMAN3_LDO_2p50V
Definition battman3.h:268
@ BATTMAN3_LDO_1p40V
Definition battman3.h:273
@ BATTMAN3_LDO_3p15V
Definition battman3.h:265
@ BATTMAN3_LDO_3p60V
Definition battman3.h:263
@ BATTMAN3_LDO_1p50V
Definition battman3.h:272
@ BATTMAN3_LDO_1p00V
Definition battman3.h:277
@ BATTMAN3_LDO_1p30V
Definition battman3.h:274
@ BATTMAN3_LDO_1p80V
Definition battman3.h:271
@ BATTMAN3_LDO_2p30V
Definition battman3.h:269
@ BATTMAN3_LDO_1p20V
Definition battman3.h:275
@ BATTMAN3_LDO_2p10V
Definition battman3.h:270
@ BATTMAN3_LDO_3p30V
Definition battman3.h:264
@ BATTMAN3_LDO_4p20V
Definition battman3.h:262
@ BATTMAN3_LDO_2p85V
Definition battman3.h:267
@ BATTMAN3_LDO_1p10V
Definition battman3.h:276
err_t battman3_reg_write(battman3_t *ctx, uint8_t reg, uint8_t tx_data)
Register writing function.
err_t battman3_generic_write(battman3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
BATT-MAN 3 I2C writing function.
err_t battman3_init(battman3_t *ctx, battman3_cfg_t *cfg)
BATT-MAN 3 initialization function.
err_t battman3_set_charge_state(battman3_t *ctx, uint8_t enable)
Enable/Disable charging.
err_t battman3_default_cfg(battman3_t *ctx)
BATT-MAN 3 default configuration function.
err_t battman3_set_ldo_state(battman3_t *ctx, battman3_ldo_t ldo, uint8_t enable)
Enable/Disable LDO.
err_t battman3_reg_read(battman3_t *ctx, uint8_t reg, uint8_t *rx_data)
Register reading function.
err_t battman3_set_charge_voltage_threshold(battman3_t *ctx, battman3_vtrk_dead_t vtrk_dead, float vweak)
Set charge termination voltage.
err_t battman3_set_charge_vbus_current_limit(battman3_t *ctx, uint16_t current)
Set charge current limit.
uint8_t battman3_get_power_good(battman3_t *ctx)
Get power good.
err_t battman3_set_ldo_vout(battman3_t *ctx, battman3_ldo_t ldo, battman3_ldo_vout_t vout)
Set voltage output on LDO.
uint8_t battman3_get_interrupt(battman3_t *ctx)
Get interrupt.
uint8_t battman3_get_battery_ok(battman3_t *ctx)
Get battery OK.
err_t battman3_generic_read(battman3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
BATT-MAN 3 I2C reading function.
err_t battman3_get_battery_voltage(battman3_t *ctx, float *vout)
Read battery voltage level.
void battman3_cfg_setup(battman3_cfg_t *cfg)
BATT-MAN 3 configuration object setup function.
err_t battman3_set_charge_termination_voltage(battman3_t *ctx, float voltage)
Set charge termination voltage.
BATT-MAN 3 Click configuration object.
Definition battman3.h:232
uint32_t i2c_speed
Definition battman3.h:240
pin_name_t pgood
Definition battman3.h:236
pin_name_t scl
Definition battman3.h:233
pin_name_t int_pin
Definition battman3.h:238
pin_name_t bok
Definition battman3.h:237
pin_name_t sda
Definition battman3.h:234
uint8_t i2c_address
Definition battman3.h:241
BATT-MAN 3 Click context object.
Definition battman3.h:213
digital_in_t bok
Definition battman3.h:216
digital_in_t pgood
Definition battman3.h:215
digital_in_t int_pin
Definition battman3.h:217
i2c_master_t i2c
Definition battman3.h:220
uint8_t slave_address
Definition battman3.h:223