Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 9ff01927

History | View | Annotate | Download (23.8 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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
ROMCONST 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   */ {
466
    /* left wheel   */ 0.05571f,
467
    /* right wheel  */ 0.05571f,
468
  },
469
  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
470
};
471
aos_unittest_t moduleUtAlldA3906  = {
472
  /* name           */ "A3906",
473
  /* info           */ "motor driver",
474
  /* test function  */ utAlldA3906Func,
475
  /* shell command  */ {
476
    /* name     */ "unittest:MotorDriver",
477
    /* callback */ _utShellCmdCb_AlldA3906,
478
    /* next     */ NULL,
479
  },
480
  /* data           */ &_utA3906Data,
481
};
482

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

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

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

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

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

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

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

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

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

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

    
790
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
791

    
792
/** @} */
793
/** @} */