amiro-os / modules / DiWheelDrive_1-2 / module.c @ f606e2bf
History | View | Annotate | Download (17.4 KB)
1 | abb8b3f4 | Thomas Schöpping | /*
|
---|---|---|---|
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 | c53ef0b1 | Thomas Schöpping | #include <amiroos.h> |
28 | |||
29 | #include <string.h> |
||
30 | abb8b3f4 | Thomas Schöpping | |
31 | /*===========================================================================*/
|
||
32 | /**
|
||
33 | * @name Module specific functions
|
||
34 | * @{
|
||
35 | */
|
||
36 | /*===========================================================================*/
|
||
37 | |||
38 | /** @} */
|
||
39 | |||
40 | /*===========================================================================*/
|
||
41 | /**
|
||
42 | * @name ChibiOS/HAL configuration
|
||
43 | * @{
|
||
44 | */
|
||
45 | /*===========================================================================*/
|
||
46 | |||
47 | CANConfig moduleHalCanConfig = { |
||
48 | /* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||
49 | /* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
||
50 | }; |
||
51 | |||
52 | I2CConfig moduleHalI2cImuConfig = { |
||
53 | /* I²C mode */ OPMODE_I2C,
|
||
54 | /* frequency */ 400000, |
||
55 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
56 | }; |
||
57 | |||
58 | I2CConfig moduleHalI2cProxEepromPwrmtrConfig = { |
||
59 | /* I²C mode */ OPMODE_I2C,
|
||
60 | /* frequency */ 400000, |
||
61 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
62 | }; |
||
63 | |||
64 | PWMConfig moduleHalPwmDriveConfig = { |
||
65 | /* frequency */ 7200000, |
||
66 | /* period */ 360, |
||
67 | /* callback */ NULL, |
||
68 | /* channel configurations */ {
|
||
69 | /* channel 0 */ {
|
||
70 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
71 | /* callback */ NULL |
||
72 | }, |
||
73 | /* channel 1 */ {
|
||
74 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
75 | /* callback */ NULL |
||
76 | }, |
||
77 | /* channel 2 */ {
|
||
78 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
79 | /* callback */ NULL |
||
80 | }, |
||
81 | /* channel 3 */ {
|
||
82 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
83 | /* callback */ NULL |
||
84 | }, |
||
85 | }, |
||
86 | /* TIM CR2 register */ 0, |
||
87 | #if (STM32_PWM_USE_ADVANCED == TRUE)
|
||
88 | /* TIM BDTR register */ 0, |
||
89 | #endif /* (STM32_PWM_USE_ADVANCED == TRUE) */ |
||
90 | /* TIM DIER register */ 0 |
||
91 | }; |
||
92 | |||
93 | QEIConfig moduleHalQeiConfig = { |
||
94 | /* mode */ QEI_COUNT_BOTH,
|
||
95 | /* channel config */ {
|
||
96 | /* channel 0 */ {
|
||
97 | /* input mode */ QEI_INPUT_NONINVERTED,
|
||
98 | }, |
||
99 | /* channel 1 */ {
|
||
100 | /* input mode */ QEI_INPUT_NONINVERTED,
|
||
101 | }, |
||
102 | }, |
||
103 | /* encoder range */ 0x10000u, |
||
104 | }; |
||
105 | |||
106 | SerialConfig moduleHalProgIfConfig = { |
||
107 | /* bit rate */ 115200, |
||
108 | /* CR1 */ 0, |
||
109 | /* CR1 */ 0, |
||
110 | /* CR1 */ 0, |
||
111 | }; |
||
112 | |||
113 | /** @} */
|
||
114 | |||
115 | /*===========================================================================*/
|
||
116 | /**
|
||
117 | * @name GPIO definitions
|
||
118 | * @{
|
||
119 | */
|
||
120 | /*===========================================================================*/
|
||
121 | |||
122 | /**
|
||
123 | * @brief LED output signal GPIO.
|
||
124 | */
|
||
125 | static apalGpio_t _gpioLed = {
|
||
126 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LED,
|
127 | abb8b3f4 | Thomas Schöpping | }; |
128 | ROMCONST apalControlGpio_t moduleGpioLed = { |
||
129 | /* GPIO */ &_gpioLed,
|
||
130 | /* meta */ {
|
||
131 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
132 | 4c72a54c | Thomas Schöpping | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
133 | abb8b3f4 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
134 | }, |
||
135 | }; |
||
136 | |||
137 | /**
|
||
138 | * @brief POWER_EN output signal GPIO.
|
||
139 | */
|
||
140 | static apalGpio_t _gpioPowerEn = {
|
||
141 | 3106e8cc | Thomas Schöpping | /* line */ LINE_POWER_EN,
|
142 | abb8b3f4 | Thomas Schöpping | }; |
143 | ROMCONST apalControlGpio_t moduleGpioPowerEn = { |
||
144 | /* GPIO */ &_gpioPowerEn,
|
||
145 | /* meta */ {
|
||
146 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
147 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
148 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
149 | }, |
||
150 | }; |
||
151 | |||
152 | /**
|
||
153 | * @brief IR_INT input signal GPIO.
|
||
154 | */
|
||
155 | static apalGpio_t _gpioIrInt = {
|
||
156 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IR_INT,
|
157 | abb8b3f4 | Thomas Schöpping | }; |
158 | ROMCONST apalControlGpio_t moduleGpioIrInt = { |
||
159 | /* GPIO */ &_gpioIrInt,
|
||
160 | /* meta */ {
|
||
161 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
162 | /* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
163 | /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
||
164 | }, |
||
165 | }; |
||
166 | |||
167 | /**
|
||
168 | * @brief SYS_UART_UP bidirectional signal GPIO.
|
||
169 | */
|
||
170 | static apalGpio_t _gpioSysUartUp = {
|
||
171 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_UART_UP,
|
172 | abb8b3f4 | Thomas Schöpping | }; |
173 | ROMCONST apalControlGpio_t moduleGpioSysUartUp = { |
||
174 | /* GPIO */ &_gpioSysUartUp,
|
||
175 | /* meta */ {
|
||
176 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
177 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
178 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
179 | }, |
||
180 | }; |
||
181 | |||
182 | /**
|
||
183 | * @brief IMU_INT input signal GPIO.
|
||
184 | */
|
||
185 | static apalGpio_t _gpioImuInt = {
|
||
186 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IMU_INT,
|
187 | abb8b3f4 | Thomas Schöpping | }; |
188 | ROMCONST apalControlGpio_t moduleGpioImuInt = { |
||
189 | /* GPIO */ &_gpioImuInt,
|
||
190 | /* meta */ {
|
||
191 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
192 | /* active state */ APAL_GPIO_ACTIVE_HIGH, // TODO |
||
193 | /* interrupt edge */ APAL_GPIO_EDGE_RISING, // TODO |
||
194 | }, |
||
195 | }; |
||
196 | |||
197 | /**
|
||
198 | * @brief SYS_SNYC bidirectional signal GPIO.
|
||
199 | */
|
||
200 | static apalGpio_t _gpioSysSync = {
|
||
201 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_INT_N,
|
202 | abb8b3f4 | Thomas Schöpping | }; |
203 | ROMCONST apalControlGpio_t moduleGpioSysSync = { |
||
204 | /* GPIO */ &_gpioSysSync,
|
||
205 | /* meta */ {
|
||
206 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
207 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
208 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
209 | }, |
||
210 | }; |
||
211 | |||
212 | /**
|
||
213 | * @brief IMU_RESET output signal GPIO.
|
||
214 | */
|
||
215 | static apalGpio_t _gpioImuReset = {
|
||
216 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IMU_RESET_N,
|
217 | abb8b3f4 | Thomas Schöpping | }; |
218 | ROMCONST apalControlGpio_t moduleGpioImuReset = { |
||
219 | /* GPIO */ &_gpioImuReset,
|
||
220 | /* meta */ {
|
||
221 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
222 | /* active state */ APAL_GPIO_ACTIVE_LOW, // TODO |
||
223 | /* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO |
||
224 | }, |
||
225 | }; |
||
226 | |||
227 | /**
|
||
228 | * @brief PATH_DCSTAT input signal GPIO.
|
||
229 | */
|
||
230 | static apalGpio_t _gpioPathDcStat = {
|
||
231 | 3106e8cc | Thomas Schöpping | /* line */ LINE_PATH_DCSTAT,
|
232 | abb8b3f4 | Thomas Schöpping | }; |
233 | ROMCONST apalControlGpio_t moduleGpioPathDcStat = { |
||
234 | /* GPIO */ &_gpioPathDcStat,
|
||
235 | /* meta */ {
|
||
236 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
237 | /* active state */ LTC4412_LLD_STAT_ACTIVE_STATE,
|
||
238 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
239 | }, |
||
240 | }; |
||
241 | |||
242 | /**
|
||
243 | * @brief PATH_DCEN output signal GPIO.
|
||
244 | */
|
||
245 | static apalGpio_t _gpioPathDcEn = {
|
||
246 | 3106e8cc | Thomas Schöpping | /* line */ LINE_PATH_DCEN,
|
247 | abb8b3f4 | Thomas Schöpping | }; |
248 | ROMCONST apalControlGpio_t moduleGpioPathDcEn = { |
||
249 | /* GPIO */ &_gpioPathDcEn,
|
||
250 | /* meta */ {
|
||
251 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
252 | /* active state */ LTC4412_LLD_CTRL_ACTIVE_STATE,
|
||
253 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
254 | }, |
||
255 | }; |
||
256 | |||
257 | /**
|
||
258 | * @brief SYS_PD bidirectional signal GPIO.
|
||
259 | */
|
||
260 | static apalGpio_t _gpioSysPd = {
|
||
261 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_PD_N,
|
262 | abb8b3f4 | Thomas Schöpping | }; |
263 | ROMCONST apalControlGpio_t moduleGpioSysPd = { |
||
264 | /* GPIO */ &_gpioSysPd,
|
||
265 | /* meta */ {
|
||
266 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
267 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
268 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
269 | }, |
||
270 | }; |
||
271 | |||
272 | /**
|
||
273 | * @brief SYS_REG_EN input signal GPIO.
|
||
274 | */
|
||
275 | static apalGpio_t _gpioSysRegEn = {
|
||
276 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_REG_EN,
|
277 | abb8b3f4 | Thomas Schöpping | }; |
278 | ROMCONST apalControlGpio_t moduleGpioSysRegEn = { |
||
279 | /* GPIO */ &_gpioSysRegEn,
|
||
280 | /* meta */ {
|
||
281 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
282 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
283 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
284 | }, |
||
285 | }; |
||
286 | |||
287 | /**
|
||
288 | * @brief IMU_BOOT_LOAD output signal GPIO.
|
||
289 | */
|
||
290 | static apalGpio_t _gpioImuBootLoad = {
|
||
291 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IMU_BOOT_LOAD_N,
|
292 | abb8b3f4 | Thomas Schöpping | }; |
293 | ROMCONST apalControlGpio_t moduleGpioImuBootLoad = { |
||
294 | /* GPIO */ &_gpioImuBootLoad,
|
||
295 | /* meta */ {
|
||
296 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
297 | /* active state */ APAL_GPIO_ACTIVE_LOW, // TODO |
||
298 | /* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO |
||
299 | }, |
||
300 | }; |
||
301 | |||
302 | /**
|
||
303 | * @brief IMU_BL_IND input signal GPIO.
|
||
304 | */
|
||
305 | static apalGpio_t _gpioImuBlInd = {
|
||
306 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IMU_BL_IND,
|
307 | abb8b3f4 | Thomas Schöpping | }; |
308 | ROMCONST apalControlGpio_t moduleGpioImuBlInd = { |
||
309 | /* GPIO */ &_gpioImuBlInd,
|
||
310 | /* meta */ {
|
||
311 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
312 | /* active state */ APAL_GPIO_ACTIVE_HIGH, // TODO |
||
313 | /* interrupt edge */ APAL_GPIO_EDGE_NONE, // TODO |
||
314 | }, |
||
315 | }; |
||
316 | |||
317 | /**
|
||
318 | * @brief SYS_WARMRST bidirectional signal GPIO.
|
||
319 | */
|
||
320 | static apalGpio_t _gpioSysWarmrst = {
|
||
321 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_WARMRST_N,
|
322 | abb8b3f4 | Thomas Schöpping | }; |
323 | ROMCONST apalControlGpio_t moduleGpioSysWarmrst = { |
||
324 | /* GPIO */ &_gpioSysWarmrst,
|
||
325 | /* meta */ {
|
||
326 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
327 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
328 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
329 | }, |
||
330 | }; |
||
331 | |||
332 | /** @} */
|
||
333 | |||
334 | /*===========================================================================*/
|
||
335 | /**
|
||
336 | * @name AMiRo-OS core configurations
|
||
337 | * @{
|
||
338 | */
|
||
339 | /*===========================================================================*/
|
||
340 | |||
341 | cda14729 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
342 | abb8b3f4 | Thomas Schöpping | ROMCONST char* moduleShellPrompt = "DiWheelDrive"; |
343 | cda14729 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
344 | abb8b3f4 | Thomas Schöpping | |
345 | /** @} */
|
||
346 | |||
347 | /*===========================================================================*/
|
||
348 | /**
|
||
349 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
350 | * @{
|
||
351 | */
|
||
352 | /*===========================================================================*/
|
||
353 | |||
354 | c53ef0b1 | Thomas Schöpping | #if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__) |
355 | |||
356 | /* some local definitions */
|
||
357 | // maximum number of bytes per CAN frame
|
||
358 | #define CAN_BYTES_PER_FRAME 8 |
||
359 | // identifier (as dominant as possible)
|
||
360 | #define MSI_BCBMSG_CANID 0 |
||
361 | |||
362 | aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
|
||
363 | { |
||
364 | aosDbgCheck(buffer != NULL);
|
||
365 | aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
|
||
366 | |||
367 | // local variables
|
||
368 | CANTxFrame frame; |
||
369 | |||
370 | // setup the common parts of the message frame
|
||
371 | frame.DLC = (uint8_t)length; |
||
372 | frame.RTR = CAN_RTR_DATA; |
||
373 | frame.IDE = CAN_IDE_STD; |
||
374 | frame.SID = MSI_BCBMSG_CANID; |
||
375 | memcpy(frame.data8, buffer, length); |
||
376 | |||
377 | // sent the frame and return
|
||
378 | return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
|
||
379 | } |
||
380 | |||
381 | aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length) |
||
382 | { |
||
383 | aosDbgCheck(buffer != NULL);
|
||
384 | aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
|
||
385 | |||
386 | // local variables
|
||
387 | CANRxFrame frame; |
||
388 | |||
389 | // receive a frame and check for errors
|
||
390 | if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
|
||
391 | // a correct frame was received
|
||
392 | if (frame.DLC == length &&
|
||
393 | frame.RTR == CAN_RTR_DATA && |
||
394 | frame.IDE == CAN_IDE_STD && |
||
395 | frame.SID == MSI_BCBMSG_CANID) { |
||
396 | // success: fetch the data and return
|
||
397 | memcpy(buffer, frame.data8, length); |
||
398 | return AOS_SSSP_BCB_SUCCESS;
|
||
399 | } |
||
400 | // an unexpected frame was received
|
||
401 | else {
|
||
402 | return AOS_SSSP_BCB_INVALIDMSG;
|
||
403 | } |
||
404 | } else {
|
||
405 | // failure: return with error
|
||
406 | return AOS_SSSP_BCB_ERROR;
|
||
407 | } |
||
408 | } |
||
409 | |||
410 | #undef MSI_BCBMSG_CANID
|
||
411 | #undef CAN_BYTES_PER_FRAME
|
||
412 | |||
413 | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */ |
||
414 | |||
415 | abb8b3f4 | Thomas Schöpping | /** @} */
|
416 | |||
417 | /*===========================================================================*/
|
||
418 | /**
|
||
419 | * @name Low-level drivers
|
||
420 | * @{
|
||
421 | */
|
||
422 | /*===========================================================================*/
|
||
423 | |||
424 | A3906Driver moduleLldMotors = { |
||
425 | /* power enable GPIO */ &moduleGpioPowerEn,
|
||
426 | }; |
||
427 | |||
428 | AT24C01BDriver moduleLldEeprom = { |
||
429 | /* I2C driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
||
430 | /* I²C address */ AT24C01B_LLD_I2C_ADDR_FIXED,
|
||
431 | }; |
||
432 | |||
433 | 4c72a54c | Thomas Schöpping | // TODO: BNO055
|
434 | |||
435 | abb8b3f4 | Thomas Schöpping | INA219Driver moduleLldPowerMonitorVdd = { |
436 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
||
437 | /* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
||
438 | /* current LSB (uA) */ 0x00u, |
||
439 | /* configuration */ NULL, |
||
440 | }; |
||
441 | |||
442 | LEDDriver moduleLldStatusLed = { |
||
443 | /* LED enable Gpio */ &moduleGpioLed,
|
||
444 | }; |
||
445 | |||
446 | LTC4412Driver moduleLldPowerPathController = { |
||
447 | /* Control GPIO */ &moduleGpioPathDcEn,
|
||
448 | /* Status GPIO */ &moduleGpioPathDcStat,
|
||
449 | }; |
||
450 | |||
451 | PCA9544ADriver moduleLldI2cMultiplexer = { |
||
452 | /* I²C driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
||
453 | /* I²C address */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
||
454 | }; |
||
455 | |||
456 | TPS6211xDriver moduleLldStepDownConverterVdrive = { |
||
457 | /* Power enable Gpio */ &moduleGpioPowerEn,
|
||
458 | }; |
||
459 | |||
460 | VCNL4020Driver moduleLldProximity = { |
||
461 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
|
||
462 | }; |
||
463 | |||
464 | /** @} */
|
||
465 | |||
466 | /*===========================================================================*/
|
||
467 | /**
|
||
468 | 4c72a54c | Thomas Schöpping | * @name Tests
|
469 | abb8b3f4 | Thomas Schöpping | * @{
|
470 | */
|
||
471 | /*===========================================================================*/
|
||
472 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
473 | |||
474 | /*
|
||
475 | * A3906 (motor driver)
|
||
476 | */
|
||
477 | 4c72a54c | Thomas Schöpping | #include <module_test_A3906.h> |
478 | static int _testA3906ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
479 | abb8b3f4 | Thomas Schöpping | { |
480 | 4c72a54c | Thomas Schöpping | return moduleTestA3906ShellCb(stream, argc, argv, NULL); |
481 | abb8b3f4 | Thomas Schöpping | } |
482 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestA3906ShellCmd, "test:MotorDriver", _testA3906ShellCmdCb);
|
483 | abb8b3f4 | Thomas Schöpping | |
484 | /*
|
||
485 | 4c72a54c | Thomas Schöpping | * AT24C01BN-SH-B (EEPROM)
|
486 | abb8b3f4 | Thomas Schöpping | */
|
487 | 4c72a54c | Thomas Schöpping | #include <module_test_AT24C01B.h> |
488 | static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
489 | abb8b3f4 | Thomas Schöpping | { |
490 | 4c72a54c | Thomas Schöpping | return moduleTestAt24c01bShellCb(stream, argc, argv, NULL); |
491 | abb8b3f4 | Thomas Schöpping | } |
492 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
|
493 | |||
494 | // TODO: BNO055
|
||
495 | abb8b3f4 | Thomas Schöpping | |
496 | /*
|
||
497 | * INA219 (power monitor)
|
||
498 | */
|
||
499 | 4c72a54c | Thomas Schöpping | #include <module_test_INA219.h> |
500 | static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
501 | abb8b3f4 | Thomas Schöpping | { |
502 | 4c72a54c | Thomas Schöpping | return moduleTestIna219ShellCb(stream, argc, argv, NULL); |
503 | abb8b3f4 | Thomas Schöpping | } |
504 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
|
505 | abb8b3f4 | Thomas Schöpping | |
506 | /*
|
||
507 | * Status LED
|
||
508 | */
|
||
509 | 4c72a54c | Thomas Schöpping | #include <module_test_LED.h> |
510 | static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
511 | abb8b3f4 | Thomas Schöpping | { |
512 | 4c72a54c | Thomas Schöpping | return moduleTestLedShellCb(stream, argc, argv, NULL); |
513 | abb8b3f4 | Thomas Schöpping | } |
514 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
|
515 | abb8b3f4 | Thomas Schöpping | |
516 | /*
|
||
517 | * LTC4412 (power path controller)
|
||
518 | */
|
||
519 | 4c72a54c | Thomas Schöpping | #include <module_test_LTC4412.h> |
520 | static int _testLtc4412ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
521 | abb8b3f4 | Thomas Schöpping | { |
522 | 4c72a54c | Thomas Schöpping | return moduleTestLtc4412ShellCb(stream, argc, argv, NULL); |
523 | abb8b3f4 | Thomas Schöpping | } |
524 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestLtc4412ShellCmd, "test:PowerPathController", _testLtc4412ShellCmdCb);
|
525 | abb8b3f4 | Thomas Schöpping | |
526 | /*
|
||
527 | * PCA9544A (I2C multiplexer)
|
||
528 | */
|
||
529 | 4c72a54c | Thomas Schöpping | #include <module_test_PCA9544A.h> |
530 | static int _testPca9544aShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
531 | abb8b3f4 | Thomas Schöpping | { |
532 | 4c72a54c | Thomas Schöpping | return moduleTestPca9544aShellCb(stream, argc, argv, NULL); |
533 | abb8b3f4 | Thomas Schöpping | } |
534 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestPca9544aShellCmd, "test:I2CMultiplexer", _testPca9544aShellCmdCb);
|
535 | abb8b3f4 | Thomas Schöpping | |
536 | /*
|
||
537 | * TPS62113 (step-down converter)
|
||
538 | */
|
||
539 | 4c72a54c | Thomas Schöpping | #include <module_test_TPS6211x.h> |
540 | static int _testTps6211xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
541 | abb8b3f4 | Thomas Schöpping | { |
542 | 4c72a54c | Thomas Schöpping | return moduleTestTps6211xShellCb(stream, argc, argv, NULL); |
543 | abb8b3f4 | Thomas Schöpping | } |
544 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestTps62113ShellCmd, "test:StepDownConverter", _testTps6211xShellCmdCb);
|
545 | abb8b3f4 | Thomas Schöpping | |
546 | /*
|
||
547 | * VCNL4020 (proximity sensor)
|
||
548 | */
|
||
549 | 4c72a54c | Thomas Schöpping | #include <module_test_VCNL4020.h> |
550 | static int _testVcnl4020ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
551 | abb8b3f4 | Thomas Schöpping | { |
552 | 4c72a54c | Thomas Schöpping | return moduleTestVcnl4020ShellCb(stream, argc, argv, NULL); |
553 | abb8b3f4 | Thomas Schöpping | } |
554 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestVcnl4020ShellCmd, "test:ProximitySensor", _testVcnl4020ShellCmdCb);
|
555 | |||
556 | /*
|
||
557 | * entire module
|
||
558 | */
|
||
559 | static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
560 | abb8b3f4 | Thomas Schöpping | { |
561 | 4c72a54c | Thomas Schöpping | (void)argc;
|
562 | (void)argv;
|
||
563 | |||
564 | int status = AOS_OK;
|
||
565 | char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL}; |
||
566 | aos_testresult_t result_test = {0, 0}; |
||
567 | aos_testresult_t result_total = {0, 0}; |
||
568 | |||
569 | /* A3906 (motor driver) */
|
||
570 | status |= moduleTestA3906ShellCb(stream, 0, targv, &result_test);
|
||
571 | result_total = aosTestResultAdd(result_total, result_test); |
||
572 | |||
573 | /* AT24C01B (EEPROM) */
|
||
574 | status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
|
||
575 | result_total = aosTestResultAdd(result_total, result_test); |
||
576 | |||
577 | // TODO: BNO055
|
||
578 | |||
579 | /* INA219 (power monitor) */
|
||
580 | status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
|
||
581 | result_total = aosTestResultAdd(result_total, result_test); |
||
582 | |||
583 | /* Status LED */
|
||
584 | status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
|
||
585 | result_total = aosTestResultAdd(result_total, result_test); |
||
586 | |||
587 | /* LTC4412 (power path controller) */
|
||
588 | status |= moduleTestLtc4412ShellCb(stream, 0, targv, &result_test);
|
||
589 | result_total = aosTestResultAdd(result_total, result_test); |
||
590 | |||
591 | /* PCA9544A (I2C multiplexer) */
|
||
592 | status |= moduleTestPca9544aShellCb(stream, 0, targv, &result_test);
|
||
593 | result_total = aosTestResultAdd(result_total, result_test); |
||
594 | |||
595 | /* TPS62113 (step-down converter) */
|
||
596 | status |= moduleTestTps6211xShellCb(stream, 0, targv, &result_test);
|
||
597 | result_total = aosTestResultAdd(result_total, result_test); |
||
598 | |||
599 | /* VCNL4020 (proximity sensor) */
|
||
600 | // wheel left
|
||
601 | targv[1] = "-wl"; |
||
602 | status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
|
||
603 | result_total = aosTestResultAdd(result_total, result_test); |
||
604 | // front left
|
||
605 | targv[1] = "-fl"; |
||
606 | status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
|
||
607 | result_total = aosTestResultAdd(result_total, result_test); |
||
608 | // front right
|
||
609 | targv[1] = "-fr"; |
||
610 | status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
|
||
611 | result_total = aosTestResultAdd(result_total, result_test); |
||
612 | // wheel right
|
||
613 | targv[1] = "-wr"; |
||
614 | status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
|
||
615 | result_total = aosTestResultAdd(result_total, result_test); |
||
616 | targv[1] = ""; |
||
617 | |||
618 | // print total result
|
||
619 | chprintf(stream, "\n");
|
||
620 | aosTestResultPrintSummary(stream, &result_total, "entire module");
|
||
621 | |||
622 | return status;
|
||
623 | abb8b3f4 | Thomas Schöpping | } |
624 | 4c72a54c | Thomas Schöpping | AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
|
625 | abb8b3f4 | Thomas Schöpping | |
626 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
||
627 | |||
628 | /** @} */
|
||
629 | /** @} */ |