-
Notifications
You must be signed in to change notification settings - Fork 2
/
bq24157.h
146 lines (131 loc) · 5.98 KB
/
bq24157.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef __BQ24157_H
#define __BQ24157_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx_hal.h"
#include <stdbool.h>
#define BQ24157_I2C_ADDRESS 0xD4
#define HAL_I2C_INSTANCE hi2c2
#define HAL_BQ24157_TIMEOUT 1
#define BQ24157_STATUS_CONTROL_REG 0x00
#define BQ24157_CONTROL_REG 0x01
#define BQ24157_CONTROL_VOLTAGE_REG 0x02
#define BQ24157_VENDOR_PART_REV_REG 0x03
#define BQ24157_BATT_TERM_CURRENT_REG 0x04
#define BQ24157_SPEC_CHRG_EN_PIN_REG 0x05
#define BQ24157_SAFTEY_LIMIT_REG 0x06
// In value v, MODify BIT at position p to be at state s
#define MOD_BIT(v,p,s) ((v&(~(1U<<p)))|(-s&(1U<<p)))
typedef enum
{
BQ24157_STAT_READY = 0,
BQ24157_STAT_CHARGING,
BQ24157_STAT_CHARGE_DONE,
BQ24157_STAT_FAULT,
BQ24157_ERROR = -1
}
BQ24157_STAT_TYPE;
typedef enum
{
BQ24157_CHARGE_FAULT_NORMAL = 0,
BQ24157_CHARGE_FAULT_VBUSOVP,
BQ24157_CHARGE_FAULT_SLEEP,
BQ24157_CHARGE_FAULT_VBUSLOW,
BQ24157_CHARGE_FAULT_OUTPUTOVP,
BQ24157_CHARGE_FAULT_THERMALSHUTDOWN,
BQ24157_CHARGE_FAULT_TIMERFAULT,
BQ24157_CHARGE_FAULT_NOBATTERY,
BQ24157_BOOST_FAULT_NORMAL,
BQ24157_BOOST_FAULT_VBUSOVP,
BQ24157_BOOST_FAULT_OVERLOAD,
BQ24157_BOOST_FAULT_BATTLOW,
BQ24157_BOOST_FAULT_BATTOVP,
BQ24157_BOOST_FAULT_THERMALSHUTDOWN,
BQ24157_BOOST_FAULT_TIMERFAULT,
BQ24157_BOOST_FAULT_NA,
BQ24157_FAULT_ERROR = -1
}
BQ24157_FAULT_TYPE;
typedef enum
{
BQ24157_INPUT_CURRENT_100MA = 0,
BQ24157_INPUT_CURRENT_500MA,
BQ24157_INPUT_CURRENT_800MA,
BQ24157_INPUT_CURRENT_NO_LIMIT,
BQ24157_INPUT_CURRENT_ERROR = -1
}
BQ24157_INPUT_CURRENT_LIMIT_TYPE;
int16_t _rSense_mOhm;
typedef struct
{
uint16_t rSense_mOhm;
uint16_t chargeCurrent_mA;
uint16_t terminationCurrent_mA;
uint16_t lowBatteryThreshold_mV;
uint16_t inputCurrentLimit_mA;
uint16_t batteryRegulationVoltage_mV;
uint16_t specialChargeVoltage_mV;
uint16_t maxBatteryRegulationVoltage_mV;
uint16_t maxChargeCurrent_mA;
BQ24157_STAT_TYPE status;
BQ24157_FAULT_TYPE fault;
bool isCharging;
bool isBoosting;
bool isEnabled;
bool otgPinStatus;
}
bq24157_info;
bool bq24157_register_write(uint8_t reg, uint8_t data);
bool bq24157_register_read(uint8_t reg, uint8_t *data);
bool bq24157_init(uint16_t rsense_mohm, uint16_t batVoltage_mV, uint16_t chargeCurrent_mA);
bool bq24157_update( bq24157_info *charger );
bool bq24157_setRSense(uint16_t rsense_mohm);
int16_t bq24157_getRSense(void);
bool bq24157_resetSafteyTimer(void);
int8_t bq24157_getOtgPinStatus(void);
int8_t bq24157_getStatPinFunction(void);
bool bq24157_setStatPinFunction(bool status);
BQ24157_STAT_TYPE bq24157_getStatus(void);
int8_t bq24157_getBoostMode(void);
BQ24157_FAULT_TYPE bq24157_getFault(void);
BQ24157_INPUT_CURRENT_LIMIT_TYPE bq24157_getInputCurrentLimit(void);
bool bq24157_setInputCurrentLimit(BQ24157_INPUT_CURRENT_LIMIT_TYPE inputCurrent);
int16_t bq24157_getWeakBatteryThreshold(void);
bool bq24157_setWeakBatteryThreshold(uint16_t voltage);
int8_t bq24157_getChargeCurrentTerm(void);
bool bq24157_setChargeCurrentTerm(bool status);
int8_t bq24157_getChargerEnable(void);
bool bq24157_setChargerEnable(bool status);
int8_t bq24157_getHighImpedanceMode(void);
bool bq24157_setHighImpedanceMode(bool status);
int8_t bq24157_getOperationMode(void);
bool bq24157_setOperationMode(bool mode);
int16_t bq24157_getBatteryRegulationVoltage(void);
bool bq24157_setBatteryRegulationVoltage(uint16_t voltage);
int8_t bq24157_getOtgPinPolarity(void);
bool bq24157_setOtgPinPolarity(bool polarity);
int8_t bq24157_getOtgPinEnable(void);
bool bq24157_setOtgPinEnable(bool enable);
int8_t bq24157_getVendorCode(void);
int8_t bq24157_getPartCode(void);
int8_t bq24157_getPartRevision(void);
bool bq24157_setReset(void);
int16_t bq24157_getChargeCurrentSenseVoltage(void);
bool bq24157_setChargeCurrentSenseVoltage(uint16_t voltage);
int16_t bq24157_getTermCurrentSenseVoltage(void);
bool bq24157_setTermCurrentSenseVoltage(uint16_t voltage);
int8_t bq24157_getLowChargeCurrentSenseVoltage(void);
bool bq24157_setLowChargeCurrentSenseVoltage(bool low_chg);
int8_t bq24157_getDpmStatus(void);
int8_t bq24157_getCdStatus(void);
int16_t bq24157_getSpecialChargerVoltage(void);
bool bq24157_setSpecialChargerVoltage(uint16_t voltage);
int16_t bq24157_getMaxChargeCurrentSenseVoltage(void);
bool bq24157_setMaxChargeCurrentSenseVoltage(uint16_t voltage);
int16_t bq24157_getMaxBatteryRegulationVoltage(void);
bool bq24157_setMaxBatteryRegulationVoltage(uint16_t voltage);
#ifdef __cplusplus
}
#endif
#endif /* __BQ24157_H */