Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.c @ 9ae7c4f3

History | View | Annotate | Download (13.114 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
 * @brief   Structures and constant for the LightRing v1.0 module.
22
 *
23
 * @addtogroup lightring_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 moduleHalI2cEepromBreakoutConfig = {
51
  /* I²C mode   */ OPMODE_I2C,
52
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
53
  /* duty cycle */ FAST_DUTY_CYCLE_2,
54
};
55
56
SerialConfig moduleHalProgIfConfig = {
57
  /* bit rate */ 115200,
58
  /* CR1      */ 0,
59
  /* CR1      */ 0,
60
  /* CR1      */ 0,
61
};
62
63
SPIConfig moduleHalSpiLightConfig = {
64
  /* circular buffer mode        */ false,
65
  /* callback function pointer   */ NULL,
66
  /* chip select line port       */ GPIOC,
67
  /* chip select line pad number */ GPIOC_LIGHT_XLAT,
68
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
69
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
70
};
71
72
73
/*===========================================================================*/
74
/**
75
 * @name GPIO definitions
76
 * @{
77
 */
78
/*===========================================================================*/
79
80
/**
81
 * @brief   LIGHT_BANK output signal GPIO.
82
 */
83
static apalGpio_t _gpioLightBlank = {
84
  /* port */ GPIOA,
85
  /* pad  */ GPIOA_LIGHT_BLANK,
86
};
87
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
88
  /* GPIO */ &_gpioLightBlank,
89
  /* meta */ {
90
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
91
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
92
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
93
  },
94
};
95
96
/**
97
 * @brief   RS232_R_EN_N output signal GPIO.
98
 */
99
static apalGpio_t _gpioRs232En = {
100
  /* port */ GPIOA,
101
  /* pad  */ GPIOA_RS232_R_EN_N,
102
};
103
ROMCONST apalControlGpio_t moduleGpioRs232En = {
104
  /* GPIO */ &_gpioRs232En,
105
  /* meta */ {
106
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
107
    /* active state   */ APAL_GPIO_ACTIVE_LOW, //TODO
108
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
109
  },
110
};
111
112
/**
113
 * @brief   SW_V33_EN output signal GPIO.
114
 */
115
static apalGpio_t _gpioSwV33En = {
116
  /* port */ GPIOB,
117
  /* pad  */ GPIOB_SW_V33_EN,
118
};
119
ROMCONST apalControlGpio_t moduleGpioSwV33En = {
120
  /* GPIO */ &_gpioSwV33En,
121
  /* meta */ {
122
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
123
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, //TODO
124
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
125
  },
126
};
127
128
/**
129
 * @brief   SW_V42_EN output signal GPIO.
130
 */
131
static apalGpio_t _gpioSwV42En = {
132
  /* port */ GPIOB,
133
  /* pad  */ GPIOB_SW_V42_EN,
134
};
135
ROMCONST apalControlGpio_t moduleGpioSwV42En = {
136
  /* GPIO */ &_gpioSwV42En,
137
  /* meta */ {
138
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
139
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, //TODO
140
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
141
  },
142
};
143
144
/**
145
 * @brief   SW_V50_EN output signal GPIO.
146
 */
147
static apalGpio_t _gpioSwV50En = {
148
  /* port */ GPIOB,
149
  /* pad  */ GPIOB_SW_V50_EN,
150
};
151
ROMCONST apalControlGpio_t moduleGpioSwV50En = {
152
  /* GPIO */ &_gpioSwV50En,
153
  /* meta */ {
154
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
155
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, //TODO
156
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
157
  },
158
};
159
160
/**
161
 * @brief   IO_3 breakout signal GPIO.
162
 */
163
static apalGpio_t _gpioBreakoutIo3 = {
164
  /* port */ GPIOB,
165
  /* pad  */ GPIOB_IO_3,
166
};
167
apalControlGpio_t moduleGpioBreakoutIo3 = {
168
  /* GPIO */ &_gpioBreakoutIo3,
169
  /* meta */ {
170
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
171
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
172
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
173
  },
174
};
175
176
/**
177
 * @brief   IO_5 breakout signal GPIO.
178
 */
179
static apalGpio_t _gpioBreakoutIo5 = {
180
  /* port */ GPIOB,
181
  /* pad  */ GPIOB_IO_5,
182
};
183
apalControlGpio_t moduleGpioBreakoutIo5 = {
184
  /* GPIO */ &_gpioBreakoutIo5,
185
  /* meta */ {
186
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
187
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
188
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
189
  },
190
};
191
192
/**
193
 * @brief   IO_6 breakout signal GPIO.
194
 */
195
static apalGpio_t _gpioBreakoutIo6 = {
196
  /* port */ GPIOB,
197
  /* pad  */ GPIOB_IO_6,
198
};
199
apalControlGpio_t moduleGpioBreakoutIo6 = {
200
  /* GPIO */ &_gpioBreakoutIo6,
201
  /* meta */ {
202
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
203
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
204
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
205
  },
206
};
207
208
/**
209
 * @brief   SYS_UART_DN bidirectional signal GPIO.
210
 */
211
static apalGpio_t _gpioSysUartDn = {
212
  /* port */ GPIOB,
213
  /* pad  */ GPIOB_SYS_UART_DN,
214
};
215
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
216
  /* GPIO */ &_gpioSysUartDn,
217
  /* meta */ {
218
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
219
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
220
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
221
  },
222
};
223
224
/**
225
 * @brief   IO_7 breakout signal GPIO.
226
 */
227
static apalGpio_t _gpioBreakoutIo7 = {
228
  /* port */ GPIOB,
229
  /* pad  */ GPIOB_IO_7,
230
};
231
apalControlGpio_t moduleGpioBreakoutIo7 = {
232
  /* GPIO */ &_gpioBreakoutIo7,
233
  /* meta */ {
234
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
235
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
236
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
237
  },
238
};
239
240
/**
241
 * @brief   IO_8 breakout signal GPIO.
242
 */
243
static apalGpio_t _gpioBreakoutIo8 = {
244
  /* port */ GPIOB,
245
  /* pad  */ GPIOB_IO_8,
246
};
247
apalControlGpio_t moduleGpioBreakoutIo8 = {
248
  /* GPIO */ &_gpioBreakoutIo8,
249
  /* meta */ {
250
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
251
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
252
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
253
  },
254
};
255
256
/**
257
 * @brief   IO_4 breakout signal GPIO.
258
 */
259
static apalGpio_t _gpioBreakoutIo4 = {
260
  /* port */ GPIOC,
261
  /* pad  */ GPIOC_IO_4,
262
};
263
apalControlGpio_t moduleGpioBreakoutIo4 = {
264
  /* GPIO */ &_gpioBreakoutIo4,
265
  /* meta */ {
266
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
267
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
268
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
269
  },
270
};
271
272
/**
273
 * @brief   IO_1 breakout signal GPIO.
274
 */
275
static apalGpio_t _gpioBreakoutIo1 = {
276
  /* port */ GPIOC,
277
  /* pad  */ GPIOC_IO_1,
278
};
279
apalControlGpio_t moduleGpioBreakoutIo1 = {
280
  /* GPIO */ &_gpioBreakoutIo1,
281
  /* meta */ {
282
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
283
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
284
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
285
  },
286
};
287
288
/**
289
 * @brief   IO_2 breakout signal GPIO.
290
 */
291
static apalGpio_t _gpioBreakoutIo2 = {
292
  /* port */ GPIOC,
293
  /* pad  */ GPIOC_IO_2,
294
};
295
apalControlGpio_t moduleGpioBreakoutIo2 = {
296
  /* GPIO */ &_gpioBreakoutIo2,
297
  /* meta */ {
298
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
299
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
300
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
301
  },
302
};
303
304
/**
305
 * @brief   LED output signal GPIO.
306
 */
307
static apalGpio_t _gpioLed = {
308
  /* port */ GPIOC,
309
  /* pad  */ GPIOC_LED,
310
};
311
ROMCONST apalControlGpio_t moduleGpioLed = {
312
  /* GPIO */ &_gpioLed,
313
  /* meta */ {
314
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
315
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
316
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
317
  },
318
};
319
320
/**
321
 * @brief   LIGHT_XLAT output signal GPIO.
322
 */
323
static apalGpio_t _gpioLightXlat = {
324
  /* port */ GPIOC,
325
  /* pad  */ GPIOC_LIGHT_XLAT,
326
};
327
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
328
  /* GPIO */ &_gpioLightXlat,
329
  /* meta */ {
330
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
331
    /* active state   */ TLC5947_LLD_XLAT_ACTIVE_STATE,
332
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
333
  },
334
};
335
336
/**
337
 * @brief   SW_V18_EN output signal GPIO.
338
 */
339
static apalGpio_t _gpioSwV18En = {
340
  /* port */ GPIOC,
341
  /* pad  */ GPIOC_SW_V18_EN,
342
};
343
ROMCONST apalControlGpio_t moduleGpioSwV18En = {
344
  /* GPIO */ &_gpioSwV18En,
345
  /* meta */ {
346
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
347
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, //TODO
348
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
349
  },
350
};
351
352
/**
353
 * @brief   SW_VSYS_EN output signal GPIO.
354
 */
355
static apalGpio_t _gpioSwVsysEn = {
356
  /* port */ GPIOC,
357
  /* pad  */ GPIOC_SW_VSYS_EN,
358
};
359
ROMCONST apalControlGpio_t moduleGpioSwVsysEn = {
360
  /* GPIO */ &_gpioSwVsysEn,
361
  /* meta */ {
362
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
363
    /* active state   */ APAL_GPIO_ACTIVE_HIGH, //TODO
364
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
365
  },
366
};
367
368
/**
369
 * @brief   SYS_UART_UP bidirectional signal GPIO.
370
 */
371
static apalGpio_t _gpioSysUartUp = {
372
  /* port */ GPIOC,
373
  /* pad  */ GPIOC_SYS_UART_UP,
374
};
375
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
376
  /* GPIO */ &_gpioSysUartUp,
377
  /* meta */ {
378
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
379
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
380
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
381
  },
382
};
383
384
/**
385
 * @brief   SYS_PD bidirectional signal GPIO.
386
 */
387
static apalGpio_t _gpioSysPd = {
388
  /* port */ GPIOC,
389
  /* pad  */ GPIOC_SYS_PD_N,
390
};
391
ROMCONST apalControlGpio_t moduleGpioSysPd = {
392
  /* GPIO */ &_gpioSysPd,
393
  /* meta */ {
394
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
395
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
396
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
397
  },
398
};
399
400
/**
401
 * @brief   SYS_SYNC bidirectional signal GPIO.
402
 */
403
static apalGpio_t _gpioSysSync = {
404
  /* port */ GPIOD,
405
  /* pad  */ GPIOD_SYS_INT_N,
406
};
407
ROMCONST apalControlGpio_t moduleGpioSysSync = {
408
  /* GPIO */ &_gpioSysSync,
409
  /* meta */ {
410
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
411
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
412
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
413
  },
414
};
415
416
/** @} */
417
418
/*===========================================================================*/
419
/**
420
 * @name AMiRo-OS core configurations
421
 * @{
422
 */
423
/*===========================================================================*/
424
425
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
426
ROMCONST char* moduleShellPrompt = "LightRing";
427
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
428
429
/** @} */
430
431
/*===========================================================================*/
432
/**
433
 * @name Startup Shutdown Synchronization Protocol (SSSP)
434
 * @{
435
 */
436
/*===========================================================================*/
437
438
/** @} */
439
440
/*===========================================================================*/
441
/**
442
 * @name Low-level drivers
443
 * @{
444
 */
445
/*===========================================================================*/
446
447
AT24C01BDriver moduleLldEeprom = {
448
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM_BREAKOUT,
449
  /* I2C address  */ 0x00u,
450
};
451
452
TLC5947Driver moduleLldLedPwm = {
453
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
454
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
455
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
456
};
457
458
/** @} */
459
460
/*===========================================================================*/
461
/**
462
 * @name Unit tests (UT)
463
 * @{
464
 */
465
/*===========================================================================*/
466
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
467
468
/*
469
 * EEPROM (AT24C01B)
470
 */
471
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
472
{
473
  (void)argc;
474
  (void)argv;
475
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
476
  return AOS_OK;
477
}
478
static ut_at24c01bdata_t _utAlldAt24c01bData = {
479
  /* driver   */ &moduleLldEeprom,
480
  /* timeout  */ MICROSECONDS_PER_SECOND,
481
};
482
aos_unittest_t moduleUtAlldAt24c01b = {
483
  /* name           */ "AT24C01B",
484
  /* info           */ "1kbit EEPROM",
485
  /* test function  */ utAlldAt24c01bFunc,
486
  /* shell command  */ {
487
    /* name     */ "unittest:EEPROM",
488
    /* callback */ _utShellCmdCb_AlldAt24c01b,
489
    /* next     */ NULL,
490
  },
491
  /* data           */ &_utAlldAt24c01bData,
492
};
493
494
/*
495
 * LED PWM driver (TLC5947)
496
 */
497
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
498
{
499
  (void)argc;
500
  (void)argv;
501
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
502
  return AOS_OK;
503
}
504
aos_unittest_t moduleUtAlldTlc5947 = {
505
  /* info           */ "TLC5947",
506
  /* name           */ "LED PWM driver",
507
  /* test function  */ utAlldTlc5947Func,
508
  /* shell command  */ {
509
    /* name     */ "unittest:Lights",
510
    /* callback */ _utShellCmdCb_Tlc5947,
511
    /* next     */ NULL,
512
  },
513
  /* data           */ &moduleLldLedPwm,
514
};
515
516
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
517
518
/** @} */
519
/** @} */