Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-2 / module.c @ a7e54ea4

History | View | Annotate | Download (35.611 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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
/**
20
 * @file
21
 * @brief   Structures and constant for the PowerManagement module.
22
 *
23
 * @addtogroup powermanagement_module
24
 * @{
25
 */
26

    
27
#include <amiroos.h>
28

    
29
#include <string.h>
30

    
31
/*===========================================================================*/
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
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1),
66
};
67

    
68
I2CConfig moduleHalI2cSrPm18Pm33GaugeRearConfig = {
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 moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig = {
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 == TRUE)
104
  /* TIM BDTR register      */ 0,
105
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */
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
/**
126
 * @brief   SWITCH_STATUS input signal GPIO.
127
 */
128
static apalGpio_t _gpioSwitchStatus = {
129
  /* line */ LINE_SWITCH_STATUS_N,
130
};
131
ROMCONST apalControlGpio_t moduleGpioSwitchStatus = {
132
  /* GPIO */ &_gpioSwitchStatus,
133
  /* meta */ {
134
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
135
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
136
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
137
  },
138
};
139

    
140
/**
141
 * @brief   SYS_REG_EN output signal GPIO.
142
 */
143
static apalGpio_t _gpioSysRegEn = {
144
  /* line */ LINE_SYS_REG_EN,
145
};
146
ROMCONST apalControlGpio_t moduleGpioSysRegEn = {
147
  /* GPIO */ &_gpioSysRegEn,
148
  /* meta */ {
149
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
150
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
151
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
152
  },
153
};
154

    
155
/**
156
 * @brief   IR_INT1 input signal GPIO.
157
 */
158
static apalGpio_t _gpioIrInt1 = {
159
  /* line */ LINE_IR_INT1_N,
160
};
161
ROMCONST apalControlGpio_t moduleGpioIrInt1 = {
162
  /* GPIO */ &_gpioIrInt1,
163
  /* meta */ {
164
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
165
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
166
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
167
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
168
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
169
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
170
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
171
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
172
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
173
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
174
#else /* (BOARD_SENSORRING == ?) */
175
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
176
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
177
#endif /* (BOARD_SENSORRING == ?) */
178
  },
179
};
180

    
181
/**
182
 * @brief   POWER_EN output signal GPIO.
183
 */
184
static apalGpio_t _gpioPowerEn = {
185
  /* line */ LINE_POWER_EN,
186
};
187
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
188
  /* GPIO */ &_gpioPowerEn,
189
  /* meta */ {
190
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
191
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
192
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
193
  },
194
};
195

    
196
/**
197
 * @brief   SYS_UART_DN bidirectional signal GPIO.
198
 */
199
static apalGpio_t _gpioSysUartDn = {
200
  /* line */ LINE_SYS_UART_DN,
201
};
202
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
203
  /* GPIO */ &_gpioSysUartDn,
204
  /* meta */ {
205
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
206
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
207
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
208
  },
209
};
210

    
211
/**
212
 * @brief   CHARGE_STAT2A input signal GPIO.
213
 */
214
static apalGpio_t _gpioChargeStat2A = {
215
  /* line */ LINE_CHARGE_STAT2A,
216
};
217
ROMCONST apalControlGpio_t moduleGpioChargeStat2A = {
218
  /* GPIO */ &_gpioChargeStat2A,
219
  /* meta */ {
220
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
221
    /* active state   */ BQ241xx_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
222
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
223
  },
224
};
225

    
226
/**
227
 * @brief   GAUGE_BATLOW2 input signal GPIO.
228
 */
229
static apalGpio_t _gpioGaugeBatLow2 = {
230
  /* line */ LINE_GAUGE_BATLOW2,
231
};
232
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2 = {
233
  /* GPIO */ &_gpioGaugeBatLow2,
234
  /* meta */ {
235
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
236
    /* active state   */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
237
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
238
  },
239
};
240

    
241
/**
242
 * @brief   GAUGE_BATGD2 input signal GPIO.
243
 */
244
static apalGpio_t _gpioGaugeBatGd2 = {
245
  /* line */ LINE_GAUGE_BATGD2_N,
246
};
247
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2 = {
248
  /* GPIO */ &_gpioGaugeBatGd2,
249
  /* meta */ {
250
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
251
    /* active state   */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
252
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
253
  },
254
};
255

    
256
/**
257
 * @brief   LED output signal GPIO.
258
 */
259
static apalGpio_t _gpioLed = {
260
  /* line */ LINE_LED,
261
};
262
ROMCONST apalControlGpio_t moduleGpioLed = {
263
  /* GPIO */ &_gpioLed,
264
  /* meta */ {
265
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
266
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
267
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
268
  },
269
};
270

    
271
/**
272
 * @brief   SYS_UART_UP bidirectional signal GPIO.
273
 */
274
static apalGpio_t _gpioSysUartUp = {
275
  /* line */ LINE_SYS_UART_UP,
276
};
277
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
278
  /* GPIO */ &_gpioSysUartUp,
279
  /* meta */ {
280
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
281
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
282
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
283
  },
284
};
285

    
286
/**
287
 * @brief   CHARGE_STAT1A input signal GPIO.
288
 */
289
static apalGpio_t _gpioChargeStat1A = {
290
  /* line */ LINE_CHARGE_STAT1A,
291
};
292
ROMCONST apalControlGpio_t moduleGpioChargeStat1A = {
293
  /* GPIO */ &_gpioChargeStat1A,
294
  /* meta */ {
295
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
296
    /* active state   */ BQ241xx_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
297
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
298
  },
299
};
300

    
301
/**
302
 * @brief   GAUGE_BATLOW1 input signal GPIO.
303
 */
304
static apalGpio_t _gpioGaugeBatLow1 = {
305
  /* line */ LINE_GAUGE_BATLOW1,
306
};
307
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1 = {
308
  /* GPIO */ &_gpioGaugeBatLow1,
309
  /* meta */ {
310
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
311
    /* active state   */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
312
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
313
  },
314
};
315

    
316
/**
317
 * @brief   GAUGE_BATGD1 input signal GPIO.
318
 */
319
static apalGpio_t _gpioGaugeBatGd1 = {
320
  /* line */ LINE_GAUGE_BATGD1_N,
321
};
322
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1 = {
323
  /* GPIO */ &_gpioGaugeBatGd1,
324
  /* meta */ {
325
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
326
    /* active state   */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
327
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
328
  },
329
};
330

    
331
/**
332
 * @brief   CHARG_EN1 output signal GPIO.
333
 */
334
static apalGpio_t _gpioChargeEn1 = {
335
  /* line */ LINE_CHARGE_EN1_N,
336
};
337
ROMCONST apalControlGpio_t moduleGpioChargeEn1 = {
338
  /* GPIO */ &_gpioChargeEn1,
339
  /* meta */ {
340
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
341
    /* active state   */ BQ241xx_LLD_ENABLED_GPIO_ACTIVE_STATE,
342
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
343
  },
344
};
345

    
346
/**
347
 * @brief   IR_INT2 input signal GPIO.
348
 */
349
static apalGpio_t _gpioIrInt2 = {
350
  /* line */ LINE_IR_INT2_N,
351
};
352
ROMCONST apalControlGpio_t moduleGpioIrInt2 = {
353
  /* GPIO */ &_gpioIrInt2,
354
  /* meta */ {
355
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
356
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
357
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
358
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
359
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
360
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
361
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
362
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
363
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
364
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
365
#else /* (BOARD_SENSORRING == ?) */
366
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
367
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
368
#endif /* (BOARD_SENSORRING == ?) */
369
  },
370
};
371

    
372
/**
373
 * @brief   TOUCH_INT input signal GPIO.
374
 */
375
static apalGpio_t _gpioTouchInt = {
376
  /* line */ LINE_TOUCH_INT_N,
377
};
378
ROMCONST apalControlGpio_t moduleGpioTouchInt = {
379
  /* GPIO */ &_gpioTouchInt,
380
  /* meta */ {
381
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
382
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
383
    /* active state   */ (MPR121_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
384
    /* interrupt edge */ MPR121_LLD_INT_EDGE,
385
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
386
    /* active state   */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
387
    /* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
388
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
389
    /* active state   */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
390
    /* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
391
#else /* (BOARD_SENSORRING == ?) */
392
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
393
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
394
#endif /* (BOARD_SENSORRING == ?) */
395
  },
396
};
397

    
398
/**
399
 * @brief   SYS_DONE input signal GPIO.
400
 */
401
static apalGpio_t _gpioSysDone = {
402
  /* line */ LINE_SYS_DONE,
403
};
404
ROMCONST apalControlGpio_t moduleGpioSysDone = {
405
  /* GPIO */ &_gpioSysDone,
406
  /* meta */ {
407
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
408
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
409
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
410
  },
411
};
412

    
413
/**
414
 * @brief   SYS_PROG output signal GPIO.
415
 */
416
static apalGpio_t _gpioSysProg = {
417
  /* line */ LINE_SYS_PROG_N,
418
};
419
ROMCONST apalControlGpio_t moduleGpioSysProg = {
420
  /* GPIO */ &_gpioSysProg,
421
  /* meta */ {
422
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
423
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
424
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
425
  },
426
};
427

    
428
/**
429
 * @brief   PATH_DC input signal GPIO.
430
 */
431
static apalGpio_t _gpioPathDc = {
432
  /* line */ LINE_PATH_DC,
433
};
434
ROMCONST apalControlGpio_t moduleGpioPathDc = {
435
  /* GPIO */ &_gpioPathDc,
436
  /* meta */ {
437
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
438
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
439
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
440
  },
441
};
442

    
443
/**
444
 * @brief   SYS_SPI_DIR bidirectional signal GPIO.
445
 */
446
static apalGpio_t _gpioSysSpiDir = {
447
  /* line */ LINE_SYS_SPI_DIR,
448
};
449
ROMCONST apalControlGpio_t moduleGpioSysSpiDir = {
450
  /* GPIO */ &_gpioSysSpiDir,
451
  /* meta */ {
452
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
453
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
454
    /* interrupt edge */ APAL_GPIO_EDGE_FALLING,
455
  },
456
};
457

    
458
/**
459
 * @brief   SYS_SYNC bidirectional signal GPIO.
460
 */
461
static apalGpio_t _gpioSysSync = {
462
  /* line */ LINE_SYS_INT_N,
463
};
464
ROMCONST apalControlGpio_t moduleGpioSysSync = {
465
  /* GPIO */ &_gpioSysSync,
466
  /* meta */ {
467
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
468
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
469
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
470
  },
471
};
472

    
473
/**
474
 * @brief   SYS_PD bidirectional signal GPIO.
475
 */
476
static apalGpio_t _gpioSysPd = {
477
  /* line */ LINE_SYS_PD_N,
478
};
479
ROMCONST apalControlGpio_t moduleGpioSysPd = {
480
  /* GPIO */ &_gpioSysPd,
481
  /* meta */ {
482
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
483
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
484
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
485
  },
486
};
487

    
488
/**
489
 * @brief   SYS_WARMRST bidirectional signal GPIO.
490
 */
491
static apalGpio_t _gpioSysWarmrst = {
492
  /* line */ LINE_SYS_WARMRST_N,
493
};
494
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
495
  /* GPIO */ &_gpioSysWarmrst,
496
  /* meta */ {
497
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
498
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
499
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
500
  },
501
};
502

    
503
/**
504
 * @brief   BT_RST output signal GPIO.
505
 */
506
static apalGpio_t _gpioBtRst = {
507
  /* line */ LINE_BT_RST,
508
};
509
ROMCONST apalControlGpio_t moduleGpioBtRst = {
510
  /* GPIO */ &_gpioBtRst,
511
  /* meta */ {
512
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
513
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
514
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
515
  },
516
};
517

    
518
/**
519
 * @brief   CHARGE_EN2 output signal GPIO.
520
 */
521
static apalGpio_t _gpioChargeEn2 = {
522
  /* line */ LINE_CHARGE_EN2_N,
523
};
524
ROMCONST apalControlGpio_t moduleGpioChargeEn2 = {
525
  /* GPIO */ &_gpioChargeEn2,
526
  /* meta */ {
527
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
528
    /* active state   */ BQ241xx_LLD_ENABLED_GPIO_ACTIVE_STATE,
529
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
530
  },
531
};
532

    
533
/** @} */
534

    
535
/*===========================================================================*/
536
/**
537
 * @name AMiRo-OS core configurations
538
 * @{
539
 */
540
/*===========================================================================*/
541

    
542
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
543
ROMCONST char* moduleShellPrompt = "PowerManagement";
544
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
545

    
546
/** @} */
547

    
548
/*===========================================================================*/
549
/**
550
 * @name Startup Shutdown Synchronization Protocol (SSSP)
551
 * @{
552
 */
553
/*===========================================================================*/
554

    
555
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__)
556

    
557
/* some local definitions */
558
// maximum number of bytes per CAN frame
559
#define CAN_BYTES_PER_FRAME                     8
560
// identifier (as dominant as possible)
561
#define MSI_BCBMSG_CANID                        0
562

    
563
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
564
{
565
  aosDbgCheck(buffer != NULL);
566
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
567

    
568
  // local variables
569
  CANTxFrame frame;
570

    
571
  // setup the common parts of the message frame
572
  frame.DLC = (uint8_t)length;
573
  frame.RTR = CAN_RTR_DATA;
574
  frame.IDE = CAN_IDE_STD;
575
  frame.SID = MSI_BCBMSG_CANID;
576
  memcpy(frame.data8, buffer, length);
577

    
578
  // sent the frame and return
579
  return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
580
}
581

    
582
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length)
583
{
584
  aosDbgCheck(buffer != NULL);
585
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
586

    
587
  // local variables
588
  CANRxFrame frame;
589

    
590
  // receive a frame and check for errors
591
  if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
592
    // a correct frame was received
593
    if (frame.DLC == length &&
594
        frame.RTR == CAN_RTR_DATA &&
595
        frame.IDE == CAN_IDE_STD &&
596
        frame.SID == MSI_BCBMSG_CANID) {
597
      // success: fetch the data and return
598
      memcpy(buffer, frame.data8, length);
599
      return AOS_SSSP_BCB_SUCCESS;
600
    }
601
    // an unexpected frame was received
602
    else {
603
      return AOS_SSSP_BCB_INVALIDMSG;
604
    }
605
  } else {
606
    // failure: return with error
607
    return AOS_SSSP_BCB_ERROR;
608
  }
609
}
610

    
611
#undef MSI_BCBMSG_CANID
612
#undef CAN_BYTES_PER_FRAME
613

    
614
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */
615

    
616
/** @} */
617

    
618
/*===========================================================================*/
619
/**
620
 * @name Low-level drivers
621
 * @{
622
 */
623
/*===========================================================================*/
624

    
625
AT24C01BDriver moduleLldEeprom = {
626
  /* I2C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
627
  /* I2C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
628
};
629

    
630
BQ241xxDriver moduleLldBatteryChargerFront = {
631
  /* charge enable GPIO */ &moduleGpioChargeEn1,
632
  /* charge status GPIO */ &moduleGpioChargeStat1A,
633
};
634

    
635
BQ241xxDriver moduleLldBatteryChargerRear = {
636
  /* charge enable GPIO */ &moduleGpioChargeEn2,
637
  /* charge status GPIO */ &moduleGpioChargeStat2A,
638
};
639

    
640
BQ27500Driver moduleLldFuelGaugeFront = {
641
  /* I2C driver         */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
642
  /* battery low GPIO   */ &moduleGpioGaugeBatLow1,
643
  /* battery good GPIO  */ &moduleGpioGaugeBatGd1,
644
};
645

    
646
BQ27500Driver moduleLldFuelGaugeRear = {
647
  /* I2C driver         */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
648
  /* battery low GPIO   */ &moduleGpioGaugeBatLow2,
649
  /* battery good GPIO  */ &moduleGpioGaugeBatGd2,
650
};
651

    
652
INA219Driver moduleLldPowerMonitorVdd = {
653
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
654
  /* I²C address      */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
655
  /* current LSB (uA) */ 0x00u,
656
  /* configuration    */ NULL,
657
};
658

    
659
INA219Driver moduleLldPowerMonitorVio18 = {
660
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
661
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
662
  /* current LSB (uA) */ 0x00u,
663
  /* configuration    */ NULL,
664
};
665

    
666
INA219Driver moduleLldPowerMonitorVio33 = {
667
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
668
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
669
  /* current LSB (uA) */ 0x00u,
670
  /* configuration    */ NULL,
671
};
672

    
673
INA219Driver moduleLldPowerMonitorVsys42 = {
674
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
675
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
676
  /* current LSB (uA) */ 0x00u,
677
  /* configuration    */ NULL,
678
};
679

    
680
INA219Driver moduleLldPowerMonitorVio50 = {
681
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
682
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
683
  /* current LSB (uA) */ 0x00u,
684
  /* configuration    */ NULL,
685
};
686

    
687
LEDDriver moduleLldStatusLed = {
688
  /* LED GPIO */ &moduleGpioLed,
689
};
690

    
691
SwitchDriver moduleLldBatterySwitch = {
692
  /* GPIO */ &moduleGpioSwitchStatus,
693
};
694

    
695
TPS6211xDriver moduleLldStepDownConverter = {
696
  /* Power enable GPIO */ &moduleGpioPowerEn,
697
};
698

    
699
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
700

    
701
MPR121Driver moduleLldTouch = {
702
  /* I²C Driver */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
703
};
704

    
705
PCA9544ADriver moduleLldI2cMultiplexer1 = {
706
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
707
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
708
};
709

    
710
PCA9544ADriver moduleLldI2cMultiplexer2 = {
711
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
712
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
713
};
714

    
715
VCNL4020Driver moduleLldProximity1 = {
716
  /* I²C Driver */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
717
};
718

    
719
VCNL4020Driver moduleLldProximity2 = {
720
  /* I²C Driver */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
721
};
722

    
723
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
724

    
725
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
726

    
727
PCAL6524Driver moduleLldGpioExtender1 = {
728
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
729
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
730
};
731

    
732
PCAL6524Driver moduleLldGpioExtender2 = {
733
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
734
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
735
};
736

    
737
AT42QT1050Driver moduleLldTouch = {
738
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
739
  /* I²C address  */ AT42QT1050_LLD_I2C_ADDRSEL_LOW,
740
};
741

    
742
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
743

    
744
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
745

    
746
PCAL6524Driver moduleLldGpioExtender1 = {
747
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
748
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
749
};
750

    
751
PCAL6524Driver moduleLldGpioExtender2 = {
752
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
753
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
754
};
755

    
756
AT42QT1050Driver moduleLldTouch = {
757
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
758
  /* I²C address  */ AT42QT1050_LLD_I2C_ADDRSEL_LOW,
759
};
760

    
761
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
762

    
763
/** @} */
764

    
765
/*===========================================================================*/
766
/**
767
 * @name Tests
768
 * @{
769
 */
770
/*===========================================================================*/
771
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
772

    
773
/*
774
 * ADC (VSYS)
775
 */
776
#include <module_test_adc.h>
777
static int _testAdcShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
778
{
779
  return moduleTestAdcShellCb(stream, argc, argv, NULL);
780
}
781
AOS_SHELL_COMMAND(moduleTestAdcShellCmd, "test:ADC", _testAdcShellCmdCb);
782

    
783
/*
784
 * AT24C01BN-SH-B (EEPROM)
785
 */
786
#include <module_test_AT24C01B.h>
787
static int _testAt24c01bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
788
{
789
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
790
}
791
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24c01bShellCmdCb);
792

    
793
/*
794
 * bq24103a (battery charger)
795
 */
796
#include <module_test_bq241xx.h>
797
static int _testBq241xxShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
798
{
799
  return moduleTestBq241xxShellCb(stream, argc, argv, NULL);
800
}
801
AOS_SHELL_COMMAND(moduleTestBq241xxShellCmd, "test:BatteryCharger", _testBq241xxShellCmdCb);
802

    
803
/*
804
 * bq27500 (fuel gauge)
805
 */
806
#include <module_test_bq27500.h>
807
static int _testBq27500ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
808
{
809
  return moduleTestBq27500ShellCb(stream, argc, argv, NULL);
810
}
811
AOS_SHELL_COMMAND(moduleTestBq27500ShellCmd, "test:FuelGauge", _testBq27500ShellCmdCb);
812

    
813
/*
814
 * bq27500 (fuel gauge) in combination with bq24103a (battery charger)
815
 */
816
#include <module_test_bq27500_bq241xx.h>
817
static int _testBq27500Bq241xxShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
818
{
819
  return moduleTestBq27500Bq241xxShellCb(stream, argc, argv, NULL);
820
}
821
AOS_SHELL_COMMAND(moduleTestBq27500Bq241xxShellCmd, "test:FuelGauge&BatteryCharger", _testBq27500Bq241xxShellCmdCb);
822

    
823
/*
824
 * INA219 (power monitor)
825
 */
826
#include <module_test_INA219.h>
827
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
828
{
829
  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
830
}
831
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
832

    
833
/*
834
 * Status LED
835
 */
836
#include <module_test_LED.h>
837
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
838
{
839
  return moduleTestLedShellCb(stream, argc, argv, NULL);
840
}
841
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
842

    
843
/*
844
 * PKLCS1212E4001 (buzzer)
845
 */
846
#include <module_test_PKxxxExxx.h>
847
static int _testPkxxxexxxShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
848
{
849
  return moduleTestPkxxxexxxShellCb(stream, argc, argv, NULL);
850
}
851
AOS_SHELL_COMMAND(moduleTestPkxxxexxxShellCmd, "test:Buzzer", _testPkxxxexxxShellCmdCb);
852

    
853
/*
854
 * switch
855
 */
856
#include <module_test_switch.h>
857
static int _testSwitchShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
858
{
859
  return moduleTestSwitchShellCb(stream, argc, argv, NULL);
860
}
861
AOS_SHELL_COMMAND(moduleTestSwitchShellCmd, "test:Switch", _testSwitchShellCmdCb);
862

    
863
/*
864
 * TPS62113 (step-down converter)
865
 */
866
#include <module_test_TPS6211x.h>
867
static int _testTps6211xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
868
{
869
  return moduleTestTps6211xShellCb(stream, argc, argv, NULL);
870
}
871
AOS_SHELL_COMMAND(moduleTestTps6211xShellCmd, "test:StepDownConverter", _testTps6211xShellCmdCb);
872

    
873
/*
874
 * TPS62113 (step-sown converter) in combination with INA219 (power monitor)
875
 */
876
#include <module_test_TPS6211x_INA219.h>
877
static int _testTps6211xIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
878
{
879
  return moduleTestTps6211xIna219ShellCb(stream, argc, argv, NULL);
880
}
881
AOS_SHELL_COMMAND(moduleTestTps6211xIna219ShellCmd, "test:StepDownConverter&PowerMonitor", _testTps6211xIna219ShellCmdCb);
882

    
883
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
884

    
885
/*
886
 * MPR121 (touch sensor)
887
 */
888
#include <module_test_MPR121.h>
889
static int _testMpr121ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
890
{
891
  return moduleTestMpr121ShellCb(stream, argc, argv, NULL);
892
}
893
AOS_SHELL_COMMAND(moduleTestMpr121ShellCmd, "test:Touch", _testMpr121ShellCmdCb);
894

    
895
/*
896
 * PCA9544A (I2C multiplexer)
897
 */
898
#include <module_test_PCA9544A.h>
899
static int _testPca9544aShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
900
{
901
  return moduleTestPca9544aShellCb(stream, argc, argv, NULL);
902
}
903
AOS_SHELL_COMMAND(moduleTestPca9544aShellCmd, "test:I2CMultiplexer", _testPca9544aShellCmdCb);
904

    
905
/*
906
 * VCNL4020 (proximity sensor)
907
 */
908
#include <module_test_VCNL4020.h>
909
static int _testVcnl4020ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
910
{
911
  return moduleTestVcnl4020ShellCb(stream, argc, argv, NULL);
912
}
913
AOS_SHELL_COMMAND(moduleTestVcnl4020ShellCmd, "test:Proximity", _testVcnl4020ShellCmdCb);
914

    
915
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
916

    
917
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
918

    
919
/*
920
 * PCAL6524 (GPIO extender)
921
 */
922
#include <module_test_PCAL6524.h>
923
static int _testPcal6524ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
924
{
925
  return moduleTestPcal6524ShellCb(stream, argc, argv, NULL);
926
}
927
AOS_SHELL_COMMAND(moduleTestPcal6524ShellCmd, "test:GPIOExtenter", _testPcal6524ShellCmdCb);
928

    
929
/*
930
 * AT42QT1050 (touch sensor)
931
 */
932
#include <module_test_AT42QT1050.h>
933
static int _testAt42qt1050ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
934
{
935
  return moduleTestAt42qt1050ShellCb(stream, argc, argv, NULL);
936
}
937
AOS_SHELL_COMMAND(moduleTestAt42qt1050ShellCmd, "test:Touch", _testAt42qt1050ShellCmdCb);
938

    
939
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
940

    
941
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
942

    
943
/*
944
 * PCAL6524 (GPIO extender)
945
 */
946
#include <module_test_PCAL6524.h>
947
static int _testPcal6524ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
948
{
949
  return moduleTestPcal6524ShellCb(stream, argc, argv, NULL);
950
}
951
AOS_SHELL_COMMAND(moduleTestPcal6524ShellCmd, "test:GPIOExtenter", _testPcal6524ShellCmdCb);
952

    
953
/*
954
 * AT42QT1050 (touch sensor)
955
 */
956
#include <module_test_AT42QT1050.h>
957
static int _testAt42qt1050ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
958
{
959
  return moduleTestAt42qt1050ShellCb(stream, argc, argv, NULL);
960
}
961
AOS_SHELL_COMMAND(moduleTestAt42qt1050ShellCmd, "test:Touch", _testAt42qt1050ShellCmdCb);
962

    
963
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
964

    
965
/*
966
 * entire module
967
 */
968
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
969
{
970
  (void)argc;
971
  (void)argv;
972

    
973
  int status = AOS_OK;
974
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
975
  aos_testresult_t result_test = {0, 0};
976
  aos_testresult_t result_total = {0, 0};
977

    
978
  /* ADC */
979
  status |= moduleTestAdcShellCb(stream, 0, targv, &result_test);
980
  result_total = aosTestResultAdd(result_total, result_test);
981

    
982
  /* AT24C01BN-SH-B (EEPROM) */
983
  status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
984
  result_total = aosTestResultAdd(result_total, result_test);
985

    
986
  /* bq24103a (battery charger) */
987
  // front
988
  targv[1] = "-f";
989
  status |= moduleTestBq241xxShellCb(stream, 2, targv, &result_test);
990
  result_total = aosTestResultAdd(result_total, result_test);
991
  // rear
992
  targv[1] = "-r";
993
  status |= moduleTestBq241xxShellCb(stream, 2, targv, &result_test);
994
  result_total = aosTestResultAdd(result_total, result_test);
995
  targv[1] = "";
996

    
997
  /* bq27500 (fuel gauge) */
998
  // front
999
  targv[1] = "-f";
1000
  status |= moduleTestBq27500ShellCb(stream, 2, targv, &result_test);
1001
  result_total = aosTestResultAdd(result_total, result_test);
1002
  // rear
1003
  targv[1] = "-r";
1004
  status |= moduleTestBq27500ShellCb(stream, 2, targv, &result_test);
1005
  result_total = aosTestResultAdd(result_total, result_test);
1006
  targv[1] = "";
1007

    
1008
  /* bq 27500 (fuel gauge) in combination with bq24103a (battery charger) */
1009
  // front
1010
  targv[1] = "-f";
1011
  status |= moduleTestBq27500Bq241xxShellCb(stream, 2, targv, &result_test);
1012
  result_total = aosTestResultAdd(result_total, result_test);
1013
  // rear
1014
  targv[1] = "-r";
1015
  status |= moduleTestBq27500Bq241xxShellCb(stream, 2, targv, &result_test);
1016
  result_total = aosTestResultAdd(result_total, result_test);
1017
  targv[1] = "";
1018

    
1019
  /* INA219 (power monitor) */
1020
  // VDD
1021
  targv[1] = "VDD";
1022
  status |= moduleTestIna219ShellCb(stream, 2, targv, &result_test);
1023
  result_total = aosTestResultAdd(result_total, result_test);
1024
  // VIO 1.8V
1025
  targv[1] = "VIO1.8";
1026
  status |= moduleTestIna219ShellCb(stream, 2, targv, &result_test);
1027
  result_total = aosTestResultAdd(result_total, result_test);
1028
  // VIO 3.3V
1029
  targv[1] = "VIO3.3";
1030
  status |= moduleTestIna219ShellCb(stream, 2, targv, &result_test);
1031
  result_total = aosTestResultAdd(result_total, result_test);
1032
  // VSYS 4.2V
1033
  targv[1] = "VSYS4.2";
1034
  status |= moduleTestIna219ShellCb(stream, 2, targv, &result_test);
1035
  result_total = aosTestResultAdd(result_total, result_test);
1036
  // VIO 5.0V
1037
  targv[1] = "VIO5.0";
1038
  status |= moduleTestIna219ShellCb(stream, 2, targv, &result_test);
1039
  result_total = aosTestResultAdd(result_total, result_test);
1040
  targv[1] = "";
1041

    
1042
  /* status LED */
1043
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
1044
  result_total = aosTestResultAdd(result_total, result_test);
1045

    
1046
  /* PKLCS1212E4001 (buzzer) */
1047
  status |= moduleTestPkxxxexxxShellCb(stream, 0, targv, &result_test);
1048
  result_total = aosTestResultAdd(result_total, result_test);
1049

    
1050
  /* battery switch */
1051
  status |= moduleTestSwitchShellCb(stream, 0, targv, &result_test);
1052
  result_total = aosTestResultAdd(result_total, result_test);
1053

    
1054
  /* TPS62113 (step-down converter) */
1055
  status |= moduleTestTps6211xShellCb(stream, 0, targv, &result_test);
1056
  result_total = aosTestResultAdd(result_total, result_test);
1057

    
1058
  /* TPS62113 (step-down converter) in combination with INA219 (power monitor) */
1059
  status |= moduleTestTps6211xIna219ShellCb(stream, 0, targv, &result_test);
1060
  result_total = aosTestResultAdd(result_total, result_test);
1061

    
1062
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
1063

    
1064
  /* MPR121 (touch sensor) */
1065
  status |= moduleTestMpr121ShellCb(stream, 0, targv, &result_test);
1066
  result_total = aosTestResultAdd(result_total, result_test);
1067

    
1068
  /* PCA9544A (I2C multiplexer) */
1069
  // #1
1070
  targv[1] = "#1";
1071
  status |= moduleTestPca9544aShellCb(stream, 2, targv, &result_test);
1072
  result_total = aosTestResultAdd(result_total, result_test);
1073
  // #2
1074
  targv[1] = "#2";
1075
  status |= moduleTestPca9544aShellCb(stream, 2, targv, &result_test);
1076
  result_total = aosTestResultAdd(result_total, result_test);
1077
  targv[1] = "";
1078

    
1079
  /* VCNL4020 (proximity sensor) */
1080
  // north-northeast
1081
  targv[1] = "-nne";
1082
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1083
  result_total = aosTestResultAdd(result_total, result_test);
1084
  // east-northeast
1085
  targv[1] = "-ene";
1086
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1087
  result_total = aosTestResultAdd(result_total, result_test);
1088
  // east-southeast
1089
  targv[1] = "-ese";
1090
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1091
  result_total = aosTestResultAdd(result_total, result_test);
1092
  // south-southeast
1093
  targv[1] = "-sse";
1094
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1095
  result_total = aosTestResultAdd(result_total, result_test);
1096
  // south-southwest
1097
  targv[1] = "-ssw";
1098
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1099
  result_total = aosTestResultAdd(result_total, result_test);
1100
  // west-southwest
1101
  targv[1] = "-wsw";
1102
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1103
  result_total = aosTestResultAdd(result_total, result_test);
1104
  // west-northwest
1105
  targv[1] = "-wnw";
1106
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1107
  result_total = aosTestResultAdd(result_total, result_test);
1108
  // west-northwest
1109
  targv[1] = "-nnw";
1110
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
1111
  result_total = aosTestResultAdd(result_total, result_test);
1112
  targv[1] = "";
1113

    
1114
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
1115

    
1116
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
1117

    
1118
  /* PCAL6524 (GPIO extender) */
1119
  // #1
1120
  targv[1] = "#1";
1121
  status |= moduleTestPcal6524ShellCb(stream, 2, targv, &result_test);
1122
  result_total = aosTestResultAdd(result_total, result_test);
1123
  // #2
1124
  targv[1] = "#2";
1125
  status |= moduleTestPcal6524ShellCb(stream, 2, targv, &result_test);
1126
  result_total = aosTestResultAdd(result_total, result_test);
1127
  targv[1] = "";
1128

    
1129
  /* AT42QT1050 (touch sensor) */
1130
  status |= moduleTestAt42qt1050ShellCb(stream, 2, targv, &result_test);
1131
  result_total = aosTestResultAdd(result_total, result_test);
1132

    
1133
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
1134

    
1135
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
1136

    
1137
  /* PCAL6524 (GPIO extender) */
1138
  // #1
1139
  targv[1] = "#1";
1140
  status |= moduleTestPcal6524ShellCb(stream, 2, targv, &result_test);
1141
  result_total = aosTestResultAdd(result_total, result_test);
1142
  // #2
1143
  targv[1] = "#2";
1144
  status |= moduleTestPcal6524ShellCb(stream, 2, targv, &result_test);
1145
  result_total = aosTestResultAdd(result_total, result_test);
1146
  targv[1] = "";
1147

    
1148
  /* AT42QT1050 (touch sensor) */
1149
  status |= moduleTestAt42qt1050ShellCb(stream, 2, targv, &result_test);
1150
  result_total = aosTestResultAdd(result_total, result_test);
1151

    
1152
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
1153

    
1154
  // print total result
1155
  chprintf(stream, "\n");
1156
  aosTestResultPrintSummary(stream, &result_total, "entire module");
1157

    
1158
  return status;
1159
}
1160
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
1161

    
1162
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
1163

    
1164
/** @} */
1165
/** @} */