Statistics
| Branch: | Tag: | Revision:

amiro-os / os / modules / DiWheelDrive_1-1 / module.c @ b6b45e4c

History | View | Annotate | Download (24.235 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include "module.h"
20
21
/*===========================================================================*/
22
/**
23
 * @name Module specific functions
24
 * @{
25
 */
26
/*===========================================================================*/
27
#include <amiroos.h>
28
29
/**
30
 * @brief   Interrupt service routine callback for I/O interrupt signals.
31
 *
32
 * @param   extp      EXT driver to handle the ISR.
33
 * @param   channel   Channel on which the interrupt was encountered.
34
 */
35
static void _moduleIsrCallback(EXTDriver* extp, expchannel_t channel) {
36
  (void)extp;
37
38
  chSysLockFromISR();
39
  chEvtBroadcastFlagsI(&aos.events.io.source, (1 << channel));
40
  chSysUnlockFromISR();
41
42
  return;
43
}
44
45
/** @} */
46
47
/*===========================================================================*/
48
/**
49
 * @name ChibiOS/HAL configuration
50
 * @{
51
 */
52
/*===========================================================================*/
53
54
CANConfig moduleHalCanConfig = {
55
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
56
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
57
};
58
59
EXTConfig moduleHalExtConfig = {
60
  /* channel configrations */ {
61
    /* channel  0 */ {
62
      /* mode     */ EXT_CH_MODE_DISABLED,
63
      /* callback */ NULL,
64
    },
65
    /* channel  1 */ { // SYS_INT_N/SYS_SYNC_N: automatic interrupt on event
66
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
67
      /* callback */ _moduleIsrCallback,
68
    },
69
    /* channel  2 */ { // SYS_WARMRST_N: automatic interrupt when activated
70
      /* mode     */ EXT_MODE_GPIOD | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
71
      /* callback */ _moduleIsrCallback,
72
    },
73
    /* channel  3 */ { // PATH_DCSTAT: must be enabled explicitely when charging is in progress to detect unexpected voltage drop
74
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE,
75
      /* callback */ _moduleIsrCallback,
76
    },
77
    /* channel  4 */ {
78
      /* mode     */ EXT_CH_MODE_DISABLED,
79
      /* callback */ NULL,
80
    },
81
    /* channel  5 */ { // COMPASS_DRDY: must be enabled explicitely
82
      /* mode     */ EXT_MODE_GPIOB | APAL2CH_EDGE(HMC5883L_LLD_INT_EDGE),
83
      /* callback */ _moduleIsrCallback,
84
    },
85
    /* channel  6 */ {
86
      /* mode     */ EXT_CH_MODE_DISABLED,
87
      /* callback */ NULL,
88
    },
89
    /* channel  7 */ {
90
      /* mode     */ EXT_CH_MODE_DISABLED,
91
      /* callback */ NULL,
92
    },
93
    /* channel  8 */ { // SYS_PD_N: automatic interrupt when activated
94
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
95
      /* callback */ _moduleIsrCallback,
96
    },
97
    /* channel  9 */ { // SYS_REG_EN: automatic interrupt when activated
98
      /* mode     */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
99
      /* callback */ _moduleIsrCallback,
100
    },
101
    /* channel 10 */ {
102
      /* mode     */ EXT_CH_MODE_DISABLED,
103
      /* callback */ NULL,
104
    },
105
    /* channel 11 */ {
106
      /* mode     */ EXT_CH_MODE_DISABLED,
107
      /* callback */ NULL,
108
    },
109
    /* channel 12 */ { // IR_INT: must be enabled explicitely
110
      /* mode     */ EXT_MODE_GPIOB | APAL2CH_EDGE(VCNL4020_LLD_INT_EDGE),
111
      /* callback */ _moduleIsrCallback,
112
    },
113
    /* channel 13 */ { // GYRO_DRDY: must be enabled explicitely
114
      /* mode     */ EXT_MODE_GPIOB | APAL2CH_EDGE(L3G4200D_LLD_INT_EDGE),
115
      /* callback */ _moduleIsrCallback,
116
    },
117
    /* channel 14 */ { // SYS_UART_UP: automatic interrupt on event
118
      /* mode     */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
119
      /* callback */ _moduleIsrCallback,
120
    },
121
    /* channel 15 */ { // ACCEL_INT_N: must be enabled explicitely
122
      /* mode     */ EXT_MODE_GPIOB | APAL2CH_EDGE(LIS331DLH_LLD_INT_EDGE),
123
      /* callback */ _moduleIsrCallback,
124
    },
125
    /* channel 16 */ {
126
      /* mode     */ EXT_CH_MODE_DISABLED,
127
      /* callback */ NULL,
128
    },
129
    /* channel 17 */ {
130
      /* mode     */ EXT_CH_MODE_DISABLED,
131
      /* callback */ NULL,
132
    },
133
    /* channel 18 */ {
134
      /* mode     */ EXT_CH_MODE_DISABLED,
135
      /* callback */ NULL,
136
    },
137
  },
138
};
139
140
I2CConfig moduleHalI2cCompassConfig = {
141
  /* I²C mode   */ OPMODE_I2C,
142
  /* frequency  */ 400000,
143
  /* duty cycle */ FAST_DUTY_CYCLE_2,
144
};
145
146
I2CConfig moduleHalI2cProxEepromPwrmtrConfig = {
147
  /* I²C mode   */ OPMODE_I2C,
148
  /* frequency  */ 400000,
149
  /* duty cycle */ FAST_DUTY_CYCLE_2,
150
};
151
152
PWMConfig moduleHalPwmDriveConfig = {
153
  /* frequency              */ 7200000,
154
  /* period                 */ 360,
155
  /* callback               */ NULL,
156
  /* channel configurations */ {
157
    /* channel 0              */ {
158
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
159
      /* callback               */ NULL
160
    },
161
    /* channel 1              */ {
162
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
163
      /* callback               */ NULL
164
    },
165
    /* channel 2              */ {
166
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
167
      /* callback               */ NULL
168
    },
169
    /* channel 3              */ {
170
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
171
      /* callback               */ NULL
172
    },
173
  },
174
  /* TIM CR2 register       */ 0,
175
#if STM32_PWM_USE_ADVANCED
176
  /* TIM BDTR register      */ 0,
177
#endif
178
  /* TIM DIER register      */ 0
179
};
180
181
QEIConfig moduleHalQeiConfig = {
182
  /* mode           */ QEI_COUNT_BOTH,
183
  /* channel config */ {
184
    /* channel 0 */ {
185
      /* input mode */ QEI_INPUT_NONINVERTED,
186
    },
187
    /* channel 1 */ {
188
      /* input mode */ QEI_INPUT_NONINVERTED,
189
    },
190
  },
191
  /* encoder range  */  0x10000u,
192
};
193
194
SerialConfig moduleHalProgIfConfig = {
195
  /* bit rate */ 115200,
196
  /* CR1      */ 0,
197
  /* CR1      */ 0,
198
  /* CR1      */ 0,
199
};
200
201
SPIConfig moduleHalSpiAccelerometerConfig = {
202
  /* callback function pointer    */ NULL,
203
  /* chip select line port        */ GPIOC,
204
  /* chip select line pad number  */ GPIOC_ACCEL_SS_N,
205
  /* CR1                          */ SPI_CR1_BR_0,
206
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
207
};
208
209
SPIConfig moduleHalSpiGyroscopeConfig = {
210
  /* callback function pointer    */ NULL,
211
  /* chip select line port        */ GPIOC,
212
  /* chip select line pad number  */ GPIOC_GYRO_SS_N,
213
  /* CR1                          */ SPI_CR1_BR_0,
214
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
215
};
216
217
/** @} */
218
219
/*===========================================================================*/
220
/**
221
 * @name GPIO definitions
222
 * @{
223
 */
224
/*===========================================================================*/
225
226
apalGpio_t moduleGpioLed = {
227
  /* port */ GPIOA,
228
  /* pad  */ GPIOA_LED,
229
};
230
231
apalGpio_t moduleGpioPowerEn = {
232
  /* port */GPIOB,
233
  /* pad  */  GPIOB_POWER_EN,
234
};
235
236
apalGpio_t moduleGpioCompassDrdy = {
237
  /* port */ GPIOB,
238
  /* pad  */ GPIOB_COMPASS_DRDY,
239
};
240
241
 apalGpio_t moduleGpioIrInt = {
242
  /* port */ GPIOB,
243
  /* pad  */ GPIOB_IR_INT,
244
};
245
246
apalGpio_t moduleGpioGyroDrdy = {
247
  /* port */ GPIOB,
248
  /* pad  */ GPIOB_GYRO_DRDY,
249
};
250
251
apalGpio_t moduleGpioSysUartUp = {
252
  /* port */ GPIOB,
253
  /* pad  */ GPIOB_SYS_UART_UP,
254
};
255
256
apalGpio_t moduleGpioAccelInt = {
257
  /* port */ GPIOB,
258
  /* pad  */ GPIOB_ACCEL_INT_N,
259
};
260
261
apalGpio_t moduleGpioSysSync = {
262
  /* port */ GPIOC,
263
  /* pad  */ GPIOC_SYS_INT_N,
264
};
265
266
apalGpio_t moduleGpioPathDcStat = {
267
  /* port */ GPIOC,
268
  /* pad  */ GPIOC_PATH_DCSTAT,
269
};
270
271
apalGpio_t moduleGpioPathDcEn = {
272
  /* port */ GPIOC,
273
  /* pad  */ GPIOC_PATH_DCEN,
274
};
275
276
apalGpio_t moduleGpioSysPd = {
277
  /* port */ GPIOC,
278
  /* pad  */ GPIOC_SYS_PD_N,
279
};
280
281
apalGpio_t moduleGpioSysRegEn = {
282
  /* port */ GPIOC,
283
  /* pad  */ GPIOC_SYS_REG_EN,
284
};
285
286
apalGpio_t moduleGpioSysWarmrst = {
287
  /* port */ GPIOD,
288
  /* pad  */ GPIOD_SYS_WARMRST_N,
289
};
290
291
/** @} */
292
293
/*===========================================================================*/
294
/**
295
 * @name AMiRo-OS core configurations
296
 * @{
297
 */
298
/*===========================================================================*/
299
300
apalControlGpio_t moduleSsspPd = {
301
  /* GPIO */ &moduleGpioSysPd,
302
  /* meta */ {
303
    /* active state */ APAL_GPIO_ACTIVE_LOW,
304
    /* edge         */ APAL_GPIO_EDGE_FALLING,
305
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
306
  },
307
};
308
309
apalControlGpio_t moduleSsspSync = {
310
  /* GPIO */ &moduleGpioSysSync,
311
  /* meta */ {
312
    /* active state */ APAL_GPIO_ACTIVE_LOW,
313
    /* edge         */ APAL_GPIO_EDGE_FALLING,
314
    /* direction    */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
315
  },
316
};
317
318
const char* moduleShellPrompt = "DiWheelDrive";
319
320
/** @} */
321
322
/*===========================================================================*/
323
/**
324
 * @name Low-level drivers
325
 * @{
326
 */
327
/*===========================================================================*/
328
329
A3906Driver moduleLldMotors = {
330
  /* power enable GPIO  */ {
331
    /* GPIO */& moduleGpioPowerEn,
332
    /* meta */ {
333
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
334
      /* edge         */ APAL_GPIO_EDGE_NONE,
335
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
336
    },
337
  },
338
};
339
340
AT24C01BNDriver moduleLldEeprom = {
341
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
342
  /* I²C address  */ AT24C01BN_LLD_I2C_ADDR_FIXED,
343
};
344
345
HMC5883LDriver moduleLldCompass = {
346
  /* I²C Driver */ &MODULE_HAL_I2C_COMPASS,
347
};
348
349
INA219Driver moduleLldPowerMonitorVdd = {
350
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
351
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
352
  /* current LSB (uA) */ 0x00u,
353
  /* configuration    */ NULL,
354
};
355
356
L3G4200DDriver moduleLldGyroscope = {
357
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
358
};
359
360
LEDDriver moduleLldStatusLed = {
361
  /* LED enable Gpio */ {
362
    /* GPIO       */ &moduleGpioLed,
363
    /* GPIO meta  */ {
364
      /* active state */ APAL_GPIO_ACTIVE_LOW,
365
      /* edge         */ APAL_GPIO_EDGE_NONE,
366
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
367
    },
368
  },
369
};
370
371
LIS331DLHDriver moduleLldAccelerometer = {
372
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
373
};
374
375
LTC4412Driver moduleLldPowerPathController = {
376
  /* Control GPIO */ {
377
    /* GPIO       */ &moduleGpioPathDcEn,
378
    /* GPIO meta  */ {
379
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
380
      /* edge         */ APAL_GPIO_EDGE_NONE,
381
      /* direction    */ APAL_GPIO_DIRECTION_OUTPUT,
382
    },
383
  },
384
  /* Status GPIO */ {
385
    /* GPIO       */ &moduleGpioPathDcStat,
386
    /* GPIO meta  */ {
387
      /* active state */ APAL_GPIO_ACTIVE_HIGH,
388
      /* edge         */ APAL_GPIO_EDGE_NONE,
389
      /* direction    */ APAL_GPIO_DIRECTION_INPUT,
390
    },
391
  },
392
};
393
394
PCA9544ADriver moduleLldI2cMultiplexer = {
395
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
396
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
397
};
398
399
TPS62113Driver moduleLldStepDownConverterVdrive = {
400
  /* Power enable Gpio */ {
401
    /* GPIO       */ &moduleGpioPowerEn,
402
    /* GPIO meta  */ {
403
      /* 'power on' state */ APAL_GPIO_ACTIVE_HIGH,
404
      /* edge             */ APAL_GPIO_EDGE_NONE,
405
      /* direction        */ APAL_GPIO_DIRECTION_OUTPUT,
406
    },
407
  },
408
};
409
410
VCNL4020Driver moduleLldProximity = {
411
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
412
};
413
414
/** @} */
415
416
/*===========================================================================*/
417
/**
418
 * @name Unit tests (UT)
419
 * @{
420
 */
421
/*===========================================================================*/
422
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
423
#include <string.h>
424
#include <chprintf.h>
425
426
/* A3906 (motor driver) */
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   */ 0.05571f,
451
  /* timeout          */ 10* MICROSECONDS_PER_SECOND,
452
};
453
aos_unittest_t moduleUtAlldA3906  = {
454
  /* name           */ "A3906",
455
  /* info           */ "motor driver",
456
  /* test function  */ utAlldA3906Func,
457
  /* shell command  */ {
458
    /* name     */ "unittest:MotorDriver",
459
    /* callback */ _utShellCmdCb_AlldA3906,
460
    /* next     */ NULL,
461
  },
462
  /* data           */ &_utA3906Data,
463
};
464
465
/* AT24C01BN (EEPROM) */
466
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
467
{
468
  (void)argc;
469
  (void)argv;
470
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
471
  return AOS_OK;
472
}
473
static ut_at24c01bndata_t _utAt24c01bnData = {
474
  /* driver   */ &moduleLldEeprom,
475
  /* timeout  */ MICROSECONDS_PER_SECOND,
476
};
477
aos_unittest_t moduleUtAlldAt24c01bn = {
478
  /* name           */ "AT24C01BN-SH-B",
479
  /* info           */ "1kbit EEPROM",
480
  /* test function  */ utAlldAt24c01bnFunc,
481
  /* shell command  */ {
482
    /* name     */ "unittest:EEPROM",
483
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
484
    /* next     */ NULL,
485
  },
486
  /* data           */ &_utAt24c01bnData,
487
};
488
489
/* HMC5883L (compass) */
490
static int _utShellCmdCb_AlldHmc5883l(BaseSequentialStream* stream, int argc, char* argv[])
491
{
492
  (void)argc;
493
  (void)argv;
494
  extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_COMPASSDRDY);
495
  aosUtRun(stream, &moduleUtAlldHmc5883l, NULL);
496
  return AOS_OK;
497
}
498
static ut_hmc5883ldata_t _utHmc5883lData = {
499
  /* HMC driver   */ &moduleLldCompass,
500
  /* event source */ &aos.events.io.source,
501
  /* event flags  */ (1 << MODULE_GPIO_EXTCHANNEL_COMPASSDRDY),
502
  /* timeout      */ MICROSECONDS_PER_SECOND,
503
};
504
aos_unittest_t moduleUtAlldHmc5883l = {
505
  /* name           */ "HMC5883L",
506
  /* info           */ "compass",
507
  /* test function  */ utAlldHmc5883lFunc,
508
  /* shell command  */ {
509
    /* name     */ "unittest:Compass",
510
    /* callback */ _utShellCmdCb_AlldHmc5883l,
511
    /* next     */ NULL,
512
  },
513
  /* data           */ &_utHmc5883lData,
514
};
515
516
/* INA219 (power monitor) */
517
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
518
{
519
  (void)argc;
520
  (void)argv;
521
  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
522
  return AOS_OK;
523
}
524
static ut_ina219data_t _utIna219Data = {
525
  /* driver           */ &moduleLldPowerMonitorVdd,
526
  /* expected voltage */ 3.3f,
527
  /* tolerance        */ 0.05f,
528
  /* timeout */ MICROSECONDS_PER_SECOND,
529
};
530
aos_unittest_t moduleUtAlldIna219 = {
531
  /* name           */ "INA219",
532
  /* info           */ "power monitor",
533
  /* test function  */ utAlldIna219Func,
534
  /* shell command  */ {
535
    /* name     */ "unittest:PowerMonitor",
536
    /* callback */ _utShellCmdCb_AlldIna219,
537
    /* next     */ NULL,
538
  },
539
  /* data           */ &_utIna219Data,
540
};
541
542
/* L3G4200D (gyroscope) */
543
static int _utShellCmdCb_AlldL3g4200d(BaseSequentialStream* stream, int argc, char* argv[])
544
{
545
  (void)argc;
546
  (void)argv;
547
  extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_GYRODRDY);
548
  spiStart(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid, ((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->spiconf);
549
  aosUtRun(stream, &moduleUtAlldL3g4200d, NULL);
550
  spiStop(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid);
551
  return AOS_OK;
552
}
553
static ut_l3g4200ddata_t _utL3g4200dData = {
554
  /* driver            */ &moduleLldGyroscope,
555
  /* SPI configuration */ &moduleHalSpiGyroscopeConfig,
556
  /* event source */ &aos.events.io.source,
557
  /* event flags  */ (1 << MODULE_GPIO_EXTCHANNEL_GYRODRDY),
558
};
559
aos_unittest_t moduleUtAlldL3g4200d = {
560
  /* name           */ "L3G4200D",
561
  /* info           */ "Gyroscope",
562
  /* test function  */ utAlldL3g4200dFunc,
563
  /* shell command  */ {
564
    /* name     */ "unittest:Gyroscope",
565
    /* callback */ _utShellCmdCb_AlldL3g4200d,
566
    /* next     */ NULL,
567
  },
568
  /* data           */ &_utL3g4200dData,
569
};
570
571
/* Status LED */
572
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
573
{
574
  (void)argc;
575
  (void)argv;
576
  aosUtRun(stream, &moduleUtAlldLed, NULL);
577
  return AOS_OK;
578
}
579
aos_unittest_t moduleUtAlldLed = {
580
  /* name           */ "LED",
581
  /* info           */ NULL,
582
  /* test function  */ utAlldLedFunc,
583
  /* shell command  */ {
584
    /* name     */ "unittest:StatusLED",
585
    /* callback */ _utShellCmdCb_AlldLed,
586
    /* next     */ NULL,
587
  },
588
  /* data           */ &moduleLldStatusLed,
589
};
590
591
/* LIS331DLH (accelerometer) */
592
static int _utShellCmdCb_AlldLis331dlh(BaseSequentialStream* stream, int argc, char* argv[])
593
{
594
  (void)argc;
595
  (void)argv;
596
  extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_ACCELINT);
597
  spiStart(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid, ((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->spiconf);
598
  aosUtRun(stream, &moduleUtAlldLis331dlh, NULL);
599
  spiStop(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid);
600
  return AOS_OK;
601
}
602
static ut_lis331dlhdata_t _utLis331dlhData = {
603
  /* driver            */ &moduleLldAccelerometer,
604
  /* SPI configuration */ &moduleHalSpiAccelerometerConfig,
605
  /* event source */ &aos.events.io.source,
606
  /* event flags  */ (1 << MODULE_GPIO_EXTCHANNEL_ACCELINT),
607
};
608
aos_unittest_t moduleUtAlldLis331dlh = {
609
  /* name           */ "LIS331DLH",
610
  /* info           */ "Accelerometer",
611
  /* test function  */ utAlldLis331dlhFunc,
612
  /* shell command  */ {
613
    /* name     */ "unittest:Accelerometer",
614
    /* callback */ _utShellCmdCb_AlldLis331dlh,
615
    /* next     */ NULL,
616
  },
617
  /* data           */ &_utLis331dlhData,
618
};
619
620
/* LTC4412 (power path controller) */
621
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
622
{
623
  (void)argc;
624
  (void)argv;
625
  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
626
  return AOS_OK;
627
}
628
aos_unittest_t moduleUtAlldLtc4412 = {
629
  /* name           */ "LTC4412",
630
  /* info           */ "Power path controller",
631
  /* test function  */ utAlldLtc4412Func,
632
  /* shell command  */ {
633
    /* name     */ "unittest:PowerPathController",
634
    /* callback */ _utShellCmdCb_AlldLtc4412,
635
    /* next     */ NULL,
636
  },
637
  /* data           */ &moduleLldPowerPathController,
638
};
639
640
/* PCA9544A (I2C multiplexer) */
641
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
642
{
643
  (void)argc;
644
  (void)argv;
645
  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
646
  return AOS_OK;
647
}
648
static ut_pca9544adata_t _utPca9544aData = {
649
  /* driver  */ &moduleLldI2cMultiplexer,
650
  /* timeout */ MICROSECONDS_PER_SECOND,
651
};
652
aos_unittest_t moduleUtAlldPca9544a = {
653
  /* name           */ "PCA9544A",
654
  /* info           */ "I2C multiplexer",
655
  /* test function  */ utAlldPca9544aFunc,
656
  /* shell command  */ {
657
    /* name     */ "unittest:I2CMultiplexer",
658
    /* callback */ _utShellCmdCb_AlldPca9544a,
659
    /* next     */ NULL,
660
  },
661
  /* data           */ &_utPca9544aData,
662
};
663
664
/* TPS62113 (step-down converter) */
665
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
666
{
667
  (void)argc;
668
  (void)argv;
669
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
670
  return AOS_OK;
671
}
672
aos_unittest_t moduleUtAlldTps62113 = {
673
  /* name           */ "TPS62113",
674
  /* info           */ "Step down converter",
675
  /* test function  */ utAlldTps62113Func,
676
  /* shell command  */ {
677
    /* name     */ "unittest:StepDownConverter",
678
    /* callback */ _utShellCmdCb_AlldTps62113,
679
    /* next     */ NULL,
680
  },
681
  /* data           */ &moduleLldStepDownConverterVdrive,
682
};
683
684
/* VCNL4020 (proximity sensor) */
685
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
686
{
687
  uint8_t intstatus;
688
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
689
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
690
  if (intstatus) {
691
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
692
  }
693
  return;
694
}
695
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
696
{
697
  enum {
698
    UNKNOWN,
699
    FL, FR, WL, WR,
700
  } sensor = UNKNOWN;
701
  // evaluate arguments
702
  if (argc == 2) {
703
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
704
      sensor = FL;
705
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
706
      sensor = FR;
707
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
708
      sensor = WL;
709
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
710
      sensor = WR;
711
    }
712
  }
713
  if (sensor != UNKNOWN) {
714
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
715
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
716
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
717
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
718
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
719
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
720
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
721
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
722
    extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT);
723
    switch (sensor) {
724
      case FL:
725
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
726
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left snesor");
727
        break;
728
      case FR:
729
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
730
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
731
        break;
732
      case WL:
733
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
734
        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
735
        break;
736
      case WR:
737
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
738
        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
739
        break;
740
      default:
741
        break;
742
    }
743
    return AOS_OK;
744
  }
745
  // print help
746
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
747
  chprintf(stream, "Options:\n");
748
  chprintf(stream, "  --frontleft, -fl\n");
749
  chprintf(stream, "    Test front left proximity sensor.\n");
750
  chprintf(stream, "  --frontrigt, -fr\n");
751
  chprintf(stream, "    Test front right proximity sensor.\n");
752
  chprintf(stream, "  --wheelleft, -wl\n");
753
  chprintf(stream, "    Test left wheel proximity sensor.\n");
754
  chprintf(stream, "  --wheelright, -wr\n");
755
  chprintf(stream, "    Test right wheel proximity sensor.\n");
756
  return AOS_INVALID_ARGUMENTS;
757
}
758
static ut_vcnl4020data_t _utVcnl4020Data = {
759
  /* driver       */ &moduleLldProximity,
760
  /* timeout      */ MICROSECONDS_PER_SECOND,
761
  /* event source */ &aos.events.io.source,
762
  /* event flags  */ (1 << MODULE_GPIO_EXTCHANNEL_IRINT),
763
};
764
aos_unittest_t moduleUtAlldVcnl4020 = {
765
  /* name           */ "VCNL4020",
766
  /* info           */ "proximity sensor",
767
  /* test function  */ utAlldVcnl4020Func,
768
  /* shell command  */ {
769
    /* name     */ "unittest:Proximity",
770
    /* callback */ _utShellCmdCb_AlldVcnl4020,
771
    /* next     */ NULL,
772
  },
773
  /* data           */ &_utVcnl4020Data,
774
};
775
776
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
777
778
/** @} */