amiro-os / modules / PowerManagement_1-1 / module.c @ 63592e51
History | View | Annotate | Download (38.323 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2018 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 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 General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
#include "module.h" |
20 |
|
21 |
#include <amiroos.h> |
22 |
|
23 |
/*===========================================================================*/
|
24 |
/**
|
25 |
* @name Module specific functions
|
26 |
* @{
|
27 |
*/
|
28 |
/*===========================================================================*/
|
29 |
|
30 |
/** @} */
|
31 |
|
32 |
/*===========================================================================*/
|
33 |
/**
|
34 |
* @name ChibiOS/HAL configuration
|
35 |
* @{
|
36 |
*/
|
37 |
/*===========================================================================*/
|
38 |
|
39 |
ADCConversionGroup moduleHalAdcVsysConversionGroup = { |
40 |
/* buffer type */ true, |
41 |
/* number of channels */ 1, |
42 |
/* callback function */ NULL, |
43 |
/* error callback */ NULL, |
44 |
/* CR1 */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
|
45 |
/* CR2 */ ADC_CR2_SWSTART | ADC_CR2_CONT,
|
46 |
/* SMPR1 */ 0, |
47 |
/* SMPR2 */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
|
48 |
/* HTR */ ADC_HTR_HT,
|
49 |
/* LTR */ 0, |
50 |
/* SQR1 */ ADC_SQR1_NUM_CH(1), |
51 |
/* SQR2 */ 0, |
52 |
/* SQR3 */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
|
53 |
}; |
54 |
|
55 |
CANConfig moduleHalCanConfig = { |
56 |
/* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
57 |
/* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1), |
58 |
}; |
59 |
|
60 |
I2CConfig moduleHalI2cProxPm18Pm33GaugeRearConfig = { |
61 |
/* I²C mode */ OPMODE_I2C,
|
62 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
63 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
64 |
}; |
65 |
|
66 |
I2CConfig moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig = { |
67 |
/* I²C mode */ OPMODE_I2C,
|
68 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
69 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
70 |
}; |
71 |
|
72 |
PWMConfig moduleHalPwmBuzzerConfig = { |
73 |
/* frequency */ 1000000, |
74 |
/* period */ 0, |
75 |
/* callback */ NULL, |
76 |
/* channel configurations */ {
|
77 |
/* channel 0 */ {
|
78 |
/* mode */ PWM_OUTPUT_DISABLED,
|
79 |
/* callback */ NULL |
80 |
}, |
81 |
/* channel 1 */ {
|
82 |
/* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
83 |
/* callback */ NULL |
84 |
}, |
85 |
/* channel 2 */ {
|
86 |
/* mode */ PWM_OUTPUT_DISABLED,
|
87 |
/* callback */ NULL |
88 |
}, |
89 |
/* channel 3 */ {
|
90 |
/* mode */ PWM_OUTPUT_DISABLED,
|
91 |
/* callback */ NULL |
92 |
}, |
93 |
}, |
94 |
/* TIM CR2 register */ 0, |
95 |
#if STM32_PWM_USE_ADVANCED
|
96 |
/* TIM BDTR register */ 0, |
97 |
#endif
|
98 |
/* TIM DIER register */ 0, |
99 |
}; |
100 |
|
101 |
SerialConfig moduleHalProgIfConfig = { |
102 |
/* bit rate */ 115200, |
103 |
/* CR1 */ 0, |
104 |
/* CR1 */ 0, |
105 |
/* CR1 */ 0, |
106 |
}; |
107 |
|
108 |
/** @} */
|
109 |
|
110 |
/*===========================================================================*/
|
111 |
/**
|
112 |
* @name GPIO definitions
|
113 |
* @{
|
114 |
*/
|
115 |
/*===========================================================================*/
|
116 |
|
117 |
/**
|
118 |
* @brief SYS_REG_EN output signal GPIO.
|
119 |
*/
|
120 |
static apalGpio_t _gpioSysRegEn = {
|
121 |
/* port */ GPIOA,
|
122 |
/* pad */ GPIOA_SYS_REG_EN,
|
123 |
}; |
124 |
apalControlGpio_t moduleSysRegEn = { |
125 |
/* GPIO */ &_gpioSysRegEn,
|
126 |
/* meta */ {
|
127 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
128 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
129 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
130 |
}, |
131 |
}; |
132 |
|
133 |
/**
|
134 |
* @brief IR_INT1 input signal GPIO.
|
135 |
*/
|
136 |
static apalGpio_t _gpioIrInt1 = {
|
137 |
/* port */ GPIOB,
|
138 |
/* pad */ GPIOB_IR_INT1_N,
|
139 |
}; |
140 |
apalControlGpio_t moduleGpioIrInt1 = { |
141 |
/* GPIO */ &_gpioIrInt1,
|
142 |
/* meta */ {
|
143 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
144 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
145 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
146 |
}, |
147 |
}; |
148 |
|
149 |
/**
|
150 |
* @brief POWER_EN output signal GPIO.
|
151 |
*/
|
152 |
static apalGpio_t _gpioPowerEn = {
|
153 |
/* port */ GPIOB,
|
154 |
/* pad */ GPIOB_POWER_EN,
|
155 |
}; |
156 |
apalControlGpio_t moduleGpioPowerEn = { |
157 |
/* GPIO */ &_gpioPowerEn,
|
158 |
/* meta */ {
|
159 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
160 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
161 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
162 |
}, |
163 |
}; |
164 |
|
165 |
/**
|
166 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
167 |
*/
|
168 |
static apalGpio_t _gpioSysUartDn = {
|
169 |
/* port */ GPIOB,
|
170 |
/* pad */ GPIOB_SYS_UART_DN,
|
171 |
}; |
172 |
apalControlGpio_t moduleGpioSysUartDn = { |
173 |
/* GPIO */ &_gpioSysUartDn,
|
174 |
/* meta */ {
|
175 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
176 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
177 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
178 |
}, |
179 |
}; |
180 |
|
181 |
/**
|
182 |
* @brief CHARGE_STAT2A input signal GPIO.
|
183 |
*/
|
184 |
static apalGpio_t _gpioChargeStat2A = {
|
185 |
/* port */ GPIOB,
|
186 |
/* pad */ GPIOB_CHARGE_STAT2A,
|
187 |
}; |
188 |
apalControlGpio_t moduleGpioChargeStat2A = { |
189 |
/* GPIO */ &_gpioChargeStat2A,
|
190 |
/* meta */ {
|
191 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
192 |
/* active state */ BQ24103A_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
193 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
194 |
}, |
195 |
}; |
196 |
|
197 |
/**
|
198 |
* @brief GAUGE_BATLOW2 input signal GPIO.
|
199 |
*/
|
200 |
static apalGpio_t _gpioGaugeBatLow2 = {
|
201 |
/* port */ GPIOB,
|
202 |
/* pad */ GPIOB_GAUGE_BATLOW2,
|
203 |
}; |
204 |
apalControlGpio_t moduleGpioGaugeBatLow2 = { |
205 |
/* GPIO */ &_gpioGaugeBatLow2,
|
206 |
/* meta */ {
|
207 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
208 |
/* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
209 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
210 |
}, |
211 |
}; |
212 |
|
213 |
/**
|
214 |
* @brief GAUGE_BATGD2 input signal GPIO.
|
215 |
*/
|
216 |
static apalGpio_t _gpioGaugeBatGd2 = {
|
217 |
/* port */ GPIOB,
|
218 |
/* pad */ GPIOB_GAUGE_BATGD2_N,
|
219 |
}; |
220 |
apalControlGpio_t moduleGpioGaugeBatGd2 = { |
221 |
/* GPIO */ &_gpioGaugeBatGd2,
|
222 |
/* meta */ {
|
223 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
224 |
/* active state */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
|
225 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
226 |
}, |
227 |
}; |
228 |
|
229 |
/**
|
230 |
* @brief LED output signal GPIO.
|
231 |
*/
|
232 |
static apalGpio_t _gpioLed = {
|
233 |
/* port */ GPIOB,
|
234 |
/* pad */ GPIOB_LED,
|
235 |
}; |
236 |
apalControlGpio_t moduleGpioLed = { |
237 |
/* GPIO */ &_gpioLed,
|
238 |
/* meta */ {
|
239 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
240 |
/* active state */ LED_LLD_GPIO_ACTIVE_STATE,
|
241 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
242 |
}, |
243 |
}; |
244 |
|
245 |
/**
|
246 |
* @brief SYS_UART_UP bidirectional signal GPIO.
|
247 |
*/
|
248 |
static apalGpio_t _gpioSysUartUp = {
|
249 |
/* port */ GPIOB,
|
250 |
/* pad */ GPIOB_SYS_UART_UP,
|
251 |
}; |
252 |
apalControlGpio_t moduleGpioSysUartUp = { |
253 |
/* GPIO */ &_gpioSysUartUp,
|
254 |
/* meta */ {
|
255 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
256 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
257 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
258 |
}, |
259 |
}; |
260 |
|
261 |
/**
|
262 |
* @brief CHARGE_STAT1A input signal GPIO.
|
263 |
*/
|
264 |
static apalGpio_t _gpioChargeStat1A = {
|
265 |
/* port */ GPIOC,
|
266 |
/* pad */ GPIOC_CHARGE_STAT1A,
|
267 |
}; |
268 |
apalControlGpio_t moduleGpioChargeStat1A = { |
269 |
/* GPIO */ &_gpioChargeStat1A,
|
270 |
/* meta */ {
|
271 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
272 |
/* active state */ BQ24103A_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
273 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
274 |
}, |
275 |
}; |
276 |
|
277 |
/**
|
278 |
* @brief GAUGE_BATLOW1 input signal GPIO.
|
279 |
*/
|
280 |
static apalGpio_t _gpioGaugeBatLow1 = {
|
281 |
/* port */ GPIOC,
|
282 |
/* pad */ GPIOC_GAUGE_BATLOW1,
|
283 |
}; |
284 |
apalControlGpio_t moduleGpioGaugeBatLow1 = { |
285 |
/* GPIO */ &_gpioGaugeBatLow1,
|
286 |
/* meta */ {
|
287 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
288 |
/* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
289 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
290 |
}, |
291 |
}; |
292 |
|
293 |
/**
|
294 |
* @brief GAUGE_BATGD1 input signal GPIO.
|
295 |
*/
|
296 |
static apalGpio_t _gpioGaugeBatGd1 = {
|
297 |
/* port */ GPIOC,
|
298 |
/* pad */ GPIOC_GAUGE_BATGD1_N,
|
299 |
}; |
300 |
apalControlGpio_t moduleGpioGaugeBatGd1 = { |
301 |
/* GPIO */ &_gpioGaugeBatGd1,
|
302 |
/* meta */ {
|
303 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
304 |
/* active state */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
|
305 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
306 |
}, |
307 |
}; |
308 |
|
309 |
/**
|
310 |
* @brief CHARG_EN1 output signal GPIO.
|
311 |
*/
|
312 |
static apalGpio_t _gpioChargeEn1 = {
|
313 |
/* port */ GPIOC,
|
314 |
/* pad */ GPIOC_CHARGE_EN1_N,
|
315 |
}; |
316 |
apalControlGpio_t moduleGpioChargeEn1 = { |
317 |
/* GPIO */ &_gpioChargeEn1,
|
318 |
/* meta */ {
|
319 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
320 |
/* active state */ BQ24103A_LLD_ENABLED_GPIO_ACTIVE_STATE,
|
321 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
322 |
}, |
323 |
}; |
324 |
|
325 |
/**
|
326 |
* @brief IR_INT2 input signal GPIO.
|
327 |
*/
|
328 |
static apalGpio_t _gpioIrInt2 = {
|
329 |
/* port */ GPIOC,
|
330 |
/* pad */ GPIOC_IR_INT2_N,
|
331 |
}; |
332 |
apalControlGpio_t moduleGpioIrInt2 = { |
333 |
/* GPIO */ &_gpioIrInt2,
|
334 |
/* meta */ {
|
335 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
336 |
/* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
337 |
/* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
338 |
}, |
339 |
}; |
340 |
|
341 |
/**
|
342 |
* @brief TOUCH_INT input signal GPIO.
|
343 |
*/
|
344 |
static apalGpio_t _gpioTouchInt = {
|
345 |
/* port */ GPIOC,
|
346 |
/* pad */ GPIOC_TOUCH_INT_N,
|
347 |
}; |
348 |
apalControlGpio_t moduleGpioTouchInt = { |
349 |
/* GPIO */ &_gpioTouchInt,
|
350 |
/* meta */ {
|
351 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
352 |
/* active state */ (MPR121_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
353 |
/* interrupt edge */ MPR121_LLD_INT_EDGE,
|
354 |
}, |
355 |
}; |
356 |
|
357 |
/**
|
358 |
* @brief SYS_DONE input signal GPIO.
|
359 |
*/
|
360 |
static apalGpio_t _gpioSysDone = {
|
361 |
/* port */ GPIOC,
|
362 |
/* pad */ GPIOC_SYS_DONE,
|
363 |
}; |
364 |
apalControlGpio_t moduleGpioSysDone = { |
365 |
/* GPIO */ &_gpioSysDone,
|
366 |
/* meta */ {
|
367 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
368 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
369 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
370 |
}, |
371 |
}; |
372 |
|
373 |
/**
|
374 |
* @brief SYS_PROG output signal GPIO.
|
375 |
*/
|
376 |
static apalGpio_t _gpioSysProg = {
|
377 |
/* port */ GPIOC,
|
378 |
/* pad */ GPIOC_SYS_PROG_N,
|
379 |
}; |
380 |
apalControlGpio_t moduleGpioSysProg = { |
381 |
/* GPIO */ &_gpioSysProg,
|
382 |
/* meta */ {
|
383 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
384 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
385 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
386 |
}, |
387 |
}; |
388 |
|
389 |
/**
|
390 |
* @brief PATH_DC input signal GPIO.
|
391 |
*/
|
392 |
static apalGpio_t _gpioPathDc = {
|
393 |
/* port */ GPIOC,
|
394 |
/* pad */ GPIOC_PATH_DC,
|
395 |
}; |
396 |
apalControlGpio_t moduleGpioPathDc = { |
397 |
/* GPIO */ &_gpioPathDc,
|
398 |
/* meta */ {
|
399 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
400 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
401 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
402 |
}, |
403 |
}; |
404 |
|
405 |
/**
|
406 |
* @brief SYS_SPI_DIR bidirectional signal GPIO.
|
407 |
*/
|
408 |
static apalGpio_t _gpioSysSpiDir = {
|
409 |
/* port */ GPIOC,
|
410 |
/* pad */ GPIOC_SYS_SPI_DIR,
|
411 |
}; |
412 |
apalControlGpio_t moduleGpioSysSpiDir = { |
413 |
/* GPIO */ &_gpioSysSpiDir,
|
414 |
/* meta */ {
|
415 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
416 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
417 |
/* interrupt edge */ APAL_GPIO_EDGE_FALLING,
|
418 |
}, |
419 |
}; |
420 |
|
421 |
/**
|
422 |
* @brief SYS_SYNC bidirectional signal GPIO.
|
423 |
*/
|
424 |
static apalGpio_t _gpioSysSync = {
|
425 |
/* port */ GPIOC,
|
426 |
/* pad */ GPIOC_SYS_INT_N,
|
427 |
}; |
428 |
apalControlGpio_t moduleGpioSysSync = { |
429 |
/* GPIO */ &_gpioSysSync,
|
430 |
/* meta */ {
|
431 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
432 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
433 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
434 |
}, |
435 |
}; |
436 |
|
437 |
/**
|
438 |
* @brief SYS_PD bidirectional signal GPIO.
|
439 |
*/
|
440 |
static apalGpio_t _gpioSysPd = {
|
441 |
/* port */ GPIOC,
|
442 |
/* pad */ GPIOC_SYS_PD_N,
|
443 |
}; |
444 |
apalControlGpio_t moduleGpioSysPd = { |
445 |
/* GPIO */ &_gpioSysPd,
|
446 |
/* meta */ {
|
447 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
448 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
449 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
450 |
}, |
451 |
}; |
452 |
|
453 |
/**
|
454 |
* @brief SYS_WARMRST bidirectional signal GPIO.
|
455 |
*/
|
456 |
static apalGpio_t _gpioSysWarmrst = {
|
457 |
/* port */ GPIOC,
|
458 |
/* pad */ GPIOC_SYS_WARMRST_N,
|
459 |
}; |
460 |
apalControlGpio_t moduleGpioSysWarmrst = { |
461 |
/* GPIO */ &_gpioSysWarmrst,
|
462 |
/* meta */ {
|
463 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
464 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
465 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
466 |
}, |
467 |
}; |
468 |
|
469 |
/**
|
470 |
* @brief BT_RST output signal GPIO.
|
471 |
*/
|
472 |
static apalGpio_t _gpioBtRst = {
|
473 |
/* port */ GPIOC,
|
474 |
/* pad */ GPIOC_BT_RST,
|
475 |
}; |
476 |
apalControlGpio_t moduleGpioBtRst = { |
477 |
/* GPIO */ &_gpioBtRst,
|
478 |
/* meta */ {
|
479 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
480 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
481 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
482 |
}, |
483 |
}; |
484 |
|
485 |
/**
|
486 |
* @brief CHARGE_EN2 output signal GPIO.
|
487 |
*/
|
488 |
static apalGpio_t _gpioChargeEn2 = {
|
489 |
/* port */ GPIOD,
|
490 |
/* pad */ GPIOD_CHARGE_EN2_N,
|
491 |
}; |
492 |
apalControlGpio_t moduleGpioChargeEn2 = { |
493 |
/* GPIO */ &_gpioChargeEn2,
|
494 |
/* meta */ {
|
495 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
496 |
/* active state */ BQ24103A_LLD_ENABLED_GPIO_ACTIVE_STATE,
|
497 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
498 |
}, |
499 |
}; |
500 |
|
501 |
/** @} */
|
502 |
|
503 |
/*===========================================================================*/
|
504 |
/**
|
505 |
* @name AMiRo-OS core configurations
|
506 |
* @{
|
507 |
*/
|
508 |
/*===========================================================================*/
|
509 |
|
510 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
511 |
const char* moduleShellPrompt = "PowerManagement"; |
512 |
#endif
|
513 |
|
514 |
/** @} */
|
515 |
|
516 |
/*===========================================================================*/
|
517 |
/**
|
518 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
519 |
* @{
|
520 |
*/
|
521 |
/*===========================================================================*/
|
522 |
|
523 |
/** @} */
|
524 |
|
525 |
/*===========================================================================*/
|
526 |
/**
|
527 |
* @name Low-level drivers
|
528 |
* @{
|
529 |
*/
|
530 |
/*===========================================================================*/
|
531 |
|
532 |
AT24C01BNDriver moduleLldEeprom = { |
533 |
/* I2C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
534 |
/* I2C address */ AT24C01BN_LLD_I2C_ADDR_FIXED,
|
535 |
}; |
536 |
|
537 |
BQ24103ADriver moduleLldBatteryChargerFront = { |
538 |
/* charge enable GPIO */ &moduleGpioChargeEn1,
|
539 |
/* charge status GPIO */ &moduleGpioChargeStat1A,
|
540 |
}; |
541 |
|
542 |
BQ24103ADriver moduleLldBatteryChargerRear = { |
543 |
/* charge enable GPIO */ &moduleGpioChargeEn2,
|
544 |
/* charge status GPIO */ &moduleGpioChargeStat2A,
|
545 |
}; |
546 |
|
547 |
BQ27500Driver moduleLldFuelGaugeFront = { |
548 |
/* I2C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
549 |
/* battery low GPIO */ &moduleGpioGaugeBatLow1,
|
550 |
/* battery good GPIO */ &moduleGpioGaugeBatGd1,
|
551 |
}; |
552 |
|
553 |
BQ27500Driver moduleLldFuelGaugeRear = { |
554 |
/* I2C driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
555 |
/* battery low GPIO */ &moduleGpioGaugeBatLow2,
|
556 |
/* battery good GPIO */ &moduleGpioGaugeBatGd2,
|
557 |
}; |
558 |
|
559 |
INA219Driver moduleLldPowerMonitorVdd = { |
560 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
561 |
/* I²C address */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
|
562 |
/* current LSB (uA) */ 0x00u, |
563 |
/* configuration */ NULL, |
564 |
}; |
565 |
|
566 |
INA219Driver moduleLldPowerMonitorVio18 = { |
567 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
568 |
/* I²C address */ INA219_LLD_I2C_ADDR_A1,
|
569 |
/* current LSB (uA) */ 0x00u, |
570 |
/* configuration */ NULL, |
571 |
}; |
572 |
|
573 |
INA219Driver moduleLldPowerMonitorVio33 = { |
574 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
575 |
/* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
576 |
/* current LSB (uA) */ 0x00u, |
577 |
/* configuration */ NULL, |
578 |
}; |
579 |
|
580 |
INA219Driver moduleLldPowerMonitorVsys42 = { |
581 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
582 |
/* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
583 |
/* current LSB (uA) */ 0x00u, |
584 |
/* configuration */ NULL, |
585 |
}; |
586 |
|
587 |
INA219Driver moduleLldPowerMonitorVio50 = { |
588 |
/* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
589 |
/* I²C address */ INA219_LLD_I2C_ADDR_A1,
|
590 |
/* current LSB (uA) */ 0x00u, |
591 |
/* configuration */ NULL, |
592 |
}; |
593 |
|
594 |
LEDDriver moduleLldStatusLed = { |
595 |
/* LED GPIO */ &moduleGpioLed,
|
596 |
}; |
597 |
|
598 |
MPR121Driver moduleLldTouch = { |
599 |
/* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
600 |
}; |
601 |
|
602 |
PCA9544ADriver moduleLldI2cMultiplexer1 = { |
603 |
/* I²C driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
604 |
/* I²C address */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
605 |
}; |
606 |
|
607 |
PCA9544ADriver moduleLldI2cMultiplexer2 = { |
608 |
/* I²C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
609 |
/* I²C address */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
610 |
}; |
611 |
|
612 |
TPS62113Driver moduleLldStepDownConverter = { |
613 |
/* Power enable GPIO */ &moduleGpioPowerEn,
|
614 |
}; |
615 |
|
616 |
VCNL4020Driver moduleLldProximity1 = { |
617 |
/* I²C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
618 |
}; |
619 |
|
620 |
VCNL4020Driver moduleLldProximity2 = { |
621 |
/* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
622 |
}; |
623 |
|
624 |
/** @} */
|
625 |
|
626 |
/*===========================================================================*/
|
627 |
/**
|
628 |
* @name Unit tests (UT)
|
629 |
* @{
|
630 |
*/
|
631 |
/*===========================================================================*/
|
632 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
633 |
#include <string.h> |
634 |
|
635 |
/* ADC */
|
636 |
static int _utShellCmdCb_Adc(BaseSequentialStream* stream, int argc, char* argv[]) |
637 |
{ |
638 |
(void)argc;
|
639 |
(void)argv;
|
640 |
aosUtRun(stream, &moduleUtAdcVsys, NULL);
|
641 |
return AOS_OK;
|
642 |
} |
643 |
static ut_adcdata_t _utAdcVsysData = {
|
644 |
/* driver */ &MODULE_HAL_ADC_VSYS,
|
645 |
/* ADC conversion group */ &moduleHalAdcVsysConversionGroup,
|
646 |
}; |
647 |
aos_unittest_t moduleUtAdcVsys = { |
648 |
/* name */ "ADC", |
649 |
/* info */ "VSYS", |
650 |
/* test function */ utAdcFunc,
|
651 |
/* shell command */ {
|
652 |
/* name */ "unittest:ADC", |
653 |
/* callback */ _utShellCmdCb_Adc,
|
654 |
/* next */ NULL, |
655 |
}, |
656 |
/* data */ &_utAdcVsysData,
|
657 |
}; |
658 |
|
659 |
/* AT24C01BN-SH-B (EEPROM) */
|
660 |
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
661 |
{ |
662 |
(void)argc;
|
663 |
(void)argv;
|
664 |
aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
665 |
return AOS_OK;
|
666 |
} |
667 |
static ut_at24c01bndata_t _utAlldAt24c01bnData = {
|
668 |
/* driver */ &moduleLldEeprom,
|
669 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
670 |
}; |
671 |
aos_unittest_t moduleUtAlldAt24c01bn = { |
672 |
/* name */ "AT24C01BN-SH-B", |
673 |
/* info */ "1kbit EEPROM", |
674 |
/* test function */ utAlldAt24c01bnFunc,
|
675 |
/* shell command */ {
|
676 |
/* name */ "unittest:EEPROM", |
677 |
/* callback */ _utShellCmdCb_AlldAt24c01bn,
|
678 |
/* next */ NULL, |
679 |
}, |
680 |
/* data */ &_utAlldAt24c01bnData,
|
681 |
}; |
682 |
|
683 |
/* BQ24103A (battery charger) */
|
684 |
static int _utShellCmdCb_AlldBq24103a(BaseSequentialStream* stream, int argc, char* argv[]) |
685 |
{ |
686 |
// local variables
|
687 |
bool print_help = false; |
688 |
|
689 |
// evaluate argument
|
690 |
if (argc == 2) { |
691 |
if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
692 |
moduleUtAlldBq24103a.data = &moduleLldBatteryChargerFront; |
693 |
aosUtRun(stream, &moduleUtAlldBq24103a, "front battery");
|
694 |
moduleUtAlldBq24103a.data = NULL;
|
695 |
} |
696 |
else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
697 |
moduleUtAlldBq24103a.data = &moduleLldBatteryChargerRear; |
698 |
aosUtRun(stream, &moduleUtAlldBq24103a, "rear battery");
|
699 |
moduleUtAlldBq24103a.data = NULL;
|
700 |
} |
701 |
else {
|
702 |
print_help = true;
|
703 |
} |
704 |
} else {
|
705 |
print_help = true;
|
706 |
} |
707 |
|
708 |
// print help or just return
|
709 |
if (print_help) {
|
710 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
711 |
chprintf(stream, "Options:\n");
|
712 |
chprintf(stream, " --front, -f\n");
|
713 |
chprintf(stream, " Test the front battery charger.\n");
|
714 |
chprintf(stream, " --rear, -r\n");
|
715 |
chprintf(stream, " Test the rear battery charger.\n");
|
716 |
return AOS_INVALID_ARGUMENTS;
|
717 |
} else {
|
718 |
return AOS_OK;
|
719 |
} |
720 |
} |
721 |
aos_unittest_t moduleUtAlldBq24103a = { |
722 |
/* name */ "BQ24103A", |
723 |
/* info */ "battery charger", |
724 |
/* test function */ utAlldBq24103aFunc,
|
725 |
/* shell command */ {
|
726 |
/* name */ "unittest:BatteryCharger", |
727 |
/* callback */ _utShellCmdCb_AlldBq24103a,
|
728 |
/* next */ NULL, |
729 |
}, |
730 |
/* data */ NULL, |
731 |
}; |
732 |
|
733 |
/* BQ27500 (fuel gauge) */
|
734 |
static int _utShellCmdCb_AlldBq27500(BaseSequentialStream* stream, int argc, char* argv[]) |
735 |
{ |
736 |
// evaluate arguments
|
737 |
if (argc == 2) { |
738 |
if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
739 |
((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeFront; |
740 |
aosUtRun(stream, &moduleUtAlldBq27500, "front battery");
|
741 |
((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
|
742 |
return AOS_OK;
|
743 |
} |
744 |
else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
745 |
((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeRear; |
746 |
aosUtRun(stream, &moduleUtAlldBq27500, "rear battery");
|
747 |
((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
|
748 |
return AOS_OK;
|
749 |
} |
750 |
} |
751 |
// print help
|
752 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
753 |
chprintf(stream, "Options:\n");
|
754 |
chprintf(stream, " --front, -f\n");
|
755 |
chprintf(stream, " Test the front battery fuel gauge.\n");
|
756 |
chprintf(stream, " --rear, -r\n");
|
757 |
chprintf(stream, " Test the rear battery fuel gauge.\n");
|
758 |
return AOS_INVALID_ARGUMENTS;
|
759 |
} |
760 |
static ut_bq27500data_t _utAlldBq27500Data = {
|
761 |
/* driver */ NULL, |
762 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
763 |
}; |
764 |
aos_unittest_t moduleUtAlldBq27500 = { |
765 |
/* name */ "BQ27500", |
766 |
/* info */ "fuel gauge", |
767 |
/* test function */ utAlldBq27500Func,
|
768 |
/* shell command */ {
|
769 |
/* name */ "unittest:FuelGauge", |
770 |
/* callback */ _utShellCmdCb_AlldBq27500,
|
771 |
/* next */ NULL, |
772 |
}, |
773 |
/* data */ &_utAlldBq27500Data,
|
774 |
}; |
775 |
|
776 |
/* BQ27500 (fuel gauge) in combination with BQ24103A (battery charger) */
|
777 |
static int _utShellCmdCb_AlldBq27500Bq24103a(BaseSequentialStream* stream, int argc, char* argv[]) |
778 |
{ |
779 |
// evaluate arguments
|
780 |
if (argc == 2) { |
781 |
if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
782 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeFront; |
783 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerFront; |
784 |
aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "front battery");
|
785 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
|
786 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
|
787 |
return AOS_OK;
|
788 |
} |
789 |
else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
790 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeRear; |
791 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerRear; |
792 |
aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "rear battery");
|
793 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
|
794 |
((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
|
795 |
return AOS_OK;
|
796 |
} |
797 |
} |
798 |
// print help
|
799 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
800 |
chprintf(stream, "Options:\n");
|
801 |
chprintf(stream, " --front, -f\n");
|
802 |
chprintf(stream, " Test the front battery fuel gauge and charger.\n");
|
803 |
chprintf(stream, " --rear, -r\n");
|
804 |
chprintf(stream, " Test the rear battery fuel gauge and charger.\n");
|
805 |
return AOS_INVALID_ARGUMENTS;
|
806 |
} |
807 |
static ut_bq27500bq24103adata_t _utAlldBq27500Bq24103aData= {
|
808 |
/* BQ27500 driver */ NULL, |
809 |
/* BQ23203A driver */ NULL, |
810 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
811 |
}; |
812 |
aos_unittest_t moduleUtAlldBq27500Bq24103a = { |
813 |
/* name */ "BQ27500 & BQ24103A", |
814 |
/* info */ "fuel gauge & battery charger", |
815 |
/* test function */ utAlldBq27500Bq24103aFunc,
|
816 |
/* shell command */ {
|
817 |
/* name */ "unittest:FuelGauge&BatteryCharger", |
818 |
/* callback */ _utShellCmdCb_AlldBq27500Bq24103a,
|
819 |
/* next */ NULL, |
820 |
}, |
821 |
/* data */ &_utAlldBq27500Bq24103aData,
|
822 |
}; |
823 |
|
824 |
/* INA219 (power monitor) */
|
825 |
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[]) |
826 |
{ |
827 |
// evaluate arguments
|
828 |
if (argc == 2) { |
829 |
if (strcmp(argv[1], "VDD") == 0) { |
830 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVdd; |
831 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f; |
832 |
aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
|
833 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
834 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
835 |
return AOS_OK;
|
836 |
} |
837 |
else if (strcmp(argv[1], "VIO1.8") == 0) { |
838 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio18; |
839 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 1.8f; |
840 |
aosUtRun(stream, &moduleUtAlldIna219, "VIO (1.8V)");
|
841 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
842 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
843 |
return AOS_OK;
|
844 |
} |
845 |
else if (strcmp(argv[1], "VIO3.3") == 0) { |
846 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio33; |
847 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f; |
848 |
aosUtRun(stream, &moduleUtAlldIna219, "VIO (3.3V)");
|
849 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
850 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
851 |
return AOS_OK;
|
852 |
} |
853 |
else if (strcmp(argv[1], "VSYS4.2") == 0) { |
854 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVsys42; |
855 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 4.2f; |
856 |
aosUtRun(stream, &moduleUtAlldIna219, "VSYS (4.2V)");
|
857 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
858 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
859 |
return AOS_OK;
|
860 |
} |
861 |
else if (strcmp(argv[1], "VIO5.0") == 0) { |
862 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio50; |
863 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 5.0f; |
864 |
aosUtRun(stream, &moduleUtAlldIna219, "VIO (5.0V)");
|
865 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
866 |
((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
867 |
return AOS_OK;
|
868 |
} |
869 |
} |
870 |
// print help
|
871 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
872 |
chprintf(stream, "Options:\n");
|
873 |
chprintf(stream, " VDD\n");
|
874 |
chprintf(stream, " Test VDD (3.3V) power monitor.\n");
|
875 |
chprintf(stream, " VIO1.8\n");
|
876 |
chprintf(stream, " Test VIO 1.8V power monitor.\n");
|
877 |
chprintf(stream, " VIO3.3\n");
|
878 |
chprintf(stream, " Test VIO 3.3V power monitor.\n");
|
879 |
chprintf(stream, " VSYS4.2\n");
|
880 |
chprintf(stream, " Test VSYS 4.2V power monitor.\n");
|
881 |
chprintf(stream, " VIO5.0\n");
|
882 |
chprintf(stream, " Test VIO 5.0V power monitor.\n");
|
883 |
return AOS_INVALID_ARGUMENTS;
|
884 |
} |
885 |
static ut_ina219data_t _utAlldIna219Data = {
|
886 |
/* driver */ NULL, |
887 |
/* expected voltage */ 0.0f, |
888 |
/* tolerance */ 0.05f, |
889 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
890 |
}; |
891 |
aos_unittest_t moduleUtAlldIna219 = { |
892 |
/* name */ "INA219", |
893 |
/* info */ "power monitor", |
894 |
/* test function */ utAlldIna219Func,
|
895 |
/* shell command */ {
|
896 |
/* name */ "unittest:PowerMonitor", |
897 |
/* callback */ _utShellCmdCb_AlldIna219,
|
898 |
/* next */ NULL, |
899 |
}, |
900 |
/* data */ &_utAlldIna219Data,
|
901 |
}; |
902 |
|
903 |
/* Status LED */
|
904 |
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[]) |
905 |
{ |
906 |
(void)argc;
|
907 |
(void)argv;
|
908 |
aosUtRun(stream, &moduleUtAlldLed, NULL);
|
909 |
return AOS_OK;
|
910 |
} |
911 |
aos_unittest_t moduleUtAlldLed = { |
912 |
/* name */ "LED", |
913 |
/* info */ NULL, |
914 |
/* test function */ utAlldLedFunc,
|
915 |
/* shell command */ {
|
916 |
/* name */ "unittest:StatusLED", |
917 |
/* callback */ _utShellCmdCb_AlldLed,
|
918 |
/* next */ NULL, |
919 |
}, |
920 |
/* data */ &moduleLldStatusLed,
|
921 |
}; |
922 |
|
923 |
/* MPR121 (touch sensor) */
|
924 |
static int _utShellCmdCb_AlldMpr121(BaseSequentialStream* stream, int argc, char* argv[]) |
925 |
{ |
926 |
(void)argc;
|
927 |
(void)argv;
|
928 |
aosUtRun(stream, &moduleUtAlldMpr121, NULL);
|
929 |
return AOS_OK;
|
930 |
} |
931 |
static ut_mpr121data_t _utAlldMpr121Data= {
|
932 |
/* MPR121 driver */ &moduleLldTouch,
|
933 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
934 |
/* event source */ &aos.events.io,
|
935 |
/* event flags */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
|
936 |
}; |
937 |
aos_unittest_t moduleUtAlldMpr121 = { |
938 |
/* name */ "MPR121", |
939 |
/* info */ "touch sensor", |
940 |
/* test function */ utAlldMpr121Func,
|
941 |
/* shell command */ {
|
942 |
/* name */ "unittest:Touch", |
943 |
/* callback */ _utShellCmdCb_AlldMpr121,
|
944 |
/* next */ NULL, |
945 |
}, |
946 |
/* data */ &_utAlldMpr121Data,
|
947 |
}; |
948 |
|
949 |
/* PCA9544A (I2C multiplexer) */
|
950 |
static int _utShellCmdCb_AlldPca5944a(BaseSequentialStream* stream, int argc, char* argv[]) |
951 |
{ |
952 |
// evaluate arguments
|
953 |
if (argc == 2) { |
954 |
if (strcmp(argv[1], "#1") == 0) { |
955 |
((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer1; |
956 |
aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #1");
|
957 |
((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
|
958 |
return AOS_OK;
|
959 |
} |
960 |
else if (strcmp(argv[1], "#2") == 0) { |
961 |
((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer2; |
962 |
aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #2");
|
963 |
((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
|
964 |
return AOS_OK;
|
965 |
} |
966 |
} |
967 |
// print help
|
968 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
969 |
chprintf(stream, "Options:\n");
|
970 |
chprintf(stream, " #1\n");
|
971 |
chprintf(stream, " Test the multiplexer on the I2C bus #1.\n");
|
972 |
chprintf(stream, " #2\n");
|
973 |
chprintf(stream, " Test the multiplexer on the I2C bus #2.\n");
|
974 |
return AOS_INVALID_ARGUMENTS;
|
975 |
} |
976 |
static ut_pca9544adata_t _utAlldPca9544aData = {
|
977 |
/* driver */ NULL, |
978 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
979 |
}; |
980 |
aos_unittest_t moduleUtAlldPca9544a = { |
981 |
/* name */ "PCA9544A", |
982 |
/* info */ "I2C multiplexer", |
983 |
/* test function */ utAlldPca9544aFunc,
|
984 |
/* shell command */ {
|
985 |
/* name */ "unittest:I2CMultiplexer", |
986 |
/* callback */ _utShellCmdCb_AlldPca5944a,
|
987 |
/* next */ NULL, |
988 |
}, |
989 |
/* data */ &_utAlldPca9544aData,
|
990 |
}; |
991 |
|
992 |
/* PKLCS1212E4001 (buzzer) */
|
993 |
static int _utShellCmdCb_AlldPklcs1212e4001(BaseSequentialStream* stream, int argc, char* argv[]) |
994 |
{ |
995 |
(void)argc;
|
996 |
(void)argv;
|
997 |
aosUtRun(stream, &moduleUtAlldPklcs1212e4001, NULL);
|
998 |
return AOS_OK;
|
999 |
} |
1000 |
static ut_pklcs1212e4001_t _utAlldPklcs1212e4001Data = {
|
1001 |
/* PWM driver */ &MODULE_HAL_PWM_BUZZER,
|
1002 |
/* PWM channel */ MODULE_HAL_PWM_BUZZER_CHANNEL
|
1003 |
}; |
1004 |
aos_unittest_t moduleUtAlldPklcs1212e4001 = { |
1005 |
/* name */ "PKLCS1212E4001", |
1006 |
/* info */ "buzzer", |
1007 |
/* test function */ utAlldPklcs1212e4001Func,
|
1008 |
/* shell command */ {
|
1009 |
/* name */ "unittest:Buzzer", |
1010 |
/* callback */ _utShellCmdCb_AlldPklcs1212e4001,
|
1011 |
/* next */ NULL, |
1012 |
}, |
1013 |
/* data */ &_utAlldPklcs1212e4001Data,
|
1014 |
}; |
1015 |
|
1016 |
/* TPS62113 (stop-down converter) */
|
1017 |
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[]) |
1018 |
{ |
1019 |
// Although there are four TPS62113 on the PCB, they all share the same input signal.
|
1020 |
// A sa result, no additional shell arguments need to be evaluated.
|
1021 |
(void)argc;
|
1022 |
(void)argv;
|
1023 |
aosUtRun(stream, &moduleUtAlldTps62113, NULL);
|
1024 |
return AOS_OK;
|
1025 |
} |
1026 |
aos_unittest_t moduleUtAlldTps62113 = { |
1027 |
/* name */ "TPS62113", |
1028 |
/* info */ "step-down converter", |
1029 |
/* test function */ utAlldTps62113Func,
|
1030 |
/* shell command */ {
|
1031 |
/* name */ "unittest:StepDownConverter", |
1032 |
/* callback */ _utShellCmdCb_AlldTps62113,
|
1033 |
/* next */ NULL, |
1034 |
}, |
1035 |
/* data */ &moduleLldStepDownConverter,
|
1036 |
}; |
1037 |
|
1038 |
/* TPS62113 (step-donw converter) in combination with INA219 (power monitor) */
|
1039 |
static int _utShellCmdCb_AlldTps62113Ina219(BaseSequentialStream* stream, int argc, char* argv[]) |
1040 |
{ |
1041 |
(void)argc;
|
1042 |
(void)argv;
|
1043 |
aosUtRun(stream, &moduleUtAlldTps62113Ina219, "VSYS (4.2V)");
|
1044 |
return AOS_OK;
|
1045 |
} |
1046 |
ut_tps62113ina219data_t _utAlldTps62113Ina219Data = { |
1047 |
/* TPS62113 */ &moduleLldStepDownConverter,
|
1048 |
/* INA219 */ &moduleLldPowerMonitorVsys42,
|
1049 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
1050 |
}; |
1051 |
aos_unittest_t moduleUtAlldTps62113Ina219 = { |
1052 |
/* name */ "TPS62113 & INA219", |
1053 |
/* info */ "step-down converter & power monitor", |
1054 |
/* test function */ utAlldTps62113Ina219Func,
|
1055 |
/* shell command */ {
|
1056 |
/* name */ "unittest:StepDownConverter&PowerMonitor", |
1057 |
/* callback */ _utShellCmdCb_AlldTps62113Ina219,
|
1058 |
/* next */ NULL, |
1059 |
}, |
1060 |
/* data */ &_utAlldTps62113Ina219Data,
|
1061 |
}; |
1062 |
|
1063 |
/* VCNL4020 (proximity sensor) */
|
1064 |
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl) |
1065 |
{ |
1066 |
uint8_t intstatus; |
1067 |
vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
|
1068 |
vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1069 |
if (intstatus) {
|
1070 |
vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1071 |
} |
1072 |
return;
|
1073 |
} |
1074 |
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[]) |
1075 |
{ |
1076 |
enum {
|
1077 |
UNKNOWN, |
1078 |
NNE, ENE, ESE, SSE, SSW,WSW,WNW, NNW, |
1079 |
} sensor = UNKNOWN; |
1080 |
// evaluate arguments
|
1081 |
if (argc == 2) { |
1082 |
if (strcmp(argv[1], "-nne") == 0) { |
1083 |
sensor = NNE; |
1084 |
} else if (strcmp(argv[1], "-ene") == 0) { |
1085 |
sensor = ENE; |
1086 |
} else if (strcmp(argv[1], "-ese") == 0) { |
1087 |
sensor = ESE; |
1088 |
} else if (strcmp(argv[1], "-sse") == 0) { |
1089 |
sensor = SSE; |
1090 |
} else if (strcmp(argv[1], "-ssw") == 0) { |
1091 |
sensor = SSW; |
1092 |
} else if (strcmp(argv[1], "-wsw") == 0) { |
1093 |
sensor = WSW; |
1094 |
} else if (strcmp(argv[1], "-wnw") == 0) { |
1095 |
sensor = WNW; |
1096 |
} else if (strcmp(argv[1], "-nnw") == 0) { |
1097 |
sensor = NNW; |
1098 |
} |
1099 |
} |
1100 |
if (sensor != UNKNOWN) {
|
1101 |
PCA9544ADriver* mux = NULL;
|
1102 |
switch (sensor) {
|
1103 |
case SSE:
|
1104 |
case SSW:
|
1105 |
case WSW:
|
1106 |
case WNW:
|
1107 |
mux = &moduleLldI2cMultiplexer1; |
1108 |
((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity1; |
1109 |
((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = MODULE_OS_IOEVENTFLAGS_IRINT2; |
1110 |
break;
|
1111 |
case NNW:
|
1112 |
case NNE:
|
1113 |
case ENE:
|
1114 |
case ESE:
|
1115 |
mux = &moduleLldI2cMultiplexer2; |
1116 |
((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity2; |
1117 |
((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = MODULE_OS_IOEVENTFLAGS_IRINT1; |
1118 |
break;
|
1119 |
default:
|
1120 |
break;
|
1121 |
} |
1122 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1123 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
1124 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1125 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
1126 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1127 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
1128 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1129 |
_utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
1130 |
switch (sensor) {
|
1131 |
case NNE:
|
1132 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1133 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northeast sensor");
|
1134 |
break;
|
1135 |
case ENE:
|
1136 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1137 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "east-northeast sensor");
|
1138 |
break;
|
1139 |
case ESE:
|
1140 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1141 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "north-southeast sensor");
|
1142 |
break;
|
1143 |
case SSE:
|
1144 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1145 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southeast sensor");
|
1146 |
break;
|
1147 |
case SSW:
|
1148 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1149 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southwest sensor");
|
1150 |
break;
|
1151 |
case WSW:
|
1152 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1153 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "west-southwest sensor");
|
1154 |
break;
|
1155 |
case WNW:
|
1156 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1157 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "west-northwest sensor");
|
1158 |
break;
|
1159 |
case NNW:
|
1160 |
pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
1161 |
aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northwest sensor");
|
1162 |
break;
|
1163 |
default:
|
1164 |
break;
|
1165 |
} |
1166 |
((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = NULL;
|
1167 |
((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = 0;
|
1168 |
return AOS_OK;
|
1169 |
} |
1170 |
// print help
|
1171 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
1172 |
chprintf(stream, "Options:\n");
|
1173 |
chprintf(stream, " -nne\n");
|
1174 |
chprintf(stream, " Test north-northeast sensor.\n");
|
1175 |
chprintf(stream, " -ene\n");
|
1176 |
chprintf(stream, " Test east-northeast sensor.\n");
|
1177 |
chprintf(stream, " -ese\n");
|
1178 |
chprintf(stream, " Test east-southeast sensor.\n");
|
1179 |
chprintf(stream, " -sse\n");
|
1180 |
chprintf(stream, " Test south-southeast sensor.\n");
|
1181 |
chprintf(stream, " -ssw\n");
|
1182 |
chprintf(stream, " Test south-southwest sensor.\n");
|
1183 |
chprintf(stream, " -wsw\n");
|
1184 |
chprintf(stream, " Test west-southwest sensor.\n");
|
1185 |
chprintf(stream, " -wnw\n");
|
1186 |
chprintf(stream, " Test west-northwest sensor.\n");
|
1187 |
chprintf(stream, " -nnw\n");
|
1188 |
chprintf(stream, " Test north-northwest sensor.\n");
|
1189 |
return AOS_INVALID_ARGUMENTS;
|
1190 |
} |
1191 |
static ut_vcnl4020data_t _utAlldVcnl4020Data = {
|
1192 |
/* driver */ NULL, |
1193 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
1194 |
/* event source */ &aos.events.io,
|
1195 |
/* event flags */ 0, |
1196 |
}; |
1197 |
aos_unittest_t moduleUtAlldVcnl4020 = { |
1198 |
/* name */ "VCNL4020", |
1199 |
/* info */ "proximity sensor", |
1200 |
/* test function */ utAlldVcnl4020Func,
|
1201 |
/* shell command */ {
|
1202 |
/* name */ "unittest:Proximity", |
1203 |
/* callback */ _utShellCmdCb_AlldVcnl4020,
|
1204 |
/* next */ NULL, |
1205 |
}, |
1206 |
/* data */ &_utAlldVcnl4020Data,
|
1207 |
}; |
1208 |
|
1209 |
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
1210 |
|
1211 |
/** @} */
|