amiro-lld / include / bq27500 / v1 / alld_bq27500_v1.h @ 9797f02a
History | View | Annotate | Download (13.038 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file alld_bq27500_v1.h
|
21 |
* @brief Fuel Gauge constants and structures.
|
22 |
*
|
23 |
* @addtogroup lld_gauge
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROLLD_BQ27500_V1_H
|
28 |
#define AMIROLLD_BQ27500_V1_H
|
29 |
|
30 |
#include <amiro-lld.h> |
31 |
|
32 |
#if (defined(AMIROLLD_CFG_BQ27500) && (AMIROLLD_CFG_BQ27500 == 1)) || defined(__DOXYGEN__) |
33 |
|
34 |
/******************************************************************************/
|
35 |
/* CONSTANTS */
|
36 |
/******************************************************************************/
|
37 |
|
38 |
/**
|
39 |
* @brief Hardware version number.
|
40 |
* @details There are three different revisions of the bq27500 fuel gauge:
|
41 |
* 100, 120, and 130.
|
42 |
* If no version is set, it defaults to 100.
|
43 |
*/
|
44 |
#if !defined(BQ27500_LLD_HWVERSION)
|
45 |
#define BQ27500_LLD_HWVERSION 100 |
46 |
#endif
|
47 |
|
48 |
/* hardware version santity checks */
|
49 |
#if (BQ27500_LLD_HWVERSION != 100) && (BQ27500_LLD_HWVERSION != 120) && (BQ27500_LLD_HWVERSION != 130) |
50 |
#error "Invalid hardware version selected" |
51 |
#endif
|
52 |
|
53 |
/**
|
54 |
* @brief fixed I2C address
|
55 |
*/
|
56 |
#define BQ27500_LLD_I2C_ADDR 0x55u |
57 |
|
58 |
/**
|
59 |
* @brief maximum I2C frequency in Hz
|
60 |
*/
|
61 |
#if (BQ27500_LLD_HWVERSION == 100) |
62 |
#define BQ27500_LLD_I2C_MAXFREQUENCY 100000 |
63 |
#elif (BQ27500_LLD_HWVERSION == 120) |
64 |
#define BQ27500_LLD_I2C_MAXFREQUENCY 400000 |
65 |
#elif (BQ27500_LLD_HWVERSION == 130) |
66 |
#define BQ27500_LLD_I2C_MAXFREQUENCY 400000 |
67 |
#endif
|
68 |
|
69 |
/**
|
70 |
* @brief default key0 to get into unsealed mode
|
71 |
*/
|
72 |
#define BQ27500_LLD_DEFAULT_UNSEAL_KEY0 0x3672u |
73 |
|
74 |
/**
|
75 |
* @brief default key1 to get into unsealed mode
|
76 |
*/
|
77 |
#define BQ27500_LLD_DEFAULT_UNSEAL_KEY1 0x0414u |
78 |
|
79 |
/**
|
80 |
* @brief Active state of battery low gpio.
|
81 |
*/
|
82 |
#define BQ27500_LLD_BATLOW_ACTIVE_STATE APAL_GPIO_ACTIVE_HIGH
|
83 |
|
84 |
/**
|
85 |
* @brief Active state of battery good gpio.
|
86 |
*/
|
87 |
#define BQ27500_LLD_BATGOOD_ACTIVE_STATE APAL_GPIO_ACTIVE_LOW
|
88 |
|
89 |
/******************************************************************************/
|
90 |
/* SETTINGS */
|
91 |
/******************************************************************************/
|
92 |
|
93 |
/******************************************************************************/
|
94 |
/* CHECKS */
|
95 |
/******************************************************************************/
|
96 |
|
97 |
/******************************************************************************/
|
98 |
/* DATA STRUCTURES AND TYPES */
|
99 |
/******************************************************************************/
|
100 |
|
101 |
/**
|
102 |
* @brief Possible standard commands.
|
103 |
*/
|
104 |
typedef enum { |
105 |
// unit | access
|
106 |
// | sealed | unsealed
|
107 |
// ---------+---------+----------
|
108 |
BQ27500_LLD_STD_CMD_Control = 0x00u, BQ27500_LLD_STD_CMD_CNTL = 0x00u, // N/A | R/W | R/W |
109 |
BQ27500_LLD_STD_CMD_AtRate = 0x02u, BQ27500_LLD_STD_CMD_AR = 0x02u, // mA | R/W | R/W |
110 |
BQ27500_LLD_STD_CMD_AtRateTimeToEmpty = 0x04u, BQ27500_LLD_STD_CMD_ARTTE = 0x04u, // minutes | R | R/W |
111 |
BQ27500_LLD_STD_CMD_Temperature = 0x06u, BQ27500_LLD_STD_CMD_TEMP = 0x06u, // 0.1 K | R | R/W |
112 |
BQ27500_LLD_STD_CMD_Voltage = 0x08u, BQ27500_LLD_STD_CMD_VOLT = 0x08u, // mV | R | R/W |
113 |
BQ27500_LLD_STD_CMD_Flags = 0x0Au, BQ27500_LLD_STD_CMD_FLAGS = 0x0Au, // N/A | R | R/W |
114 |
BQ27500_LLD_STD_CMD_NominalAvailableCapacity = 0x0Cu, BQ27500_LLD_STD_CMD_NAC = 0x0Cu, // mAh | R | R/W |
115 |
BQ27500_LLD_STD_CMD_FullAvailableCapacity = 0x0Eu, BQ27500_LLD_STD_CMD_FAC = 0x0Eu, // mAh | R | R/W |
116 |
BQ27500_LLD_STD_CMD_RemainingCapacity = 0x10u, BQ27500_LLD_STD_CMD_RM = 0x10u, // mAh | R | R/W |
117 |
BQ27500_LLD_STD_CMD_FullChargeCapacity = 0x12u, BQ27500_LLD_STD_CMD_FCC = 0x12u, // mAh | R | R/W |
118 |
BQ27500_LLD_STD_CMD_AverageCurrent = 0x14u, BQ27500_LLD_STD_CMD_AI = 0x14u, // mA | R | R/W |
119 |
BQ27500_LLD_STD_CMD_TimeToEmpty = 0x16u, BQ27500_LLD_STD_CMD_TTE = 0x16u, // minutes | R | R/W |
120 |
BQ27500_LLD_STD_CMD_TimeToFull = 0x18u, BQ27500_LLD_STD_CMD_TTF = 0x18u, // minutes | R | R/W |
121 |
BQ27500_LLD_STD_CMD_StandbyCurrent = 0x1Au, BQ27500_LLD_STD_CMD_SI = 0x1Au, // mA | R | R/W |
122 |
BQ27500_LLD_STD_CMD_StandbyTimeToEmpty = 0x1Cu, BQ27500_LLD_STD_CMD_STTE = 0x1Cu, // minutes | R | R/W |
123 |
BQ27500_LLD_STD_CMD_MaxLoadCurrent = 0x1Eu, BQ27500_LLD_STD_CMD_MLI = 0x1Eu, // mA | R | R/W |
124 |
BQ27500_LLD_STD_CMD_MaxLoadTimeToEmpty = 0x20u, BQ27500_LLD_STD_CMD_MLTTE = 0x20u, // minutes | R | R/W |
125 |
BQ27500_LLD_STD_CMD_AvailableEnergy = 0x22u, BQ27500_LLD_STD_CMD_AE = 0x22u, // mWh | R | R/W |
126 |
BQ27500_LLD_STD_CMD_AveragePower = 0x24u, BQ27500_LLD_STD_CMD_AP = 0x24u, // mW | R | R/W |
127 |
BQ27500_LLD_STD_CMD_TimeToEmptyAtConstantPower = 0x26u, BQ27500_LLD_STD_CMD_TTECP = 0x26u, // minutes | R | R/W |
128 |
BQ27500_LLD_STD_CMD_CycleCount = 0x2Au, BQ27500_LLD_STD_CMD_CC = 0x2Au, // counts | R | R/W |
129 |
BQ27500_LLD_STD_CMD_StateOfCharge = 0x2Cu, BQ27500_LLD_STD_CMD_SOC = 0x2Cu // % | R | R/W |
130 |
} bq27500_lld_std_command_t; |
131 |
|
132 |
/**
|
133 |
* @brief Subcommands of the control command.
|
134 |
*/
|
135 |
typedef enum { |
136 |
// sealed access
|
137 |
// -------------
|
138 |
BQ27500_LLD_SUB_CMD_CONTROL_STATUS = 0x0000u, // yes |
139 |
BQ27500_LLD_SUB_CMD_DEVICE_TYPE = 0x0001u, // yes |
140 |
BQ27500_LLD_SUB_CMD_FW_VERSION = 0x0002u, // yes |
141 |
BQ27500_LLD_SUB_CMD_HW_VERSION = 0x0003u, // yes |
142 |
BQ27500_LLD_SUB_CMD_DF_CHECKSUM = 0x0004u, // no |
143 |
BQ27500_LLD_SUB_CMD_RESET_DATA = 0x0005u, // yes |
144 |
BQ27500_LLD_SUB_CMD_PREV_MACWRITE = 0x0007u, // yes |
145 |
BQ27500_LLD_SUB_CMD_CHEM_ID = 0x0008u, // yes |
146 |
BQ27500_LLD_SUB_CMD_BOARD_OFFSET = 0x0009u, // no |
147 |
BQ27500_LLD_SUB_CMD_CC_INT_OFFSET = 0x000Au, // no |
148 |
BQ27500_LLD_SUB_CMD_WRITE_OFFSET = 0x000Bu, // no |
149 |
BQ27500_LLD_SUB_CMD_SET_HIBERNATE = 0x0011u, // yes |
150 |
BQ27500_LLD_SUB_CMD_CLEAR_HIBERNATE = 0x0012u, // yes |
151 |
BQ27500_LLD_SUB_CMD_SET_SLEEPp = 0x0013u, // yes |
152 |
BQ27500_LLD_SUB_CMD_CLEAR_SLEEPp = 0x0014u, // yes |
153 |
BQ27500_LLD_SUB_CMD_SEALED = 0x0020u, // no |
154 |
BQ27500_LLD_SUB_CMD_IT_ENABLE = 0x0021u, // no |
155 |
BQ27500_LLD_SUB_CMD_IF_CHECKSUM = 0x0022u, // no |
156 |
BQ27500_LLD_SUB_CMD_CAL_MODE = 0x0040u, // no |
157 |
BQ27500_LLD_SUB_CMD_RESET = 0x0041u, // no |
158 |
} bq27500_lld_control_subcmd_t; |
159 |
|
160 |
/**
|
161 |
* @brief Extended commands.
|
162 |
*/
|
163 |
typedef enum { |
164 |
// length | unit | sealed | unsealed
|
165 |
// -------+------+--------+----------
|
166 |
BQ27500_LLD_EXT_CMD_DesignCapacity = 0x3Cu, EXT_CMD_DCAP = 0x3Cu, // 2 | mAh | R | R |
167 |
BQ27500_LLD_EXT_CMD_DataFlashClass = 0x3Eu, EXT_CMD_DFCLS = 0x3Eu, // 1 | N/A | N/A | R/W |
168 |
BQ27500_LLD_EXT_CMD_DataFlashBlock = 0x3Fu, EXT_CMD_DFBLK = 0x3Fu, // 1 | N/A | R/W | R/W |
169 |
BQ27500_LLD_EXT_CMD_BlockData = 0x40u, EXT_CMD_DFD = 0x40u, // 32 | N/A | R | R/W |
170 |
BQ27500_LLD_EXT_CMD_BlockDataCheckSum = 0x60u,EXT_CMD_DFDCKS = 0x60u, // 1 | N/A | R/W | R/W |
171 |
BQ27500_LLD_EXT_CMD_BlockDataControl = 0x61u, EXT_CMD_DFDCNTL = 0x61u, // 1 | N/A | N/A | R/W |
172 |
BQ27500_LLD_EXT_CMD_DeviceNameLength = 0x62u, EXT_CMD_DNAMELEN = 0x62u, // 1 | N/A | R | R |
173 |
BQ27500_LLD_EXT_CMD_DeviceName = 0x63u, EXT_CMD_DNAME = 0x63u, // 7 | N/A | R | R |
174 |
BQ27500_LLD_EXT_CMD_ApplicationStatus = 0x6Au, EXT_CMD_APPSTAT = 0x6Au // 1 | N/A | R | R |
175 |
} bq27500_lld_ext_command_t; |
176 |
|
177 |
/**
|
178 |
* @brief Read or write access to extended commands.
|
179 |
*/
|
180 |
typedef enum { |
181 |
BQ27500_LLD_EXT_CMD_READ = 0,
|
182 |
BQ27500_LLD_EXT_CMD_WRITE = 1,
|
183 |
} bq27500_lld_ext_cmd_access_t; |
184 |
|
185 |
/**
|
186 |
* @brief Union to inspect the version value.
|
187 |
*/
|
188 |
typedef union { |
189 |
uint16_t value; |
190 |
struct {
|
191 |
uint16_t minor_low : 4;
|
192 |
uint16_t minor_high : 4;
|
193 |
uint16_t major_low : 4;
|
194 |
uint16_t major_high : 4;
|
195 |
} content; |
196 |
} bq27500_lld_version_t; |
197 |
|
198 |
/**
|
199 |
* @brief Union to inspect the flags register.
|
200 |
*/
|
201 |
typedef union { |
202 |
uint16_t value; |
203 |
struct {
|
204 |
uint16_t dsg : 1;
|
205 |
uint16_t socf : 1;
|
206 |
uint16_t soc1 : 1;
|
207 |
uint16_t bat_det : 1;
|
208 |
uint16_t wait_id : 1;
|
209 |
uint16_t ocv_gd : 1;
|
210 |
uint16_t rsvd_6_7 : 2;
|
211 |
uint16_t chg : 1;
|
212 |
uint16_t fc : 1;
|
213 |
uint16_t xchg : 1;
|
214 |
uint16_t chg_inh : 1;
|
215 |
uint16_t rsvd_12_13 : 2;
|
216 |
uint16_t otd : 1;
|
217 |
uint16_t otc : 1;
|
218 |
} content; |
219 |
} bq27500_lld_flags_t; |
220 |
|
221 |
/**
|
222 |
* @brief Union to inspect the control status.
|
223 |
*/
|
224 |
typedef union { |
225 |
uint16_t value; |
226 |
struct {
|
227 |
uint16_t qen : 1;
|
228 |
uint16_t vok : 1;
|
229 |
uint16_t rup_dis : 1;
|
230 |
uint16_t ldmd : 1;
|
231 |
uint16_t sleep : 1;
|
232 |
uint16_t snooze : 1;
|
233 |
uint16_t hibernate : 1;
|
234 |
uint16_t rsvd_7_8_9 : 3;
|
235 |
uint16_t bca : 1;
|
236 |
uint16_t cca : 1;
|
237 |
uint16_t csv : 1;
|
238 |
uint16_t ss : 1;
|
239 |
uint16_t fas : 1;
|
240 |
uint16_t rsvd_15 : 1;
|
241 |
} content; |
242 |
} bq27500_lld_control_status_t; |
243 |
|
244 |
/**
|
245 |
* @brief BQ27500 Driver struct.
|
246 |
*/
|
247 |
typedef struct { |
248 |
apalI2CDriver_t* i2cd; /**< @brief I2C driver to access the BQ27500 */
|
249 |
const apalControlGpio_t* gpio_batlow; /**< @brief Gpio to indicate whether the battery is low */ |
250 |
const apalControlGpio_t* gpio_batgood; /**< @brief Gpio to indicate whether the battery is good */ |
251 |
} BQ27500Driver; |
252 |
|
253 |
/**
|
254 |
* @brief Battery low enum.
|
255 |
*/
|
256 |
typedef enum { |
257 |
BQ27500_LLD_BATTERY_LOW = 0x01,
|
258 |
BQ27500_LLD_BATTERY_NOT_LOW = 0x00,
|
259 |
} bq27500_lld_batlow_t; |
260 |
|
261 |
/**
|
262 |
* @brief Battery good enum.
|
263 |
*/
|
264 |
typedef enum { |
265 |
BQ27500_LLD_BATTERY_GOOD = 0x01,
|
266 |
BQ27500_LLD_BATTERY_NOT_GOOD = 0x00,
|
267 |
} bq27500_lld_batgood_t; |
268 |
|
269 |
/******************************************************************************/
|
270 |
/* MACROS */
|
271 |
/******************************************************************************/
|
272 |
|
273 |
/******************************************************************************/
|
274 |
/* EXTERN DECLARATIONS */
|
275 |
/******************************************************************************/
|
276 |
|
277 |
#ifdef __cplusplus
|
278 |
extern "C" { |
279 |
#endif
|
280 |
apalExitStatus_t bq27500_lld_read_batlow(const BQ27500Driver* const bq27500, bq27500_lld_batlow_t* const batlow); |
281 |
apalExitStatus_t bq27500_lld_read_batgood(const BQ27500Driver* const bq27500, bq27500_lld_batgood_t* const batgood); |
282 |
apalExitStatus_t bq27500_lld_std_command(const BQ27500Driver* const bq27500, const bq27500_lld_std_command_t cmd, uint16_t* const dst, const apalTime_t timeout); |
283 |
apalExitStatus_t bq27500_lld_sub_command_call(const BQ27500Driver* const bq27500, const bq27500_lld_control_subcmd_t cmd, const apalTime_t timeout); |
284 |
apalExitStatus_t bq27500_lld_sub_command_read(const BQ27500Driver* const bq27500, uint16_t* const data, const apalTime_t timeout); |
285 |
apalExitStatus_t bq27500_lld_ext_command(const BQ27500Driver* const bq27500, const bq27500_lld_ext_command_t cmd, const bq27500_lld_ext_cmd_access_t rw, uint8_t* const buffer, const uint8_t length, const uint8_t offset, const apalTime_t timeout); |
286 |
apalExitStatus_t bq27500_lld_send_ctnl_data(const BQ27500Driver* const bq27500, const uint16_t data, const apalTime_t timeout); |
287 |
apalExitStatus_t bq27500_lld_compute_blockdata_checksum(const uint8_t* const blockdata, uint8_t* const sum); |
288 |
#ifdef __cplusplus
|
289 |
} |
290 |
#endif
|
291 |
|
292 |
/******************************************************************************/
|
293 |
/* INLINE FUNCTIONS */
|
294 |
/******************************************************************************/
|
295 |
|
296 |
#endif /* defined(AMIROLLD_CFG_BQ27500) && (AMIROLLD_CFG_BQ27500 == 1) */ |
297 |
|
298 |
#endif /* AMIROLLD_BQ27500_V1_H */ |
299 |
|
300 |
/** @} */
|