Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 341cc329

History | View | Annotate | Download (24.935 KB)

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