amiro-os / modules / LightRing_1-2 / module.c @ a7e54ea4
History | View | Annotate | Download (21.797 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2020 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 LightRing v1.2 module.
|
22 |
*
|
23 |
* @addtogroup lightring_module
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include <amiroos.h> |
28 |
|
29 |
#include <string.h> |
30 |
|
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 moduleHalI2cEepromPwrmtrBreakoutConfig = { |
53 |
/* I²C mode */ OPMODE_I2C,
|
54 |
/* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
55 |
/* duty cycle */ FAST_DUTY_CYCLE_2,
|
56 |
}; |
57 |
|
58 |
SerialConfig moduleHalProgIfConfig = { |
59 |
/* bit rate */ 115200, |
60 |
/* CR1 */ 0, |
61 |
/* CR1 */ 0, |
62 |
/* CR1 */ 0, |
63 |
}; |
64 |
|
65 |
SPIConfig moduleHalSpiLightConfig = { |
66 |
/* circular buffer mode */ false, |
67 |
/* callback function pointer */ NULL, |
68 |
/* chip select line port */ PAL_PORT(LINE_LIGHT_XLAT),
|
69 |
/* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
|
70 |
/* CR1 */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
|
71 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
72 |
}; |
73 |
|
74 |
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
|
75 |
|
76 |
SPIConfig moduleHalSpiUwbHsConfig = { |
77 |
/* circular buffer mode */ false, |
78 |
/* callback function pointer */ NULL, |
79 |
/* chip select line port */ PAL_PORT(LINE_SPI_SS_N),
|
80 |
/* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
|
81 |
/* CR1 */ 0, // 36/2 Mbps |
82 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN, // 0 |
83 |
}; |
84 |
|
85 |
SPIConfig moduleHalSpiUwbLsConfig = { |
86 |
/* circular buffer mode */ false, |
87 |
/* callback function pointer */ NULL, |
88 |
/* chip select line port */ PAL_PORT(LINE_SPI_SS_N),
|
89 |
/* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
|
90 |
/* CR1 */ SPI_CR1_BR_1 | SPI_CR1_BR_0, // 36/16 Mbps |
91 |
/* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN, // 0 |
92 |
}; |
93 |
|
94 |
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */ |
95 |
|
96 |
/*===========================================================================*/
|
97 |
/**
|
98 |
* @name GPIO definitions
|
99 |
* @{
|
100 |
*/
|
101 |
/*===========================================================================*/
|
102 |
|
103 |
/**
|
104 |
* @brief LIGHT_BANK output signal GPIO.
|
105 |
*/
|
106 |
static apalGpio_t _gpioLightBlank = {
|
107 |
/* line */ LINE_LIGHT_BLANK,
|
108 |
}; |
109 |
ROMCONST apalControlGpio_t moduleGpioLightBlank = { |
110 |
/* GPIO */ &_gpioLightBlank,
|
111 |
/* meta */ {
|
112 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
113 |
/* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
114 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
115 |
}, |
116 |
}; |
117 |
|
118 |
/**
|
119 |
* @brief RS232_R_EN_N output signal GPIO.
|
120 |
*/
|
121 |
static apalGpio_t _gpioRs232En = {
|
122 |
/* line */ LINE_RS232_R_EN_N,
|
123 |
}; |
124 |
ROMCONST apalControlGpio_t moduleGpioRs232En = { |
125 |
/* GPIO */ &_gpioRs232En,
|
126 |
/* meta */ {
|
127 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
128 |
/* active state */ APAL_GPIO_ACTIVE_LOW, //TODO |
129 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
130 |
}, |
131 |
}; |
132 |
|
133 |
/**
|
134 |
* @brief SW_V33_EN output signal GPIO.
|
135 |
*/
|
136 |
static apalGpio_t _gpioSwV33En = {
|
137 |
/* line */ LINE_SW_V33_EN,
|
138 |
}; |
139 |
ROMCONST apalControlGpio_t moduleGpioSwV33En = { |
140 |
/* GPIO */ &_gpioSwV33En,
|
141 |
/* meta */ {
|
142 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
143 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
144 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
145 |
}, |
146 |
}; |
147 |
|
148 |
// The 4.2V switch is disabled due to a hardware bug.
|
149 |
///**
|
150 |
// * @brief SW_V42_EN output signal GPIO.
|
151 |
// */
|
152 |
//static apalGpio_t _gpioSwV42En = {
|
153 |
// /* line */ LINE_SW_V42_EN,
|
154 |
//};
|
155 |
//ROMCONST apalControlGpio_t moduleGpioSwV42En = {
|
156 |
// /* GPIO */ &_gpioSwV42En,
|
157 |
// /* meta */ {
|
158 |
// /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
159 |
// /* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
160 |
// /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
161 |
// },
|
162 |
//};
|
163 |
|
164 |
/**
|
165 |
* @brief SW_V50_EN output signal GPIO.
|
166 |
*/
|
167 |
static apalGpio_t _gpioSwV50En = {
|
168 |
/* line */ LINE_SW_V50_EN,
|
169 |
}; |
170 |
ROMCONST apalControlGpio_t moduleGpioSwV50En = { |
171 |
/* GPIO */ &_gpioSwV50En,
|
172 |
/* meta */ {
|
173 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
174 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
175 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
176 |
}, |
177 |
}; |
178 |
|
179 |
/**
|
180 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
181 |
*/
|
182 |
static apalGpio_t _gpioSysUartDn = {
|
183 |
/* line */ LINE_SYS_UART_DN,
|
184 |
}; |
185 |
ROMCONST apalControlGpio_t moduleGpioSysUartDn = { |
186 |
/* GPIO */ &_gpioSysUartDn,
|
187 |
/* meta */ {
|
188 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
189 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
190 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
191 |
}, |
192 |
}; |
193 |
|
194 |
/**
|
195 |
* @brief LED output signal GPIO.
|
196 |
*/
|
197 |
static apalGpio_t _gpioLed = {
|
198 |
/* line */ LINE_LED,
|
199 |
}; |
200 |
ROMCONST apalControlGpio_t moduleGpioLed = { |
201 |
/* GPIO */ &_gpioLed,
|
202 |
/* meta */ {
|
203 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
204 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
205 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
206 |
}, |
207 |
}; |
208 |
|
209 |
/**
|
210 |
* @brief LIGHT_XLAT output signal GPIO.
|
211 |
*/
|
212 |
static apalGpio_t _gpioLightXlat = {
|
213 |
/* line */ LINE_LIGHT_XLAT,
|
214 |
}; |
215 |
ROMCONST apalControlGpio_t moduleGpioLightXlat = { |
216 |
/* GPIO */ &_gpioLightXlat,
|
217 |
/* meta */ {
|
218 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
219 |
/* active state */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
220 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
221 |
}, |
222 |
}; |
223 |
|
224 |
/**
|
225 |
* @brief SW_V18_EN output signal GPIO.
|
226 |
*/
|
227 |
static apalGpio_t _gpioSwV18En = {
|
228 |
/* line */ LINE_SW_V18_EN,
|
229 |
}; |
230 |
ROMCONST apalControlGpio_t moduleGpioSwV18En = { |
231 |
/* GPIO */ &_gpioSwV18En,
|
232 |
/* meta */ {
|
233 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
234 |
/* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
235 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
236 |
}, |
237 |
}; |
238 |
|
239 |
/**
|
240 |
* @brief SW_VSYS_EN output signal GPIO.
|
241 |
*/
|
242 |
static apalGpio_t _gpioSwVsysEn = {
|
243 |
/* line */ LINE_SW_VSYS_EN,
|
244 |
}; |
245 |
ROMCONST apalControlGpio_t moduleGpioSwVsysEn = { |
246 |
/* GPIO */ &_gpioSwVsysEn,
|
247 |
/* meta */ {
|
248 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
249 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
250 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
251 |
}, |
252 |
}; |
253 |
|
254 |
/**
|
255 |
* @brief SYS_UART_UP bidirectional signal GPIO.
|
256 |
*/
|
257 |
static apalGpio_t _gpioSysUartUp = {
|
258 |
/* line */ LINE_SYS_UART_UP,
|
259 |
}; |
260 |
ROMCONST apalControlGpio_t moduleGpioSysUartUp = { |
261 |
/* GPIO */ &_gpioSysUartUp,
|
262 |
/* meta */ {
|
263 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
264 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
265 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
266 |
}, |
267 |
}; |
268 |
|
269 |
/**
|
270 |
* @brief SYS_PD bidirectional signal GPIO.
|
271 |
*/
|
272 |
static apalGpio_t _gpioSysPd = {
|
273 |
/* line */ LINE_SYS_PD_N,
|
274 |
}; |
275 |
ROMCONST apalControlGpio_t moduleGpioSysPd = { |
276 |
/* GPIO */ &_gpioSysPd,
|
277 |
/* meta */ {
|
278 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
279 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
280 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
281 |
}, |
282 |
}; |
283 |
|
284 |
/**
|
285 |
* @brief SYS_SYNC bidirectional signal GPIO.
|
286 |
*/
|
287 |
static apalGpio_t _gpioSysSync = {
|
288 |
/* line */ LINE_SYS_INT_N,
|
289 |
}; |
290 |
ROMCONST apalControlGpio_t moduleGpioSysSync = { |
291 |
/* GPIO */ &_gpioSysSync,
|
292 |
/* meta */ {
|
293 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
294 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
295 |
/* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
296 |
}, |
297 |
}; |
298 |
|
299 |
/**
|
300 |
* @brief IO_1 breakout signal GPIO.
|
301 |
*/
|
302 |
static apalGpio_t _gpioBreakoutIo1 = {
|
303 |
/* line */ LINE_IO_1,
|
304 |
}; |
305 |
|
306 |
/**
|
307 |
* @brief IO_2 breakout signal GPIO.
|
308 |
*/
|
309 |
static apalGpio_t _gpioBreakoutIo2 = {
|
310 |
/* line */ LINE_IO_2,
|
311 |
}; |
312 |
|
313 |
/**
|
314 |
* @brief IO_3 breakout signal GPIO.
|
315 |
*/
|
316 |
static apalGpio_t _gpioBreakoutIo3 = {
|
317 |
/* line */ LINE_IO_3,
|
318 |
}; |
319 |
|
320 |
/**
|
321 |
* @brief IO_4 breakout signal GPIO.
|
322 |
*/
|
323 |
static apalGpio_t _gpioBreakoutIo4 = {
|
324 |
/* line */ LINE_IO_4,
|
325 |
}; |
326 |
|
327 |
/**
|
328 |
* @brief IO_5 breakout signal GPIO.
|
329 |
*/
|
330 |
static apalGpio_t _gpioBreakoutIo5 = {
|
331 |
/* line */ LINE_IO_5,
|
332 |
}; |
333 |
|
334 |
/**
|
335 |
* @brief IO_6 breakout signal GPIO.
|
336 |
*/
|
337 |
static apalGpio_t _gpioBreakoutIo6 = {
|
338 |
/* line */ LINE_IO_6,
|
339 |
}; |
340 |
|
341 |
/**
|
342 |
* @brief IO_7 breakout signal GPIO.
|
343 |
*/
|
344 |
static apalGpio_t _gpioBreakoutIo7 = {
|
345 |
/* line */ LINE_IO_7,
|
346 |
}; |
347 |
|
348 |
/**
|
349 |
* @brief IO_8 breakout signal GPIO.
|
350 |
*/
|
351 |
static apalGpio_t _gpioBreakoutIo8 = {
|
352 |
/* line */ LINE_IO_8,
|
353 |
}; |
354 |
|
355 |
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_NONE)
|
356 |
|
357 |
apalControlGpio_t moduleGpioBreakoutIo1 = { |
358 |
/* GPIO */ &_gpioBreakoutIo1,
|
359 |
/* meta */ {
|
360 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
361 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
362 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
363 |
}, |
364 |
}; |
365 |
|
366 |
apalControlGpio_t moduleGpioBreakoutIo2 = { |
367 |
/* GPIO */ &_gpioBreakoutIo2,
|
368 |
/* meta */ {
|
369 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
370 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
371 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
372 |
}, |
373 |
}; |
374 |
|
375 |
apalControlGpio_t moduleGpioBreakoutIo3 = { |
376 |
/* GPIO */ &_gpioBreakoutIo3,
|
377 |
/* meta */ {
|
378 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
379 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
380 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
381 |
}, |
382 |
}; |
383 |
|
384 |
apalControlGpio_t moduleGpioBreakoutIo4 = { |
385 |
/* GPIO */ &_gpioBreakoutIo4,
|
386 |
/* meta */ {
|
387 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
388 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
389 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
390 |
}, |
391 |
}; |
392 |
|
393 |
apalControlGpio_t moduleGpioBreakoutIo5 = { |
394 |
/* GPIO */ &_gpioBreakoutIo5,
|
395 |
/* meta */ {
|
396 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
397 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
398 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
399 |
}, |
400 |
}; |
401 |
|
402 |
apalControlGpio_t moduleGpioBreakoutIo6 = { |
403 |
/* GPIO */ &_gpioBreakoutIo6,
|
404 |
/* meta */ {
|
405 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
406 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
407 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
408 |
}, |
409 |
}; |
410 |
|
411 |
apalControlGpio_t moduleGpioBreakoutIo7 = { |
412 |
/* GPIO */ &_gpioBreakoutIo7,
|
413 |
/* meta */ {
|
414 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
415 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
416 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
417 |
}, |
418 |
}; |
419 |
|
420 |
apalControlGpio_t moduleGpioBreakoutIo8 = { |
421 |
/* GPIO */ &_gpioBreakoutIo8,
|
422 |
/* meta */ {
|
423 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
424 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
425 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
426 |
}, |
427 |
}; |
428 |
|
429 |
#elif (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
|
430 |
|
431 |
apalControlGpio_t moduleGpioBreakoutIo1 = { |
432 |
/* GPIO */ &_gpioBreakoutIo1,
|
433 |
/* meta */ {
|
434 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
435 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
436 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
437 |
}, |
438 |
}; |
439 |
|
440 |
apalControlGpio_t moduleGpioBreakoutIo2 = { |
441 |
/* GPIO */ &_gpioBreakoutIo2,
|
442 |
/* meta */ {
|
443 |
/* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
444 |
/* active state */ APAL_GPIO_ACTIVE_HIGH,
|
445 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
446 |
}, |
447 |
}; |
448 |
|
449 |
apalControlGpio_t moduleGpioBreakoutIo3 = { |
450 |
/* GPIO */ &_gpioBreakoutIo3,
|
451 |
/* meta */ {
|
452 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
453 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
454 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
455 |
}, |
456 |
}; |
457 |
|
458 |
apalControlGpio_t moduleGpioBreakoutIo4 = { |
459 |
/* GPIO */ &_gpioBreakoutIo4,
|
460 |
/* meta */ {
|
461 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
462 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
463 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
464 |
}, |
465 |
}; |
466 |
|
467 |
apalControlGpio_t moduleGpioBreakoutIo5 = { |
468 |
/* GPIO */ &_gpioBreakoutIo5,
|
469 |
/* meta */ {
|
470 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
471 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
472 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
473 |
}, |
474 |
}; |
475 |
|
476 |
apalControlGpio_t moduleGpioBreakoutIo6 = { |
477 |
/* GPIO */ &_gpioBreakoutIo6,
|
478 |
/* meta */ {
|
479 |
/* direction */ APAL_GPIO_DIRECTION_UNDEFINED,
|
480 |
/* active state */ APAL_GPIO_ACTIVE_NONE,
|
481 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
482 |
}, |
483 |
}; |
484 |
|
485 |
apalControlGpio_t moduleGpioBreakoutIo7 = { |
486 |
/* GPIO */ &_gpioBreakoutIo7,
|
487 |
/* meta */ {
|
488 |
/* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
489 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
490 |
/* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
491 |
}, |
492 |
}; |
493 |
|
494 |
apalControlGpio_t moduleGpioBreakoutIo8 = { |
495 |
/* GPIO */ &_gpioBreakoutIo8,
|
496 |
/* meta */ {
|
497 |
/* direction */ APAL_GPIO_DIRECTION_INPUT,
|
498 |
/* active state */ APAL_GPIO_ACTIVE_LOW,
|
499 |
/* interrupt edge */ APAL_GPIO_EDGE_RISING,
|
500 |
}, |
501 |
}; |
502 |
|
503 |
#endif
|
504 |
|
505 |
/** @} */
|
506 |
|
507 |
/*===========================================================================*/
|
508 |
/**
|
509 |
* @name AMiRo-OS core configurations
|
510 |
* @{
|
511 |
*/
|
512 |
/*===========================================================================*/
|
513 |
|
514 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
515 |
ROMCONST char* moduleShellPrompt = "LightRing"; |
516 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
517 |
|
518 |
/** @} */
|
519 |
|
520 |
/*===========================================================================*/
|
521 |
/**
|
522 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
523 |
* @{
|
524 |
*/
|
525 |
/*===========================================================================*/
|
526 |
|
527 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__) |
528 |
|
529 |
/* some local definitions */
|
530 |
// maximum number of bytes per CAN frame
|
531 |
#define CAN_BYTES_PER_FRAME 8 |
532 |
// identifier (as dominant as possible)
|
533 |
#define MSI_BCBMSG_CANID 0 |
534 |
|
535 |
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
|
536 |
{ |
537 |
aosDbgCheck(buffer != NULL);
|
538 |
aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
|
539 |
|
540 |
// local variables
|
541 |
CANTxFrame frame; |
542 |
|
543 |
// setup the common parts of the message frame
|
544 |
frame.DLC = (uint8_t)length; |
545 |
frame.RTR = CAN_RTR_DATA; |
546 |
frame.IDE = CAN_IDE_STD; |
547 |
frame.SID = MSI_BCBMSG_CANID; |
548 |
memcpy(frame.data8, buffer, length); |
549 |
|
550 |
// sent the frame and return
|
551 |
return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
|
552 |
} |
553 |
|
554 |
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length) |
555 |
{ |
556 |
aosDbgCheck(buffer != NULL);
|
557 |
aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
|
558 |
|
559 |
// local variables
|
560 |
CANRxFrame frame; |
561 |
|
562 |
// receive a frame and check for errors
|
563 |
if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
|
564 |
// a correct frame was received
|
565 |
if (frame.DLC == length &&
|
566 |
frame.RTR == CAN_RTR_DATA && |
567 |
frame.IDE == CAN_IDE_STD && |
568 |
frame.SID == MSI_BCBMSG_CANID) { |
569 |
// success: fetch the data and return
|
570 |
memcpy(buffer, frame.data8, length); |
571 |
return AOS_SSSP_BCB_SUCCESS;
|
572 |
} |
573 |
// an unexpected frame was received
|
574 |
else {
|
575 |
return AOS_SSSP_BCB_INVALIDMSG;
|
576 |
} |
577 |
} else {
|
578 |
// failure: return with error
|
579 |
return AOS_SSSP_BCB_ERROR;
|
580 |
} |
581 |
} |
582 |
|
583 |
#undef MSI_BCBMSG_CANID
|
584 |
#undef CAN_BYTES_PER_FRAME
|
585 |
|
586 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */ |
587 |
|
588 |
/** @} */
|
589 |
|
590 |
/*===========================================================================*/
|
591 |
/**
|
592 |
* @name Low-level drivers
|
593 |
* @{
|
594 |
*/
|
595 |
/*===========================================================================*/
|
596 |
|
597 |
AT24C01BDriver moduleLldEeprom = { |
598 |
/* I2C driver */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
|
599 |
/* I2C address */ 0x00u, |
600 |
}; |
601 |
|
602 |
INA219Driver moduleLldPowerMonitorVled = { |
603 |
/* I2C Driver */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
|
604 |
/* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
605 |
/* current LSB (uA) */ 0x00u, |
606 |
/* configuration */ NULL, |
607 |
}; |
608 |
|
609 |
LEDDriver moduleLldStatusLed = { |
610 |
/* LED enable Gpio */ &moduleGpioLed,
|
611 |
}; |
612 |
|
613 |
MIC9404xDriver moduleLldPowerSwitchV18 = { |
614 |
/* power enable GPIO */ &moduleGpioSwV18En,
|
615 |
}; |
616 |
|
617 |
MIC9404xDriver moduleLldPowerSwitchV33 = { |
618 |
/* power enable GPIO */ &moduleGpioSwV33En,
|
619 |
}; |
620 |
|
621 |
// The 4.2V switch is disabled due to a hardware bug.
|
622 |
//MIC9404xDriver moduleLldPowerSwitchV42 = {
|
623 |
// /* power enable GPIO */ &moduleGpioSwV42En,
|
624 |
//};
|
625 |
|
626 |
MIC9404xDriver moduleLldPowerSwitchV50 = { |
627 |
/* power enable GPIO */ &moduleGpioSwV50En,
|
628 |
}; |
629 |
|
630 |
MIC9404xDriver moduleLldPowerSwitchVsys = { |
631 |
/* power enable GPIO */ &moduleGpioSwVsysEn,
|
632 |
}; |
633 |
|
634 |
// TODO: add SNx5C3221E
|
635 |
|
636 |
TLC5947Driver moduleLldLedPwm = { |
637 |
/* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
638 |
/* BLANK signal GPIO */ &moduleGpioLightBlank,
|
639 |
/* XLAT signal GPIO */ &moduleGpioLightXlat,
|
640 |
}; |
641 |
|
642 |
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
|
643 |
|
644 |
DW1000Driver moduleLldDw1000 = { |
645 |
/* SPI driver */ &MODULE_HAL_SPI_UWB,
|
646 |
/* interrupt GPIO */ &moduleGpioBreakoutIo8,
|
647 |
/* reset GPIO */ &moduleGpioBreakoutIo7,
|
648 |
}; |
649 |
|
650 |
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */ |
651 |
|
652 |
/** @} */
|
653 |
|
654 |
/*===========================================================================*/
|
655 |
/**
|
656 |
* @name Tests
|
657 |
* @{
|
658 |
*/
|
659 |
/*===========================================================================*/
|
660 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
661 |
|
662 |
/*
|
663 |
* AT24C01BN-SH-B (EEPROM)
|
664 |
*/
|
665 |
#include <module_test_AT24C01B.h> |
666 |
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
667 |
{ |
668 |
return moduleTestAt24c01bShellCb(stream, argc, argv, NULL); |
669 |
} |
670 |
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
|
671 |
|
672 |
/*
|
673 |
* INA219 (power monitor)
|
674 |
*/
|
675 |
#include <module_test_INA219.h> |
676 |
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
677 |
{ |
678 |
return moduleTestIna219ShellCb(stream, argc, argv, NULL); |
679 |
} |
680 |
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
|
681 |
|
682 |
/*
|
683 |
* Status LED
|
684 |
*/
|
685 |
#include <module_test_LED.h> |
686 |
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
687 |
{ |
688 |
return moduleTestLedShellCb(stream, argc, argv, NULL); |
689 |
} |
690 |
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
|
691 |
|
692 |
/*
|
693 |
* MIC9404x (power switch)
|
694 |
*/
|
695 |
#include <module_test_MIC9404x.h> |
696 |
static int _testMic9404xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
697 |
{ |
698 |
return moduleTestMic9404xShellCb(stream, argc, argv, NULL); |
699 |
} |
700 |
AOS_SHELL_COMMAND(moduleTestMic9404xShellCmd, "test:PowerSwitch", _testMic9404xShellCmdCb);
|
701 |
|
702 |
// TODO: add SNx5C3221E
|
703 |
|
704 |
/*
|
705 |
* TLC5947 (24 channel PWM LED driver)
|
706 |
*/
|
707 |
#include <module_test_TLC5947.h> |
708 |
static int _testTlc5947ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
709 |
{ |
710 |
return moduleTestTlc5947ShellCb(stream, argc, argv, NULL); |
711 |
} |
712 |
AOS_SHELL_COMMAND(moduleTestTlc5947ShellCmd, "test:Lights", _testTlc5947ShellCmdCb);
|
713 |
|
714 |
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
|
715 |
|
716 |
/*
|
717 |
* UwB Driver (DW1000)
|
718 |
*/
|
719 |
#include <module_test_DW1000.h> |
720 |
static int _testDw1000ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
721 |
{ |
722 |
return moduleTestDw1000ShellCb(stream, argc, argv, NULL); |
723 |
} |
724 |
AOS_SHELL_COMMAND(moduleTestDw1000ShellCmd, "test:DW1000", _testDw1000ShellCmdCb);
|
725 |
|
726 |
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */ |
727 |
|
728 |
/*
|
729 |
* entire module
|
730 |
*/
|
731 |
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
732 |
{ |
733 |
(void)argc;
|
734 |
(void)argv;
|
735 |
|
736 |
int status = AOS_OK;
|
737 |
char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL}; |
738 |
aos_testresult_t result_test = {0, 0}; |
739 |
aos_testresult_t result_total = {0, 0}; |
740 |
|
741 |
/* AT24C01B (EEPROM) */
|
742 |
status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
|
743 |
result_total = aosTestResultAdd(result_total, result_test); |
744 |
|
745 |
/* INA219 (power monitor) */
|
746 |
status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
|
747 |
result_total = aosTestResultAdd(result_total, result_test); |
748 |
|
749 |
/* Status LED */
|
750 |
status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
|
751 |
result_total = aosTestResultAdd(result_total, result_test); |
752 |
|
753 |
/* MIC9404x (power switch) */
|
754 |
// 1.8V
|
755 |
targv[1] = "1.8V"; |
756 |
status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
|
757 |
result_total = aosTestResultAdd(result_total, result_test); |
758 |
// 3.3V
|
759 |
targv[1] = "3.3V"; |
760 |
status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
|
761 |
result_total = aosTestResultAdd(result_total, result_test); |
762 |
// The 4.2V switch is disabled due to a hardware bug.
|
763 |
// // 4.2V
|
764 |
// targv[1] = "4.2V";
|
765 |
// status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
|
766 |
// result_total = aosTestResultAdd(result_total, result_test);
|
767 |
// 5.0V
|
768 |
targv[1] = "5.0V"; |
769 |
status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
|
770 |
result_total = aosTestResultAdd(result_total, result_test); |
771 |
//VSYS
|
772 |
targv[1] = "VSYS"; |
773 |
status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
|
774 |
result_total = aosTestResultAdd(result_total, result_test); |
775 |
targv[1] = ""; |
776 |
|
777 |
// TODO: add SNx5C3221E
|
778 |
|
779 |
/* TLC5947 (24 channel PWM LED driver) */
|
780 |
status |= moduleTestTlc5947ShellCb(stream, 0, targv, &result_test);
|
781 |
result_total = aosTestResultAdd(result_total, result_test); |
782 |
|
783 |
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
|
784 |
/* DW1000 (UWB transceiver) */
|
785 |
status |= moduleTestDw1000ShellCb(stream, 0, targv, &result_test);
|
786 |
result_total = aosTestResultAdd(result_total, result_test); |
787 |
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */ |
788 |
|
789 |
// print total result
|
790 |
chprintf(stream, "\n");
|
791 |
aosTestResultPrintSummary(stream, &result_total, "entire module");
|
792 |
|
793 |
return status;
|
794 |
} |
795 |
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
|
796 |
|
797 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
798 |
|
799 |
/** @} */
|
800 |
/** @} */
|