Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.c @ c7cd988c

History | View | Annotate | Download (21.8 KB)

1 9ae7c4f3 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 034cb15a Thomas Schöpping
 * @brief   Structures and constant for the LightRing v1.2 module.
22 9ae7c4f3 Thomas Schöpping
 *
23
 * @addtogroup lightring_module
24
 * @{
25
 */
26
27 c53ef0b1 Thomas Schöpping
#include <amiroos.h>
28
29
#include <string.h>
30 9ae7c4f3 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 ee884101 Thomas Schöpping
I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig = {
53 9ae7c4f3 Thomas Schöpping
  /* 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 3106e8cc Thomas Schöpping
  /* chip select line port       */ PAL_PORT(LINE_LIGHT_XLAT),
69
  /* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
70 9ae7c4f3 Thomas Schöpping
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
71
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
72
};
73
74 f606f432 Thomas Schöpping
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
75 0b989911 Cung Sang
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 f606f432 Thomas Schöpping
85 0b989911 Cung Sang
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 f606f432 Thomas Schöpping
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
95 9ae7c4f3 Thomas Schöpping
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 3106e8cc Thomas Schöpping
  /* line */ LINE_LIGHT_BLANK,
108 9ae7c4f3 Thomas Schöpping
};
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 3106e8cc Thomas Schöpping
  /* line */ LINE_RS232_R_EN_N,
123 9ae7c4f3 Thomas Schöpping
};
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 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V33_EN,
138 9ae7c4f3 Thomas Schöpping
};
139
ROMCONST apalControlGpio_t moduleGpioSwV33En = {
140
  /* GPIO */ &_gpioSwV33En,
141
  /* meta */ {
142
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
143 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
144 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
145
  },
146
};
147
148 9acb8326 Thomas Schöpping
// 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 9ae7c4f3 Thomas Schöpping
164
/**
165
 * @brief   SW_V50_EN output signal GPIO.
166
 */
167
static apalGpio_t _gpioSwV50En = {
168 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V50_EN,
169 9ae7c4f3 Thomas Schöpping
};
170
ROMCONST apalControlGpio_t moduleGpioSwV50En = {
171
  /* GPIO */ &_gpioSwV50En,
172
  /* meta */ {
173
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
174 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
175 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
176
  },
177
};
178
179
/**
180 f606f432 Thomas Schöpping
 * @brief   SYS_UART_DN bidirectional signal GPIO.
181 9ae7c4f3 Thomas Schöpping
 */
182 f606f432 Thomas Schöpping
static apalGpio_t _gpioSysUartDn = {
183
  /* line */ LINE_SYS_UART_DN,
184 9ae7c4f3 Thomas Schöpping
};
185 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
186
  /* GPIO */ &_gpioSysUartDn,
187 9ae7c4f3 Thomas Schöpping
  /* meta */ {
188 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
189 9ae7c4f3 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
190 f606f432 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
191 9ae7c4f3 Thomas Schöpping
  },
192
};
193
194
/**
195 f606f432 Thomas Schöpping
 * @brief   LED output signal GPIO.
196 9ae7c4f3 Thomas Schöpping
 */
197 f606f432 Thomas Schöpping
static apalGpio_t _gpioLed = {
198
  /* line */ LINE_LED,
199 9ae7c4f3 Thomas Schöpping
};
200 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
201
  /* GPIO */ &_gpioLed,
202 9ae7c4f3 Thomas Schöpping
  /* meta */ {
203 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
204 9ae7c4f3 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
205
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
206
  },
207
};
208
209
/**
210 f606f432 Thomas Schöpping
 * @brief   LIGHT_XLAT output signal GPIO.
211 9ae7c4f3 Thomas Schöpping
 */
212 f606f432 Thomas Schöpping
static apalGpio_t _gpioLightXlat = {
213
  /* line */ LINE_LIGHT_XLAT,
214 9ae7c4f3 Thomas Schöpping
};
215 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
216
  /* GPIO */ &_gpioLightXlat,
217 9ae7c4f3 Thomas Schöpping
  /* meta */ {
218 f606f432 Thomas Schöpping
    /* 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 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
221
  },
222
};
223
224
/**
225 f606f432 Thomas Schöpping
 * @brief   SW_V18_EN output signal GPIO.
226 9ae7c4f3 Thomas Schöpping
 */
227 f606f432 Thomas Schöpping
static apalGpio_t _gpioSwV18En = {
228
  /* line */ LINE_SW_V18_EN,
229 9ae7c4f3 Thomas Schöpping
};
230 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSwV18En = {
231
  /* GPIO */ &_gpioSwV18En,
232 9ae7c4f3 Thomas Schöpping
  /* meta */ {
233 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
234
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
235
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
236 9ae7c4f3 Thomas Schöpping
  },
237
};
238
239
/**
240 f606f432 Thomas Schöpping
 * @brief   SW_VSYS_EN output signal GPIO.
241 9ae7c4f3 Thomas Schöpping
 */
242 f606f432 Thomas Schöpping
static apalGpio_t _gpioSwVsysEn = {
243
  /* line */ LINE_SW_VSYS_EN,
244 0b989911 Cung Sang
};
245 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSwVsysEn = {
246
  /* GPIO */ &_gpioSwVsysEn,
247 0b989911 Cung Sang
  /* meta */ {
248 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
249
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
250
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
251 0b989911 Cung Sang
  },
252
};
253
254
/**
255 f606f432 Thomas Schöpping
 * @brief   SYS_UART_UP bidirectional signal GPIO.
256 0b989911 Cung Sang
 */
257 f606f432 Thomas Schöpping
static apalGpio_t _gpioSysUartUp = {
258
  /* line */ LINE_SYS_UART_UP,
259 9ae7c4f3 Thomas Schöpping
};
260 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
261
  /* GPIO */ &_gpioSysUartUp,
262 9ae7c4f3 Thomas Schöpping
  /* meta */ {
263 0b989911 Cung Sang
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
264 9ae7c4f3 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
265 f606f432 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
266 9ae7c4f3 Thomas Schöpping
  },
267
};
268
269
/**
270 f606f432 Thomas Schöpping
 * @brief   SYS_PD bidirectional signal GPIO.
271 0b989911 Cung Sang
 */
272 f606f432 Thomas Schöpping
static apalGpio_t _gpioSysPd = {
273
  /* line */ LINE_SYS_PD_N,
274 0b989911 Cung Sang
};
275 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysPd = {
276
  /* GPIO */ &_gpioSysPd,
277 0b989911 Cung Sang
  /* meta */ {
278 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
279
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
280
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
281 0b989911 Cung Sang
  },
282
};
283
284
/**
285 f606f432 Thomas Schöpping
 * @brief   SYS_SYNC bidirectional signal GPIO.
286 0b989911 Cung Sang
 */
287 f606f432 Thomas Schöpping
static apalGpio_t _gpioSysSync = {
288
  /* line */ LINE_SYS_INT_N,
289 0b989911 Cung Sang
};
290 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysSync = {
291
  /* GPIO */ &_gpioSysSync,
292 0b989911 Cung Sang
  /* meta */ {
293 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
294 0b989911 Cung Sang
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
295 f606f432 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
296 0b989911 Cung Sang
  },
297
};
298 f606f432 Thomas Schöpping
299 0b989911 Cung Sang
/**
300 f606f432 Thomas Schöpping
 * @brief   IO_1 breakout signal GPIO.
301 9ae7c4f3 Thomas Schöpping
 */
302 f606f432 Thomas Schöpping
static apalGpio_t _gpioBreakoutIo1 = {
303
  /* line */ LINE_IO_1,
304 9ae7c4f3 Thomas Schöpping
};
305 f606f432 Thomas Schöpping
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 9ae7c4f3 Thomas Schöpping
};
340
341
/**
342 0b989911 Cung Sang
 * @brief   IO_7 breakout signal GPIO.
343
 */
344
static apalGpio_t _gpioBreakoutIo7 = {
345
  /* line */ LINE_IO_7,
346
};
347 f606f432 Thomas Schöpping
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 0b989911 Cung Sang
  /* meta */ {
360
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
361 f606f432 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
362 0b989911 Cung Sang
    /* 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 f606f432 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
371 0b989911 Cung Sang
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
372
  },
373
};
374
375 f606f432 Thomas Schöpping
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 9ae7c4f3 Thomas Schöpping
};
383 f606f432 Thomas Schöpping
384 9ae7c4f3 Thomas Schöpping
apalControlGpio_t moduleGpioBreakoutIo4 = {
385
  /* GPIO */ &_gpioBreakoutIo4,
386
  /* meta */ {
387
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
388 f606f432 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
389 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
390
  },
391
};
392
393 f606f432 Thomas Schöpping
apalControlGpio_t moduleGpioBreakoutIo5 = {
394
  /* GPIO */ &_gpioBreakoutIo5,
395 9ae7c4f3 Thomas Schöpping
  /* meta */ {
396
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
397 f606f432 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
398 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
399
  },
400
};
401
402 f606f432 Thomas Schöpping
apalControlGpio_t moduleGpioBreakoutIo6 = {
403
  /* GPIO */ &_gpioBreakoutIo6,
404 9ae7c4f3 Thomas Schöpping
  /* meta */ {
405 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
406
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
407 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
408
  },
409
};
410
411 f606f432 Thomas Schöpping
apalControlGpio_t moduleGpioBreakoutIo7 = {
412
  /* GPIO */ &_gpioBreakoutIo7,
413 c930aa01 Thomas Schöpping
  /* meta */ {
414 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
415
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
416 c930aa01 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
417
  },
418
};
419
420 f606f432 Thomas Schöpping
apalControlGpio_t moduleGpioBreakoutIo8 = {
421
  /* GPIO */ &_gpioBreakoutIo8,
422 9ae7c4f3 Thomas Schöpping
  /* meta */ {
423 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
424
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
425 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
426
  },
427
};
428
429 f606f432 Thomas Schöpping
#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 9ae7c4f3 Thomas Schöpping
};
439 f606f432 Thomas Schöpping
440
apalControlGpio_t moduleGpioBreakoutIo2 = {
441
  /* GPIO */ &_gpioBreakoutIo2,
442 9ae7c4f3 Thomas Schöpping
  /* meta */ {
443
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
444 ee884101 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
445 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
446
  },
447
};
448
449 f606f432 Thomas Schöpping
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 9ae7c4f3 Thomas Schöpping
};
457 f606f432 Thomas Schöpping
458
apalControlGpio_t moduleGpioBreakoutIo4 = {
459
  /* GPIO */ &_gpioBreakoutIo4,
460 9ae7c4f3 Thomas Schöpping
  /* meta */ {
461 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
462
    /* active state   */ APAL_GPIO_ACTIVE_NONE,
463
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
464 9ae7c4f3 Thomas Schöpping
  },
465
};
466
467 f606f432 Thomas Schöpping
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 9ae7c4f3 Thomas Schöpping
};
475 f606f432 Thomas Schöpping
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 9ae7c4f3 Thomas Schöpping
  /* meta */ {
488
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
489
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
490 f606f432 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
491 9ae7c4f3 Thomas Schöpping
  },
492
};
493
494 f606f432 Thomas Schöpping
apalControlGpio_t moduleGpioBreakoutIo8 = {
495
  /* GPIO */ &_gpioBreakoutIo8,
496 9ae7c4f3 Thomas Schöpping
  /* meta */ {
497 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
498 9ae7c4f3 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
499 f606f432 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_RISING,
500 9ae7c4f3 Thomas Schöpping
  },
501
};
502
503 f606f432 Thomas Schöpping
#endif
504
505 9ae7c4f3 Thomas Schöpping
/** @} */
506
507
/*===========================================================================*/
508
/**
509
 * @name AMiRo-OS core configurations
510
 * @{
511
 */
512
/*===========================================================================*/
513
514 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
515 9ae7c4f3 Thomas Schöpping
ROMCONST char* moduleShellPrompt = "LightRing";
516 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
517 9ae7c4f3 Thomas Schöpping
518
/** @} */
519
520
/*===========================================================================*/
521
/**
522
 * @name Startup Shutdown Synchronization Protocol (SSSP)
523
 * @{
524
 */
525
/*===========================================================================*/
526
527 c53ef0b1 Thomas Schöpping
#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 9ae7c4f3 Thomas Schöpping
/** @} */
589
590
/*===========================================================================*/
591
/**
592
 * @name Low-level drivers
593
 * @{
594
 */
595
/*===========================================================================*/
596
597
AT24C01BDriver moduleLldEeprom = {
598 ee884101 Thomas Schöpping
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
599 9ae7c4f3 Thomas Schöpping
  /* I2C address  */ 0x00u,
600
};
601
602 ee884101 Thomas Schöpping
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 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
622
//MIC9404xDriver moduleLldPowerSwitchV42 = {
623
//  /* power enable GPIO  */ &moduleGpioSwV42En,
624
//};
625 ee884101 Thomas Schöpping
626
MIC9404xDriver moduleLldPowerSwitchV50 = {
627
  /* power enable GPIO  */ &moduleGpioSwV50En,
628
};
629
630
MIC9404xDriver moduleLldPowerSwitchVsys = {
631
  /* power enable GPIO  */ &moduleGpioSwVsysEn,
632
};
633
634 4c72a54c Thomas Schöpping
// TODO: add SNx5C3221E
635
636 9ae7c4f3 Thomas Schöpping
TLC5947Driver moduleLldLedPwm = {
637
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
638
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
639 c930aa01 Thomas Schöpping
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
640 9ae7c4f3 Thomas Schöpping
};
641
642 f606f432 Thomas Schöpping
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
643
644 0b989911 Cung Sang
DW1000Driver moduleLldDw1000 = {
645 f606f432 Thomas Schöpping
  /* SPI driver     */ &MODULE_HAL_SPI_UWB,
646
  /* interrupt GPIO */ &moduleGpioBreakoutIo8,
647
  /* reset GPIO     */ &moduleGpioBreakoutIo7,
648 0b989911 Cung Sang
};
649
650 f606f432 Thomas Schöpping
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
651 0b989911 Cung Sang
652 9ae7c4f3 Thomas Schöpping
/** @} */
653
654
/*===========================================================================*/
655
/**
656 4c72a54c Thomas Schöpping
 * @name Tests
657 9ae7c4f3 Thomas Schöpping
 * @{
658
 */
659
/*===========================================================================*/
660
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
661
662
/*
663 4c72a54c Thomas Schöpping
 * AT24C01BN-SH-B (EEPROM)
664 9ae7c4f3 Thomas Schöpping
 */
665 4c72a54c Thomas Schöpping
#include <module_test_AT24C01B.h>
666
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
667 9ae7c4f3 Thomas Schöpping
{
668 4c72a54c Thomas Schöpping
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
669 9ae7c4f3 Thomas Schöpping
}
670 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
671 9ae7c4f3 Thomas Schöpping
672
/*
673 ee884101 Thomas Schöpping
 * INA219 (power monitor)
674
 */
675 4c72a54c Thomas Schöpping
#include <module_test_INA219.h>
676
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
677 ee884101 Thomas Schöpping
{
678 4c72a54c Thomas Schöpping
  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
679 ee884101 Thomas Schöpping
}
680 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
681 ee884101 Thomas Schöpping
682
/*
683
 * Status LED
684
 */
685 4c72a54c Thomas Schöpping
#include <module_test_LED.h>
686
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
687 ee884101 Thomas Schöpping
{
688 4c72a54c Thomas Schöpping
  return moduleTestLedShellCb(stream, argc, argv, NULL);
689 ee884101 Thomas Schöpping
}
690 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
691 ee884101 Thomas Schöpping
692
/*
693 4c72a54c Thomas Schöpping
 * MIC9404x (power switch)
694 ee884101 Thomas Schöpping
 */
695 4c72a54c Thomas Schöpping
#include <module_test_MIC9404x.h>
696
static int _testMic9404xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
697 ee884101 Thomas Schöpping
{
698 4c72a54c Thomas Schöpping
  return moduleTestMic9404xShellCb(stream, argc, argv, NULL);
699 ee884101 Thomas Schöpping
}
700 4c72a54c Thomas Schöpping
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 ee884101 Thomas Schöpping
714 f606f432 Thomas Schöpping
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
715
716 0b989911 Cung Sang
/*
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 f606f432 Thomas Schöpping
726
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
727 0b989911 Cung Sang
728 ee884101 Thomas Schöpping
/*
729 4c72a54c Thomas Schöpping
 * entire module
730 9ae7c4f3 Thomas Schöpping
 */
731 4c72a54c Thomas Schöpping
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
732 9ae7c4f3 Thomas Schöpping
{
733
  (void)argc;
734
  (void)argv;
735 4c72a54c Thomas Schöpping
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 f606f432 Thomas Schöpping
#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 4c72a54c Thomas Schöpping
  // print total result
790
  chprintf(stream, "\n");
791
  aosTestResultPrintSummary(stream, &result_total, "entire module");
792
793
  return status;
794 9ae7c4f3 Thomas Schöpping
}
795 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
796
797 9ae7c4f3 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
798
799
/** @} */
800
/** @} */