Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.h @ c60ee2dd

History | View | Annotate | Download (13.743 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 module.
22
 *
23
 * @addtogroup lightring_module
24
 * @{
25
 */
26
27
#ifndef AMIROOS_MODULE_H
28
#define AMIROOS_MODULE_H
29
30
#include <amiroos.h>
31
32
/*===========================================================================*/
33
/**
34
 * @name Module specific functions
35
 * @{
36
 */
37
/*===========================================================================*/
38
39
/** @} */
40
41
/*===========================================================================*/
42
/**
43
 * @name ChibiOS/HAL configuration
44
 * @{
45
 */
46
/*===========================================================================*/
47
48
/**
49
 * @brief   CAN driver to use.
50
 */
51
#define MODULE_HAL_CAN                          CAND1
52
53
/**
54
 * @brief   Configuration for the CAN driver.
55
 */
56
extern CANConfig moduleHalCanConfig;
57
58
/**
59 ee884101 Thomas Schöpping
 * @brief   I2C driver to access the EEPROM, power monitor and the breakout header.
60 9ae7c4f3 Thomas Schöpping
 */
61 ee884101 Thomas Schöpping
#define MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT   I2CD2
62 9ae7c4f3 Thomas Schöpping
63
/**
64 ee884101 Thomas Schöpping
 * @brief   Configuration for the EEPROM, power monitor and breakout I2C driver.
65 9ae7c4f3 Thomas Schöpping
 */
66 ee884101 Thomas Schöpping
extern I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig;
67 9ae7c4f3 Thomas Schöpping
68
/**
69
 * @brief   Serial driver of the programmer interface.
70
 */
71
#define MODULE_HAL_PROGIF                       SD1
72
73
/**
74
 * @brief   Configuration for the programmer serial interface driver.
75
 */
76
extern SerialConfig moduleHalProgIfConfig;
77
78
/**
79
 * @brief   SPI interface driver for the motion sensors (gyroscope and accelerometer).
80
 */
81
#define MODULE_HAL_SPI_LIGHT                    SPID1
82
83
/**
84
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
85
 */
86
extern SPIConfig moduleHalSpiLightConfig;
87
88
/**
89
 * @brief   SPI interface driver for the breakout header.
90
 */
91
#define MODULE_HAL_SPI_BREAKOUT                 SPID2
92
93
/**
94
 * @brief   UART interface driver for the breakout header (alternative to serial).
95
 */
96
#define MODULE_HAL_UART_BREAKOUT                UARTD2
97
98
/**
99
 * @brief   Real-Time Clock driver.
100
 */
101
#define MODULE_HAL_RTC                          RTCD1
102
103
/** @} */
104
105
/*===========================================================================*/
106
/**
107
 * @name GPIO definitions
108
 * @{
109
 */
110
/*===========================================================================*/
111
112
/**
113
 * @brief   LIGHT_BANK output signal GPIO.
114
 */
115
extern ROMCONST apalControlGpio_t moduleGpioLightBlank;
116
117
/**
118
 * @brief   RS232_R_EN_N output signal GPIO.
119
 */
120
extern ROMCONST apalControlGpio_t moduleGpioRs232En;
121
122
/**
123
 * @brief   SW_V33_EN output signal GPIO.
124
 */
125
extern ROMCONST apalControlGpio_t moduleGpioSwV33En;
126
127 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
128
///**
129
// * @brief   SW_V42_EN output signal GPIO.
130
// */
131
//extern ROMCONST apalControlGpio_t moduleGpioSwV42En;
132 9ae7c4f3 Thomas Schöpping
133
/**
134
 * @brief   SW_V50_EN output signal GPIO.
135
 */
136
extern ROMCONST apalControlGpio_t moduleGpioSwV50En;
137
138
/**
139
 * @brief   IO_3 breakout signal GPIO.
140
 */
141
extern apalControlGpio_t moduleGpioBreakoutIo3;
142
143
/**
144
 * @brief   IO_5 breakout signal GPIO.
145
 */
146
extern apalControlGpio_t moduleGpioBreakoutIo5;
147
148
/**
149
 * @brief   IO_6 breakout signal GPIO.
150
 */
151
extern apalControlGpio_t moduleGpioBreakoutIo6;
152
153
/**
154
 * @brief   SYS_UART_DN bidirectional signal GPIO.
155
 */
156
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
157
158
/**
159
 * @brief   IO_7 breakout signal GPIO.
160
 */
161
extern apalControlGpio_t moduleGpioBreakoutIo7;
162
163
/**
164
 * @brief   IO_8 breakout signal GPIO.
165
 */
166
extern apalControlGpio_t moduleGpioBreakoutIo8;
167
168
/**
169
 * @brief   IO_4 breakout signal GPIO.
170
 */
171
extern apalControlGpio_t moduleGpioBreakoutIo4;
172
173
/**
174
 * @brief   IO_1 breakout signal GPIO.
175
 */
176
extern apalControlGpio_t moduleGpioBreakoutIo1;
177
178
/**
179
 * @brief   IO_2 breakout signal GPIO.
180
 */
181
extern apalControlGpio_t moduleGpioBreakoutIo2;
182
183
/**
184
 * @brief   LED output signal GPIO.
185
 */
186
extern ROMCONST apalControlGpio_t moduleGpioLed;
187
188
/**
189 c930aa01 Thomas Schöpping
 * @brief   LIGHT_XLAT output signal.
190
 */
191
extern ROMCONST apalControlGpio_t moduleGpioLightXlat;
192
193
/**
194 9ae7c4f3 Thomas Schöpping
 * @brief   SW_V18_EN output signal GPIO.
195
 */
196
extern ROMCONST apalControlGpio_t moduleGpioSwV18En;
197
198
/**
199
 * @brief   SW_VSYS_EN output signal GPIO.
200
 */
201
extern ROMCONST apalControlGpio_t moduleGpioSwVsysEn;
202
203
/**
204
 * @brief   SYS_UART_UP bidirectional signal GPIO.
205
 */
206
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
207
208
/**
209
 * @brief   SYS_PD bidirectional signal GPIO.
210
 */
211
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
212
213
/**
214
 * @brief   SYS_SYNC bidirectional signal GPIO.
215
 */
216
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
217
218
/** @} */
219
220
/*===========================================================================*/
221
/**
222
 * @name AMiRo-OS core configurations
223
 * @{
224
 */
225
/*===========================================================================*/
226
227
/**
228
 * @brief   Event flag to be set on a IO_4 (breakout) interrupt.
229
 */
230 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO4      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_4))
231 9ae7c4f3 Thomas Schöpping
232
/**
233
 * @brief   Event flag to be set on a IO_1 (breakout) interrupt.
234
 */
235 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO1      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_1))
236 9ae7c4f3 Thomas Schöpping
237
/**
238
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
239
 */
240 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
241 9ae7c4f3 Thomas Schöpping
242
/**
243
 * @brief   Event flag to be set on a IO_3 (breakout) interrupt.
244
 */
245 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO3      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_3))
246 9ae7c4f3 Thomas Schöpping
247
/**
248
 * @brief   Event flag to be set on a IO_5 (breakout) interrupt.
249
 */
250 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO5      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_5))
251 9ae7c4f3 Thomas Schöpping
252
/**
253
 * @brief   Event flag to be set on a IO_6 (breakout) interrupt.
254
 */
255 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO6      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_6))
256 9ae7c4f3 Thomas Schöpping
257
/**
258
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
259
 */
260 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_DN))
261 9ae7c4f3 Thomas Schöpping
262
/**
263
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
264
 */
265 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
266 9ae7c4f3 Thomas Schöpping
267
/**
268
 * @brief   Event flag to be set on a IO_7 (breakout) interrupt.
269
 */
270 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO7      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_7))
271 9ae7c4f3 Thomas Schöpping
272
/**
273
 * @brief   Event flag to be set on a IO_8 (breakout) interrupt.
274
 */
275 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO8      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_8))
276 9ae7c4f3 Thomas Schöpping
277
/**
278
 * @brief   Event flag to be set on a SYS_PD interrupt.
279
 */
280 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
281 9ae7c4f3 Thomas Schöpping
282
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
283
/**
284
 * @brief   Shell prompt text.
285
 */
286
extern ROMCONST char* moduleShellPrompt;
287
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
288
289
/**
290
 * @brief   Interrupt initialization macro.
291
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
292
 */
293
#define MODULE_INIT_INTERRUPTS() {                                            \
294
  /* breakout interrupts must be enabled explicitely */                       \
295
}
296
297
/**
298
 * @brief   Unit test initialization hook.
299
 */
300
#define MODULE_INIT_TESTS() {                                                 \
301 4c72a54c Thomas Schöpping
  /* initialize tests and add to shell */                                     \
302
  aosShellAddCommand(&aos.shell, &moduleTestAt24c01bShellCmd);                \
303
  aosShellAddCommand(&aos.shell, &moduleTestIna219ShellCmd);                  \
304
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
305
  aosShellAddCommand(&aos.shell, &moduleTestMic9404xShellCmd);                \
306 c60ee2dd Julia Niermann
  aosShellAddCommand(&aos.shell, &moduleTestP9221rShellCmd);                 \
307 4c72a54c Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleTestTlc5947ShellCmd);                 \
308
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
309 9ae7c4f3 Thomas Schöpping
}
310
311
/**
312
 * @brief   Periphery communication interfaces initialization hook.
313
 */
314 4c72a54c Thomas Schöpping
#define MODULE_INIT_PERIPHERY_IF() {                                          \
315 9ae7c4f3 Thomas Schöpping
  /* serial driver */                                                         \
316
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
317
  /* I2C */                                                                   \
318 ee884101 Thomas Schöpping
  moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \
319
  moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \
320
  moduleHalI2cEepromPwrmtrBreakoutConfig.duty_cycle = (moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
321
  i2cStart(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, &moduleHalI2cEepromPwrmtrBreakoutConfig);  \
322 9ae7c4f3 Thomas Schöpping
  /* SPI */                                                                   \
323
  spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
324
}
325
326
/**
327
 * @brief   Periphery communication interface deinitialization hook.
328
 */
329 4c72a54c Thomas Schöpping
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
330 9ae7c4f3 Thomas Schöpping
  /* SPI */                                                                   \
331
  spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
332
  /* I2C */                                                                   \
333 ee884101 Thomas Schöpping
  i2cStop(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT);                            \
334 9ae7c4f3 Thomas Schöpping
  /* don't stop the serial driver so messages can still be printed */         \
335
}
336
337
/** @} */
338
339
/*===========================================================================*/
340
/**
341
 * @name Startup Shutdown Synchronization Protocol (SSSP)
342
 * @{
343
 */
344
/*===========================================================================*/
345
346
/**
347
 * @brief   PD signal GPIO.
348
 */
349
#define moduleSsspGpioPd                        moduleGpioSysPd
350
351
/**
352
 * @brief   SYNC signal GPIO.
353
 */
354
#define moduleSsspGpioSync                      moduleGpioSysSync
355
356
/**
357
 * @brief   UP signal GPIO.
358
 */
359
#define moduleSsspGpioUp                        moduleGpioSysUartUp
360
361
/**
362
 * @brief   DN signal GPIO.
363
 */
364
#define moduleSsspGpioDn                        moduleGpioSysUartDn
365
366
/**
367
 * @brief   Event flags for PD signal events.
368
 */
369
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
370
371
/**
372
 * @brief   Event flags for SYNC signal events.
373
 */
374
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
375
376
/**
377
 * @brief   Event flags for UP signal events.
378
 */
379
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
380
381
/**
382
 * @brief   Event flags for DN signal events.
383
 */
384
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
385
386
/** @} */
387
388
/*===========================================================================*/
389
/**
390
 * @name Low-level drivers
391
 * @{
392
 */
393
/*===========================================================================*/
394
#include <alld_AT24C01B.h>
395 ee884101 Thomas Schöpping
#include <alld_INA219.h>
396 8cbe3240 Julia Niermann
#include <alld_P9221R.h>
397 9ae7c4f3 Thomas Schöpping
#include <alld_LED.h>
398 ee884101 Thomas Schöpping
#include <alld_MIC9404x.h>
399 4c72a54c Thomas Schöpping
// TODO: add SNx5C3221E
400 9ae7c4f3 Thomas Schöpping
#include <alld_TLC5947.h>
401
402
/**
403
 * @brief   EEPROM driver.
404
 */
405
extern AT24C01BDriver moduleLldEeprom;
406
407
/**
408 ee884101 Thomas Schöpping
 * @brief   Power monitor (VLED 4.2) driver.
409
 */
410
extern INA219Driver moduleLldPowerMonitorVled;
411
412
/**
413 5b1af1ae Julia Niermann
 * @brief   ???
414 c4989d30 Julia Niermann
 */
415
extern P9221RDriver moduleQiCharger;
416
417
/**
418 9ae7c4f3 Thomas Schöpping
 * @brief   Status LED driver.
419
 */
420
extern LEDDriver moduleLldStatusLed;
421
422
/**
423 ee884101 Thomas Schöpping
 * @brief   Power switch driver (1.8V).
424
 */
425
extern MIC9404xDriver moduleLldPowerSwitchV18;
426
427
/**
428
 * @brief   Power switch driver (3.3V).
429
 */
430
extern MIC9404xDriver moduleLldPowerSwitchV33;
431
432
/**
433
 * @brief   Power switch driver (4.2V).
434
 */
435
extern MIC9404xDriver moduleLldPowerSwitchV42;
436
437
/**
438
 * @brief   Power switch driver (5.0V).
439
 */
440
extern MIC9404xDriver moduleLldPowerSwitchV50;
441
442
/**
443
 * @brief   Pseudo power switch driver (VSYS).
444
 * @details There is no actual MIC9040x device, but the swicthable circuit behaves analogous.
445
 */
446
extern MIC9404xDriver moduleLldPowerSwitchVsys;
447
448 4c72a54c Thomas Schöpping
// TODO: add SNx5C3221E
449
450 ee884101 Thomas Schöpping
/**
451 4c72a54c Thomas Schöpping
 * @brief   24 channel PWM LED driver.
452 9ae7c4f3 Thomas Schöpping
 */
453
extern TLC5947Driver moduleLldLedPwm;
454
455
/** @} */
456
457
/*===========================================================================*/
458
/**
459 4c72a54c Thomas Schöpping
 * @name Tests
460 9ae7c4f3 Thomas Schöpping
 * @{
461
 */
462
/*===========================================================================*/
463
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
464
465
/**
466 4c72a54c Thomas Schöpping
 * @brief   AT24C01BN-SH-B (EEPROM) test command.
467 9ae7c4f3 Thomas Schöpping
 */
468 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
469 9ae7c4f3 Thomas Schöpping
470
/**
471 4c72a54c Thomas Schöpping
 * @brief   INA219 (power monitor) test command.
472 ee884101 Thomas Schöpping
 */
473 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestIna219ShellCmd;
474 ee884101 Thomas Schöpping
475
/**
476 8cbe3240 Julia Niermann
 * @brief   P9221R (qi charger) unit test object.
477
 */
478 5b1af1ae Julia Niermann
extern aos_shellcommand_t moduleTestP9221rShellCmd;
479
480
/**
481 4c72a54c Thomas Schöpping
 * @brief   Status LED test command.
482 ee884101 Thomas Schöpping
 */
483 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestLedShellCmd;
484 8cbe3240 Julia Niermann
485
/**
486 4c72a54c Thomas Schöpping
 * @brief   MIC9404x (power switch) test command.
487 ee884101 Thomas Schöpping
 */
488 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestMic9404xShellCmd;
489
490
// TODO: add SNx5C3221E
491 ee884101 Thomas Schöpping
492
/**
493 4c72a54c Thomas Schöpping
 * @brief   TLC5947 (24 channel PWM LED driver) test command.
494 ee884101 Thomas Schöpping
 */
495 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestTlc5947ShellCmd;
496 ee884101 Thomas Schöpping
497
/**
498 4c72a54c Thomas Schöpping
 * @brief   Entire module test command.
499 9ae7c4f3 Thomas Schöpping
 */
500 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestAllShellCmd;
501 9ae7c4f3 Thomas Schöpping
502
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
503
504
/** @} */
505
506
#endif /* AMIROOS_MODULE_H */
507
508
/** @} */