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