Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 53710ca3

History | View | Annotate | Download (23.7 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 DiWheelDrive module.
22
 *
23
 * @addtogroup diwheeldrive_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
CANConfig moduleHalCanConfig = {
48
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
49
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
50
};
51

    
52
I2CConfig moduleHalI2cCompassConfig = {
53
  /* I²C mode   */ OPMODE_I2C,
54
  /* frequency  */ 400000,
55
  /* duty cycle */ FAST_DUTY_CYCLE_2,
56
};
57

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

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

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

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

    
113
SPIConfig moduleHalSpiAccelerometerConfig = {
114
  /* circular buffer mode         */ false,
115
  /* callback function pointer    */ NULL,
116
  /* chip select line port        */ GPIOC,
117
  /* chip select line pad number  */ GPIOC_ACCEL_SS_N,
118
  /* CR1                          */ SPI_CR1_BR_0,
119
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
120
};
121

    
122
SPIConfig moduleHalSpiGyroscopeConfig = {
123
  /* circular buffer mode         */ false,
124
  /* callback function pointer    */ NULL,
125
  /* chip select line port        */ GPIOC,
126
  /* chip select line pad number  */ GPIOC_GYRO_SS_N,
127
  /* CR1                          */ SPI_CR1_BR_0,
128
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
129
};
130

    
131
/** @} */
132

    
133
/*===========================================================================*/
134
/**
135
 * @name GPIO definitions
136
 * @{
137
 */
138
/*===========================================================================*/
139

    
140
/**
141
 * @brief   LED output signal GPIO.
142
 */
143
static apalGpio_t _gpioLed = {
144
  /* port */ GPIOA,
145
  /* pad  */ GPIOA_LED,
146
};
147
apalControlGpio_t moduleGpioLed = {
148
  /* GPIO */ &_gpioLed,
149
  /* meta */ {
150
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
151
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
152
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
153
  },
154
};
155

    
156
/**
157
 * @brief   POWER_EN output signal GPIO.
158
 */
159
static apalGpio_t _gpioPowerEn = {
160
  /* port */ GPIOB,
161
  /* pad  */  GPIOB_POWER_EN,
162
};
163
apalControlGpio_t moduleGpioPowerEn = {
164
  /* GPIO */ &_gpioPowerEn,
165
  /* meta */ {
166
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
167
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
168
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
169
  },
170
};
171

    
172
/**
173
 * @brief   COMPASS_DRDY output signal GPIO.
174
 */
175
static apalGpio_t _gpioCompassDrdy = {
176
  /* port */ GPIOB,
177
  /* pad  */ GPIOB_COMPASS_DRDY,
178
};
179
apalControlGpio_t moduleGpioCompassDrdy = {
180
  /* GPIO */ &_gpioCompassDrdy,
181
  /* meta */ {
182
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
183
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
184
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
185
  },
186
};
187

    
188
/**
189
 * @brief   IR_INT input signal GPIO.
190
 */
191
static apalGpio_t _gpioIrInt = {
192
  /* port */ GPIOB,
193
  /* pad  */ GPIOB_IR_INT,
194
};
195
apalControlGpio_t moduleGpioIrInt = {
196
  /* GPIO */ &_gpioIrInt,
197
  /* meta */ {
198
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
199
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
200
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
201
  },
202
};
203

    
204
/**
205
 * @brief   GYRO_DRDY input signal GPIO.
206
 */
207
static apalGpio_t _gpioGyroDrdy = {
208
  /* port */ GPIOB,
209
  /* pad  */ GPIOB_GYRO_DRDY,
210
};
211
apalControlGpio_t moduleGpioGyroDrdy = {
212
  /* GPIO */ &_gpioGyroDrdy,
213
  /* meta */ {
214
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
215
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
216
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
217
  },
218
};
219

    
220
/**
221
 * @brief   SYS_UART_UP bidirectional signal GPIO.
222
 */
223
static apalGpio_t _gpioSysUartUp = {
224
  /* port */ GPIOB,
225
  /* pad  */ GPIOB_SYS_UART_UP,
226
};
227
apalControlGpio_t moduleGpioSysUartUp = {
228
  /* GPIO */ &_gpioSysUartUp,
229
  /* meta */ {
230
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
231
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
232
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
233
  },
234
};
235

    
236
/**
237
 * @brief   ACCEL_INT input signal GPIO.
238
 */
239
static apalGpio_t _gpioAccelInt = {
240
  /* port */ GPIOB,
241
  /* pad  */ GPIOB_ACCEL_INT_N,
242
};
243
apalControlGpio_t moduleGpioAccelInt = {
244
  /* GPIO */ &_gpioAccelInt,
245
  /* meta */ {
246
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
247
    /* active state   */ (LIS331DLH_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
248
    /* interrupt edge */ LIS331DLH_LLD_INT_EDGE,
249
  },
250
};
251

    
252
/**
253
 * @brief   SYS_SNYC bidirectional signal GPIO.
254
 */
255
static apalGpio_t _gpioSysSync = {
256
  /* port */ GPIOC,
257
  /* pad  */ GPIOC_SYS_INT_N,
258
};
259
apalControlGpio_t moduleGpioSysSync = {
260
  /* GPIO */ &_gpioSysSync,
261
  /* meta */ {
262
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
263
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
264
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
265
  },
266
};
267

    
268
/**
269
 * @brief   PATH_DCSTAT input signal GPIO.
270
 */
271
static apalGpio_t _gpioPathDcStat = {
272
  /* port */ GPIOC,
273
  /* pad  */ GPIOC_PATH_DCSTAT,
274
};
275
apalControlGpio_t moduleGpioPathDcStat = {
276
  /* GPIO */ &_gpioPathDcStat,
277
  /* meta */ {
278
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
279
    /* active state   */ LTC4412_LLD_STAT_ACTIVE_STATE,
280
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
281
  },
282
};
283

    
284
/**
285
 * @brief   PATH_DCEN output signal GPIO.
286
 */
287
static apalGpio_t _gpioPathDcEn = {
288
  /* port */ GPIOC,
289
  /* pad  */ GPIOC_PATH_DCEN,
290
};
291
apalControlGpio_t moduleGpioPathDcEn = {
292
  /* GPIO */ &_gpioPathDcEn,
293
  /* meta */ {
294
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
295
    /* active state   */ LTC4412_LLD_CTRL_ACTIVE_STATE,
296
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
297
  },
298
};
299

    
300
/**
301
 * @brief   SYS_PD bidirectional signal GPIO.
302
 */
303
static apalGpio_t _gpioSysPd = {
304
  /* port */ GPIOC,
305
  /* pad  */ GPIOC_SYS_PD_N,
306
};
307
apalControlGpio_t moduleGpioSysPd = {
308
  /* GPIO */ &_gpioSysPd,
309
  /* meta */ {
310
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
311
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
312
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
313
  },
314
};
315

    
316
/**
317
 * @brief   SYS_REG_EN input signal GPIO.
318
 */
319
static apalGpio_t _gpioSysRegEn = {
320
  /* port */ GPIOC,
321
  /* pad  */ GPIOC_SYS_REG_EN,
322
};
323
apalControlGpio_t moduleGpioSysRegEn = {
324
  /* GPIO */ &_gpioSysRegEn,
325
  /* meta */ {
326
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
327
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
328
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
329
  },
330
};
331

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

    
348
/** @} */
349

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

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

    
361
/** @} */
362

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

    
370
/** @} */
371

    
372
/*===========================================================================*/
373
/**
374
 * @name Low-level drivers
375
 * @{
376
 */
377
/*===========================================================================*/
378

    
379
A3906Driver moduleLldMotors = {
380
  /* power enable GPIO  */ &moduleGpioPowerEn,
381
};
382

    
383
AT24C01BNDriver moduleLldEeprom = {
384
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
385
  /* I²C address  */ AT24C01BN_LLD_I2C_ADDR_FIXED,
386
};
387

    
388
HMC5883LDriver moduleLldCompass = {
389
  /* I²C Driver */ &MODULE_HAL_I2C_COMPASS,
390
};
391

    
392
INA219Driver moduleLldPowerMonitorVdd = {
393
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
394
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
395
  /* current LSB (uA) */ 0x00u,
396
  /* configuration    */ NULL,
397
};
398

    
399
L3G4200DDriver moduleLldGyroscope = {
400
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
401
};
402

    
403
LEDDriver moduleLldStatusLed = {
404
  /* LED enable Gpio */ &moduleGpioLed,
405
};
406

    
407
LIS331DLHDriver moduleLldAccelerometer = {
408
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
409
};
410

    
411
LTC4412Driver moduleLldPowerPathController = {
412
  /* Control GPIO */ &moduleGpioPathDcEn,
413
  /* Status GPIO  */ &moduleGpioPathDcStat,
414
};
415

    
416
PCA9544ADriver moduleLldI2cMultiplexer = {
417
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
418
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
419
};
420

    
421
TPS62113Driver moduleLldStepDownConverterVdrive = {
422
  /* Power enable Gpio */ &moduleGpioPowerEn,
423
};
424

    
425
VCNL4020Driver moduleLldProximity = {
426
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
427
};
428

    
429
/** @} */
430

    
431
/*===========================================================================*/
432
/**
433
 * @name Unit tests (UT)
434
 * @{
435
 */
436
/*===========================================================================*/
437
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
438
#include <string.h>
439
#include <chprintf.h>
440

    
441
/* A3906 (motor driver) */
442
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[])
443
{
444
  (void)argc;
445
  (void)argv;
446
  aosUtRun(stream, &moduleUtAlldA3906, NULL);
447
  return AOS_OK;
448
}
449
static ut_a3906data_t _utA3906Data = {
450
  /* driver           */ &moduleLldMotors,
451
  /* PWM information  */ {
452
    /* driver   */ &MODULE_HAL_PWM_DRIVE,
453
    /* channels */ {
454
      /* left wheel forward   */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
455
      /* left wheel backward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
456
      /* right wheel forward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
457
      /* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
458
    },
459
  },
460
  /* QEI information  */ {
461
    /* left wheel               */ &MODULE_HAL_QEI_LEFT_WHEEL,
462
    /* right wheel              */ &MODULE_HAL_QEI_RIGHT_WHEEL,
463
    /* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
464
  },
465
  /* Wheel diameter   */ 0.05571f,
466
  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
467
};
468
aos_unittest_t moduleUtAlldA3906  = {
469
  /* name           */ "A3906",
470
  /* info           */ "motor driver",
471
  /* test function  */ utAlldA3906Func,
472
  /* shell command  */ {
473
    /* name     */ "unittest:MotorDriver",
474
    /* callback */ _utShellCmdCb_AlldA3906,
475
    /* next     */ NULL,
476
  },
477
  /* data           */ &_utA3906Data,
478
};
479

    
480
/* AT24C01BN (EEPROM) */
481
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
482
{
483
  (void)argc;
484
  (void)argv;
485
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
486
  return AOS_OK;
487
}
488
static ut_at24c01bndata_t _utAt24c01bnData = {
489
  /* driver   */ &moduleLldEeprom,
490
  /* timeout  */ MICROSECONDS_PER_SECOND,
491
};
492
aos_unittest_t moduleUtAlldAt24c01bn = {
493
  /* name           */ "AT24C01BN-SH-B",
494
  /* info           */ "1kbit EEPROM",
495
  /* test function  */ utAlldAt24c01bnFunc,
496
  /* shell command  */ {
497
    /* name     */ "unittest:EEPROM",
498
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
499
    /* next     */ NULL,
500
  },
501
  /* data           */ &_utAt24c01bnData,
502
};
503

    
504
/* HMC5883L (compass) */
505
static int _utShellCmdCb_AlldHmc5883l(BaseSequentialStream* stream, int argc, char* argv[])
506
{
507
  (void)argc;
508
  (void)argv;
509
  aosUtRun(stream, &moduleUtAlldHmc5883l, NULL);
510
  return AOS_OK;
511
}
512
static ut_hmc5883ldata_t _utHmc5883lData = {
513
  /* HMC driver   */ &moduleLldCompass,
514
  /* event source */ &aos.events.io,
515
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_COMPASSDRDY,
516
  /* timeout      */ MICROSECONDS_PER_SECOND,
517
};
518
aos_unittest_t moduleUtAlldHmc5883l = {
519
  /* name           */ "HMC5883L",
520
  /* info           */ "compass",
521
  /* test function  */ utAlldHmc5883lFunc,
522
  /* shell command  */ {
523
    /* name     */ "unittest:Compass",
524
    /* callback */ _utShellCmdCb_AlldHmc5883l,
525
    /* next     */ NULL,
526
  },
527
  /* data           */ &_utHmc5883lData,
528
};
529

    
530
/* INA219 (power monitor) */
531
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
532
{
533
  (void)argc;
534
  (void)argv;
535
  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
536
  return AOS_OK;
537
}
538
static ut_ina219data_t _utIna219Data = {
539
  /* driver           */ &moduleLldPowerMonitorVdd,
540
  /* expected voltage */ 3.3f,
541
  /* tolerance        */ 0.05f,
542
  /* timeout */ MICROSECONDS_PER_SECOND,
543
};
544
aos_unittest_t moduleUtAlldIna219 = {
545
  /* name           */ "INA219",
546
  /* info           */ "power monitor",
547
  /* test function  */ utAlldIna219Func,
548
  /* shell command  */ {
549
    /* name     */ "unittest:PowerMonitor",
550
    /* callback */ _utShellCmdCb_AlldIna219,
551
    /* next     */ NULL,
552
  },
553
  /* data           */ &_utIna219Data,
554
};
555

    
556
/* L3G4200D (gyroscope) */
557
static int _utShellCmdCb_AlldL3g4200d(BaseSequentialStream* stream, int argc, char* argv[])
558
{
559
  (void)argc;
560
  (void)argv;
561
  spiStart(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid, ((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->spiconf);
562
  aosUtRun(stream, &moduleUtAlldL3g4200d, NULL);
563
  spiStop(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid);
564
  return AOS_OK;
565
}
566
static ut_l3g4200ddata_t _utL3g4200dData = {
567
  /* driver            */ &moduleLldGyroscope,
568
  /* SPI configuration */ &moduleHalSpiGyroscopeConfig,
569
  /* event source */ &aos.events.io,
570
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_GYRODRDY,
571
};
572
aos_unittest_t moduleUtAlldL3g4200d = {
573
  /* name           */ "L3G4200D",
574
  /* info           */ "Gyroscope",
575
  /* test function  */ utAlldL3g4200dFunc,
576
  /* shell command  */ {
577
    /* name     */ "unittest:Gyroscope",
578
    /* callback */ _utShellCmdCb_AlldL3g4200d,
579
    /* next     */ NULL,
580
  },
581
  /* data           */ &_utL3g4200dData,
582
};
583

    
584
/* Status LED */
585
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
586
{
587
  (void)argc;
588
  (void)argv;
589
  aosUtRun(stream, &moduleUtAlldLed, NULL);
590
  return AOS_OK;
591
}
592
aos_unittest_t moduleUtAlldLed = {
593
  /* name           */ "LED",
594
  /* info           */ NULL,
595
  /* test function  */ utAlldLedFunc,
596
  /* shell command  */ {
597
    /* name     */ "unittest:StatusLED",
598
    /* callback */ _utShellCmdCb_AlldLed,
599
    /* next     */ NULL,
600
  },
601
  /* data           */ &moduleLldStatusLed,
602
};
603

    
604
/* LIS331DLH (accelerometer) */
605
static int _utShellCmdCb_AlldLis331dlh(BaseSequentialStream* stream, int argc, char* argv[])
606
{
607
  (void)argc;
608
  (void)argv;
609
  spiStart(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid, ((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->spiconf);
610
  aosUtRun(stream, &moduleUtAlldLis331dlh, NULL);
611
  spiStop(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid);
612
  return AOS_OK;
613
}
614
static ut_lis331dlhdata_t _utLis331dlhData = {
615
  /* driver            */ &moduleLldAccelerometer,
616
  /* SPI configuration */ &moduleHalSpiAccelerometerConfig,
617
  /* event source */ &aos.events.io,
618
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_ACCELINT,
619
};
620
aos_unittest_t moduleUtAlldLis331dlh = {
621
  /* name           */ "LIS331DLH",
622
  /* info           */ "Accelerometer",
623
  /* test function  */ utAlldLis331dlhFunc,
624
  /* shell command  */ {
625
    /* name     */ "unittest:Accelerometer",
626
    /* callback */ _utShellCmdCb_AlldLis331dlh,
627
    /* next     */ NULL,
628
  },
629
  /* data           */ &_utLis331dlhData,
630
};
631

    
632
/* LTC4412 (power path controller) */
633
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
634
{
635
  (void)argc;
636
  (void)argv;
637
  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
638
  return AOS_OK;
639
}
640
aos_unittest_t moduleUtAlldLtc4412 = {
641
  /* name           */ "LTC4412",
642
  /* info           */ "Power path controller",
643
  /* test function  */ utAlldLtc4412Func,
644
  /* shell command  */ {
645
    /* name     */ "unittest:PowerPathController",
646
    /* callback */ _utShellCmdCb_AlldLtc4412,
647
    /* next     */ NULL,
648
  },
649
  /* data           */ &moduleLldPowerPathController,
650
};
651

    
652
/* PCA9544A (I2C multiplexer) */
653
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
654
{
655
  (void)argc;
656
  (void)argv;
657
  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
658
  return AOS_OK;
659
}
660
static ut_pca9544adata_t _utPca9544aData = {
661
  /* driver  */ &moduleLldI2cMultiplexer,
662
  /* timeout */ MICROSECONDS_PER_SECOND,
663
};
664
aos_unittest_t moduleUtAlldPca9544a = {
665
  /* name           */ "PCA9544A",
666
  /* info           */ "I2C multiplexer",
667
  /* test function  */ utAlldPca9544aFunc,
668
  /* shell command  */ {
669
    /* name     */ "unittest:I2CMultiplexer",
670
    /* callback */ _utShellCmdCb_AlldPca9544a,
671
    /* next     */ NULL,
672
  },
673
  /* data           */ &_utPca9544aData,
674
};
675

    
676
/* TPS62113 (step-down converter) */
677
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
678
{
679
  (void)argc;
680
  (void)argv;
681
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
682
  return AOS_OK;
683
}
684
aos_unittest_t moduleUtAlldTps62113 = {
685
  /* name           */ "TPS62113",
686
  /* info           */ "Step down converter",
687
  /* test function  */ utAlldTps62113Func,
688
  /* shell command  */ {
689
    /* name     */ "unittest:StepDownConverter",
690
    /* callback */ _utShellCmdCb_AlldTps62113,
691
    /* next     */ NULL,
692
  },
693
  /* data           */ &moduleLldStepDownConverterVdrive,
694
};
695

    
696
/* VCNL4020 (proximity sensor) */
697
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
698
{
699
  uint8_t intstatus;
700
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
701
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
702
  if (intstatus) {
703
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
704
  }
705
  return;
706
}
707
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
708
{
709
  enum {
710
    UNKNOWN,
711
    FL, FR, WL, WR,
712
  } sensor = UNKNOWN;
713
  // evaluate arguments
714
  if (argc == 2) {
715
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
716
      sensor = FL;
717
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
718
      sensor = FR;
719
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
720
      sensor = WL;
721
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
722
      sensor = WR;
723
    }
724
  }
725
  if (sensor != UNKNOWN) {
726
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
727
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
728
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
729
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
730
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
731
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
732
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
733
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
734
    switch (sensor) {
735
      case FL:
736
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
737
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
738
        break;
739
      case FR:
740
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
741
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
742
        break;
743
      case WL:
744
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
745
        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
746
        break;
747
      case WR:
748
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
749
        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
750
        break;
751
      default:
752
        break;
753
    }
754
    return AOS_OK;
755
  }
756
  // print help
757
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
758
  chprintf(stream, "Options:\n");
759
  chprintf(stream, "  --frontleft, -fl\n");
760
  chprintf(stream, "    Test front left proximity sensor.\n");
761
  chprintf(stream, "  --frontrigt, -fr\n");
762
  chprintf(stream, "    Test front right proximity sensor.\n");
763
  chprintf(stream, "  --wheelleft, -wl\n");
764
  chprintf(stream, "    Test left wheel proximity sensor.\n");
765
  chprintf(stream, "  --wheelright, -wr\n");
766
  chprintf(stream, "    Test right wheel proximity sensor.\n");
767
  return AOS_INVALID_ARGUMENTS;
768
}
769
static ut_vcnl4020data_t _utVcnl4020Data = {
770
  /* driver       */ &moduleLldProximity,
771
  /* timeout      */ MICROSECONDS_PER_SECOND,
772
  /* event source */ &aos.events.io,
773
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_IRINT,
774
};
775
aos_unittest_t moduleUtAlldVcnl4020 = {
776
  /* name           */ "VCNL4020",
777
  /* info           */ "proximity sensor",
778
  /* test function  */ utAlldVcnl4020Func,
779
  /* shell command  */ {
780
    /* name     */ "unittest:Proximity",
781
    /* callback */ _utShellCmdCb_AlldVcnl4020,
782
    /* next     */ NULL,
783
  },
784
  /* data           */ &_utVcnl4020Data,
785
};
786

    
787
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
788

    
789
/** @} */
790
/** @} */