Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.c @ 933df08e

History | View | Annotate | Download (38.1 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
/*===========================================================================*/
22
/**
23
 * @name Module specific functions
24
 * @{
25
 */
26
/*===========================================================================*/
27
#include <amiroos.h>
28

    
29
/**
30
 * @brief   Interrupt service routine callback for I/O interrupt signals.
31
 *
32
 * @param   extp      EXT driver to handle the ISR.
33
 * @param   channel   Channel on which the interrupt was encountered.
34
 */
35
static void _moduleIsrCallback(EXTDriver* extp, expchannel_t channel) {
36
  (void)extp;
37

    
38
  chSysLockFromISR();
39
  chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
40
  chSysUnlockFromISR();
41

    
42
  return;
43
}
44

    
45
/** @} */
46

    
47
/*===========================================================================*/
48
/**
49
 * @name ChibiOS/HAL configuration
50
 * @{
51
 */
52
/*===========================================================================*/
53

    
54
ADCConversionGroup moduleHalAdcVsysConversionGroup = {
55
  /* buffer type        */ true,
56
  /* number of channels */ 1,
57
  /* callback function  */ NULL,
58
  /* error callback     */ NULL,
59
  /* CR1                */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
60
  /* CR2                */ ADC_CR2_SWSTART | ADC_CR2_CONT,
61
  /* SMPR1              */ 0,
62
  /* SMPR2              */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
63
  /* HTR                */ ADC_HTR_HT,
64
  /* LTR                */ 0,
65
  /* SQR1               */ ADC_SQR1_NUM_CH(1),
66
  /* SQR2               */ 0,
67
  /* SQR3               */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
68
};
69

    
70
CANConfig moduleHalCanConfig = {
71
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
72
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1),
73
};
74

    
75
EXTConfig moduleHalExtConfig = {
76
  /* channel configrations */ {
77
    /* channel  0 */ { // IR_INT1_N: must be enabled explicitely
78
      /* mode     */ EXT_MODE_GPIOB | APAL2CH_EDGE(VCNL4020_LLD_INT_EDGE),
79
      /* callback */ _moduleIsrCallback,
80
    },
81
    /* channel  1 */ { // GAUGE_BATLOW1: must be enabled explicitely
82
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_RISING_EDGE,
83
      /* callback */ _moduleIsrCallback,
84
    },
85
    /* channel  2 */ { // GAUGE_BATDG1_N: must be enabled expliciety
86
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_RISING_EDGE,
87
      /* callback */ _moduleIsrCallback,
88
    },
89
    /* channel  3 */ { // SYS_UART_DN: automatic interrupt on event
90
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
91
      /* callback */ _moduleIsrCallback,
92
    },
93
    /* channel  4 */ { // IR_INT2_N: must be enabled explicitely
94
      /* mode     */ EXT_MODE_GPIOC | APAL2CH_EDGE(VCNL4020_LLD_INT_EDGE),
95
      /* callback */ _moduleIsrCallback,
96
    },
97
    /* channel  5 */ { // TOUCH_INT: must be enabled explicitely
98
      /* mode     */ EXT_MODE_GPIOC | APAL2CH_EDGE(MPR121_LLD_INT_EDGE),
99
      /* callback */ _moduleIsrCallback,
100
    },
101
    /* channel  6 */ { // GAUGE_BATLOW2: must be enabled explicitely
102
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_RISING_EDGE,
103
      /* callback */ _moduleIsrCallback,
104
    },
105
    /* channel  7 */ { // GAUGE_BATDG2_N: must be enabled expliciety
106
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_RISING_EDGE,
107
      /* callback */ _moduleIsrCallback,
108
    },
109
    /* channel  8 */ { // PATH_DC: must be enabled explicitely
110
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES,
111
      /* callback */ _moduleIsrCallback,
112
    },
113
    /* channel  9 */ { // SYS_SPI_DIR: must be enabled explicitely
114
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES,
115
      /* callback */ _moduleIsrCallback,
116
    },
117
    /* channel 10 */ {
118
      /* mode     */ EXT_CH_MODE_DISABLED,
119
      /* callback */ NULL,
120
    },
121
    /* channel 11 */ {
122
      /* mode     */ EXT_CH_MODE_DISABLED,
123
      /* callback */ NULL,
124
    },
125
    /* channel 12 */ { // SYS_SYNC_N: automatic interrupt on event
126
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
127
      /* callback */ _moduleIsrCallback,
128
    },
129
    /* channel 13 */ { // SYS_PD_N: automatic interrupt when activated
130
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
131
      /* callback */ _moduleIsrCallback,
132
    },
133
    /* channel 14 */ { // SYS_WARMRST_N: automatic interrupt when activated
134
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
135
      /* callback */ _moduleIsrCallback,
136
    },
137
    /* channel 15 */ { // SYS_UART_UP: automatic interrupt on event
138
      /* mode     */ EXT_MODE_GPIOB| EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
139
      /* callback */ _moduleIsrCallback,
140
    },
141
    /* channel 16 */ {
142
      /* mode     */ EXT_CH_MODE_DISABLED,
143
      /* callback */ NULL,
144
    },
145
    /* channel 17 */ {
146
      /* mode     */ EXT_CH_MODE_DISABLED,
147
      /* callback */ NULL,
148
    },
149
    /* channel 18 */ {
150
      /* mode     */ EXT_CH_MODE_DISABLED,
151
      /* callback */ NULL,
152
    },
153
    /* channel 19 */ {
154
      /* mode     */ EXT_CH_MODE_DISABLED,
155
      /* callback */ NULL,
156
    },
157
    /* channel 20 */ {
158
      /* mode     */ EXT_CH_MODE_DISABLED,
159
      /* callback */ NULL,
160
    },
161
    /* channel 21 */ {
162
      /* mode     */ EXT_CH_MODE_DISABLED,
163
      /* callback */ NULL,
164
    },
165
    /* channel 22 */ {
166
      /* mode     */ EXT_CH_MODE_DISABLED,
167
      /* callback */ NULL,
168
    },
169
  },
170
};
171

    
172
I2CConfig moduleHalI2cProxPm18Pm33GaugeRearConfig = {
173
  /* I²C mode   */ OPMODE_I2C,
174
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
175
  /* duty cycle */ FAST_DUTY_CYCLE_2,
176
};
177

    
178
I2CConfig moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig = {
179
  /* I²C mode   */ OPMODE_I2C,
180
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
181
  /* duty cycle */ FAST_DUTY_CYCLE_2,
182
};
183

    
184
PWMConfig moduleHalPwmBuzzerConfig = {
185
  /* frequency              */ 1000000,
186
  /* period                 */ 0,
187
  /* callback               */ NULL,
188
  /* channel configurations */ {
189
    /* channel 0              */ {
190
      /* mode                   */ PWM_OUTPUT_DISABLED,
191
      /* callback               */ NULL
192
    },
193
    /* channel 1              */ {
194
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
195
      /* callback               */ NULL
196
    },
197
    /* channel 2              */ {
198
      /* mode                   */ PWM_OUTPUT_DISABLED,
199
      /* callback               */ NULL
200
    },
201
    /* channel 3              */ {
202
      /* mode                   */ PWM_OUTPUT_DISABLED,
203
      /* callback               */ NULL
204
    },
205
  },
206
  /* TIM CR2 register       */ 0,
207
#if STM32_PWM_USE_ADVANCED
208
  /* TIM BDTR register      */ 0,
209
#endif
210
  /* TIM DIER register      */ 0,
211
};
212

    
213
SerialConfig moduleHalProgIfConfig = {
214
  /* bit rate */ 115200,
215
  /* CR1      */ 0,
216
  /* CR1      */ 0,
217
  /* CR1      */ 0,
218
};
219

    
220
/** @} */
221

    
222
/*===========================================================================*/
223
/**
224
 * @name GPIO definitions
225
 * @{
226
 */
227
/*===========================================================================*/
228

    
229
apalGpio_t moduleGpioSysRegEn = {
230
  /* port */ GPIOA,
231
  /* pad  */ GPIOA_SYS_REG_EN,
232
};
233

    
234
apalGpio_t moduleGpioIrInt1 = {
235
  /* port */ GPIOB,
236
  /* pad  */ GPIOB_IR_INT1_N,
237
};
238

    
239
apalGpio_t moduleGpioPowerEn = {
240
  /* port */ GPIOB,
241
  /* pad  */ GPIOB_POWER_EN,
242
};
243

    
244
apalGpio_t moduleGpioSysUartDn = {
245
  /* port */ GPIOB,
246
  /* pad  */ GPIOB_SYS_UART_DN,
247
};
248

    
249
apalGpio_t moduleGpioChargeStat2A = {
250
  /* port */ GPIOB,
251
  /* pad  */ GPIOB_CHARGE_STAT2A,
252
};
253

    
254
apalGpio_t moduleGpioGaugeBatLow2 = {
255
  /* port */ GPIOB,
256
  /* pad  */ GPIOB_GAUGE_BATLOW2,
257
};
258

    
259
apalGpio_t moduleGpioGaugeBatGd2 = {
260
  /* port */ GPIOB,
261
  /* pad  */ GPIOB_GAUGE_BATGD2_N,
262
};
263

    
264
apalGpio_t moduleGpioLed = {
265
  /* port */ GPIOB,
266
  /* pad  */ GPIOB_LED,
267
};
268

    
269
apalGpio_t moduleGpioSysUartUp = {
270
  /* port */ GPIOB,
271
  /* pad  */ GPIOB_SYS_UART_UP,
272
};
273

    
274
apalGpio_t moduleGpioChargeStat1A = {
275
  /* port */ GPIOC,
276
  /* pad  */ GPIOC_CHARGE_STAT1A,
277
};
278

    
279
apalGpio_t moduleGpioGaugeBatLow1 = {
280
  /* port */ GPIOC,
281
  /* pad  */ GPIOC_GAUGE_BATLOW1,
282
};
283

    
284
apalGpio_t moduleGpioGaugeBatGd1 = {
285
  /* port */ GPIOC,
286
  /* pad  */ GPIOC_GAUGE_BATGD1_N,
287
};
288

    
289
apalGpio_t moduleGpioChargeEn1 = {
290
  /* port */ GPIOC,
291
  /* pad  */ GPIOC_CHARGE_EN1_N,
292
};
293

    
294
apalGpio_t moduleGpioIrInt2 = {
295
  /* port */ GPIOC,
296
  /* pad  */ GPIOC_IR_INT2_N,
297
};
298

    
299
apalGpio_t moduleGpioTouchInt = {
300
  /* port */ GPIOC,
301
  /* pad  */ GPIOC_TOUCH_INT_N,
302
};
303

    
304
apalGpio_t moduleGpioSysDone = {
305
  /* port */ GPIOC,
306
  /* pad  */ GPIOC_SYS_DONE,
307
};
308

    
309
apalGpio_t moduleGpioSysProg = {
310
  /* port */ GPIOC,
311
  /* pad  */ GPIOC_SYS_PROG_N,
312
};
313

    
314
apalGpio_t moduleGpioPathDc = {
315
  /* port */ GPIOC,
316
  /* pad  */ GPIOC_PATH_DC,
317
};
318

    
319
apalGpio_t moduleGpioSysSpiDir = {
320
  /* port */ GPIOC,
321
  /* pad  */ GPIOC_SYS_SPI_DIR,
322
};
323

    
324
apalGpio_t moduleGpioSysSync = {
325
  /* port */ GPIOC,
326
  /* pad  */ GPIOC_SYS_INT_N,
327
};
328

    
329
apalGpio_t moduleGpioSysPd = {
330
  /* port */ GPIOC,
331
  /* pad  */ GPIOC_SYS_PD_N,
332
};
333

    
334
apalGpio_t moduleGpioSysWarmrst = {
335
  /* port */ GPIOC,
336
  /* pad  */ GPIOC_SYS_WARMRST_N,
337
};
338

    
339
apalGpio_t moduleGpioBtRst = {
340
  /* port */ GPIOC,
341
  /* pad  */ GPIOC_BT_RST,
342
};
343

    
344
apalGpio_t moduleGpioChargeEn2 = {
345
  /* port */ GPIOD,
346
  /* pad  */ GPIOD_CHARGE_EN2_N,
347
};
348

    
349
/** @} */
350

    
351
/*===========================================================================*/
352
/**
353
 * @name AMiRo-OS core configurations
354
 * @{
355
 */
356
/*===========================================================================*/
357

    
358
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
359
const char* moduleShellPrompt = "PowerManagement";
360
#endif
361

    
362
/** @} */
363

    
364
/*===========================================================================*/
365
/**
366
 * @name Startup Shutdown Synchronization Protocol (SSSP)
367
 * @{
368
 */
369
/*===========================================================================*/
370

    
371
apalControlGpio_t moduleSsspGpioPd = {
372
  /* GPIO */ &moduleGpioSysPd,
373
  /* meta */ {
374
    /* active state */ APAL_GPIO_ACTIVE_LOW,
375
    /* edge         */ APAL_GPIO_EDGE_FALLING,
376
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
377
  },
378
};
379

    
380
apalControlGpio_t moduleSsspGpioSync = {
381
  /* GPIO */ &moduleGpioSysSync,
382
  /* meta */ {
383
    /* active state */ APAL_GPIO_ACTIVE_LOW,
384
    /* edge         */ APAL_GPIO_EDGE_FALLING,
385
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
386
  },
387
};
388

    
389
apalControlGpio_t moduleSsspGpioDn = {
390
  /* GPIO */ &moduleGpioSysUartDn,
391
  /* meta */ {
392
    /* active state */ APAL_GPIO_ACTIVE_LOW,
393
    /* edge         */ APAL_GPIO_EDGE_FALLING,
394
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
395
  },
396
};
397

    
398
apalControlGpio_t moduleSsspGpioUp = {
399
  /* GPIO */ &moduleGpioSysUartUp,
400
  /* meta */ {
401
    /* active state */ APAL_GPIO_ACTIVE_LOW,
402
    /* edge         */ APAL_GPIO_EDGE_FALLING,
403
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
404
  },
405
};
406

    
407
/** @} */
408

    
409
/*===========================================================================*/
410
/**
411
 * @name Low-level drivers
412
 * @{
413
 */
414
/*===========================================================================*/
415

    
416
AT24C01BNDriver moduleLldEeprom = {
417
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
418
  /* I2C address  */ AT24C01BN_LLD_I2C_ADDR_FIXED,
419
};
420

    
421
BQ24103ADriver moduleLldBatteryChargerFront = {
422
  /* charge enable GPIO */ {
423
    /* GPIO */ &moduleGpioChargeEn1,
424
    /* meta */ {
425
      /* active state */ APAL_GPIO_ACTIVE_LOW,
426
      /* edge         */ APAL_GPIO_EDGE_NONE,
427
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
428
    },
429
  },
430
  /* charge status GPIO */ {
431
    /* GPIO */ &moduleGpioChargeStat1A,
432
    /* meta */ {
433
      /* active state */ APAL_GPIO_ACTIVE_LOW,
434
      /* edge         */ APAL_GPIO_EDGE_NONE,
435
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
436
    },
437
  },
438
};
439

    
440
BQ24103ADriver moduleLldBatteryChargerRear = {
441
  /* charge enable GPIO */ {
442
    /* GPIO */ &moduleGpioChargeEn2,
443
    /* meta */ {
444
      /* active state */ APAL_GPIO_ACTIVE_LOW,
445
      /* edge         */ APAL_GPIO_EDGE_NONE,
446
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
447
    },
448
  },
449
  /* charge status GPIO */ {
450
    /* GPIO */ &moduleGpioChargeStat2A,
451
    /* meta */ {
452
      /* active state */ APAL_GPIO_ACTIVE_LOW,
453
      /* edge         */ APAL_GPIO_EDGE_NONE,
454
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
455
    },
456
  },
457
};
458

    
459
BQ27500Driver moduleLldFuelGaugeFront = {
460
  /* I2C driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
461
  /* battery low GPIO */ {
462
    /* GPIO */ &moduleGpioGaugeBatLow1,
463
    /* meta */ {
464
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
465
      /* edge         */ APAL_GPIO_EDGE_NONE,
466
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
467
    },
468
  },
469
  /* battery good GPIO */ {
470
    /* GPIO */ &moduleGpioGaugeBatGd1,
471
    /* meta */ {
472
      /* active state */ APAL_GPIO_ACTIVE_LOW,
473
      /* edge         */ APAL_GPIO_EDGE_NONE,
474
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
475
    },
476
  },
477
};
478

    
479
BQ27500Driver moduleLldFuelGaugeRear = {
480
  /* I2C driver       */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
481
  /* battery low GPIO */ {
482
    /* GPIO */ &moduleGpioGaugeBatLow2,
483
    /* meta */ {
484
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
485
      /* edge         */ APAL_GPIO_EDGE_NONE,
486
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
487
    },
488
  },
489
  /* battery good GPIO */ {
490
    /* GPIO */ &moduleGpioGaugeBatGd2,
491
    /* meta */ {
492
      /* active state */ APAL_GPIO_ACTIVE_LOW,
493
      /* edge         */ APAL_GPIO_EDGE_NONE,
494
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
495
    },
496
  },
497
};
498

    
499
INA219Driver moduleLldPowerMonitorVdd = {
500
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
501
  /* I²C address      */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
502
  /* current LSB (uA) */ 0x00u,
503
  /* configuration    */ NULL,
504
};
505

    
506
INA219Driver moduleLldPowerMonitorVio18 = {
507
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
508
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
509
  /* current LSB (uA) */ 0x00u,
510
  /* configuration    */ NULL,
511
};
512

    
513
INA219Driver moduleLldPowerMonitorVio33 = {
514
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
515
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
516
  /* current LSB (uA) */ 0x00u,
517
  /* configuration    */ NULL,
518
};
519

    
520
INA219Driver moduleLldPowerMonitorVsys42 = {
521
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
522
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
523
  /* current LSB (uA) */ 0x00u,
524
  /* configuration    */ NULL,
525
};
526

    
527
INA219Driver moduleLldPowerMonitorVio50 = {
528
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
529
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
530
  /* current LSB (uA) */ 0x00u,
531
  /* configuration    */ NULL,
532
};
533

    
534
LEDDriver moduleLldStatusLed = {
535
  /* LED GPIO */ {
536
    /* GPIO */ &moduleGpioLed,
537
    /* meta */ {
538
      /* active state */ APAL_GPIO_ACTIVE_LOW,
539
      /* edge         */ APAL_GPIO_EDGE_NONE,
540
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
541
    },
542
  },
543
};
544

    
545
MPR121Driver moduleLldTouch = {
546
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
547
};
548

    
549
PCA9544ADriver moduleLldI2cMultiplexer1 = {
550
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
551
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
552
};
553

    
554
PCA9544ADriver moduleLldI2cMultiplexer2 = {
555
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
556
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
557
};
558

    
559
TPS62113Driver moduleLldStepDownConverter = {
560
  /* Power enable GPIO */ {
561
    /* GPIO       */ &moduleGpioPowerEn,
562
    /* GPIO meta  */ {
563
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
564
      /* egde         */ APAL_GPIO_EDGE_NONE,
565
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
566
    },
567
  },
568
};
569

    
570
VCNL4020Driver moduleLldProximity1 = {
571
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
572
};
573

    
574
VCNL4020Driver moduleLldProximity2 = {
575
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
576
};
577

    
578
/** @} */
579

    
580
/*===========================================================================*/
581
/**
582
 * @name Unit tests (UT)
583
 * @{
584
 */
585
/*===========================================================================*/
586
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
587
#include <string.h>
588

    
589
/* ADC  */
590
static int _utShellCmdCb_Adc(BaseSequentialStream* stream, int argc, char* argv[])
591
{
592
  (void)argc;
593
  (void)argv;
594
  aosUtRun(stream, &moduleUtAdcVsys, NULL);
595
  return AOS_OK;
596
}
597
static ut_adcdata_t _utAdcVsysData = {
598
  /* driver               */ &MODULE_HAL_ADC_VSYS,
599
  /* ADC conversion group */ &moduleHalAdcVsysConversionGroup,
600
};
601
aos_unittest_t moduleUtAdcVsys = {
602
  /* name           */ "ADC",
603
  /* info           */ "VSYS",
604
  /* test function  */ utAdcFunc,
605
  /* shell command  */ {
606
    /* name     */ "unittest:ADC",
607
    /* callback */ _utShellCmdCb_Adc,
608
    /* next     */ NULL,
609
  },
610
  /* data           */ &_utAdcVsysData,
611
};
612

    
613
/* AT24C01BN-SH-B (EEPROM) */
614
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
615
{
616
  (void)argc;
617
  (void)argv;
618
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
619
  return AOS_OK;
620
}
621
static ut_at24c01bndata_t _utAlldAt24c01bnData = {
622
  /* driver   */ &moduleLldEeprom,
623
  /* timeout  */ MICROSECONDS_PER_SECOND,
624
};
625
aos_unittest_t moduleUtAlldAt24c01bn = {
626
  /* name           */ "AT24C01BN-SH-B",
627
  /* info           */ "1kbit EEPROM",
628
  /* test function  */ utAlldAt24c01bnFunc,
629
  /* shell command  */ {
630
    /* name     */ "unittest:EEPROM",
631
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
632
    /* next     */ NULL,
633
  },
634
  /* data           */ &_utAlldAt24c01bnData,
635
};
636

    
637
/* BQ24103A (battery charger) */
638
static int _utShellCmdCb_AlldBq24103a(BaseSequentialStream* stream, int argc, char* argv[])
639
{
640
  // local variables
641
  bool print_help = false;
642

    
643
  // evaluate argument
644
  if (argc == 2) {
645
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
646
      moduleUtAlldBq24103a.data = &moduleLldBatteryChargerFront;
647
      aosUtRun(stream, &moduleUtAlldBq24103a, "front battery");
648
      moduleUtAlldBq24103a.data = NULL;
649
    }
650
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
651
      moduleUtAlldBq24103a.data = &moduleLldBatteryChargerRear;
652
      aosUtRun(stream, &moduleUtAlldBq24103a, "rear battery");
653
      moduleUtAlldBq24103a.data = NULL;
654
    }
655
    else {
656
      print_help = true;
657
    }
658
  } else {
659
    print_help = true;
660
  }
661

    
662
  // print help or just return
663
  if (print_help) {
664
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
665
    chprintf(stream, "Options:\n");
666
    chprintf(stream, "  --front, -f\n");
667
    chprintf(stream, "    Test the front battery charger.\n");
668
    chprintf(stream, "  --rear, -r\n");
669
    chprintf(stream, "    Test the rear battery charger.\n");
670
    return AOS_INVALID_ARGUMENTS;
671
  } else {
672
    return AOS_OK;
673
  }
674
}
675
aos_unittest_t moduleUtAlldBq24103a = {
676
  /* name           */ "BQ24103A",
677
  /* info           */ "battery charger",
678
  /* test function  */ utAlldBq24103aFunc,
679
  /* shell command  */ {
680
    /* name     */ "unittest:BatteryCharger",
681
    /* callback */ _utShellCmdCb_AlldBq24103a,
682
    /* next     */ NULL,
683
  },
684
  /* data           */ NULL,
685
};
686

    
687
/* BQ27500 (fuel gauge) */
688
static int _utShellCmdCb_AlldBq27500(BaseSequentialStream* stream, int argc, char* argv[])
689
{
690
  // evaluate arguments
691
  if (argc == 2) {
692
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
693
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeFront;
694
      aosUtRun(stream, &moduleUtAlldBq27500, "front battery");
695
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
696
      return AOS_OK;
697
    }
698
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
699
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeRear;
700
      aosUtRun(stream, &moduleUtAlldBq27500, "rear battery");
701
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
702
      return AOS_OK;
703
    }
704
  }
705
  // print help
706
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
707
  chprintf(stream, "Options:\n");
708
  chprintf(stream, "  --front, -f\n");
709
  chprintf(stream, "    Test the front battery fuel gauge.\n");
710
  chprintf(stream, "  --rear, -r\n");
711
  chprintf(stream, "    Test the rear battery fuel gauge.\n");
712
  return AOS_INVALID_ARGUMENTS;
713
}
714
static ut_bq27500data_t _utAlldBq27500Data = {
715
  /* driver   */ NULL,
716
  /* timeout  */ MICROSECONDS_PER_SECOND,
717
};
718
aos_unittest_t moduleUtAlldBq27500 = {
719
  /* name           */ "BQ27500",
720
  /* info           */ "fuel gauge",
721
  /* test function  */ utAlldBq27500Func,
722
  /* shell command  */ {
723
    /* name     */ "unittest:FuelGauge",
724
    /* callback */ _utShellCmdCb_AlldBq27500,
725
    /* next     */ NULL,
726
  },
727
  /* data           */ &_utAlldBq27500Data,
728
};
729

    
730
/* BQ27500 (fuel gauge) in combination with BQ24103A (battery charger) */
731
static int _utShellCmdCb_AlldBq27500Bq24103a(BaseSequentialStream* stream, int argc, char* argv[])
732
{
733
  // evaluate arguments
734
  if (argc == 2) {
735
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
736
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeFront;
737
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerFront;
738
      aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "front battery");
739
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
740
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
741
      return AOS_OK;
742
    }
743
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
744
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeRear;
745
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerRear;
746
      aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "rear battery");
747
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
748
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
749
      return AOS_OK;
750
    }
751
  }
752
  // print help
753
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
754
  chprintf(stream, "Options:\n");
755
  chprintf(stream, "  --front, -f\n");
756
  chprintf(stream, "    Test the front battery fuel gauge and charger.\n");
757
  chprintf(stream, "  --rear, -r\n");
758
  chprintf(stream, "    Test the rear battery fuel gauge and charger.\n");
759
  return AOS_INVALID_ARGUMENTS;
760
}
761
static ut_bq27500bq24103adata_t _utAlldBq27500Bq24103aData= {
762
  /* BQ27500 driver   */ NULL,
763
  /* BQ23203A driver  */ NULL,
764
  /* timeout          */ MICROSECONDS_PER_SECOND,
765
};
766
aos_unittest_t moduleUtAlldBq27500Bq24103a = {
767
  /* name           */ "BQ27500 & BQ24103A",
768
  /* info           */ "fuel gauge & battery charger",
769
  /* test function  */ utAlldBq27500Bq24103aFunc,
770
  /* shell command  */ {
771
    /* name     */ "unittest:FuelGauge&BatteryCharger",
772
    /* callback */ _utShellCmdCb_AlldBq27500Bq24103a,
773
    /* next     */ NULL,
774
  },
775
  /* data           */ &_utAlldBq27500Bq24103aData,
776
};
777

    
778
/* INA219 (power monitor) */
779
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
780
{
781
  // evaluate arguments
782
  if (argc == 2) {
783
    if (strcmp(argv[1], "VDD") == 0) {
784
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVdd;
785
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f;
786
      aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
787
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
788
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
789
      return AOS_OK;
790
    }
791
    else if (strcmp(argv[1], "VIO1.8") == 0) {
792
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio18;
793
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 1.8f;
794
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (1.8V)");
795
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
796
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
797
      return AOS_OK;
798
    }
799
    else if (strcmp(argv[1], "VIO3.3") == 0) {
800
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio33;
801
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f;
802
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (3.3V)");
803
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
804
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
805
      return AOS_OK;
806
    }
807
    else if (strcmp(argv[1], "VSYS4.2") == 0) {
808
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVsys42;
809
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 4.2f;
810
      aosUtRun(stream, &moduleUtAlldIna219, "VSYS (4.2V)");
811
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
812
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
813
      return AOS_OK;
814
    }
815
    else if (strcmp(argv[1], "VIO5.0") == 0) {
816
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio50;
817
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 5.0f;
818
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (5.0V)");
819
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
820
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
821
      return AOS_OK;
822
    }
823
  }
824
  // print help
825
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
826
  chprintf(stream, "Options:\n");
827
  chprintf(stream, "  VDD\n");
828
  chprintf(stream, "    Test VDD (3.3V) power monitor.\n");
829
  chprintf(stream, "  VIO1.8\n");
830
  chprintf(stream, "    Test VIO 1.8V power monitor.\n");
831
  chprintf(stream, "  VIO3.3\n");
832
  chprintf(stream, "    Test VIO 3.3V power monitor.\n");
833
  chprintf(stream, "  VSYS4.2\n");
834
  chprintf(stream, "    Test VSYS 4.2V power monitor.\n");
835
  chprintf(stream, "  VIO5.0\n");
836
  chprintf(stream, "    Test VIO 5.0V power monitor.\n");
837
  return AOS_INVALID_ARGUMENTS;
838
}
839
static ut_ina219data_t _utAlldIna219Data = {
840
  /* driver           */ NULL,
841
  /* expected voltage */ 0.0f,
842
  /* tolerance        */ 0.05f,
843
  /* timeout          */ MICROSECONDS_PER_SECOND,
844
};
845
aos_unittest_t moduleUtAlldIna219 = {
846
  /* name           */ "INA219",
847
  /* info           */ "power monitor",
848
  /* test function  */ utAlldIna219Func,
849
  /* shell command  */ {
850
    /* name     */ "unittest:PowerMonitor",
851
    /* callback */ _utShellCmdCb_AlldIna219,
852
    /* next     */ NULL,
853
  },
854
  /* data           */ &_utAlldIna219Data,
855
};
856

    
857
/* Status LED */
858
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
859
{
860
  (void)argc;
861
  (void)argv;
862
  aosUtRun(stream, &moduleUtAlldLed, NULL);
863
  return AOS_OK;
864
}
865
aos_unittest_t moduleUtAlldLed = {
866
  /* name           */ "LED",
867
  /* info           */ NULL,
868
  /* test function  */ utAlldLedFunc,
869
  /* shell command  */ {
870
    /* name     */ "unittest:StatusLED",
871
    /* callback */ _utShellCmdCb_AlldLed,
872
    /* next     */ NULL,
873
  },
874
  /* data           */ &moduleLldStatusLed,
875
};
876

    
877
/* MPR121 (touch sensor) */
878
static int _utShellCmdCb_AlldMpr121(BaseSequentialStream* stream, int argc, char* argv[])
879
{
880
  (void)argc;
881
  (void)argv;
882
  extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_TOUCHINT);
883
  aosUtRun(stream, &moduleUtAlldMpr121, NULL);
884
  return AOS_OK;
885
}
886
static ut_mpr121data_t _utAlldMpr121Data= {
887
  /* MPR121 driver  */ &moduleLldTouch,
888
  /* timeout        */ MICROSECONDS_PER_SECOND,
889
  /* event source   */ &aos.events.io,
890
  /* event flags    */ (1 << MODULE_GPIO_EXTCHANNEL_TOUCHINT),
891
};
892
aos_unittest_t moduleUtAlldMpr121 = {
893
  /* name           */ "MPR121",
894
  /* info           */ "touch sensor",
895
  /* test function  */ utAlldMpr121Func,
896
  /* shell command  */ {
897
    /* name     */ "unittest:Touch",
898
    /* callback */ _utShellCmdCb_AlldMpr121,
899
    /* next     */ NULL,
900
  },
901
  /* data           */ &_utAlldMpr121Data,
902
};
903

    
904
/* PCA9544A (I2C multiplexer) */
905
static int _utShellCmdCb_AlldPca5944a(BaseSequentialStream* stream, int argc, char* argv[])
906
{
907
  // evaluate arguments
908
  if (argc == 2) {
909
    if (strcmp(argv[1], "#1") == 0) {
910
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer1;
911
      aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #1");
912
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
913
      return AOS_OK;
914
    }
915
    else if (strcmp(argv[1], "#2") == 0) {
916
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer2;
917
      aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #2");
918
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
919
      return AOS_OK;
920
    }
921
  }
922
  // print help
923
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
924
  chprintf(stream, "Options:\n");
925
  chprintf(stream, "  #1\n");
926
  chprintf(stream, "    Test the multiplexer on the I2C bus #1.\n");
927
  chprintf(stream, "  #2\n");
928
  chprintf(stream, "    Test the multiplexer on the I2C bus #2.\n");
929
  return AOS_INVALID_ARGUMENTS;
930
}
931
static ut_pca9544adata_t _utAlldPca9544aData = {
932
  /* driver   */ NULL,
933
  /* timeout  */ MICROSECONDS_PER_SECOND,
934
};
935
aos_unittest_t moduleUtAlldPca9544a = {
936
  /* name           */ "PCA9544A",
937
  /* info           */ "I2C multiplexer",
938
  /* test function  */ utAlldPca9544aFunc,
939
  /* shell command  */ {
940
    /* name     */ "unittest:I2CMultiplexer",
941
    /* callback */ _utShellCmdCb_AlldPca5944a,
942
    /* next     */ NULL,
943
  },
944
  /* data           */ &_utAlldPca9544aData,
945
};
946

    
947
/* PKLCS1212E4001 (buzzer) */
948
static int _utShellCmdCb_AlldPklcs1212e4001(BaseSequentialStream* stream, int argc, char* argv[])
949
{
950
  (void)argc;
951
  (void)argv;
952
  aosUtRun(stream, &moduleUtAlldPklcs1212e4001, NULL);
953
  return AOS_OK;
954
}
955
static ut_pklcs1212e4001_t _utAlldPklcs1212e4001Data = {
956
  /* PWM driver   */ &MODULE_HAL_PWM_BUZZER,
957
  /* PWM channel  */ MODULE_HAL_PWM_BUZZER_CHANNEL
958
};
959
aos_unittest_t moduleUtAlldPklcs1212e4001 = {
960
  /* name           */ "PKLCS1212E4001",
961
  /* info           */ "buzzer",
962
  /* test function  */ utAlldPklcs1212e4001Func,
963
  /* shell command  */ {
964
    /* name     */ "unittest:Buzzer",
965
    /* callback */ _utShellCmdCb_AlldPklcs1212e4001,
966
    /* next     */ NULL,
967
  },
968
  /* data           */ &_utAlldPklcs1212e4001Data,
969
};
970

    
971
/* TPS62113 (stop-down converter) */
972
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
973
{
974
  // Although there are four TPS62113 on the PCB, they all share the same input signal.
975
  // A sa result, no additional shell arguments need to be evaluated.
976
  (void)argc;
977
  (void)argv;
978
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
979
  return AOS_OK;
980
}
981
aos_unittest_t moduleUtAlldTps62113 = {
982
  /* name           */ "TPS62113",
983
  /* info           */ "step-down converter",
984
  /* test function  */ utAlldTps62113Func,
985
  /* shell command  */ {
986
    /* name     */ "unittest:StepDownConverter",
987
    /* callback */ _utShellCmdCb_AlldTps62113,
988
    /* next     */ NULL,
989
  },
990
  /* data           */ &moduleLldStepDownConverter,
991
};
992

    
993
/* TPS62113 (step-donw converter) in combination with INA219 (power monitor) */
994
static int _utShellCmdCb_AlldTps62113Ina219(BaseSequentialStream* stream, int argc, char* argv[])
995
{
996
  (void)argc;
997
  (void)argv;
998
  aosUtRun(stream, &moduleUtAlldTps62113Ina219, "VSYS (4.2V)");
999
  return AOS_OK;
1000
}
1001
ut_tps62113ina219data_t _utAlldTps62113Ina219Data = {
1002
  /* TPS62113 */ &moduleLldStepDownConverter,
1003
  /* INA219   */ &moduleLldPowerMonitorVsys42,
1004
  /* timeout  */ MICROSECONDS_PER_SECOND,
1005
};
1006
aos_unittest_t moduleUtAlldTps62113Ina219 = {
1007
  /* name           */ "TPS62113 & INA219",
1008
  /* info           */ "step-down converter & power monitor",
1009
  /* test function  */ utAlldTps62113Ina219Func,
1010
  /* shell command  */ {
1011
    /* name     */ "unittest:StepDownConverter&PowerMonitor",
1012
    /* callback */ _utShellCmdCb_AlldTps62113Ina219,
1013
    /* next     */ NULL,
1014
  },
1015
  /* data           */ &_utAlldTps62113Ina219Data,
1016
};
1017

    
1018
/* VCNL4020 (proximity sensor) */
1019
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
1020
{
1021
  uint8_t intstatus;
1022
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1023
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1024
  if (intstatus) {
1025
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1026
  }
1027
  return;
1028
}
1029
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
1030
{
1031
  enum {
1032
    UNKNOWN,
1033
    NNE, ENE, ESE, SSE, SSW,WSW,WNW, NNW,
1034
  } sensor = UNKNOWN;
1035
  // evaluate arguments
1036
  if (argc == 2) {
1037
    if (strcmp(argv[1], "-nne") == 0) {
1038
      sensor = NNE;
1039
    } else if (strcmp(argv[1], "-ene") == 0) {
1040
      sensor = ENE;
1041
    } else if (strcmp(argv[1], "-ese") == 0) {
1042
      sensor = ESE;
1043
    } else if (strcmp(argv[1], "-sse") == 0) {
1044
      sensor = SSE;
1045
    } else if (strcmp(argv[1], "-ssw") == 0) {
1046
      sensor = SSW;
1047
    } else if (strcmp(argv[1], "-wsw") == 0) {
1048
      sensor = WSW;
1049
    } else if (strcmp(argv[1], "-wnw") == 0) {
1050
      sensor = WNW;
1051
    } else if (strcmp(argv[1], "-nnw") == 0) {
1052
      sensor = NNW;
1053
    }
1054
  }
1055
  if (sensor != UNKNOWN) {
1056
    PCA9544ADriver* mux = NULL;
1057
    switch (sensor) {
1058
      case SSE:
1059
      case SSW:
1060
      case WSW:
1061
      case WNW:
1062
        mux = &moduleLldI2cMultiplexer1;
1063
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity1;
1064
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = (1 << MODULE_GPIO_EXTCHANNEL_IRINT2);
1065
        extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT2);
1066
        break;
1067
      case NNW:
1068
      case NNE:
1069
      case ENE:
1070
      case ESE:
1071
        mux = &moduleLldI2cMultiplexer2;
1072
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity2;
1073
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = (1 << MODULE_GPIO_EXTCHANNEL_IRINT1);
1074
        extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT1);
1075
        break;
1076
      default:
1077
        break;
1078
    }
1079
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1080
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1081
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1082
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1083
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1084
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1085
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1086
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1087
    switch (sensor) {
1088
      case NNE:
1089
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1090
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northeast sensor");
1091
        break;
1092
      case ENE:
1093
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1094
        aosUtRun(stream, &moduleUtAlldVcnl4020, "east-northeast sensor");
1095
        break;
1096
      case ESE:
1097
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1098
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-southeast sensor");
1099
        break;
1100
      case SSE:
1101
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1102
        aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southeast sensor");
1103
        break;
1104
      case SSW:
1105
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1106
        aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southwest sensor");
1107
        break;
1108
      case WSW:
1109
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1110
        aosUtRun(stream, &moduleUtAlldVcnl4020, "west-southwest sensor");
1111
        break;
1112
      case WNW:
1113
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1114
        aosUtRun(stream, &moduleUtAlldVcnl4020, "west-northwest sensor");
1115
        break;
1116
      case NNW:
1117
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1118
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northwest sensor");
1119
        break;
1120
      default:
1121
        break;
1122
    }
1123
    ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = NULL;
1124
    ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = 0;
1125
    return AOS_OK;
1126
  }
1127
  // print help
1128
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
1129
  chprintf(stream, "Options:\n");
1130
  chprintf(stream, "  -nne\n");
1131
  chprintf(stream, "    Test north-northeast sensor.\n");
1132
  chprintf(stream, "  -ene\n");
1133
  chprintf(stream, "    Test east-northeast sensor.\n");
1134
  chprintf(stream, "  -ese\n");
1135
  chprintf(stream, "    Test east-southeast sensor.\n");
1136
  chprintf(stream, "  -sse\n");
1137
  chprintf(stream, "    Test south-southeast sensor.\n");
1138
  chprintf(stream, "  -ssw\n");
1139
  chprintf(stream, "    Test south-southwest sensor.\n");
1140
  chprintf(stream, "  -wsw\n");
1141
  chprintf(stream, "    Test west-southwest sensor.\n");
1142
  chprintf(stream, "  -wnw\n");
1143
  chprintf(stream, "    Test west-northwest sensor.\n");
1144
  chprintf(stream, "  -nnw\n");
1145
  chprintf(stream, "    Test north-northwest sensor.\n");
1146
  return AOS_INVALID_ARGUMENTS;
1147
}
1148
static ut_vcnl4020data_t _utAlldVcnl4020Data = {
1149
  /* driver       */ NULL,
1150
  /* timeout      */ MICROSECONDS_PER_SECOND,
1151
  /* event source */ &aos.events.io,
1152
  /* event flags  */ 0,
1153
};
1154
aos_unittest_t moduleUtAlldVcnl4020 = {
1155
  /* name           */ "VCNL4020",
1156
  /* info           */ "proximity sensor",
1157
  /* test function  */ utAlldVcnl4020Func,
1158
  /* shell command  */ {
1159
    /* name     */ "unittest:Proximity",
1160
    /* callback */ _utShellCmdCb_AlldVcnl4020,
1161
    /* next     */ NULL,
1162
  },
1163
  /* data           */ &_utAlldVcnl4020Data,
1164
};
1165

    
1166
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
1167

    
1168
/** @} */