Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-2 / module.c @ abb8b3f4

History | View | Annotate | Download (20.5 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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 DiWheelDrive module.
22
 *
23
 * @addtogroup diwheeldrive_module
24
 * @{
25
 */
26

    
27
#include "module.h"
28

    
29
/*===========================================================================*/
30
/**
31
 * @name Module specific functions
32
 * @{
33
 */
34
/*===========================================================================*/
35

    
36
/** @} */
37

    
38
/*===========================================================================*/
39
/**
40
 * @name ChibiOS/HAL configuration
41
 * @{
42
 */
43
/*===========================================================================*/
44

    
45
CANConfig moduleHalCanConfig = {
46
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
47
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
48
};
49

    
50
I2CConfig moduleHalI2cImuConfig = {
51
  /* I²C mode   */ OPMODE_I2C,
52
  /* frequency  */ 400000,
53
  /* duty cycle */ FAST_DUTY_CYCLE_2,
54
};
55

    
56
I2CConfig moduleHalI2cProxEepromPwrmtrConfig = {
57
  /* I²C mode   */ OPMODE_I2C,
58
  /* frequency  */ 400000,
59
  /* duty cycle */ FAST_DUTY_CYCLE_2,
60
};
61

    
62
PWMConfig moduleHalPwmDriveConfig = {
63
  /* frequency              */ 7200000,
64
  /* period                 */ 360,
65
  /* callback               */ NULL,
66
  /* channel configurations */ {
67
    /* channel 0              */ {
68
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
69
      /* callback               */ NULL
70
    },
71
    /* channel 1              */ {
72
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
73
      /* callback               */ NULL
74
    },
75
    /* channel 2              */ {
76
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
77
      /* callback               */ NULL
78
    },
79
    /* channel 3              */ {
80
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
81
      /* callback               */ NULL
82
    },
83
  },
84
  /* TIM CR2 register       */ 0,
85
#if (STM32_PWM_USE_ADVANCED == TRUE)
86
  /* TIM BDTR register      */ 0,
87
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */
88
  /* TIM DIER register      */ 0
89
};
90

    
91
QEIConfig moduleHalQeiConfig = {
92
  /* mode           */ QEI_COUNT_BOTH,
93
  /* channel config */ {
94
    /* channel 0 */ {
95
      /* input mode */ QEI_INPUT_NONINVERTED,
96
    },
97
    /* channel 1 */ {
98
      /* input mode */ QEI_INPUT_NONINVERTED,
99
    },
100
  },
101
  /* encoder range  */  0x10000u,
102
};
103

    
104
SerialConfig moduleHalProgIfConfig = {
105
  /* bit rate */ 115200,
106
  /* CR1      */ 0,
107
  /* CR1      */ 0,
108
  /* CR1      */ 0,
109
};
110

    
111
/** @} */
112

    
113
/*===========================================================================*/
114
/**
115
 * @name GPIO definitions
116
 * @{
117
 */
118
/*===========================================================================*/
119

    
120
/**
121
 * @brief   LED output signal GPIO.
122
 */
123
static apalGpio_t _gpioLed = {
124
  /* port */ GPIOA,
125
  /* pad  */ GPIOA_LED,
126
};
127
ROMCONST apalControlGpio_t moduleGpioLed = {
128
  /* GPIO */ &_gpioLed,
129
  /* meta */ {
130
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
131
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
132
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
133
  },
134
};
135

    
136
/**
137
 * @brief   POWER_EN output signal GPIO.
138
 */
139
static apalGpio_t _gpioPowerEn = {
140
  /* port */ GPIOB,
141
  /* pad  */ GPIOB_POWER_EN,
142
};
143
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
144
  /* GPIO */ &_gpioPowerEn,
145
  /* meta */ {
146
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
147
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
148
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
149
  },
150
};
151

    
152
/**
153
 * @brief   IR_INT input signal GPIO.
154
 */
155
static apalGpio_t _gpioIrInt = {
156
  /* port */ GPIOB,
157
  /* pad  */ GPIOB_IR_INT,
158
};
159
ROMCONST apalControlGpio_t moduleGpioIrInt = {
160
  /* GPIO */ &_gpioIrInt,
161
  /* meta */ {
162
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
163
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
164
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
165
  },
166
};
167

    
168
/**
169
 * @brief   SYS_UART_UP bidirectional signal GPIO.
170
 */
171
static apalGpio_t _gpioSysUartUp = {
172
  /* port */ GPIOB,
173
  /* pad  */ GPIOB_SYS_UART_UP,
174
};
175
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
176
  /* GPIO */ &_gpioSysUartUp,
177
  /* meta */ {
178
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
179
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
180
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
181
  },
182
};
183

    
184
/**
185
 * @brief   IMU_INT input signal GPIO.
186
 */
187
static apalGpio_t _gpioImuInt = {
188
  /* port */ GPIOB,
189
  /* pad  */ GPIOB_IMU_INT,
190
};
191
ROMCONST apalControlGpio_t moduleGpioImuInt = {
192
  /* GPIO */ &_gpioImuInt,
193
  /* meta */ {
194
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
195
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, // TODO
196
    /* interrupt edge */ APAL_GPIO_EDGE_RISING, // TODO
197
  },
198
};
199

    
200
/**
201
 * @brief   SYS_SNYC bidirectional signal GPIO.
202
 */
203
static apalGpio_t _gpioSysSync = {
204
  /* port */ GPIOC,
205
  /* pad  */ GPIOC_SYS_INT_N,
206
};
207
ROMCONST apalControlGpio_t  moduleGpioSysSync = {
208
  /* GPIO */ &_gpioSysSync,
209
  /* meta */ {
210
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
211
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
212
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
213
  },
214
};
215

    
216
/**
217
 * @brief   IMU_RESET output signal GPIO.
218
 */
219
static apalGpio_t _gpioImuReset = {
220
  /* port */ GPIOC,
221
  /* pad  */ GPIOC_IMU_RESET_N,
222
};
223
ROMCONST apalControlGpio_t  moduleGpioImuReset = {
224
  /* GPIO */ &_gpioImuReset,
225
  /* meta */ {
226
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
227
    /* active state   */ APAL_GPIO_ACTIVE_LOW, // TODO
228
    /* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO
229
  },
230
};
231

    
232
/**
233
 * @brief   PATH_DCSTAT input signal GPIO.
234
 */
235
static apalGpio_t _gpioPathDcStat = {
236
  /* port */ GPIOC,
237
  /* pad  */ GPIOC_PATH_DCSTAT,
238
};
239
ROMCONST apalControlGpio_t moduleGpioPathDcStat = {
240
  /* GPIO */ &_gpioPathDcStat,
241
  /* meta */ {
242
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
243
    /* active state   */ LTC4412_LLD_STAT_ACTIVE_STATE,
244
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
245
  },
246
};
247

    
248
/**
249
 * @brief   PATH_DCEN output signal GPIO.
250
 */
251
static apalGpio_t _gpioPathDcEn = {
252
  /* port */ GPIOC,
253
  /* pad  */ GPIOC_PATH_DCEN,
254
};
255
ROMCONST apalControlGpio_t moduleGpioPathDcEn = {
256
  /* GPIO */ &_gpioPathDcEn,
257
  /* meta */ {
258
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
259
    /* active state   */ LTC4412_LLD_CTRL_ACTIVE_STATE,
260
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
261
  },
262
};
263

    
264
/**
265
 * @brief   SYS_PD bidirectional signal GPIO.
266
 */
267
static apalGpio_t _gpioSysPd = {
268
  /* port */ GPIOC,
269
  /* pad  */ GPIOC_SYS_PD_N,
270
};
271
ROMCONST apalControlGpio_t moduleGpioSysPd = {
272
  /* GPIO */ &_gpioSysPd,
273
  /* meta */ {
274
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
275
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
276
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
277
  },
278
};
279

    
280
/**
281
 * @brief   SYS_REG_EN input signal GPIO.
282
 */
283
static apalGpio_t _gpioSysRegEn = {
284
  /* port */ GPIOC,
285
  /* pad  */ GPIOC_SYS_REG_EN,
286
};
287
ROMCONST apalControlGpio_t moduleGpioSysRegEn = {
288
  /* GPIO */ &_gpioSysRegEn,
289
  /* meta */ {
290
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
291
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
292
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
293
  },
294
};
295

    
296
/**
297
 * @brief   IMU_BOOT_LOAD output signal GPIO.
298
 */
299
static apalGpio_t _gpioImuBootLoad = {
300
  /* port */ GPIOC,
301
  /* pad  */ GPIOC_IMU_BOOT_LOAD_N,
302
};
303
ROMCONST apalControlGpio_t moduleGpioImuBootLoad = {
304
  /* GPIO */ &_gpioImuBootLoad,
305
  /* meta */ {
306
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
307
    /* active state   */ APAL_GPIO_ACTIVE_LOW, // TODO
308
    /* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO
309
  },
310
};
311

    
312
/**
313
 * @brief   IMU_BL_IND input signal GPIO.
314
 */
315
static apalGpio_t _gpioImuBlInd = {
316
  /* port */ GPIOC,
317
  /* pad  */ GPIOC_IMU_BL_IND,
318
};
319
ROMCONST apalControlGpio_t moduleGpioImuBlInd = {
320
  /* GPIO */ &_gpioImuBlInd,
321
  /* meta */ {
322
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
323
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, // TODO
324
    /* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO
325
  },
326
};
327

    
328
/**
329
 * @brief   SYS_WARMRST bidirectional signal GPIO.
330
 */
331
static apalGpio_t _gpioSysWarmrst = {
332
  /* port */ GPIOD,
333
  /* pad  */ GPIOD_SYS_WARMRST_N,
334
};
335
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
336
  /* GPIO */ &_gpioSysWarmrst,
337
  /* meta */ {
338
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
339
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
340
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
341
  },
342
};
343

    
344
/** @} */
345

    
346
/*===========================================================================*/
347
/**
348
 * @name AMiRo-OS core configurations
349
 * @{
350
 */
351
/*===========================================================================*/
352

    
353
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
354
ROMCONST char* moduleShellPrompt = "DiWheelDrive";
355
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
356

    
357
/** @} */
358

    
359
/*===========================================================================*/
360
/**
361
 * @name Startup Shutdown Synchronization Protocol (SSSP)
362
 * @{
363
 */
364
/*===========================================================================*/
365

    
366
/** @} */
367

    
368
/*===========================================================================*/
369
/**
370
 * @name Low-level drivers
371
 * @{
372
 */
373
/*===========================================================================*/
374

    
375
A3906Driver moduleLldMotors = {
376
  /* power enable GPIO  */ &moduleGpioPowerEn,
377
};
378

    
379
AT24C01BDriver moduleLldEeprom = {
380
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
381
  /* I²C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
382
};
383

    
384
INA219Driver moduleLldPowerMonitorVdd = {
385
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
386
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
387
  /* current LSB (uA) */ 0x00u,
388
  /* configuration    */ NULL,
389
};
390

    
391
LEDDriver moduleLldStatusLed = {
392
  /* LED enable Gpio */ &moduleGpioLed,
393
};
394

    
395
LTC4412Driver moduleLldPowerPathController = {
396
  /* Control GPIO */ &moduleGpioPathDcEn,
397
  /* Status GPIO  */ &moduleGpioPathDcStat,
398
};
399

    
400
PCA9544ADriver moduleLldI2cMultiplexer = {
401
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
402
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
403
};
404

    
405
TPS6211xDriver moduleLldStepDownConverterVdrive = {
406
  /* Power enable Gpio */ &moduleGpioPowerEn,
407
};
408

    
409
VCNL4020Driver moduleLldProximity = {
410
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
411
};
412

    
413
/** @} */
414

    
415
/*===========================================================================*/
416
/**
417
 * @name Unit tests (UT)
418
 * @{
419
 */
420
/*===========================================================================*/
421
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
422
#include <string.h>
423

    
424
/*
425
 * A3906 (motor driver)
426
 */
427
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[])
428
{
429
  (void)argc;
430
  (void)argv;
431
  aosUtRun(stream, &moduleUtAlldA3906, NULL);
432
  return AOS_OK;
433
}
434
static ut_a3906data_t _utA3906Data = {
435
  /* driver           */ &moduleLldMotors,
436
  /* PWM information  */ {
437
    /* driver   */ &MODULE_HAL_PWM_DRIVE,
438
    /* channels */ {
439
      /* left wheel forward   */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
440
      /* left wheel backward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
441
      /* right wheel forward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
442
      /* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
443
    },
444
  },
445
  /* QEI information  */ {
446
    /* left wheel               */ &MODULE_HAL_QEI_LEFT_WHEEL,
447
    /* right wheel              */ &MODULE_HAL_QEI_RIGHT_WHEEL,
448
    /* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
449
  },
450
  /* Wheel diameter   */ {
451
    /* left wheel   */ 0.05571f,
452
    /* right wheel  */ 0.05571f,
453
  },
454
  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
455
};
456
aos_unittest_t moduleUtAlldA3906  = {
457
  /* name           */ "A3906",
458
  /* info           */ "motor driver",
459
  /* test function  */ utAlldA3906Func,
460
  /* shell command  */ {
461
    /* name     */ "unittest:MotorDriver",
462
    /* callback */ _utShellCmdCb_AlldA3906,
463
    /* next     */ NULL,
464
  },
465
  /* data           */ &_utA3906Data,
466
};
467

    
468
/*
469
 * AT24C01B (EEPROM)
470
 */
471
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
472
{
473
  (void)argc;
474
  (void)argv;
475
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
476
  return AOS_OK;
477
}
478
static ut_at24c01bdata_t _utAlldAt24c01bData = {
479
  /* driver   */ &moduleLldEeprom,
480
  /* timeout  */ MICROSECONDS_PER_SECOND,
481
};
482
aos_unittest_t moduleUtAlldAt24c01b = {
483
  /* name           */ "AT24C01B",
484
  /* info           */ "1kbit EEPROM",
485
  /* test function  */ utAlldAt24c01bFunc,
486
  /* shell command  */ {
487
    /* name     */ "unittest:EEPROM",
488
    /* callback */ _utShellCmdCb_AlldAt24c01b,
489
    /* next     */ NULL,
490
  },
491
  /* data           */ &_utAlldAt24c01bData,
492
};
493

    
494
/*
495
 * INA219 (power monitor)
496
 */
497
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
498
{
499
  (void)argc;
500
  (void)argv;
501
  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
502
  return AOS_OK;
503
}
504
static ut_ina219data_t _utIna219Data = {
505
  /* driver           */ &moduleLldPowerMonitorVdd,
506
  /* expected voltage */ 3.3f,
507
  /* tolerance        */ 0.05f,
508
  /* timeout */ MICROSECONDS_PER_SECOND,
509
};
510
aos_unittest_t moduleUtAlldIna219 = {
511
  /* name           */ "INA219",
512
  /* info           */ "power monitor",
513
  /* test function  */ utAlldIna219Func,
514
  /* shell command  */ {
515
    /* name     */ "unittest:PowerMonitor",
516
    /* callback */ _utShellCmdCb_AlldIna219,
517
    /* next     */ NULL,
518
  },
519
  /* data           */ &_utIna219Data,
520
};
521

    
522
/*
523
 * Status LED
524
 */
525
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
526
{
527
  (void)argc;
528
  (void)argv;
529
  aosUtRun(stream, &moduleUtAlldLed, NULL);
530
  return AOS_OK;
531
}
532
aos_unittest_t moduleUtAlldLed = {
533
  /* name           */ "LED",
534
  /* info           */ NULL,
535
  /* test function  */ utAlldLedFunc,
536
  /* shell command  */ {
537
    /* name     */ "unittest:StatusLED",
538
    /* callback */ _utShellCmdCb_AlldLed,
539
    /* next     */ NULL,
540
  },
541
  /* data           */ &moduleLldStatusLed,
542
};
543

    
544
/*
545
 * LTC4412 (power path controller)
546
 */
547
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
548
{
549
  (void)argc;
550
  (void)argv;
551
  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
552
  return AOS_OK;
553
}
554
aos_unittest_t moduleUtAlldLtc4412 = {
555
  /* name           */ "LTC4412",
556
  /* info           */ "Power path controller",
557
  /* test function  */ utAlldLtc4412Func,
558
  /* shell command  */ {
559
    /* name     */ "unittest:PowerPathController",
560
    /* callback */ _utShellCmdCb_AlldLtc4412,
561
    /* next     */ NULL,
562
  },
563
  /* data           */ &moduleLldPowerPathController,
564
};
565

    
566
/*
567
 * PCA9544A (I2C multiplexer)
568
 */
569
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
570
{
571
  (void)argc;
572
  (void)argv;
573
  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
574
  return AOS_OK;
575
}
576
static ut_pca9544adata_t _utPca9544aData = {
577
  /* driver  */ &moduleLldI2cMultiplexer,
578
  /* timeout */ MICROSECONDS_PER_SECOND,
579
};
580
aos_unittest_t moduleUtAlldPca9544a = {
581
  /* name           */ "PCA9544A",
582
  /* info           */ "I2C multiplexer",
583
  /* test function  */ utAlldPca9544aFunc,
584
  /* shell command  */ {
585
    /* name     */ "unittest:I2CMultiplexer",
586
    /* callback */ _utShellCmdCb_AlldPca9544a,
587
    /* next     */ NULL,
588
  },
589
  /* data           */ &_utPca9544aData,
590
};
591

    
592
/*
593
 * TPS62113 (step-down converter)
594
 */
595
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
596
{
597
  (void)argc;
598
  (void)argv;
599
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
600
  return AOS_OK;
601
}
602
aos_unittest_t moduleUtAlldTps62113 = {
603
  /* name           */ "TPS62113",
604
  /* info           */ "Step down converter",
605
  /* test function  */ utAlldTps6211xFunc,
606
  /* shell command  */ {
607
    /* name     */ "unittest:StepDownConverter",
608
    /* callback */ _utShellCmdCb_AlldTps62113,
609
    /* next     */ NULL,
610
  },
611
  /* data           */ &moduleLldStepDownConverterVdrive,
612
};
613

    
614
/*
615
 * VCNL4020 (proximity sensor)
616
 */
617
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
618
{
619
  uint8_t intstatus;
620
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
621
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
622
  if (intstatus) {
623
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
624
  }
625
  return;
626
}
627
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
628
{
629
  enum {
630
    UNKNOWN,
631
    FL, FR, WL, WR,
632
  } sensor = UNKNOWN;
633
  // evaluate arguments
634
  if (argc == 2) {
635
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
636
      sensor = FL;
637
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
638
      sensor = FR;
639
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
640
      sensor = WL;
641
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
642
      sensor = WR;
643
    }
644
  }
645
  if (sensor != UNKNOWN) {
646
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
647
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
648
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
649
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
650
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
651
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
652
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
653
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
654
    switch (sensor) {
655
      case FL:
656
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
657
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
658
        break;
659
      case FR:
660
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
661
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
662
        break;
663
      case WL:
664
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
665
        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
666
        break;
667
      case WR:
668
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
669
        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
670
        break;
671
      default:
672
        break;
673
    }
674
    return AOS_OK;
675
  }
676
  // print help
677
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
678
  chprintf(stream, "Options:\n");
679
  chprintf(stream, "  --frontleft, -fl\n");
680
  chprintf(stream, "    Test front left proximity sensor.\n");
681
  chprintf(stream, "  --frontrigt, -fr\n");
682
  chprintf(stream, "    Test front right proximity sensor.\n");
683
  chprintf(stream, "  --wheelleft, -wl\n");
684
  chprintf(stream, "    Test left wheel proximity sensor.\n");
685
  chprintf(stream, "  --wheelright, -wr\n");
686
  chprintf(stream, "    Test right wheel proximity sensor.\n");
687
  return AOS_INVALID_ARGUMENTS;
688
}
689
static ut_vcnl4020data_t _utVcnl4020Data = {
690
  /* driver       */ &moduleLldProximity,
691
  /* timeout      */ MICROSECONDS_PER_SECOND,
692
  /* event source */ &aos.events.io,
693
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_IRINT,
694
};
695
aos_unittest_t moduleUtAlldVcnl4020 = {
696
  /* name           */ "VCNL4020",
697
  /* info           */ "proximity sensor",
698
  /* test function  */ utAlldVcnl4020Func,
699
  /* shell command  */ {
700
    /* name     */ "unittest:Proximity",
701
    /* callback */ _utShellCmdCb_AlldVcnl4020,
702
    /* next     */ NULL,
703
  },
704
  /* data           */ &_utVcnl4020Data,
705
};
706

    
707
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
708

    
709
/** @} */
710
/** @} */