Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 6df420be

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