Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (23.9 KB)

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

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 53710ca3 Marc Rothmann
/**
20 acc97cbf Thomas Schöpping
 * @file
21 53710ca3 Marc Rothmann
 * @brief   Structures and constant for the DiWheelDrive module.
22
 *
23
 * @addtogroup diwheeldrive_module
24
 * @{
25
 */
26
27 e545e620 Thomas Schöpping
#include "module.h"
28
29 1e5f7648 Thomas Schöpping
#include <amiroos.h>
30
31 e545e620 Thomas Schöpping
/*===========================================================================*/
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 0128be0f Marc Rothmann
  /* circular buffer mode         */ false,
115 e545e620 Thomas Schöpping
  /* 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 0128be0f Marc Rothmann
  /* circular buffer mode         */ false,
124 e545e620 Thomas Schöpping
  /* 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 1e5f7648 Thomas Schöpping
/**
141
 * @brief   LED output signal GPIO.
142
 */
143
static apalGpio_t _gpioLed = {
144 e545e620 Thomas Schöpping
  /* port */ GPIOA,
145
  /* pad  */ GPIOA_LED,
146
};
147 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
148 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
156 1e5f7648 Thomas Schöpping
/**
157
 * @brief   POWER_EN output signal GPIO.
158
 */
159
static apalGpio_t _gpioPowerEn = {
160
  /* port */ GPIOB,
161 e545e620 Thomas Schöpping
  /* pad  */  GPIOB_POWER_EN,
162
};
163 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
164 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
172 1e5f7648 Thomas Schöpping
/**
173
 * @brief   COMPASS_DRDY output signal GPIO.
174
 */
175
static apalGpio_t _gpioCompassDrdy = {
176 e545e620 Thomas Schöpping
  /* port */ GPIOB,
177
  /* pad  */ GPIOB_COMPASS_DRDY,
178
};
179 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioCompassDrdy = {
180 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
188 1e5f7648 Thomas Schöpping
/**
189
 * @brief   IR_INT input signal GPIO.
190
 */
191
static apalGpio_t _gpioIrInt = {
192 e545e620 Thomas Schöpping
  /* port */ GPIOB,
193
  /* pad  */ GPIOB_IR_INT,
194
};
195 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt = {
196 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
204 1e5f7648 Thomas Schöpping
/**
205
 * @brief   GYRO_DRDY input signal GPIO.
206
 */
207
static apalGpio_t _gpioGyroDrdy = {
208 e545e620 Thomas Schöpping
  /* port */ GPIOB,
209
  /* pad  */ GPIOB_GYRO_DRDY,
210
};
211 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGyroDrdy = {
212 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
220 1e5f7648 Thomas Schöpping
/**
221
 * @brief   SYS_UART_UP bidirectional signal GPIO.
222
 */
223
static apalGpio_t _gpioSysUartUp = {
224 e545e620 Thomas Schöpping
  /* port */ GPIOB,
225
  /* pad  */ GPIOB_SYS_UART_UP,
226
};
227 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
228 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
236 1e5f7648 Thomas Schöpping
/**
237
 * @brief   ACCEL_INT input signal GPIO.
238
 */
239
static apalGpio_t _gpioAccelInt = {
240 e545e620 Thomas Schöpping
  /* port */ GPIOB,
241
  /* pad  */ GPIOB_ACCEL_INT_N,
242
};
243 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioAccelInt = {
244 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
252 1e5f7648 Thomas Schöpping
/**
253
 * @brief   SYS_SNYC bidirectional signal GPIO.
254
 */
255
static apalGpio_t _gpioSysSync = {
256 e545e620 Thomas Schöpping
  /* port */ GPIOC,
257
  /* pad  */ GPIOC_SYS_INT_N,
258
};
259 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t  moduleGpioSysSync = {
260 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
268 1e5f7648 Thomas Schöpping
/**
269
 * @brief   PATH_DCSTAT input signal GPIO.
270
 */
271
static apalGpio_t _gpioPathDcStat = {
272 e545e620 Thomas Schöpping
  /* port */ GPIOC,
273
  /* pad  */ GPIOC_PATH_DCSTAT,
274
};
275 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDcStat = {
276 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
284 1e5f7648 Thomas Schöpping
/**
285
 * @brief   PATH_DCEN output signal GPIO.
286
 */
287
static apalGpio_t _gpioPathDcEn = {
288 e545e620 Thomas Schöpping
  /* port */ GPIOC,
289
  /* pad  */ GPIOC_PATH_DCEN,
290
};
291 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDcEn = {
292 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
300 1e5f7648 Thomas Schöpping
/**
301
 * @brief   SYS_PD bidirectional signal GPIO.
302
 */
303
static apalGpio_t _gpioSysPd = {
304 e545e620 Thomas Schöpping
  /* port */ GPIOC,
305
  /* pad  */ GPIOC_SYS_PD_N,
306
};
307 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysPd = {
308 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
316 1e5f7648 Thomas Schöpping
/**
317
 * @brief   SYS_REG_EN input signal GPIO.
318
 */
319
static apalGpio_t _gpioSysRegEn = {
320 e545e620 Thomas Schöpping
  /* port */ GPIOC,
321
  /* pad  */ GPIOC_SYS_REG_EN,
322
};
323 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysRegEn = {
324 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
332 1e5f7648 Thomas Schöpping
/**
333
 * @brief   SYS_WARMRST bidirectional signal GPIO.
334
 */
335
static apalGpio_t _gpioSysWarmrst = {
336 e545e620 Thomas Schöpping
  /* port */ GPIOD,
337
  /* pad  */ GPIOD_SYS_WARMRST_N,
338
};
339 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
340 1e5f7648 Thomas Schöpping
  /* 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 e545e620 Thomas Schöpping
348
/** @} */
349
350
/*===========================================================================*/
351
/**
352
 * @name AMiRo-OS core configurations
353
 * @{
354
 */
355
/*===========================================================================*/
356
357 6b53f6bf Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
358 acc97cbf Thomas Schöpping
ROMCONST char* moduleShellPrompt = "DiWheelDrive";
359 6b53f6bf Thomas Schöpping
#endif
360
361
/** @} */
362
363
/*===========================================================================*/
364
/**
365
 * @name Startup Shutdown Synchronization Protocol (SSSP)
366
 * @{
367
 */
368
/*===========================================================================*/
369
370 e545e620 Thomas Schöpping
/** @} */
371
372
/*===========================================================================*/
373
/**
374
 * @name Low-level drivers
375
 * @{
376
 */
377
/*===========================================================================*/
378
379
A3906Driver moduleLldMotors = {
380 1e5f7648 Thomas Schöpping
  /* power enable GPIO  */ &moduleGpioPowerEn,
381 e545e620 Thomas Schöpping
};
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 1e5f7648 Thomas Schöpping
  /* LED enable Gpio */ &moduleGpioLed,
405 e545e620 Thomas Schöpping
};
406
407
LIS331DLHDriver moduleLldAccelerometer = {
408
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
409
};
410
411
LTC4412Driver moduleLldPowerPathController = {
412 1e5f7648 Thomas Schöpping
  /* Control GPIO */ &moduleGpioPathDcEn,
413
  /* Status GPIO  */ &moduleGpioPathDcStat,
414 e545e620 Thomas Schöpping
};
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 1e5f7648 Thomas Schöpping
  /* Power enable Gpio */ &moduleGpioPowerEn,
423 e545e620 Thomas Schöpping
};
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 1678f270 Simon Welzel
/*
442
 * A3906 (motor driver)
443
 */
444 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[])
445
{
446
  (void)argc;
447
  (void)argv;
448
  aosUtRun(stream, &moduleUtAlldA3906, NULL);
449
  return AOS_OK;
450
}
451
static ut_a3906data_t _utA3906Data = {
452
  /* driver           */ &moduleLldMotors,
453
  /* PWM information  */ {
454
    /* driver   */ &MODULE_HAL_PWM_DRIVE,
455
    /* channels */ {
456
      /* left wheel forward   */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
457
      /* left wheel backward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
458
      /* right wheel forward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
459
      /* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
460
    },
461
  },
462
  /* QEI information  */ {
463
    /* left wheel               */ &MODULE_HAL_QEI_LEFT_WHEEL,
464
    /* right wheel              */ &MODULE_HAL_QEI_RIGHT_WHEEL,
465
    /* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
466
  },
467 acc97cbf Thomas Schöpping
  /* Wheel diameter   */ {
468
    /* left wheel   */ 0.05571f,
469
    /* right wheel  */ 0.05571f,
470
  },
471 2e69d671 Thomas Schöpping
  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
472 e545e620 Thomas Schöpping
};
473
aos_unittest_t moduleUtAlldA3906  = {
474
  /* name           */ "A3906",
475
  /* info           */ "motor driver",
476
  /* test function  */ utAlldA3906Func,
477
  /* shell command  */ {
478
    /* name     */ "unittest:MotorDriver",
479
    /* callback */ _utShellCmdCb_AlldA3906,
480
    /* next     */ NULL,
481
  },
482
  /* data           */ &_utA3906Data,
483
};
484
485 1678f270 Simon Welzel
/*
486
 * AT24C01BN (EEPROM)
487
 */
488 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[])
489
{
490
  (void)argc;
491
  (void)argv;
492
  aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
493
  return AOS_OK;
494
}
495
static ut_at24c01bndata_t _utAt24c01bnData = {
496
  /* driver   */ &moduleLldEeprom,
497
  /* timeout  */ MICROSECONDS_PER_SECOND,
498
};
499
aos_unittest_t moduleUtAlldAt24c01bn = {
500
  /* name           */ "AT24C01BN-SH-B",
501
  /* info           */ "1kbit EEPROM",
502
  /* test function  */ utAlldAt24c01bnFunc,
503
  /* shell command  */ {
504
    /* name     */ "unittest:EEPROM",
505
    /* callback */ _utShellCmdCb_AlldAt24c01bn,
506
    /* next     */ NULL,
507
  },
508
  /* data           */ &_utAt24c01bnData,
509
};
510
511 1678f270 Simon Welzel
/*
512
 * HMC5883L (compass)
513
 */
514 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldHmc5883l(BaseSequentialStream* stream, int argc, char* argv[])
515
{
516
  (void)argc;
517
  (void)argv;
518
  aosUtRun(stream, &moduleUtAlldHmc5883l, NULL);
519
  return AOS_OK;
520
}
521
static ut_hmc5883ldata_t _utHmc5883lData = {
522
  /* HMC driver   */ &moduleLldCompass,
523 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
524 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_COMPASSDRDY,
525 e545e620 Thomas Schöpping
  /* timeout      */ MICROSECONDS_PER_SECOND,
526
};
527
aos_unittest_t moduleUtAlldHmc5883l = {
528
  /* name           */ "HMC5883L",
529
  /* info           */ "compass",
530
  /* test function  */ utAlldHmc5883lFunc,
531
  /* shell command  */ {
532
    /* name     */ "unittest:Compass",
533
    /* callback */ _utShellCmdCb_AlldHmc5883l,
534
    /* next     */ NULL,
535
  },
536
  /* data           */ &_utHmc5883lData,
537
};
538
539 1678f270 Simon Welzel
/*
540
 * INA219 (power monitor)
541
 */
542 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
543
{
544
  (void)argc;
545
  (void)argv;
546
  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
547
  return AOS_OK;
548
}
549
static ut_ina219data_t _utIna219Data = {
550
  /* driver           */ &moduleLldPowerMonitorVdd,
551
  /* expected voltage */ 3.3f,
552
  /* tolerance        */ 0.05f,
553
  /* timeout */ MICROSECONDS_PER_SECOND,
554
};
555
aos_unittest_t moduleUtAlldIna219 = {
556
  /* name           */ "INA219",
557
  /* info           */ "power monitor",
558
  /* test function  */ utAlldIna219Func,
559
  /* shell command  */ {
560
    /* name     */ "unittest:PowerMonitor",
561
    /* callback */ _utShellCmdCb_AlldIna219,
562
    /* next     */ NULL,
563
  },
564
  /* data           */ &_utIna219Data,
565
};
566
567 1678f270 Simon Welzel
/*
568
 * L3G4200D (gyroscope)
569
 */
570 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldL3g4200d(BaseSequentialStream* stream, int argc, char* argv[])
571
{
572
  (void)argc;
573
  (void)argv;
574
  spiStart(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid, ((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->spiconf);
575
  aosUtRun(stream, &moduleUtAlldL3g4200d, NULL);
576
  spiStop(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid);
577
  return AOS_OK;
578
}
579
static ut_l3g4200ddata_t _utL3g4200dData = {
580
  /* driver            */ &moduleLldGyroscope,
581
  /* SPI configuration */ &moduleHalSpiGyroscopeConfig,
582 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
583 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_GYRODRDY,
584 e545e620 Thomas Schöpping
};
585
aos_unittest_t moduleUtAlldL3g4200d = {
586
  /* name           */ "L3G4200D",
587
  /* info           */ "Gyroscope",
588
  /* test function  */ utAlldL3g4200dFunc,
589
  /* shell command  */ {
590
    /* name     */ "unittest:Gyroscope",
591
    /* callback */ _utShellCmdCb_AlldL3g4200d,
592
    /* next     */ NULL,
593
  },
594
  /* data           */ &_utL3g4200dData,
595
};
596
597 1678f270 Simon Welzel
/*
598
 * Status LED
599
 */
600 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
601
{
602
  (void)argc;
603
  (void)argv;
604
  aosUtRun(stream, &moduleUtAlldLed, NULL);
605
  return AOS_OK;
606
}
607
aos_unittest_t moduleUtAlldLed = {
608
  /* name           */ "LED",
609
  /* info           */ NULL,
610
  /* test function  */ utAlldLedFunc,
611
  /* shell command  */ {
612
    /* name     */ "unittest:StatusLED",
613
    /* callback */ _utShellCmdCb_AlldLed,
614
    /* next     */ NULL,
615
  },
616
  /* data           */ &moduleLldStatusLed,
617
};
618
619 1678f270 Simon Welzel
/*
620
 * LIS331DLH (accelerometer)
621
 */
622 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLis331dlh(BaseSequentialStream* stream, int argc, char* argv[])
623
{
624
  (void)argc;
625
  (void)argv;
626
  spiStart(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid, ((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->spiconf);
627
  aosUtRun(stream, &moduleUtAlldLis331dlh, NULL);
628
  spiStop(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid);
629
  return AOS_OK;
630
}
631
static ut_lis331dlhdata_t _utLis331dlhData = {
632
  /* driver            */ &moduleLldAccelerometer,
633
  /* SPI configuration */ &moduleHalSpiAccelerometerConfig,
634 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
635 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_ACCELINT,
636 e545e620 Thomas Schöpping
};
637
aos_unittest_t moduleUtAlldLis331dlh = {
638
  /* name           */ "LIS331DLH",
639
  /* info           */ "Accelerometer",
640
  /* test function  */ utAlldLis331dlhFunc,
641
  /* shell command  */ {
642
    /* name     */ "unittest:Accelerometer",
643
    /* callback */ _utShellCmdCb_AlldLis331dlh,
644
    /* next     */ NULL,
645
  },
646
  /* data           */ &_utLis331dlhData,
647
};
648
649 1678f270 Simon Welzel
/*
650
 * LTC4412 (power path controller)
651
 */
652 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
653
{
654
  (void)argc;
655
  (void)argv;
656
  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
657
  return AOS_OK;
658
}
659
aos_unittest_t moduleUtAlldLtc4412 = {
660
  /* name           */ "LTC4412",
661
  /* info           */ "Power path controller",
662
  /* test function  */ utAlldLtc4412Func,
663
  /* shell command  */ {
664
    /* name     */ "unittest:PowerPathController",
665
    /* callback */ _utShellCmdCb_AlldLtc4412,
666
    /* next     */ NULL,
667
  },
668
  /* data           */ &moduleLldPowerPathController,
669
};
670
671 1678f270 Simon Welzel
/*
672
 * PCA9544A (I2C multiplexer)
673
 */
674 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
675
{
676
  (void)argc;
677
  (void)argv;
678
  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
679
  return AOS_OK;
680
}
681
static ut_pca9544adata_t _utPca9544aData = {
682
  /* driver  */ &moduleLldI2cMultiplexer,
683
  /* timeout */ MICROSECONDS_PER_SECOND,
684
};
685
aos_unittest_t moduleUtAlldPca9544a = {
686
  /* name           */ "PCA9544A",
687
  /* info           */ "I2C multiplexer",
688
  /* test function  */ utAlldPca9544aFunc,
689
  /* shell command  */ {
690
    /* name     */ "unittest:I2CMultiplexer",
691
    /* callback */ _utShellCmdCb_AlldPca9544a,
692
    /* next     */ NULL,
693
  },
694
  /* data           */ &_utPca9544aData,
695
};
696
697 1678f270 Simon Welzel
/*
698
 * TPS62113 (step-down converter)
699
 */
700 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
701
{
702
  (void)argc;
703
  (void)argv;
704
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
705
  return AOS_OK;
706
}
707
aos_unittest_t moduleUtAlldTps62113 = {
708
  /* name           */ "TPS62113",
709
  /* info           */ "Step down converter",
710
  /* test function  */ utAlldTps62113Func,
711
  /* shell command  */ {
712
    /* name     */ "unittest:StepDownConverter",
713
    /* callback */ _utShellCmdCb_AlldTps62113,
714
    /* next     */ NULL,
715
  },
716
  /* data           */ &moduleLldStepDownConverterVdrive,
717
};
718
719 1678f270 Simon Welzel
/*
720
 * VCNL4020 (proximity sensor)
721
 */
722 e545e620 Thomas Schöpping
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
723
{
724
  uint8_t intstatus;
725
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
726
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
727
  if (intstatus) {
728
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
729
  }
730
  return;
731
}
732
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
733
{
734
  enum {
735
    UNKNOWN,
736
    FL, FR, WL, WR,
737
  } sensor = UNKNOWN;
738
  // evaluate arguments
739
  if (argc == 2) {
740
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
741
      sensor = FL;
742
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
743
      sensor = FR;
744
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
745
      sensor = WL;
746
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
747
      sensor = WR;
748
    }
749
  }
750
  if (sensor != UNKNOWN) {
751
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
752
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
753
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
754
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
755
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
756
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
757
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
758
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
759
    switch (sensor) {
760
      case FL:
761
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
762 1e5f7648 Thomas Schöpping
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
763 e545e620 Thomas Schöpping
        break;
764
      case FR:
765
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
766
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
767
        break;
768
      case WL:
769
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
770
        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
771
        break;
772
      case WR:
773
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
774
        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
775
        break;
776
      default:
777
        break;
778
    }
779
    return AOS_OK;
780
  }
781
  // print help
782
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
783
  chprintf(stream, "Options:\n");
784
  chprintf(stream, "  --frontleft, -fl\n");
785
  chprintf(stream, "    Test front left proximity sensor.\n");
786
  chprintf(stream, "  --frontrigt, -fr\n");
787
  chprintf(stream, "    Test front right proximity sensor.\n");
788
  chprintf(stream, "  --wheelleft, -wl\n");
789
  chprintf(stream, "    Test left wheel proximity sensor.\n");
790
  chprintf(stream, "  --wheelright, -wr\n");
791
  chprintf(stream, "    Test right wheel proximity sensor.\n");
792
  return AOS_INVALID_ARGUMENTS;
793
}
794
static ut_vcnl4020data_t _utVcnl4020Data = {
795
  /* driver       */ &moduleLldProximity,
796
  /* timeout      */ MICROSECONDS_PER_SECOND,
797 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
798 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_IRINT,
799 e545e620 Thomas Schöpping
};
800
aos_unittest_t moduleUtAlldVcnl4020 = {
801
  /* name           */ "VCNL4020",
802
  /* info           */ "proximity sensor",
803
  /* test function  */ utAlldVcnl4020Func,
804
  /* shell command  */ {
805
    /* name     */ "unittest:Proximity",
806
    /* callback */ _utShellCmdCb_AlldVcnl4020,
807
    /* next     */ NULL,
808
  },
809
  /* data           */ &_utVcnl4020Data,
810
};
811
812
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
813
814
/** @} */
815 53710ca3 Marc Rothmann
/** @} */