-
Notifications
You must be signed in to change notification settings - Fork 3
/
bq27441.h
147 lines (126 loc) · 5.23 KB
/
bq27441.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
147
/**
* Copyright (c) 2020 Vitaliy Nimych (Cvetaev) @ cvetaevvitaliy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BQ27441_H
#define _BQ27441_H
#include <stdint.h>
#include <stdbool.h>
#include "bq27441_definitions.h"
#define BQ72441_I2C_TIMEOUT 20000
typedef int16_t (*i2c_write_byte)(uint8_t, uint8_t, uint8_t *, uint8_t);
typedef int16_t (*i2c_read_byte)(uint8_t, uint8_t, uint8_t *, uint8_t);
typedef struct {
/** Component mandatory fields **/
uint8_t BQ27441_i2c_address;
i2c_write_byte write_reg;
i2c_read_byte read_reg;
} BQ27441_ctx_t;
// Parameters for the current() function, to specify which current to read
typedef enum {
AVG, // Average Current (DEFAULT)
STBY, // Standby Current
MAX // Max Current
} current_measure;
// Parameters for the capacity() function, to specify which capacity to read
typedef enum {
REMAIN, // Remaining Capacity (DEFAULT)
FULL, // Full Capacity
AVAIL, // Available Capacity
AVAIL_FULL, // Full Available Capacity
REMAIN_F, // Remaining Capacity Filtered
REMAIN_UF, // Remaining Capacity Unfiltered
FULL_F, // Full Capacity Filtered
FULL_UF, // Full Capacity Unfiltered
DESIGN, // Design Capacity
TRUE_REMAIN //
} capacity_measure;
// Parameters for the soc() function
typedef enum {
FILTERED, // State of Charge Filtered (DEFAULT)
UNFILTERED // State of Charge Unfiltered
} soc_measure;
// Parameters for the soh() function
typedef enum {
PERCENT, // State of Health Percentage (DEFAULT)
SOH_STAT // State of Health Status Bits
} soh_measure;
// Parameters for the temperature function
typedef enum {
BATTERY, // Battery Temperature (DEFAULT)
INTERNAL_TEMP // Internal IC Temperature
} temp_measure;
// Parameters for the setGPOUTFunction() funciton
typedef enum {
SOC_INT, // Set GPOUT to SOC_INT functionality
BAT_LOW // Set GPOUT to BAT_LOW functionality
} gpout_function;
/*****************************************************************************
************************** Initialization Functions *************************
*****************************************************************************/
bool BQ27441_init (BQ27441_ctx_t *dev);
bool BQ27441_setCapacity (uint16_t capacity);
bool BQ27441_setHibernateCurrent(uint16_t current_mA);
bool BQ27441_setDesignEnergy (uint16_t energy);
bool BQ27441_setTerminateVoltageMin (uint16_t voltage);
bool BQ27441_setChargeVChgTermination(uint16_t voltage);
bool BQ27441_setTaperRateTime (uint16_t rate);
bool BQ27441_setTaperRateVoltage(uint16_t voltage);
/*****************************************************************************
********************** Battery Characteristics Functions ********************
*****************************************************************************/
uint16_t BQ27441_voltage (void);
int16_t BQ27441_current (current_measure type);
uint16_t BQ27441_capacity (capacity_measure type);
int16_t BQ27441_power (void);
uint16_t BQ27441_soc (soc_measure type);
uint8_t BQ27441_soh (soh_measure type);
uint16_t BQ27441_temperature (temp_measure type);
/*****************************************************************************
************************** GPOUT Control Functions **************************
*****************************************************************************/
bool BQ27441_GPOUTPolarity (void);
bool BQ27441_setGPOUTPolarity (bool activeHigh);
bool BQ27441_GPOUTFunction (void);
bool BQ27441_setSLEEPenable(bool enable);
bool BQ27441_setGPOUTFunction (gpout_function function);
uint8_t BQ27441_SOC1SetThreshold (void);
uint8_t BQ27441_SOC1ClearThreshold (void);
bool BQ27441_set_BI_PU_EN(bool detect_bat_pin_enable);
bool BQ27441_setSOC1Thresholds (uint8_t set, uint8_t clear);
uint8_t BQ27441_SOCFSetThreshold (void);
uint8_t BQ27441_SOCFClearThreshold (void);
bool BQ27441_setSOCFThresholds (uint8_t set, uint8_t clear);
bool BQ27441_socFlag (void);
bool BQ27441_socfFlag (void);
bool BQ27441_itporFlag (void);
bool BQ27441_initComp(void);
bool BQ27441_fcFlag (void);
bool BQ27441_chgFlag (void);
bool BQ27441_dsgFlag (void);
uint8_t BQ27441_sociDelta (void);
bool BQ27441_setSOCIDelta (uint8_t delta);
bool BQ27441_pulseGPOUT (void);
/*****************************************************************************
*************************** Control Sub-Commands ****************************
*****************************************************************************/
uint16_t BQ27441_deviceType (void);
bool BQ27441_enterConfig (bool userControl);
bool BQ27441_exitConfig (bool resim);
uint16_t BQ27441_flags (void);
uint16_t BQ27441_status (void);
bool BQ27441_SET_HIBERNATE(void);
bool BQ27441_CLEAR_HIBERNATE(void);
void BQ27441_Full_Reset(void);
#endif // _BQ27441_H