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 BATTMON3_REG_CONTROL 0x00
74#define BATTMON3_REG_ACCUMULATED_CAPACITY 0x02
75#define BATTMON3_REG_TEMPERATURE 0x06
76#define BATTMON3_REG_VOLTAGE 0x08
77#define BATTMON3_REG_BATTERY_STATUS 0x0A
78#define BATTMON3_REG_BATTERY_ALERT 0x0B
79#define BATTMON3_REG_CURRENT 0x0C
80#define BATTMON3_REG_SCALED_R 0x16
81#define BATTMON3_REG_MEASURED_Z 0x22
82#define BATTMON3_REG_INTERNAL_TEMPERATURE 0x28
83#define BATTMON3_REG_STATE_OF_HEALTH 0x2E
84#define BATTMON3_REG_DESIGN_CAPACITY 0x3C
85#define BATTMON3_REG_MAC 0x3E
86#define BATTMON3_REG_MAC_DATA 0x40
87#define BATTMON3_REG_MAC_DATA_SUM 0x60
88#define BATTMON3_REG_MAC_DATA_LEN 0x61
89#define BATTMON3_REG_MAC_DATA_CONTROL 0x62
90#define BATTMON3_REG_CAL_COUNT 0x79
91#define BATTMON3_REG_CAL_CURRENT 0x7A
92#define BATTMON3_REG_CAL_VOLTAGE 0x7C
93#define BATTMON3_REG_CAL_TEMPERATURE 0x7E
99#define BATTMON3_CONTROL_STATUS 0x0000
100#define BATTMON3_CONTROL_DEVICE_TYPE 0x0001
101#define BATTMON3_CONTROL_FW_VERSION 0x0002
102#define BATTMON3_CONTROL_HW_VERSION 0x0003
103#define BATTMON3_CONTROL_STATIC_CHEM_CHKSUM 0x0005
104#define BATTMON3_CONTROL_CHEM_ID 0x0006
105#define BATTMON3_CONTROL_PREV_MACWRITE 0x0007
106#define BATTMON3_CONTROL_BOARD_OFFSET 0x0009
107#define BATTMON3_CONTROL_CC_OFFSET 0x000A
108#define BATTMON3_CONTROL_CC_OFFSET_SAVE 0x000B
109#define BATTMON3_CONTROL_DF_VERSION 0x000C
110#define BATTMON3_CONTROL_GAUGE_START 0x0011
111#define BATTMON3_CONTROL_GAUGE_STOP 0x0012
112#define BATTMON3_CONTROL_SEALED 0x0020
113#define BATTMON3_CONTROL_CAL_ENABLE 0x002D
114#define BATTMON3_CONTROL_LT_ENABLE 0x002E
115#define BATTMON3_CONTROL_RESET 0x0041
116#define BATTMON3_CONTROL_EXIT_CAL 0x0080
117#define BATTMON3_CONTROL_ENTER_CAL 0x0081
118#define BATTMON3_CONTROL_NEW_BATTERY 0xA613
125#define BATTMON3_DF_CC_GAIN 0x4000
126#define BATTMON3_DF_CC_DELTA 0x4004
127#define BATTMON3_DF_CC_OFFSET 0x4008
128#define BATTMON3_DF_BOARD_OFFSET 0x400C
129#define BATTMON3_DF_INT_TEMP_OFFSET 0x400D
130#define BATTMON3_DF_EXT_TEMP_OFFSET 0x400E
131#define BATTMON3_DF_PACK_V_OFFSET 0x400F
132#define BATTMON3_DF_OPERATION_CONFIG_A 0x41B1
133#define BATTMON3_DF_FULL_UNSEAL_STEP_1 0x41D0
134#define BATTMON3_DF_CELL_DESIGN_CAPACITY 0x41FE
152#define BATTMON3_CHEM_ID 0x0606
158#define BATTMON3_SEAL_CODES_DEFAULT 0x04143672ul
164#define BATTMON3_STATUS_GA_BIT_MASK 0x0001
165#define BATTMON3_STATUS_G_DONE_BIT_MASK 0x0040
166#define BATTMON3_STATUS_INIT_COMP_BIT_MASK 0x0080
167#define BATTMON3_STATUS_CCA_BIT_MASK 0x0400
168#define BATTMON3_STATUS_BCA_BIT_MASK 0x0800
169#define BATTMON3_STATUS_CAL_MODE_BIT_MASK 0x1000
170#define BATTMON3_STATUS_FLASHF_BIT_MASK 0x8000
176#define BATTMON3_OP_CONFIG_A_TEMPS_BIT_MASK 0x80
177#define BATTMON3_OP_CONFIG_A_EXTVCELL_BIT_MASK 0x40
178#define BATTMON3_OP_CONFIG_A_WRTEMP_BIT_MASK 0x20
179#define BATTMON3_OP_CONFIG_A_LF_EN_BIT_MASK 0x10
180#define BATTMON3_OP_CONFIG_A_GNDSEL_BIT_MASK 0x04
181#define BATTMON3_OP_CONFIG_A_GMSEL_BIT_MASK 0x03
188#define BATTMON3_DEVICE_ADDRESS 0x55
206#define BATTMON3_MAP_MIKROBUS( cfg, mikrobus ) \
207 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
208 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
209 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
210 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
battmon3_security_mode_t
BATT-MON 3 the security mode of the BQ35100 chip.
Definition battmon3.h:272
@ BATTMON3_SECURITY_MODE_SEALED
Normal operating mode, prevents accidental writes.
Definition battmon3.h:276
@ BATTMON3_SECURITY_MODE_UNKNOWN
Definition battmon3.h:273
@ BATTMON3_SECURITY_MODE_FULL_ACCESS
Allows writes to all of memory.
Definition battmon3.h:274
@ BATTMON3_SECURITY_MODE_UNSEALED
Allows writes to all of memory apart from the security codes area.
Definition battmon3.h:275
battmon3_gauge_mode_t
BATT-MON 3 the gauge mode of the BQ35100 chip.
Definition battmon3.h:285
@ BATTMON3_GAUGE_MODE_SOH
Definition battmon3.h:287
@ BATTMON3_GAUGE_MODE_ACCUMULATOR
Definition battmon3.h:286
@ BATTMON3_GAUGE_MODE_EOS
Definition battmon3.h:288
@ BATTMON3_GAUGE_MODE_UNKNOWN
Definition battmon3.h:289
battmon3_return_value_t
BATT-MON 3 Click return value data.
Definition battmon3.h:261
@ BATTMON3_ERROR
Definition battmon3.h:263
@ BATTMON3_OK
Definition battmon3.h:262
err_t battmon3_read_remaining_capacity(battmon3_t *ctx, float *rem_capacity)
BATT-MON 3 read remaining capacity function.
err_t battmon3_read_used_capacity(battmon3_t *ctx, float *used_capacity)
BATT-MON 3 read used capacity function.
err_t battmon3_set_security_mode(battmon3_t *ctx, uint8_t security_mode)
BATT-MON 3 set security mode function.
err_t battmon3_calibrate_voltage(battmon3_t *ctx, uint16_t voltage)
BATT-MON 3 calibrate voltage function.
err_t battmon3_perform_board_offset(battmon3_t *ctx)
BATT-MON 3 perform board offset function.
err_t battmon3_read_status(battmon3_t *ctx, uint16_t *status)
BATT-MON 3 read status function.
err_t battmon3_generic_read(battmon3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
BATT-MON 3 I2C reading function.
err_t battmon3_wait_for_status(battmon3_t *ctx, uint16_t mask, uint16_t status)
BATT-MON 3 wait for status function.
err_t battmon3_read_battery_status(battmon3_t *ctx, uint8_t *batt_status)
BATT-MON 3 read battery status function.
err_t battmon3_write_data_flash(battmon3_t *ctx, uint16_t address, uint8_t *tx_buf, uint8_t tx_len)
BATT-MON 3 write data flash function.
err_t battmon3_read_remaining_percentage(battmon3_t *ctx, float *rem_percentage)
BATT-MON 3 read remaining percentage function.
err_t battmon3_exit_calibration_mode(battmon3_t *ctx)
BATT-MON 3 exit calibration mode function.
err_t battmon3_read_state_of_health(battmon3_t *ctx, uint8_t *state_of_health)
BATT-MON 3 read state of health function.
err_t battmon3_use_internal_temperature(battmon3_t *ctx)
BATT-MON 3 use internal temperature function.
err_t battmon3_read_internal_temperature(battmon3_t *ctx, float *temperature)
BATT-MON 3 read internal temperature function.
err_t battmon3_read_two_bytes(battmon3_t *ctx, uint8_t reg, uint16_t *data_out)
BATT-MON 3 read two bytes function.
err_t battmon3_enter_calibration_mode(battmon3_t *ctx)
BATT-MON 3 enter calibration mode function.
err_t battmon3_set_gauge_mode(battmon3_t *ctx, uint8_t gauge_mode)
BATT-MON 3 set gauge mode function.
err_t battmon3_write_control(battmon3_t *ctx, uint16_t control)
BATT-MON 3 write control function.
err_t battmon3_read_scaled_r(battmon3_t *ctx, uint16_t *scaled_r)
BATT-MON 3 read scaled R function.
err_t battmon3_read_battery_alert(battmon3_t *ctx, uint8_t *batt_alert)
BATT-MON 3 read battery alert function.
err_t battmon3_read_voltage(battmon3_t *ctx, uint16_t *voltage)
BATT-MON 3 read voltage function.
err_t battmon3_stop_gauge(battmon3_t *ctx)
BATT-MON 3 stop gauge function.
err_t battmon3_reset(battmon3_t *ctx)
BATT-MON 3 reset function.
err_t battmon3_read_design_capacity(battmon3_t *ctx, uint16_t *des_capacity)
BATT-MON 3 read design capacity function.
err_t battmon3_start_gauge(battmon3_t *ctx)
BATT-MON 3 start gauge function.
err_t battmon3_read_data_flash(battmon3_t *ctx, uint16_t address, uint8_t *rx_buf, uint8_t rx_len)
BATT-MON 3 read data flash function.
err_t battmon3_check_communication(battmon3_t *ctx)
BATT-MON 3 check communication function.
err_t battmon3_use_external_temperature(battmon3_t *ctx)
BATT-MON 3 use external temperature function.
err_t battmon3_new_battery(battmon3_t *ctx, uint16_t des_capacity)
BATT-MON 3 new battery function.
void battmon3_set_en_pin_high(battmon3_t *ctx)
BATT-MON 3 set en pin high function.
void battmon3_cfg_setup(battmon3_cfg_t *cfg)
BATT-MON 3 configuration object setup function.
err_t battmon3_read_security_mode(battmon3_t *ctx)
BATT-MON 3 read security mode function.
err_t battmon3_perform_cc_offset(battmon3_t *ctx)
BATT-MON 3 perform CC offset function.
err_t battmon3_read_current(battmon3_t *ctx, int16_t *current)
BATT-MON 3 read current function.
err_t battmon3_calibrate_current(battmon3_t *ctx, int16_t current)
BATT-MON 3 calibrate current function.
err_t battmon3_read_measured_z(battmon3_t *ctx, uint16_t *measured_z)
BATT-MON 3 read measured Z function.
err_t battmon3_generic_write(battmon3_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
BATT-MON 3 I2C writing function.
void battmon3_set_en_pin_low(battmon3_t *ctx)
BATT-MON 3 set en pin low function.
err_t battmon3_read_control(battmon3_t *ctx, uint16_t control, uint16_t *data_out)
BATT-MON 3 read control function.
err_t battmon3_read_raw_calibration_data(battmon3_t *ctx, uint8_t reg, uint16_t *cal_data)
BATT-MON 3 read raw calibration data function.
err_t battmon3_set_design_capacity(battmon3_t *ctx, uint16_t des_capacity)
BATT-MON 3 set design capacity function.
err_t battmon3_read_temperature(battmon3_t *ctx, float *temperature)
BATT-MON 3 read temperature function.
err_t battmon3_disable_gauge(battmon3_t *ctx)
BATT-MON 3 disable gauge function.
err_t battmon3_init(battmon3_t *ctx, battmon3_cfg_t *cfg)
BATT-MON 3 initialization function.
err_t battmon3_default_cfg(battmon3_t *ctx)
BATT-MON 3 default configuration function.
err_t battmon3_write_two_bytes(battmon3_t *ctx, uint8_t reg, uint16_t data_in)
BATT-MON 3 write two bytes function.
err_t battmon3_calibrate_temperature(battmon3_t *ctx, float temperature)
BATT-MON 3 calibrate temperature function.
uint8_t battmon3_get_alert_pin(battmon3_t *ctx)
BATT-MON 3 get alert pin function.
BATT-MON 3 Click configuration object.
Definition battmon3.h:244
pin_name_t alr
Definition battmon3.h:249
uint32_t i2c_speed
Definition battmon3.h:251
pin_name_t scl
Definition battmon3.h:245
pin_name_t en
Definition battmon3.h:248
pin_name_t sda
Definition battmon3.h:246
uint8_t i2c_address
Definition battmon3.h:252
BATT-MON 3 Click context object.
Definition battmon3.h:220
digital_in_t alr
Definition battmon3.h:225
uint8_t security_mode
Definition battmon3.h:233
bool enabled
Definition battmon3.h:235
i2c_master_t i2c
Definition battmon3.h:228
digital_out_t en
Definition battmon3.h:222
uint8_t slave_address
Definition battmon3.h:231