Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.c @ f3b3fe09

History | View | Annotate | Download (38.727 KB)

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