Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.c @ 0039ffcb

History | View | Annotate | Download (38.684 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
/**
20
 * @file
21
 * @brief   Structures and constant for the PowerManagement module.
22
 *
23
 * @addtogroup powermanagement_module
24
 * @{
25
 */
26

    
27
#include "module.h"
28

    
29
#include <amiroos.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 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
/**
126
 * @brief   SYS_REG_EN output signal GPIO.
127
 */
128
static apalGpio_t _gpioSysRegEn = {
129
  /* port */ GPIOA,
130
  /* pad  */ GPIOA_SYS_REG_EN,
131
};
132
ROMCONST apalControlGpio_t moduleSysRegEn = {
133
  /* 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

    
141
/**
142
 * @brief   IR_INT1 input signal GPIO.
143
 */
144
static apalGpio_t _gpioIrInt1 = {
145
  /* port */ GPIOB,
146
  /* pad  */ GPIOB_IR_INT1_N,
147
};
148
ROMCONST apalControlGpio_t moduleGpioIrInt1 = {
149
  /* 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

    
157
/**
158
 * @brief   POWER_EN output signal GPIO.
159
 */
160
static apalGpio_t _gpioPowerEn = {
161
  /* port */ GPIOB,
162
  /* pad  */ GPIOB_POWER_EN,
163
};
164
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
165
  /* 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

    
173
/**
174
 * @brief   SYS_UART_DN bidirectional signal GPIO.
175
 */
176
static apalGpio_t _gpioSysUartDn = {
177
  /* port */ GPIOB,
178
  /* pad  */ GPIOB_SYS_UART_DN,
179
};
180
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
181
  /* 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

    
189
/**
190
 * @brief   CHARGE_STAT2A input signal GPIO.
191
 */
192
static apalGpio_t _gpioChargeStat2A = {
193
  /* port */ GPIOB,
194
  /* pad  */ GPIOB_CHARGE_STAT2A,
195
};
196
ROMCONST apalControlGpio_t moduleGpioChargeStat2A = {
197
  /* 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

    
205
/**
206
 * @brief   GAUGE_BATLOW2 input signal GPIO.
207
 */
208
static apalGpio_t _gpioGaugeBatLow2 = {
209
  /* port */ GPIOB,
210
  /* pad  */ GPIOB_GAUGE_BATLOW2,
211
};
212
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2 = {
213
  /* 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

    
221
/**
222
 * @brief   GAUGE_BATGD2 input signal GPIO.
223
 */
224
static apalGpio_t _gpioGaugeBatGd2 = {
225
  /* port */ GPIOB,
226
  /* pad  */ GPIOB_GAUGE_BATGD2_N,
227
};
228
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2 = {
229
  /* 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

    
237
/**
238
 * @brief   LED output signal GPIO.
239
 */
240
static apalGpio_t _gpioLed = {
241
  /* port */ GPIOB,
242
  /* pad  */ GPIOB_LED,
243
};
244
ROMCONST apalControlGpio_t moduleGpioLed = {
245
  /* 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

    
253
/**
254
 * @brief   SYS_UART_UP bidirectional signal GPIO.
255
 */
256
static apalGpio_t _gpioSysUartUp = {
257
  /* port */ GPIOB,
258
  /* pad  */ GPIOB_SYS_UART_UP,
259
};
260
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
261
  /* 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

    
269
/**
270
 * @brief   CHARGE_STAT1A input signal GPIO.
271
 */
272
static apalGpio_t _gpioChargeStat1A = {
273
  /* port */ GPIOC,
274
  /* pad  */ GPIOC_CHARGE_STAT1A,
275
};
276
ROMCONST apalControlGpio_t moduleGpioChargeStat1A = {
277
  /* 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

    
285
/**
286
 * @brief   GAUGE_BATLOW1 input signal GPIO.
287
 */
288
static apalGpio_t _gpioGaugeBatLow1 = {
289
  /* port */ GPIOC,
290
  /* pad  */ GPIOC_GAUGE_BATLOW1,
291
};
292
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1 = {
293
  /* 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

    
301
/**
302
 * @brief   GAUGE_BATGD1 input signal GPIO.
303
 */
304
static apalGpio_t _gpioGaugeBatGd1 = {
305
  /* port */ GPIOC,
306
  /* pad  */ GPIOC_GAUGE_BATGD1_N,
307
};
308
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1 = {
309
  /* 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

    
317
/**
318
 * @brief   CHARG_EN1 output signal GPIO.
319
 */
320
static apalGpio_t _gpioChargeEn1 = {
321
  /* port */ GPIOC,
322
  /* pad  */ GPIOC_CHARGE_EN1_N,
323
};
324
ROMCONST apalControlGpio_t moduleGpioChargeEn1 = {
325
  /* 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

    
333
/**
334
 * @brief   IR_INT2 input signal GPIO.
335
 */
336
static apalGpio_t _gpioIrInt2 = {
337
  /* port */ GPIOC,
338
  /* pad  */ GPIOC_IR_INT2_N,
339
};
340
ROMCONST apalControlGpio_t moduleGpioIrInt2 = {
341
  /* 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

    
349
/**
350
 * @brief   TOUCH_INT input signal GPIO.
351
 */
352
static apalGpio_t _gpioTouchInt = {
353
  /* port */ GPIOC,
354
  /* pad  */ GPIOC_TOUCH_INT_N,
355
};
356
ROMCONST apalControlGpio_t moduleGpioTouchInt = {
357
  /* 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

    
365
/**
366
 * @brief   SYS_DONE input signal GPIO.
367
 */
368
static apalGpio_t _gpioSysDone = {
369
  /* port */ GPIOC,
370
  /* pad  */ GPIOC_SYS_DONE,
371
};
372
ROMCONST apalControlGpio_t moduleGpioSysDone = {
373
  /* 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

    
381
/**
382
 * @brief   SYS_PROG output signal GPIO.
383
 */
384
static apalGpio_t _gpioSysProg = {
385
  /* port */ GPIOC,
386
  /* pad  */ GPIOC_SYS_PROG_N,
387
};
388
ROMCONST apalControlGpio_t moduleGpioSysProg = {
389
  /* 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

    
397
/**
398
 * @brief   PATH_DC input signal GPIO.
399
 */
400
static apalGpio_t _gpioPathDc = {
401
  /* port */ GPIOC,
402
  /* pad  */ GPIOC_PATH_DC,
403
};
404
ROMCONST apalControlGpio_t moduleGpioPathDc = {
405
  /* 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

    
413
/**
414
 * @brief   SYS_SPI_DIR bidirectional signal GPIO.
415
 */
416
static apalGpio_t _gpioSysSpiDir = {
417
  /* port */ GPIOC,
418
  /* pad  */ GPIOC_SYS_SPI_DIR,
419
};
420
ROMCONST apalControlGpio_t moduleGpioSysSpiDir = {
421
  /* 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

    
429
/**
430
 * @brief   SYS_SYNC bidirectional signal GPIO.
431
 */
432
static apalGpio_t _gpioSysSync = {
433
  /* port */ GPIOC,
434
  /* pad  */ GPIOC_SYS_INT_N,
435
};
436
ROMCONST apalControlGpio_t moduleGpioSysSync = {
437
  /* 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

    
445
/**
446
 * @brief   SYS_PD bidirectional signal GPIO.
447
 */
448
static apalGpio_t _gpioSysPd = {
449
  /* port */ GPIOC,
450
  /* pad  */ GPIOC_SYS_PD_N,
451
};
452
ROMCONST apalControlGpio_t moduleGpioSysPd = {
453
  /* 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

    
461
/**
462
 * @brief   SYS_WARMRST bidirectional signal GPIO.
463
 */
464
static apalGpio_t _gpioSysWarmrst = {
465
  /* port */ GPIOC,
466
  /* pad  */ GPIOC_SYS_WARMRST_N,
467
};
468
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
469
  /* 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

    
477
/**
478
 * @brief   BT_RST output signal GPIO.
479
 */
480
static apalGpio_t _gpioBtRst = {
481
  /* port */ GPIOC,
482
  /* pad  */ GPIOC_BT_RST,
483
};
484
ROMCONST apalControlGpio_t moduleGpioBtRst = {
485
  /* 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

    
493
/**
494
 * @brief   CHARGE_EN2 output signal GPIO.
495
 */
496
static apalGpio_t _gpioChargeEn2 = {
497
  /* port */ GPIOD,
498
  /* pad  */ GPIOD_CHARGE_EN2_N,
499
};
500
ROMCONST apalControlGpio_t moduleGpioChargeEn2 = {
501
  /* 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

    
509
/** @} */
510

    
511
/*===========================================================================*/
512
/**
513
 * @name AMiRo-OS core configurations
514
 * @{
515
 */
516
/*===========================================================================*/
517

    
518
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
519
ROMCONST char* moduleShellPrompt = "PowerManagement";
520
#endif
521

    
522
/** @} */
523

    
524
/*===========================================================================*/
525
/**
526
 * @name Startup Shutdown Synchronization Protocol (SSSP)
527
 * @{
528
 */
529
/*===========================================================================*/
530

    
531
/** @} */
532

    
533
/*===========================================================================*/
534
/**
535
 * @name Low-level drivers
536
 * @{
537
 */
538
/*===========================================================================*/
539

    
540
AT24C01BNDriver moduleLldEeprom = {
541
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
542
  /* I2C address  */ AT24C01BN_LLD_I2C_ADDR_FIXED,
543
};
544

    
545
BQ24103ADriver moduleLldBatteryChargerFront = {
546
  /* charge enable GPIO */ &moduleGpioChargeEn1,
547
  /* charge status GPIO */ &moduleGpioChargeStat1A,
548
};
549

    
550
BQ24103ADriver moduleLldBatteryChargerRear = {
551
  /* charge enable GPIO */ &moduleGpioChargeEn2,
552
  /* charge status GPIO */ &moduleGpioChargeStat2A,
553
};
554

    
555
BQ27500Driver moduleLldFuelGaugeFront = {
556
  /* I2C driver         */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
557
  /* battery low GPIO   */ &moduleGpioGaugeBatLow1,
558
  /* battery good GPIO  */ &moduleGpioGaugeBatGd1,
559
};
560

    
561
BQ27500Driver moduleLldFuelGaugeRear = {
562
  /* I2C driver         */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
563
  /* battery low GPIO   */ &moduleGpioGaugeBatLow2,
564
  /* battery good GPIO  */ &moduleGpioGaugeBatGd2,
565
};
566

    
567
INA219Driver moduleLldPowerMonitorVdd = {
568
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
569
  /* I²C address      */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
570
  /* current LSB (uA) */ 0x00u,
571
  /* configuration    */ NULL,
572
};
573

    
574
INA219Driver moduleLldPowerMonitorVio18 = {
575
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
576
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
577
  /* current LSB (uA) */ 0x00u,
578
  /* configuration    */ NULL,
579
};
580

    
581
INA219Driver moduleLldPowerMonitorVio33 = {
582
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
583
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
584
  /* current LSB (uA) */ 0x00u,
585
  /* configuration    */ NULL,
586
};
587

    
588
INA219Driver moduleLldPowerMonitorVsys42 = {
589
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
590
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
591
  /* current LSB (uA) */ 0x00u,
592
  /* configuration    */ NULL,
593
};
594

    
595
INA219Driver moduleLldPowerMonitorVio50 = {
596
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
597
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
598
  /* current LSB (uA) */ 0x00u,
599
  /* configuration    */ NULL,
600
};
601

    
602
LEDDriver moduleLldStatusLed = {
603
  /* LED GPIO */ &moduleGpioLed,
604
};
605

    
606
MPR121Driver moduleLldTouch = {
607
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
608
};
609

    
610
PCA9544ADriver moduleLldI2cMultiplexer1 = {
611
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
612
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
613
};
614

    
615
PCA9544ADriver moduleLldI2cMultiplexer2 = {
616
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
617
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
618
};
619

    
620
TPS62113Driver moduleLldStepDownConverter = {
621
  /* Power enable GPIO */ &moduleGpioPowerEn,
622
};
623

    
624
VCNL4020Driver moduleLldProximity1 = {
625
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
626
};
627

    
628
VCNL4020Driver moduleLldProximity2 = {
629
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
630
};
631

    
632
/** @} */
633

    
634
/*===========================================================================*/
635
/**
636
 * @name Unit tests (UT)
637
 * @{
638
 */
639
/*===========================================================================*/
640
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
641
#include <string.h>
642

    
643
/* ADC  */
644
static int _utShellCmdCb_Adc(BaseSequentialStream* stream, int argc, char* argv[])
645
{
646
  (void)argc;
647
  (void)argv;
648
  aosUtRun(stream, &moduleUtAdcVsys, NULL);
649
  return AOS_OK;
650
}
651
static ut_adcdata_t _utAdcVsysData = {
652
  /* driver               */ &MODULE_HAL_ADC_VSYS,
653
  /* ADC conversion group */ &moduleHalAdcVsysConversionGroup,
654
};
655
aos_unittest_t moduleUtAdcVsys = {
656
  /* name           */ "ADC",
657
  /* info           */ "VSYS",
658
  /* test function  */ utAdcFunc,
659
  /* shell command  */ {
660
    /* name     */ "unittest:ADC",
661
    /* callback */ _utShellCmdCb_Adc,
662
    /* next     */ NULL,
663
  },
664
  /* data           */ &_utAdcVsysData,
665
};
666

    
667
/* AT24C01BN-SH-B (EEPROM) */
668
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
669
{
670
  (void)argc;
671
  (void)argv;
672
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
673
  return AOS_OK;
674
}
675
static ut_at24c01bndata_t _utAlldAt24c01bnData = {
676
  /* driver   */ &moduleLldEeprom,
677
  /* timeout  */ MICROSECONDS_PER_SECOND,
678
};
679
aos_unittest_t moduleUtAlldAt24c01bn = {
680
  /* name           */ "AT24C01BN-SH-B",
681
  /* info           */ "1kbit EEPROM",
682
  /* test function  */ utAlldAt24c01bnFunc,
683
  /* shell command  */ {
684
    /* name     */ "unittest:EEPROM",
685
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
686
    /* next     */ NULL,
687
  },
688
  /* data           */ &_utAlldAt24c01bnData,
689
};
690

    
691
/* BQ24103A (battery charger) */
692
static int _utShellCmdCb_AlldBq24103a(BaseSequentialStream* stream, int argc, char* argv[])
693
{
694
  // local variables
695
  bool print_help = false;
696

    
697
  // evaluate argument
698
  if (argc == 2) {
699
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
700
      moduleUtAlldBq24103a.data = &moduleLldBatteryChargerFront;
701
      aosUtRun(stream, &moduleUtAlldBq24103a, "front battery");
702
      moduleUtAlldBq24103a.data = NULL;
703
    }
704
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
705
      moduleUtAlldBq24103a.data = &moduleLldBatteryChargerRear;
706
      aosUtRun(stream, &moduleUtAlldBq24103a, "rear battery");
707
      moduleUtAlldBq24103a.data = NULL;
708
    }
709
    else {
710
      print_help = true;
711
    }
712
  } else {
713
    print_help = true;
714
  }
715

    
716
  // print help or just return
717
  if (print_help) {
718
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
719
    chprintf(stream, "Options:\n");
720
    chprintf(stream, "  --front, -f\n");
721
    chprintf(stream, "    Test the front battery charger.\n");
722
    chprintf(stream, "  --rear, -r\n");
723
    chprintf(stream, "    Test the rear battery charger.\n");
724
    return AOS_INVALID_ARGUMENTS;
725
  } else {
726
    return AOS_OK;
727
  }
728
}
729
aos_unittest_t moduleUtAlldBq24103a = {
730
  /* name           */ "BQ24103A",
731
  /* info           */ "battery charger",
732
  /* test function  */ utAlldBq24103aFunc,
733
  /* shell command  */ {
734
    /* name     */ "unittest:BatteryCharger",
735
    /* callback */ _utShellCmdCb_AlldBq24103a,
736
    /* next     */ NULL,
737
  },
738
  /* data           */ NULL,
739
};
740

    
741
/* BQ27500 (fuel gauge) */
742
static int _utShellCmdCb_AlldBq27500(BaseSequentialStream* stream, int argc, char* argv[])
743
{
744
  // evaluate arguments
745
  if (argc == 2) {
746
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
747
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeFront;
748
      aosUtRun(stream, &moduleUtAlldBq27500, "front battery");
749
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
750
      return AOS_OK;
751
    }
752
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
753
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeRear;
754
      aosUtRun(stream, &moduleUtAlldBq27500, "rear battery");
755
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
756
      return AOS_OK;
757
    }
758
  }
759
  // print help
760
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
761
  chprintf(stream, "Options:\n");
762
  chprintf(stream, "  --front, -f\n");
763
  chprintf(stream, "    Test the front battery fuel gauge.\n");
764
  chprintf(stream, "  --rear, -r\n");
765
  chprintf(stream, "    Test the rear battery fuel gauge.\n");
766
  return AOS_INVALID_ARGUMENTS;
767
}
768
static ut_bq27500data_t _utAlldBq27500Data = {
769
  /* driver   */ NULL,
770
  /* timeout  */ MICROSECONDS_PER_SECOND,
771
};
772
aos_unittest_t moduleUtAlldBq27500 = {
773
  /* name           */ "BQ27500",
774
  /* info           */ "fuel gauge",
775
  /* test function  */ utAlldBq27500Func,
776
  /* shell command  */ {
777
    /* name     */ "unittest:FuelGauge",
778
    /* callback */ _utShellCmdCb_AlldBq27500,
779
    /* next     */ NULL,
780
  },
781
  /* data           */ &_utAlldBq27500Data,
782
};
783

    
784
/* BQ27500 (fuel gauge) in combination with BQ24103A (battery charger) */
785
static int _utShellCmdCb_AlldBq27500Bq24103a(BaseSequentialStream* stream, int argc, char* argv[])
786
{
787
  // evaluate arguments
788
  if (argc == 2) {
789
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
790
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeFront;
791
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerFront;
792
      aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "front battery");
793
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
794
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
795
      return AOS_OK;
796
    }
797
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
798
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeRear;
799
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerRear;
800
      aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "rear battery");
801
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
802
      ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
803
      return AOS_OK;
804
    }
805
  }
806
  // print help
807
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
808
  chprintf(stream, "Options:\n");
809
  chprintf(stream, "  --front, -f\n");
810
  chprintf(stream, "    Test the front battery fuel gauge and charger.\n");
811
  chprintf(stream, "  --rear, -r\n");
812
  chprintf(stream, "    Test the rear battery fuel gauge and charger.\n");
813
  return AOS_INVALID_ARGUMENTS;
814
}
815
static ut_bq27500bq24103adata_t _utAlldBq27500Bq24103aData= {
816
  /* BQ27500 driver   */ NULL,
817
  /* BQ23203A driver  */ NULL,
818
  /* timeout          */ MICROSECONDS_PER_SECOND,
819
};
820
aos_unittest_t moduleUtAlldBq27500Bq24103a = {
821
  /* name           */ "BQ27500 & BQ24103A",
822
  /* info           */ "fuel gauge & battery charger",
823
  /* test function  */ utAlldBq27500Bq24103aFunc,
824
  /* shell command  */ {
825
    /* name     */ "unittest:FuelGauge&BatteryCharger",
826
    /* callback */ _utShellCmdCb_AlldBq27500Bq24103a,
827
    /* next     */ NULL,
828
  },
829
  /* data           */ &_utAlldBq27500Bq24103aData,
830
};
831

    
832
/* INA219 (power monitor) */
833
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
834
{
835
  // evaluate arguments
836
  if (argc == 2) {
837
    if (strcmp(argv[1], "VDD") == 0) {
838
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVdd;
839
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f;
840
      aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
841
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
842
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
843
      return AOS_OK;
844
    }
845
    else if (strcmp(argv[1], "VIO1.8") == 0) {
846
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio18;
847
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 1.8f;
848
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (1.8V)");
849
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
850
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
851
      return AOS_OK;
852
    }
853
    else if (strcmp(argv[1], "VIO3.3") == 0) {
854
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio33;
855
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f;
856
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (3.3V)");
857
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
858
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
859
      return AOS_OK;
860
    }
861
    else if (strcmp(argv[1], "VSYS4.2") == 0) {
862
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVsys42;
863
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 4.2f;
864
      aosUtRun(stream, &moduleUtAlldIna219, "VSYS (4.2V)");
865
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
866
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
867
      return AOS_OK;
868
    }
869
    else if (strcmp(argv[1], "VIO5.0") == 0) {
870
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio50;
871
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 5.0f;
872
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (5.0V)");
873
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
874
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
875
      return AOS_OK;
876
    }
877
  }
878
  // print help
879
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
880
  chprintf(stream, "Options:\n");
881
  chprintf(stream, "  VDD\n");
882
  chprintf(stream, "    Test VDD (3.3V) power monitor.\n");
883
  chprintf(stream, "  VIO1.8\n");
884
  chprintf(stream, "    Test VIO 1.8V power monitor.\n");
885
  chprintf(stream, "  VIO3.3\n");
886
  chprintf(stream, "    Test VIO 3.3V power monitor.\n");
887
  chprintf(stream, "  VSYS4.2\n");
888
  chprintf(stream, "    Test VSYS 4.2V power monitor.\n");
889
  chprintf(stream, "  VIO5.0\n");
890
  chprintf(stream, "    Test VIO 5.0V power monitor.\n");
891
  return AOS_INVALID_ARGUMENTS;
892
}
893
static ut_ina219data_t _utAlldIna219Data = {
894
  /* driver           */ NULL,
895
  /* expected voltage */ 0.0f,
896
  /* tolerance        */ 0.05f,
897
  /* timeout          */ MICROSECONDS_PER_SECOND,
898
};
899
aos_unittest_t moduleUtAlldIna219 = {
900
  /* name           */ "INA219",
901
  /* info           */ "power monitor",
902
  /* test function  */ utAlldIna219Func,
903
  /* shell command  */ {
904
    /* name     */ "unittest:PowerMonitor",
905
    /* callback */ _utShellCmdCb_AlldIna219,
906
    /* next     */ NULL,
907
  },
908
  /* data           */ &_utAlldIna219Data,
909
};
910

    
911
/* Status LED */
912
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
913
{
914
  (void)argc;
915
  (void)argv;
916
  aosUtRun(stream, &moduleUtAlldLed, NULL);
917
  return AOS_OK;
918
}
919
aos_unittest_t moduleUtAlldLed = {
920
  /* name           */ "LED",
921
  /* info           */ NULL,
922
  /* test function  */ utAlldLedFunc,
923
  /* shell command  */ {
924
    /* name     */ "unittest:StatusLED",
925
    /* callback */ _utShellCmdCb_AlldLed,
926
    /* next     */ NULL,
927
  },
928
  /* data           */ &moduleLldStatusLed,
929
};
930

    
931
/* MPR121 (touch sensor) */
932
static int _utShellCmdCb_AlldMpr121(BaseSequentialStream* stream, int argc, char* argv[])
933
{
934
  (void)argc;
935
  (void)argv;
936
  aosUtRun(stream, &moduleUtAlldMpr121, NULL);
937
  return AOS_OK;
938
}
939
static ut_mpr121data_t _utAlldMpr121Data= {
940
  /* MPR121 driver  */ &moduleLldTouch,
941
  /* timeout        */ MICROSECONDS_PER_SECOND,
942
  /* event source   */ &aos.events.io,
943
  /* event flags    */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
944
};
945
aos_unittest_t moduleUtAlldMpr121 = {
946
  /* name           */ "MPR121",
947
  /* info           */ "touch sensor",
948
  /* test function  */ utAlldMpr121Func,
949
  /* shell command  */ {
950
    /* name     */ "unittest:Touch",
951
    /* callback */ _utShellCmdCb_AlldMpr121,
952
    /* next     */ NULL,
953
  },
954
  /* data           */ &_utAlldMpr121Data,
955
};
956

    
957
/* PCA9544A (I2C multiplexer) */
958
static int _utShellCmdCb_AlldPca5944a(BaseSequentialStream* stream, int argc, char* argv[])
959
{
960
  // evaluate arguments
961
  if (argc == 2) {
962
    if (strcmp(argv[1], "#1") == 0) {
963
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer1;
964
      aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #1");
965
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
966
      return AOS_OK;
967
    }
968
    else if (strcmp(argv[1], "#2") == 0) {
969
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer2;
970
      aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #2");
971
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
972
      return AOS_OK;
973
    }
974
  }
975
  // print help
976
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
977
  chprintf(stream, "Options:\n");
978
  chprintf(stream, "  #1\n");
979
  chprintf(stream, "    Test the multiplexer on the I2C bus #1.\n");
980
  chprintf(stream, "  #2\n");
981
  chprintf(stream, "    Test the multiplexer on the I2C bus #2.\n");
982
  return AOS_INVALID_ARGUMENTS;
983
}
984
static ut_pca9544adata_t _utAlldPca9544aData = {
985
  /* driver   */ NULL,
986
  /* timeout  */ MICROSECONDS_PER_SECOND,
987
};
988
aos_unittest_t moduleUtAlldPca9544a = {
989
  /* name           */ "PCA9544A",
990
  /* info           */ "I2C multiplexer",
991
  /* test function  */ utAlldPca9544aFunc,
992
  /* shell command  */ {
993
    /* name     */ "unittest:I2CMultiplexer",
994
    /* callback */ _utShellCmdCb_AlldPca5944a,
995
    /* next     */ NULL,
996
  },
997
  /* data           */ &_utAlldPca9544aData,
998
};
999

    
1000
/* PKLCS1212E4001 (buzzer) */
1001
static int _utShellCmdCb_AlldPklcs1212e4001(BaseSequentialStream* stream, int argc, char* argv[])
1002
{
1003
  (void)argc;
1004
  (void)argv;
1005
  aosUtRun(stream, &moduleUtAlldPklcs1212e4001, NULL);
1006
  return AOS_OK;
1007
}
1008
static ut_pklcs1212e4001_t _utAlldPklcs1212e4001Data = {
1009
  /* PWM driver   */ &MODULE_HAL_PWM_BUZZER,
1010
  /* PWM channel  */ MODULE_HAL_PWM_BUZZER_CHANNEL
1011
};
1012
aos_unittest_t moduleUtAlldPklcs1212e4001 = {
1013
  /* name           */ "PKLCS1212E4001",
1014
  /* info           */ "buzzer",
1015
  /* test function  */ utAlldPklcs1212e4001Func,
1016
  /* shell command  */ {
1017
    /* name     */ "unittest:Buzzer",
1018
    /* callback */ _utShellCmdCb_AlldPklcs1212e4001,
1019
    /* next     */ NULL,
1020
  },
1021
  /* data           */ &_utAlldPklcs1212e4001Data,
1022
};
1023

    
1024
/* TPS62113 (stop-down converter) */
1025
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
1026
{
1027
  // Although there are four TPS62113 on the PCB, they all share the same input signal.
1028
  // A sa result, no additional shell arguments need to be evaluated.
1029
  (void)argc;
1030
  (void)argv;
1031
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
1032
  return AOS_OK;
1033
}
1034
aos_unittest_t moduleUtAlldTps62113 = {
1035
  /* name           */ "TPS62113",
1036
  /* info           */ "step-down converter",
1037
  /* test function  */ utAlldTps62113Func,
1038
  /* shell command  */ {
1039
    /* name     */ "unittest:StepDownConverter",
1040
    /* callback */ _utShellCmdCb_AlldTps62113,
1041
    /* next     */ NULL,
1042
  },
1043
  /* data           */ &moduleLldStepDownConverter,
1044
};
1045

    
1046
/* TPS62113 (step-donw converter) in combination with INA219 (power monitor) */
1047
static int _utShellCmdCb_AlldTps62113Ina219(BaseSequentialStream* stream, int argc, char* argv[])
1048
{
1049
  (void)argc;
1050
  (void)argv;
1051
  aosUtRun(stream, &moduleUtAlldTps62113Ina219, "VSYS (4.2V)");
1052
  return AOS_OK;
1053
}
1054
static ut_tps62113ina219data_t _utAlldTps62113Ina219Data = {
1055
  /* TPS62113 */ &moduleLldStepDownConverter,
1056
  /* INA219   */ &moduleLldPowerMonitorVsys42,
1057
  /* timeout  */ MICROSECONDS_PER_SECOND,
1058
};
1059
aos_unittest_t moduleUtAlldTps62113Ina219 = {
1060
  /* name           */ "TPS62113 & INA219",
1061
  /* info           */ "step-down converter & power monitor",
1062
  /* test function  */ utAlldTps62113Ina219Func,
1063
  /* shell command  */ {
1064
    /* name     */ "unittest:StepDownConverter&PowerMonitor",
1065
    /* callback */ _utShellCmdCb_AlldTps62113Ina219,
1066
    /* next     */ NULL,
1067
  },
1068
  /* data           */ &_utAlldTps62113Ina219Data,
1069
};
1070

    
1071
/* VCNL4020 (proximity sensor) */
1072
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
1073
{
1074
  uint8_t intstatus;
1075
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1076
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1077
  if (intstatus) {
1078
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1079
  }
1080
  return;
1081
}
1082
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
1083
{
1084
  enum {
1085
    UNKNOWN,
1086
    NNE, ENE, ESE, SSE, SSW,WSW,WNW, NNW,
1087
  } sensor = UNKNOWN;
1088
  // evaluate arguments
1089
  if (argc == 2) {
1090
    if (strcmp(argv[1], "-nne") == 0) {
1091
      sensor = NNE;
1092
    } else if (strcmp(argv[1], "-ene") == 0) {
1093
      sensor = ENE;
1094
    } else if (strcmp(argv[1], "-ese") == 0) {
1095
      sensor = ESE;
1096
    } else if (strcmp(argv[1], "-sse") == 0) {
1097
      sensor = SSE;
1098
    } else if (strcmp(argv[1], "-ssw") == 0) {
1099
      sensor = SSW;
1100
    } else if (strcmp(argv[1], "-wsw") == 0) {
1101
      sensor = WSW;
1102
    } else if (strcmp(argv[1], "-wnw") == 0) {
1103
      sensor = WNW;
1104
    } else if (strcmp(argv[1], "-nnw") == 0) {
1105
      sensor = NNW;
1106
    }
1107
  }
1108
  if (sensor != UNKNOWN) {
1109
    PCA9544ADriver* mux = NULL;
1110
    switch (sensor) {
1111
      case SSE:
1112
      case SSW:
1113
      case WSW:
1114
      case WNW:
1115
        mux = &moduleLldI2cMultiplexer1;
1116
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity1;
1117
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = MODULE_OS_IOEVENTFLAGS_IRINT2;
1118
        break;
1119
      case NNW:
1120
      case NNE:
1121
      case ENE:
1122
      case ESE:
1123
        mux = &moduleLldI2cMultiplexer2;
1124
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity2;
1125
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = MODULE_OS_IOEVENTFLAGS_IRINT1;
1126
        break;
1127
      default:
1128
        break;
1129
    }
1130
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1131
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1132
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1133
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1134
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1135
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1136
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1137
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1138
    switch (sensor) {
1139
      case NNE:
1140
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1141
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northeast sensor");
1142
        break;
1143
      case ENE:
1144
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1145
        aosUtRun(stream, &moduleUtAlldVcnl4020, "east-northeast sensor");
1146
        break;
1147
      case ESE:
1148
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1149
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-southeast sensor");
1150
        break;
1151
      case SSE:
1152
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1153
        aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southeast sensor");
1154
        break;
1155
      case SSW:
1156
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1157
        aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southwest sensor");
1158
        break;
1159
      case WSW:
1160
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1161
        aosUtRun(stream, &moduleUtAlldVcnl4020, "west-southwest sensor");
1162
        break;
1163
      case WNW:
1164
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1165
        aosUtRun(stream, &moduleUtAlldVcnl4020, "west-northwest sensor");
1166
        break;
1167
      case NNW:
1168
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1169
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northwest sensor");
1170
        break;
1171
      default:
1172
        break;
1173
    }
1174
    ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = NULL;
1175
    ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = 0;
1176
    return AOS_OK;
1177
  }
1178
  // print help
1179
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
1180
  chprintf(stream, "Options:\n");
1181
  chprintf(stream, "  -nne\n");
1182
  chprintf(stream, "    Test north-northeast sensor.\n");
1183
  chprintf(stream, "  -ene\n");
1184
  chprintf(stream, "    Test east-northeast sensor.\n");
1185
  chprintf(stream, "  -ese\n");
1186
  chprintf(stream, "    Test east-southeast sensor.\n");
1187
  chprintf(stream, "  -sse\n");
1188
  chprintf(stream, "    Test south-southeast sensor.\n");
1189
  chprintf(stream, "  -ssw\n");
1190
  chprintf(stream, "    Test south-southwest sensor.\n");
1191
  chprintf(stream, "  -wsw\n");
1192
  chprintf(stream, "    Test west-southwest sensor.\n");
1193
  chprintf(stream, "  -wnw\n");
1194
  chprintf(stream, "    Test west-northwest sensor.\n");
1195
  chprintf(stream, "  -nnw\n");
1196
  chprintf(stream, "    Test north-northwest sensor.\n");
1197
  return AOS_INVALID_ARGUMENTS;
1198
}
1199
static ut_vcnl4020data_t _utAlldVcnl4020Data = {
1200
  /* driver       */ NULL,
1201
  /* timeout      */ MICROSECONDS_PER_SECOND,
1202
  /* event source */ &aos.events.io,
1203
  /* event flags  */ 0,
1204
};
1205
aos_unittest_t moduleUtAlldVcnl4020 = {
1206
  /* name           */ "VCNL4020",
1207
  /* info           */ "proximity sensor",
1208
  /* test function  */ utAlldVcnl4020Func,
1209
  /* shell command  */ {
1210
    /* name     */ "unittest:Proximity",
1211
    /* callback */ _utShellCmdCb_AlldVcnl4020,
1212
    /* next     */ NULL,
1213
  },
1214
  /* data           */ &_utAlldVcnl4020Data,
1215
};
1216

    
1217
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
1218

    
1219
/** @} */
1220
/** @} */