Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (23.786 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 3106e8cc Thomas Schöpping
  /* chip select line port        */ PAL_PORT(LINE_ACCEL_SS_N),
115
  /* chip select line pad number  */ PAL_PAD(LINE_ACCEL_SS_N),
116 e545e620 Thomas Schöpping
  /* 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 3106e8cc Thomas Schöpping
  /* chip select line port        */ PAL_PORT(LINE_GYRO_SS_N),
124
  /* chip select line pad number  */ PAL_PAD(LINE_GYRO_SS_N),
125 e545e620 Thomas Schöpping
  /* 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 3106e8cc Thomas Schöpping
  /* line */ LINE_LED,
143 e545e620 Thomas Schöpping
};
144 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
145 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioLed,
146
  /* meta */ {
147
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
148
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
149
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
150
  },
151
};
152 e545e620 Thomas Schöpping
153 1e5f7648 Thomas Schöpping
/**
154
 * @brief   POWER_EN output signal GPIO.
155
 */
156
static apalGpio_t _gpioPowerEn = {
157 3106e8cc Thomas Schöpping
  /* line */ LINE_POWER_EN,
158 e545e620 Thomas Schöpping
};
159 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
160 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPowerEn,
161
  /* meta */ {
162
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
163
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
164
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
165
  },
166
};
167 e545e620 Thomas Schöpping
168 1e5f7648 Thomas Schöpping
/**
169
 * @brief   COMPASS_DRDY output signal GPIO.
170
 */
171
static apalGpio_t _gpioCompassDrdy = {
172 3106e8cc Thomas Schöpping
  /* line */ LINE_COMPASS_DRDY,
173 e545e620 Thomas Schöpping
};
174 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioCompassDrdy = {
175 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioCompassDrdy,
176
  /* meta */ {
177
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
178
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
179
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
180
  },
181
};
182 e545e620 Thomas Schöpping
183 1e5f7648 Thomas Schöpping
/**
184
 * @brief   IR_INT input signal GPIO.
185
 */
186
static apalGpio_t _gpioIrInt = {
187 3106e8cc Thomas Schöpping
  /* line */ LINE_IR_INT,
188 e545e620 Thomas Schöpping
};
189 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt = {
190 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioIrInt,
191
  /* meta */ {
192
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
193
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
194
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
195
  },
196
};
197 e545e620 Thomas Schöpping
198 1e5f7648 Thomas Schöpping
/**
199
 * @brief   GYRO_DRDY input signal GPIO.
200
 */
201
static apalGpio_t _gpioGyroDrdy = {
202 3106e8cc Thomas Schöpping
  /* line */ LINE_GYRO_DRDY,
203 e545e620 Thomas Schöpping
};
204 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGyroDrdy = {
205 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGyroDrdy,
206
  /* meta */ {
207
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
208
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
209
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
210
  },
211
};
212 e545e620 Thomas Schöpping
213 1e5f7648 Thomas Schöpping
/**
214
 * @brief   SYS_UART_UP bidirectional signal GPIO.
215
 */
216
static apalGpio_t _gpioSysUartUp = {
217 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_UART_UP,
218 e545e620 Thomas Schöpping
};
219 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
220 1e5f7648 Thomas Schöpping
  /* 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 3106e8cc Thomas Schöpping
  /* line */ LINE_ACCEL_INT_N,
233 e545e620 Thomas Schöpping
};
234 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioAccelInt = {
235 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioAccelInt,
236
  /* meta */ {
237
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
238
    /* active state   */ (LIS331DLH_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
239
    /* interrupt edge */ LIS331DLH_LLD_INT_EDGE,
240
  },
241
};
242 e545e620 Thomas Schöpping
243 1e5f7648 Thomas Schöpping
/**
244
 * @brief   SYS_SNYC bidirectional signal GPIO.
245
 */
246
static apalGpio_t _gpioSysSync = {
247 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_INT_N,
248 e545e620 Thomas Schöpping
};
249 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t  moduleGpioSysSync = {
250 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysSync,
251
  /* meta */ {
252
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
253
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
254
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
255
  },
256
};
257 e545e620 Thomas Schöpping
258 1e5f7648 Thomas Schöpping
/**
259
 * @brief   PATH_DCSTAT input signal GPIO.
260
 */
261
static apalGpio_t _gpioPathDcStat = {
262 3106e8cc Thomas Schöpping
  /* line */ LINE_PATH_DCSTAT,
263 e545e620 Thomas Schöpping
};
264 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDcStat = {
265 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPathDcStat,
266
  /* meta */ {
267
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
268
    /* active state   */ LTC4412_LLD_STAT_ACTIVE_STATE,
269
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
270
  },
271
};
272 e545e620 Thomas Schöpping
273 1e5f7648 Thomas Schöpping
/**
274
 * @brief   PATH_DCEN output signal GPIO.
275
 */
276
static apalGpio_t _gpioPathDcEn = {
277 3106e8cc Thomas Schöpping
  /* line */ LINE_PATH_DCEN,
278 e545e620 Thomas Schöpping
};
279 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDcEn = {
280 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPathDcEn,
281
  /* meta */ {
282
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
283
    /* active state   */ LTC4412_LLD_CTRL_ACTIVE_STATE,
284
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
285
  },
286
};
287 e545e620 Thomas Schöpping
288 1e5f7648 Thomas Schöpping
/**
289
 * @brief   SYS_PD bidirectional signal GPIO.
290
 */
291
static apalGpio_t _gpioSysPd = {
292 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_PD_N,
293 e545e620 Thomas Schöpping
};
294 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysPd = {
295 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysPd,
296
  /* meta */ {
297
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
298
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
299
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
300
  },
301
};
302 e545e620 Thomas Schöpping
303 1e5f7648 Thomas Schöpping
/**
304
 * @brief   SYS_REG_EN input signal GPIO.
305
 */
306
static apalGpio_t _gpioSysRegEn = {
307 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_REG_EN,
308 e545e620 Thomas Schöpping
};
309 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysRegEn = {
310 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysRegEn,
311
  /* meta */ {
312
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
313
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
314
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
315
  },
316
};
317 e545e620 Thomas Schöpping
318 1e5f7648 Thomas Schöpping
/**
319
 * @brief   SYS_WARMRST bidirectional signal GPIO.
320
 */
321
static apalGpio_t _gpioSysWarmrst = {
322 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_WARMRST_N,
323 e545e620 Thomas Schöpping
};
324 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
325 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysWarmrst,
326
  /* meta */ {
327
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
328
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
329
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
330
  },
331
};
332 e545e620 Thomas Schöpping
333
/** @} */
334
335
/*===========================================================================*/
336
/**
337
 * @name AMiRo-OS core configurations
338
 * @{
339
 */
340
/*===========================================================================*/
341
342 2dd2e257 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
343 acc97cbf Thomas Schöpping
ROMCONST char* moduleShellPrompt = "DiWheelDrive";
344 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
345 6b53f6bf Thomas Schöpping
346
/** @} */
347
348
/*===========================================================================*/
349
/**
350
 * @name Startup Shutdown Synchronization Protocol (SSSP)
351
 * @{
352
 */
353
/*===========================================================================*/
354
355 e545e620 Thomas Schöpping
/** @} */
356
357
/*===========================================================================*/
358
/**
359
 * @name Low-level drivers
360
 * @{
361
 */
362
/*===========================================================================*/
363
364
A3906Driver moduleLldMotors = {
365 1e5f7648 Thomas Schöpping
  /* power enable GPIO  */ &moduleGpioPowerEn,
366 e545e620 Thomas Schöpping
};
367
368 ddf34c3d Thomas Schöpping
AT24C01BDriver moduleLldEeprom = {
369 e545e620 Thomas Schöpping
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
370 ddf34c3d Thomas Schöpping
  /* I²C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
371 e545e620 Thomas Schöpping
};
372
373
HMC5883LDriver moduleLldCompass = {
374
  /* I²C Driver */ &MODULE_HAL_I2C_COMPASS,
375
};
376
377
INA219Driver moduleLldPowerMonitorVdd = {
378
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
379
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
380
  /* current LSB (uA) */ 0x00u,
381
  /* configuration    */ NULL,
382
};
383
384
L3G4200DDriver moduleLldGyroscope = {
385
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
386
};
387
388
LEDDriver moduleLldStatusLed = {
389 1e5f7648 Thomas Schöpping
  /* LED enable Gpio */ &moduleGpioLed,
390 e545e620 Thomas Schöpping
};
391
392
LIS331DLHDriver moduleLldAccelerometer = {
393
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
394
};
395
396
LTC4412Driver moduleLldPowerPathController = {
397 1e5f7648 Thomas Schöpping
  /* Control GPIO */ &moduleGpioPathDcEn,
398
  /* Status GPIO  */ &moduleGpioPathDcStat,
399 e545e620 Thomas Schöpping
};
400
401
PCA9544ADriver moduleLldI2cMultiplexer = {
402
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
403
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
404
};
405
406 ddf34c3d Thomas Schöpping
TPS6211xDriver moduleLldStepDownConverterVdrive = {
407 1e5f7648 Thomas Schöpping
  /* Power enable Gpio */ &moduleGpioPowerEn,
408 e545e620 Thomas Schöpping
};
409
410
VCNL4020Driver moduleLldProximity = {
411
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
412
};
413
414
/** @} */
415
416
/*===========================================================================*/
417
/**
418
 * @name Unit tests (UT)
419
 * @{
420
 */
421
/*===========================================================================*/
422
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
423
#include <string.h>
424
425 8be006e0 Thomas Schöpping
/*
426
 * A3906 (motor driver)
427
 */
428 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[])
429
{
430
  (void)argc;
431
  (void)argv;
432
  aosUtRun(stream, &moduleUtAlldA3906, NULL);
433
  return AOS_OK;
434
}
435
static ut_a3906data_t _utA3906Data = {
436
  /* driver           */ &moduleLldMotors,
437
  /* PWM information  */ {
438
    /* driver   */ &MODULE_HAL_PWM_DRIVE,
439
    /* channels */ {
440
      /* left wheel forward   */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
441
      /* left wheel backward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
442
      /* right wheel forward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
443
      /* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
444
    },
445
  },
446
  /* QEI information  */ {
447
    /* left wheel               */ &MODULE_HAL_QEI_LEFT_WHEEL,
448
    /* right wheel              */ &MODULE_HAL_QEI_RIGHT_WHEEL,
449
    /* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
450
  },
451 acc97cbf Thomas Schöpping
  /* Wheel diameter   */ {
452
    /* left wheel   */ 0.05571f,
453
    /* right wheel  */ 0.05571f,
454
  },
455 2e69d671 Thomas Schöpping
  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
456 e545e620 Thomas Schöpping
};
457
aos_unittest_t moduleUtAlldA3906  = {
458
  /* name           */ "A3906",
459
  /* info           */ "motor driver",
460
  /* test function  */ utAlldA3906Func,
461
  /* shell command  */ {
462
    /* name     */ "unittest:MotorDriver",
463
    /* callback */ _utShellCmdCb_AlldA3906,
464
    /* next     */ NULL,
465
  },
466
  /* data           */ &_utA3906Data,
467
};
468
469 8be006e0 Thomas Schöpping
/*
470 ddf34c3d Thomas Schöpping
 * AT24C01B (EEPROM)
471 8be006e0 Thomas Schöpping
 */
472 ddf34c3d Thomas Schöpping
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
473 e545e620 Thomas Schöpping
{
474
  (void)argc;
475
  (void)argv;
476 ddf34c3d Thomas Schöpping
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
477 e545e620 Thomas Schöpping
  return AOS_OK;
478
}
479 ddf34c3d Thomas Schöpping
static ut_at24c01bdata_t _utAlldAt24c01bData = {
480 e545e620 Thomas Schöpping
  /* driver   */ &moduleLldEeprom,
481
  /* timeout  */ MICROSECONDS_PER_SECOND,
482
};
483 ddf34c3d Thomas Schöpping
aos_unittest_t moduleUtAlldAt24c01b = {
484
  /* name           */ "AT24C01B",
485 e545e620 Thomas Schöpping
  /* info           */ "1kbit EEPROM",
486 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldAt24c01bFunc,
487 e545e620 Thomas Schöpping
  /* shell command  */ {
488
    /* name     */ "unittest:EEPROM",
489 ddf34c3d Thomas Schöpping
    /* callback */ _utShellCmdCb_AlldAt24c01b,
490 e545e620 Thomas Schöpping
    /* next     */ NULL,
491
  },
492 ddf34c3d Thomas Schöpping
  /* data           */ &_utAlldAt24c01bData,
493 e545e620 Thomas Schöpping
};
494
495 8be006e0 Thomas Schöpping
/*
496
 * HMC5883L (compass)
497
 */
498 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldHmc5883l(BaseSequentialStream* stream, int argc, char* argv[])
499
{
500
  (void)argc;
501
  (void)argv;
502
  aosUtRun(stream, &moduleUtAlldHmc5883l, NULL);
503
  return AOS_OK;
504
}
505
static ut_hmc5883ldata_t _utHmc5883lData = {
506
  /* HMC driver   */ &moduleLldCompass,
507 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
508 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_COMPASSDRDY,
509 e545e620 Thomas Schöpping
  /* timeout      */ MICROSECONDS_PER_SECOND,
510
};
511
aos_unittest_t moduleUtAlldHmc5883l = {
512
  /* name           */ "HMC5883L",
513
  /* info           */ "compass",
514
  /* test function  */ utAlldHmc5883lFunc,
515
  /* shell command  */ {
516
    /* name     */ "unittest:Compass",
517
    /* callback */ _utShellCmdCb_AlldHmc5883l,
518
    /* next     */ NULL,
519
  },
520
  /* data           */ &_utHmc5883lData,
521
};
522
523 8be006e0 Thomas Schöpping
/*
524
 * INA219 (power monitor)
525
 */
526 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
527
{
528
  (void)argc;
529
  (void)argv;
530
  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
531
  return AOS_OK;
532
}
533
static ut_ina219data_t _utIna219Data = {
534
  /* driver           */ &moduleLldPowerMonitorVdd,
535
  /* expected voltage */ 3.3f,
536
  /* tolerance        */ 0.05f,
537
  /* timeout */ MICROSECONDS_PER_SECOND,
538
};
539
aos_unittest_t moduleUtAlldIna219 = {
540
  /* name           */ "INA219",
541
  /* info           */ "power monitor",
542
  /* test function  */ utAlldIna219Func,
543
  /* shell command  */ {
544
    /* name     */ "unittest:PowerMonitor",
545
    /* callback */ _utShellCmdCb_AlldIna219,
546
    /* next     */ NULL,
547
  },
548
  /* data           */ &_utIna219Data,
549
};
550
551 8be006e0 Thomas Schöpping
/*
552
 * L3G4200D (gyroscope)
553
 */
554 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldL3g4200d(BaseSequentialStream* stream, int argc, char* argv[])
555
{
556
  (void)argc;
557
  (void)argv;
558
  spiStart(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid, ((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->spiconf);
559
  aosUtRun(stream, &moduleUtAlldL3g4200d, NULL);
560
  spiStop(((ut_l3g4200ddata_t*)moduleUtAlldL3g4200d.data)->l3gd->spid);
561
  return AOS_OK;
562
}
563
static ut_l3g4200ddata_t _utL3g4200dData = {
564
  /* driver            */ &moduleLldGyroscope,
565
  /* SPI configuration */ &moduleHalSpiGyroscopeConfig,
566 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
567 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_GYRODRDY,
568 e545e620 Thomas Schöpping
};
569
aos_unittest_t moduleUtAlldL3g4200d = {
570
  /* name           */ "L3G4200D",
571
  /* info           */ "Gyroscope",
572
  /* test function  */ utAlldL3g4200dFunc,
573
  /* shell command  */ {
574
    /* name     */ "unittest:Gyroscope",
575
    /* callback */ _utShellCmdCb_AlldL3g4200d,
576
    /* next     */ NULL,
577
  },
578
  /* data           */ &_utL3g4200dData,
579
};
580
581 8be006e0 Thomas Schöpping
/*
582
 * Status LED
583
 */
584 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
585
{
586
  (void)argc;
587
  (void)argv;
588
  aosUtRun(stream, &moduleUtAlldLed, NULL);
589
  return AOS_OK;
590
}
591
aos_unittest_t moduleUtAlldLed = {
592
  /* name           */ "LED",
593
  /* info           */ NULL,
594
  /* test function  */ utAlldLedFunc,
595
  /* shell command  */ {
596
    /* name     */ "unittest:StatusLED",
597
    /* callback */ _utShellCmdCb_AlldLed,
598
    /* next     */ NULL,
599
  },
600
  /* data           */ &moduleLldStatusLed,
601
};
602
603 8be006e0 Thomas Schöpping
/*
604
 * LIS331DLH (accelerometer)
605
 */
606 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLis331dlh(BaseSequentialStream* stream, int argc, char* argv[])
607
{
608
  (void)argc;
609
  (void)argv;
610
  spiStart(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid, ((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->spiconf);
611
  aosUtRun(stream, &moduleUtAlldLis331dlh, NULL);
612
  spiStop(((ut_lis331dlhdata_t*)moduleUtAlldLis331dlh.data)->lisd->spid);
613
  return AOS_OK;
614
}
615
static ut_lis331dlhdata_t _utLis331dlhData = {
616
  /* driver            */ &moduleLldAccelerometer,
617
  /* SPI configuration */ &moduleHalSpiAccelerometerConfig,
618 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
619 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_ACCELINT,
620 e545e620 Thomas Schöpping
};
621
aos_unittest_t moduleUtAlldLis331dlh = {
622
  /* name           */ "LIS331DLH",
623
  /* info           */ "Accelerometer",
624
  /* test function  */ utAlldLis331dlhFunc,
625
  /* shell command  */ {
626
    /* name     */ "unittest:Accelerometer",
627
    /* callback */ _utShellCmdCb_AlldLis331dlh,
628
    /* next     */ NULL,
629
  },
630
  /* data           */ &_utLis331dlhData,
631
};
632
633 8be006e0 Thomas Schöpping
/*
634
 * LTC4412 (power path controller)
635
 */
636 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
637
{
638
  (void)argc;
639
  (void)argv;
640
  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
641
  return AOS_OK;
642
}
643
aos_unittest_t moduleUtAlldLtc4412 = {
644
  /* name           */ "LTC4412",
645
  /* info           */ "Power path controller",
646
  /* test function  */ utAlldLtc4412Func,
647
  /* shell command  */ {
648
    /* name     */ "unittest:PowerPathController",
649
    /* callback */ _utShellCmdCb_AlldLtc4412,
650
    /* next     */ NULL,
651
  },
652
  /* data           */ &moduleLldPowerPathController,
653
};
654
655 8be006e0 Thomas Schöpping
/*
656
 * PCA9544A (I2C multiplexer)
657
 */
658 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
659
{
660
  (void)argc;
661
  (void)argv;
662
  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
663
  return AOS_OK;
664
}
665
static ut_pca9544adata_t _utPca9544aData = {
666
  /* driver  */ &moduleLldI2cMultiplexer,
667
  /* timeout */ MICROSECONDS_PER_SECOND,
668
};
669
aos_unittest_t moduleUtAlldPca9544a = {
670
  /* name           */ "PCA9544A",
671
  /* info           */ "I2C multiplexer",
672
  /* test function  */ utAlldPca9544aFunc,
673
  /* shell command  */ {
674
    /* name     */ "unittest:I2CMultiplexer",
675
    /* callback */ _utShellCmdCb_AlldPca9544a,
676
    /* next     */ NULL,
677
  },
678
  /* data           */ &_utPca9544aData,
679
};
680
681 8be006e0 Thomas Schöpping
/*
682
 * TPS62113 (step-down converter)
683
 */
684 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
685
{
686
  (void)argc;
687
  (void)argv;
688
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
689
  return AOS_OK;
690
}
691
aos_unittest_t moduleUtAlldTps62113 = {
692
  /* name           */ "TPS62113",
693
  /* info           */ "Step down converter",
694 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldTps6211xFunc,
695 e545e620 Thomas Schöpping
  /* shell command  */ {
696
    /* name     */ "unittest:StepDownConverter",
697
    /* callback */ _utShellCmdCb_AlldTps62113,
698
    /* next     */ NULL,
699
  },
700
  /* data           */ &moduleLldStepDownConverterVdrive,
701
};
702
703 8be006e0 Thomas Schöpping
/*
704
 * VCNL4020 (proximity sensor)
705
 */
706 e545e620 Thomas Schöpping
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
707
{
708
  uint8_t intstatus;
709
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
710
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
711
  if (intstatus) {
712
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
713
  }
714
  return;
715
}
716
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
717
{
718
  enum {
719
    UNKNOWN,
720
    FL, FR, WL, WR,
721
  } sensor = UNKNOWN;
722
  // evaluate arguments
723
  if (argc == 2) {
724
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
725
      sensor = FL;
726
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
727
      sensor = FR;
728
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
729
      sensor = WL;
730
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
731
      sensor = WR;
732
    }
733
  }
734
  if (sensor != UNKNOWN) {
735
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
736
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
737
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
738
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
739
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
740
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
741
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
742
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
743
    switch (sensor) {
744
      case FL:
745
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
746 1e5f7648 Thomas Schöpping
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
747 e545e620 Thomas Schöpping
        break;
748
      case FR:
749
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
750
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
751
        break;
752
      case WL:
753
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
754
        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
755
        break;
756
      case WR:
757
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
758
        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
759
        break;
760
      default:
761
        break;
762
    }
763
    return AOS_OK;
764
  }
765
  // print help
766
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
767
  chprintf(stream, "Options:\n");
768
  chprintf(stream, "  --frontleft, -fl\n");
769
  chprintf(stream, "    Test front left proximity sensor.\n");
770
  chprintf(stream, "  --frontrigt, -fr\n");
771
  chprintf(stream, "    Test front right proximity sensor.\n");
772
  chprintf(stream, "  --wheelleft, -wl\n");
773
  chprintf(stream, "    Test left wheel proximity sensor.\n");
774
  chprintf(stream, "  --wheelright, -wr\n");
775
  chprintf(stream, "    Test right wheel proximity sensor.\n");
776 916f8d28 Thomas Schöpping
  return AOS_INVALIDARGUMENTS;
777 e545e620 Thomas Schöpping
}
778
static ut_vcnl4020data_t _utVcnl4020Data = {
779
  /* driver       */ &moduleLldProximity,
780
  /* timeout      */ MICROSECONDS_PER_SECOND,
781 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
782 1e5f7648 Thomas Schöpping
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_IRINT,
783 e545e620 Thomas Schöpping
};
784
aos_unittest_t moduleUtAlldVcnl4020 = {
785
  /* name           */ "VCNL4020",
786
  /* info           */ "proximity sensor",
787
  /* test function  */ utAlldVcnl4020Func,
788
  /* shell command  */ {
789
    /* name     */ "unittest:Proximity",
790
    /* callback */ _utShellCmdCb_AlldVcnl4020,
791
    /* next     */ NULL,
792
  },
793
  /* data           */ &_utVcnl4020Data,
794
};
795
796 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
797 e545e620 Thomas Schöpping
798
/** @} */
799 53710ca3 Marc Rothmann
/** @} */