Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-2 / module.h @ 4532b1ab

History | View | Annotate | Download (30.97 KB)

1 b010278f 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 PowerManagement module.
22
 *
23
 * @addtogroup powermanagement_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
 * @brief Makro to store data in the core coupled memory (ccm).
41
 *        Example:
42
 *        int compute_buffer[128] CCM_RAM;
43
 *
44
 * @note The ccm is not connected to any bus system.
45
 */
46
#define CCM_RAM(...)                            __attribute__((section(".ram4"), ##__VA_ARGS__))
47
48
/**
49
 * @brief Makro to store data in the ethernet memory (eth).
50
 *        Example:
51
 *        int dma_buffer[128] ETH_RAM;
52
 *
53
 * @note The eth is a dedicated memory block with its own DMA controller.
54
 */
55
#define ETH_RAM(...)                            __attribute__((section(".ram2"), ##__VA_ARGS__))
56
57
/**
58
 * @brief Makro to store data in the backup memory (bckp).
59
 *        Example:
60
 *        int backup_buffer[128] BCKP_RAM;
61
 *
62
 * @note The eth is a dedicated memory block with its own DMA controller.
63
 */
64
#define BCKP_RAM(...)                           __attribute__((section(".ram5"), ##__VA_ARGS__))
65
66
/** @} */
67
68
/*===========================================================================*/
69
/**
70
 * @name ChibiOS/HAL configuration
71
 * @{
72
 */
73
/*===========================================================================*/
74
75
/**
76
 * @brief   ADC driver for reading the system voltage.
77
 */
78
#define MODULE_HAL_ADC_VSYS                     ADCD1
79
80
/**
81
 * @brief   Configuration for the ADC.
82
 */
83
extern ADCConversionGroup moduleHalAdcVsysConversionGroup;
84
85
/**
86
 * @brief   CAN driver to use.
87
 */
88
#define MODULE_HAL_CAN                          CAND1
89
90
/**
91
 * @brief   Configuration for the CAN driver.
92
 */
93
extern CANConfig moduleHalCanConfig;
94
95
/**
96
 * @brief   I2C driver to access the sensor ring, power monitors for VIO1.8 and VIO3.3, and fuel gauge (rear battery).
97
 * @details Depending on the attached sensor ring, the devices connected to this bus vary:
98
 *          ProximitySensor:
99
 *            - I2C multiplexer (PCA9544A)
100
 *            - proximity sensors (VCNL4020) #1 - #4
101
 *          DistanceSensor (VL53L0X):
102
 *            TODO
103
 *          DistanceSensor (VL53L1X):
104
 *            TODO
105
 */
106
#define MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR   I2CD1
107
108
/**
109
 * @brief   Configuration for the sensor ring, power monitors for VIO1.8 and VIO3.3, and fuel gauge (rear battery) I2C driver.
110
 * @details Depending on the attached sensor ring, the devices connected to this bus vary:
111
 *          ProximitySensor:
112
 *            - I2C multiplexer (PCA9544A)
113
 *            - proximity sensors (VCNL4020) #1 - #4
114
 *          DistanceSensor (VL53L0X):
115
 *            TODO
116
 *          DistanceSensor (VL53L1X):
117
 *            TODO
118
 */
119
extern I2CConfig moduleHalI2cSrPm18Pm33GaugeRearConfig;
120
121
/**
122
 * @brief   I2C driver to access the sensor ring, power monitors for VSYS4.2, VIO5.0 and VDD, EEPROM, and fuel gauge (front battery).
123
 * @details Depending on the attached sensor ring, the devices connected to this bus vary:
124
 *          ProximitySensor:
125
 *            - I2C multiplexer (PCA9544A)
126
 *            - proximity sensors (VCNL4020) #1 - #4
127
 *            - touch sensor (MPR121)
128
 *          DistanceSensor (VL53L0X):
129
 *            TODO
130
 *          DistanceSensor (VL53L1X):
131
 *            TODO
132
 */
133
#define MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT I2CD2
134
135
/**
136
 * @brief   Configuration for the sensor ring, power monitors for VSYS4.2, VIO5.0 and VDD, EEPROM, and fuel gauge (front battery) I2C driver.
137
 * @details Depending on the attached sensor ring, the devices connected to this bus vary:
138
 *          ProximitySensor:
139
 *            - I2C multiplexer (PCA9544A)
140
 *            - proximity sensors (VCNL4020) #1 - #4
141
 *            - touch sensor (MPR121)
142
 *          DistanceSensor (VL53L0X):
143
 *            TODO
144
 *          DistanceSensor (VL53L1X):
145
 *            TODO
146
 */
147
extern I2CConfig moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig;
148
149
/**
150
 * @brief   PWM driver for the buzzer.
151
 */
152
#define MODULE_HAL_PWM_BUZZER                   PWMD3
153
154
/**
155
 * @brief   Configuration of the PWM driver.
156
 */
157
extern PWMConfig moduleHalPwmBuzzerConfig;
158
159
/**
160
 * @brief   PWM channeö for the buzzer.
161
 */
162
#define MODULE_HAL_PWM_BUZZER_CHANNEL           1
163
164
/**
165
 * @brief   Serial driver of the programmer interface.
166
 */
167
#define MODULE_HAL_PROGIF                       SD1
168
169
/**
170
 * @brief   Configuration for the programmer serial interface driver.
171
 */
172
extern SerialConfig moduleHalProgIfConfig;
173
174
/**
175
 * @brief   Real-Time Clock driver.
176
 */
177
#define MODULE_HAL_RTC                          RTCD1
178
179
/** @} */
180
181
/*===========================================================================*/
182
/**
183
 * @name GPIO definitions
184
 * @{
185
 */
186
/*===========================================================================*/
187
188
/**
189
 * @brief   SWITCH_STATUS input signal GPIO.
190
 */
191
extern ROMCONST apalControlGpio_t moduleGpioSwitchStatus;
192
193
/**
194
 * @brief   SYS_REG_EN output signal GPIO.
195
 */
196
extern ROMCONST apalControlGpio_t moduleGpioSysRegEn;
197
198
/**
199
 * @brief   IR_INT1 input signal GPIO.
200
 */
201
extern ROMCONST apalControlGpio_t moduleGpioIrInt1;
202
203
/**
204
 * @brief   POWER_EN output signal GPIO.
205
 */
206
extern ROMCONST apalControlGpio_t moduleGpioPowerEn;
207
208
/**
209
 * @brief   SYS_UART_DN bidirectional signal GPIO.
210
 */
211
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
212
213
/**
214
 * @brief   CHARGE_STAT2A input signal GPIO.
215
 */
216
extern ROMCONST apalControlGpio_t moduleGpioChargeStat2A;
217
218
/**
219
 * @brief   GAUGE_BATLOW2 input signal GPIO.
220
 */
221
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2;
222
223
/**
224
 * @brief   GAUGE_BATGD2 input signal GPIO.
225
 */
226
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2;
227
228
/**
229
 * @brief   LED output signal GPIO.
230
 */
231
extern ROMCONST apalControlGpio_t moduleGpioLed;
232
233
/**
234
 * @brief   SYS_UART_UP bidirectional signal GPIO.
235
 */
236
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
237
238
/**
239
 * @brief   CHARGE_STAT1A input signal GPIO.
240
 */
241
extern ROMCONST apalControlGpio_t moduleGpioChargeStat1A;
242
243
/**
244
 * @brief   GAUGE_BATLOW1 input signal GPIO.
245
 */
246
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1;
247
248
/**
249
 * @brief   GAUGE_BATGD1 input signal GPIO.
250
 */
251
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1;
252
253
/**
254
 * @brief   CHARG_EN1 output signal GPIO.
255
 */
256
extern ROMCONST apalControlGpio_t moduleGpioChargeEn1;
257
258
/**
259
 * @brief   IR_INT2 input signal GPIO.
260
 */
261
extern ROMCONST apalControlGpio_t moduleGpioIrInt2;
262
263
/**
264
 * @brief   TOUCH_INT input signal GPIO.
265
 */
266
extern ROMCONST apalControlGpio_t moduleGpioTouchInt;
267
268
/**
269
 * @brief   SYS_DONE input signal GPIO.
270
 */
271
extern ROMCONST apalControlGpio_t moduleGpioSysDone;
272
273
/**
274
 * @brief   SYS_PROG output signal GPIO.
275
 */
276
extern ROMCONST apalControlGpio_t moduleGpioSysProg;
277
278
/**
279
 * @brief   PATH_DC input signal GPIO.
280
 */
281
extern ROMCONST apalControlGpio_t moduleGpioPathDc;
282
283
/**
284
 * @brief   SYS_SPI_DIR bidirectional signal GPIO.
285
 */
286
extern ROMCONST apalControlGpio_t moduleGpioSysSpiDir;
287
288
/**
289
 * @brief   SYS_SYNC bidirectional signal GPIO.
290
 */
291
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
292
293
/**
294
 * @brief   SYS_PD bidirectional signal GPIO.
295
 */
296
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
297
298
/**
299
 * @brief   SYS_WARMRST bidirectional signal GPIO.
300
 */
301
extern ROMCONST apalControlGpio_t moduleGpioSysWarmrst;
302
303
/**
304
 * @brief   BT_RST output signal GPIO.
305
 */
306
extern ROMCONST apalControlGpio_t moduleGpioBtRst;
307
308
/**
309
 * @brief   CHARGE_EN2 output signal GPIO.
310
 */
311
extern ROMCONST apalControlGpio_t moduleGpioChargeEn2;
312
313
/** @} */
314
315
/*===========================================================================*/
316
/**
317
 * @name AMiRo-OS core configurations
318
 * @{
319
 */
320
/*===========================================================================*/
321
322
/**
323
 * @brief   Event flag to be set on a IR_INT1 / CHARGE_STAT1A interrupt.
324
 */
325 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_IRINT1           AOS_IOEVENT_FLAG(PAL_PAD(LINE_IR_INT1_N))
326 b010278f Thomas Schöpping
327
/**
328
 * @brief   Event flag to be set on a GAUGE_BATLOW1 interrupt.
329
 */
330 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATLOW1     AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATLOW1))
331 b010278f Thomas Schöpping
332
/**
333
 * @brief   Event flag to be set on a GAUGE_BATGD1 interrupt.
334
 */
335 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATGD1      AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATGD1_N))
336 b010278f Thomas Schöpping
337
/**
338
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
339
 */
340 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_DN))
341 b010278f Thomas Schöpping
342
/**
343
 * @brief   Event flag to be set on a IR_INT2 / CHARGE_STAT2A interrupt.
344
 */
345 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_IRINT2           AOS_IOEVENT_FLAG(PAL_PAD(LINE_IR_INT2_N))
346 b010278f Thomas Schöpping
347
/**
348
 * @brief   Event flag to be set on a TOUCH_INT interrupt.
349
 */
350 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_TOUCHINT         AOS_IOEVENT_FLAG(PAL_PAD(LINE_TOUCH_INT_N))
351 b010278f Thomas Schöpping
352
/**
353
 * @brief   Event flag to be set on a GAUGE_BATLOW2 interrupt.
354
 */
355 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATLOW2     AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATLOW2))
356 b010278f Thomas Schöpping
357
/**
358
 * @brief   Event flag to be set on a GAUGE_BATGD2 interrupt.
359
 */
360 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATGD2      AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATGD2_N))
361 b010278f Thomas Schöpping
362
/**
363
 * @brief   Event flag to be set on a PATH_DC interrupt.
364
 */
365 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_PATHDC           AOS_IOEVENT_FLAG(PAL_PAD(LINE_PATH_DC))
366 b010278f Thomas Schöpping
367
/**
368
 * @brief   Event flag to be set on a SYS_SPI_DIR interrupt.
369
 */
370 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSSPIDIR        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_SPI_DIR))
371 b010278f Thomas Schöpping
372
/**
373
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
374
 */
375 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
376 b010278f Thomas Schöpping
377
/**
378
 * @brief   Event flag to be set on a SYS_PD interrupt.
379
 */
380 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
381 b010278f Thomas Schöpping
382
/**
383
 * @brief   Event flag to be set on a SYS_WARMRST interrupt.
384
 */
385 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSWARMRST       AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_WARMRST_N))
386 b010278f Thomas Schöpping
387
/**
388
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
389
 */
390 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
391 b010278f Thomas Schöpping
392
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
393
/**
394
 * @brief   Shell prompt text.
395
 */
396
extern ROMCONST char* moduleShellPrompt;
397
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
398
399
/**
400
 * @brief   Interrupt initialization macro.
401
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
402
 */
403
#define MODULE_INIT_INTERRUPTS() {                                            \
404
  /* IR_INT1 */                                                               \
405 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioIrInt1.gpio->line, aosSysGetStdIntCallback(), &moduleGpioIrInt1.gpio->line); \
406
  palEnableLineEvent(moduleGpioIrInt1.gpio->line, APAL2CH_EDGE(moduleGpioIrInt1.meta.edge));                \
407 b010278f Thomas Schöpping
  /* GAUGE_BATLOW2 */                                                         \
408 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioGaugeBatLow2.gpio->line, aosSysGetStdIntCallback(), &moduleGpioGaugeBatLow2.gpio->line); \
409
  palEnableLineEvent(moduleGpioGaugeBatLow2.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatLow2.meta.edge));                \
410 b010278f Thomas Schöpping
  /* GAUGE_BATGD2 */                                                          \
411 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioGaugeBatGd2.gpio->line, aosSysGetStdIntCallback(), &moduleGpioGaugeBatGd2.gpio->line); \
412
  palEnableLineEvent(moduleGpioGaugeBatGd2.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatGd2.meta.edge));                \
413 b010278f Thomas Schöpping
  /* GAUGE_BATLOW1 */                                                         \
414 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioGaugeBatLow1.gpio->line, aosSysGetStdIntCallback(), &moduleGpioGaugeBatLow1.gpio->line); \
415
  palEnableLineEvent(moduleGpioGaugeBatLow1.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatLow1.meta.edge));                \
416 b010278f Thomas Schöpping
  /* GAUGE_BATGD1 */                                                          \
417 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioGaugeBatGd1.gpio->line, aosSysGetStdIntCallback(), &moduleGpioGaugeBatGd1.gpio->line); \
418
  palEnableLineEvent(moduleGpioGaugeBatGd1.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatGd1.meta.edge));                \
419 b010278f Thomas Schöpping
  /* IR_INT2 */                                                               \
420 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioIrInt2.gpio->line, aosSysGetStdIntCallback(), &moduleGpioIrInt2.gpio->line); \
421
  palEnableLineEvent(moduleGpioIrInt2.gpio->line, APAL2CH_EDGE(moduleGpioIrInt2.meta.edge));                \
422 b010278f Thomas Schöpping
  /* TOUCH_INT */                                                             \
423 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioTouchInt.gpio->line, aosSysGetStdIntCallback(), &moduleGpioTouchInt.gpio->line); \
424
  palEnableLineEvent(moduleGpioTouchInt.gpio->line, APAL2CH_EDGE(moduleGpioTouchInt.meta.edge));                \
425 b010278f Thomas Schöpping
  /* PATH_DC */                                                               \
426 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioPathDc.gpio->line, aosSysGetStdIntCallback(), &moduleGpioPathDc.gpio->line); \
427
  palEnableLineEvent(moduleGpioPathDc.gpio->line, APAL2CH_EDGE(moduleGpioPathDc.meta.edge));                \
428 b010278f Thomas Schöpping
  /* SYS_SPI_DIR */                                                           \
429 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioSysSpiDir.gpio->line, aosSysGetStdIntCallback(), &moduleGpioSysSpiDir.gpio->line); \
430
  palEnableLineEvent(moduleGpioSysSpiDir.gpio->line, APAL2CH_EDGE(moduleGpioSysSpiDir.meta.edge));                \
431 b010278f Thomas Schöpping
  /* SYS_WARMRST */                                                           \
432 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioSysWarmrst.gpio->line, aosSysGetStdIntCallback(), &moduleGpioSysWarmrst.gpio->line); \
433
  palEnableLineEvent(moduleGpioSysWarmrst.gpio->line, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));                \
434 b010278f Thomas Schöpping
}
435
436
/**
437
 * @brief   Unit test initialization hook.
438
 */
439
#define MODULE_INIT_TESTS() {                                                 \
440
  /* add unit-test shell commands */                                          \
441
  aosShellAddCommand(&aos.shell, &moduleUtAdcVsys.shellcmd);                  \
442
  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01b.shellcmd);             \
443
  aosShellAddCommand(&aos.shell, &moduleUtAlldBq24103a.shellcmd);             \
444
  aosShellAddCommand(&aos.shell, &moduleUtAlldBq27500.shellcmd);              \
445
  aosShellAddCommand(&aos.shell, &moduleUtAlldBq27500Bq24103a.shellcmd);      \
446
  aosShellAddCommand(&aos.shell, &moduleUtAlldIna219.shellcmd);               \
447
  aosShellAddCommand(&aos.shell, &moduleUtAlldPklcs1212e4001.shellcmd);       \
448
  aosShellAddCommand(&aos.shell, &moduleUtAlldLed.shellcmd);                  \
449
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113.shellcmd);             \
450
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113Ina219.shellcmd);       \
451
  MODULE_INIT_TEST_SENSORRING();                                              \
452
}
453
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
454
  #define MODULE_INIT_TEST_SENSORRING() {                                     \
455
    aosShellAddCommand(&aos.shell, &moduleUtAlldPca9544a.shellcmd);           \
456
    aosShellAddCommand(&aos.shell, &moduleUtAlldMpr121.shellcmd);             \
457
    aosShellAddCommand(&aos.shell, &moduleUtAlldVcnl4020.shellcmd);           \
458
  }
459
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
460
  #define MODULE_INIT_TEST_SENSORRING() {                                     \
461
    aosShellAddCommand(&aos.shell, &moduleUtAlldPcal6524.shellcmd);           \
462
    aosShellAddCommand(&aos.shell, &moduleUtAlldAt42qt1050.shellcmd);         \
463
  }
464
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
465
  #define MODULE_INIT_TEST_SENSORRING() {                                     \
466
    aosShellAddCommand(&aos.shell, &moduleUtAlldPcal6524.shellcmd);           \
467
    aosShellAddCommand(&aos.shell, &moduleUtAlldAt42qt1050.shellcmd);         \
468
  }
469
#else /* (BOARD_SENSORRING == ?) */
470
  #define MODULE_INIT_TEST_SENSORRING()         {}
471
#endif /* (BOARD_SENSORRING == ?) */
472
473
/**
474
 * @brief   Periphery communication interfaces initialization hook.
475
 */
476
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
477
  MODULE_INIT_PERIPHERY_COMM_SENSORRING();                                    \
478
  /* serial driver */                                                         \
479
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
480
  /* I2C */                                                                   \
481
  moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
482
  moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (BQ27500_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? BQ27500_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
483
  moduleHalI2cSrPm18Pm33GaugeRearConfig.duty_cycle = (moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
484
  i2cStart(&MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR, &moduleHalI2cSrPm18Pm33GaugeRearConfig); \
485
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
486
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
487
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (BQ27500_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? BQ27500_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
488
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.duty_cycle = (moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
489
  i2cStart(&MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT, &moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig);  \
490
  /* ADC */                                                                   \
491
  adcStart(&MODULE_HAL_ADC_VSYS, NULL);                                       \
492
  /* PWM */                                                                   \
493
  pwmStart(&MODULE_HAL_PWM_BUZZER, &moduleHalPwmBuzzerConfig);                \
494
  moduleHalPwmBuzzerConfig.frequency = MODULE_HAL_PWM_BUZZER.clock;           \
495
  pwmStop(&MODULE_HAL_PWM_BUZZER);                                            \
496
  moduleHalPwmBuzzerConfig.period = moduleHalPwmBuzzerConfig.frequency / PKxxxExxx_LLD_FREQUENCY_SPEC; \
497
  pwmStart(&MODULE_HAL_PWM_BUZZER, &moduleHalPwmBuzzerConfig);                \
498
}
499
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
500
  #define MODULE_INIT_PERIPHERY_COMM_SENSORRING() {                           \
501
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
502
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
503
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
504
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
505
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (MPR121_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? MPR121_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
506
  }
507
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
508
  #define MODULE_INIT_PERIPHERY_COMM_SENSORRING() {                           \
509
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
510
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
511
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (AT42QT1050_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? AT42QT1050_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
512
  }
513
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
514
  #define MODULE_INIT_PERIPHERY_COMM_SENSORRING() {                           \
515
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
516
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
517
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (AT42QT1050_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? AT42QT1050_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
518
  }
519
#else /* (BOARD_SENSORRING == ?) */
520
  #define MODULE_INIT_PERIPHERY_COMM_SENSORRING() {}
521
#endif /* (BOARD_SENSORRING == ?) */
522
523
/**
524
 * @brief   Periphery communication interface deinitialization hook.
525
 */
526
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
527
  /* PWM */                                                                   \
528
  pwmStop(&MODULE_HAL_PWM_BUZZER);                                            \
529
  /* ADC */                                                                   \
530
  adcStop(&MODULE_HAL_ADC_VSYS);                                              \
531
  /* I2C */                                                                   \
532
  i2cStop(&MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR);                            \
533
  i2cStop(&MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT);              \
534
  /* don't stop the serial driver so messages can still be printed */         \
535
}
536
537
/** @} */
538
539
/*===========================================================================*/
540
/**
541
 * @name Startup Shutdown Synchronization Protocol (SSSP)
542
 * @{
543
 */
544
/*===========================================================================*/
545
546
/**
547
 * @brief   PD signal GPIO.
548
 */
549
#define moduleSsspGpioPd                        moduleGpioSysPd
550
551
/**
552
 * @brief   SYNC signal GPIO.
553
 */
554
#define moduleSsspGpioSync                       moduleGpioSysSync
555
556
/**
557
 * @brief   DN signal GPIO.
558
 */
559
#define moduleSsspGpioDn                        moduleGpioSysUartDn
560
561
/**
562
 * @brief   UP signal GPIO.
563
 */
564
#define moduleSsspGpioUp                        moduleGpioSysUartUp
565
566
/**
567
 * @brief   Event flags for PD signal events.
568
 */
569
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
570
571
/**
572
 * @brief   Event flags for SYNC signal events.
573
 */
574
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
575
576
/**
577
 * @brief   Event flags for UP signal events.
578
 */
579
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
580
581
/**
582
 * @brief   Event flags for DN signal events.
583
 */
584
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
585
586
/** @} */
587
588
/*===========================================================================*/
589
/**
590
 * @name Low-level drivers
591
 * @{
592
 */
593
/*===========================================================================*/
594
#include <alld_AT24C01B.h>
595
#include <alld_bq241xx.h>
596
#include <alld_bq27500.h>
597
#include <alld_INA219.h>
598
#include <alld_LED.h>
599
#include <alld_PKxxxExxx.h>
600
#include <alld_TPS6211x.h>
601
602
/**
603
 * @brief   EEPROM driver.
604
 */
605
extern AT24C01BDriver moduleLldEeprom;
606
607
/**
608
 * @brief   Battery charger (front battery) driver.
609
 */
610
extern BQ241xxDriver moduleLldBatteryChargerFront;
611
612
/**
613
 * @brief   Battery charger (rear battery) driver.
614
 */
615
extern BQ241xxDriver moduleLldBatteryChargerRear;
616
617
/**
618
 * @brief   Fuel gauge (front battery) driver.
619
 */
620
extern BQ27500Driver moduleLldFuelGaugeFront;
621
622
/**
623
 * @brief   Fuel gauge (rear battery) driver.
624
 */
625
extern BQ27500Driver moduleLldFuelGaugeRear;
626
627
/**
628
 * @brief   Power monitor (VDD) driver.
629
 */
630
extern INA219Driver moduleLldPowerMonitorVdd;
631
632
/**
633
 * @brief   Power monitor (VIO 1.8) driver.
634
 */
635
extern INA219Driver moduleLldPowerMonitorVio18;
636
637
/**
638
 * @brief   Power monitor (VIO 3.3) driver.
639
 */
640
extern INA219Driver moduleLldPowerMonitorVio33;
641
642
/**
643
 * @brief   Power monitor (VSYS 4.2) driver.
644
 */
645
extern INA219Driver moduleLldPowerMonitorVsys42;
646
647
/**
648
 * @brief   Power monitor (VIO 5.0) driver.
649
 */
650
extern INA219Driver moduleLldPowerMonitorVio50;
651
652
/**
653
 * @brief   Status LED driver.
654
 */
655
extern LEDDriver moduleLldStatusLed;
656
657
/**
658
 * @brief   Step down converter driver.
659
 * @note    Although there multiple TPS6211x, those are completely identical from driver few (share the same signals).
660
 */
661
extern TPS6211xDriver moduleLldStepDownConverter;
662
663
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
664
665
#include <alld_MPR121.h>
666
#include <alld_PCA9544A.h>
667
#include <alld_VCNL4020.h>
668
669
/**
670
 * @brief   Touch sensor driver.
671
 */
672
extern MPR121Driver moduleLldTouch;
673
674
/**
675
 * @brief   I2C multiplexer (I2C #1) driver.
676
 */
677
extern PCA9544ADriver moduleLldI2cMultiplexer1;
678
679
/**
680
 * @brief   I2C multiplexer (I2C #2) driver.
681
 */
682
extern PCA9544ADriver moduleLldI2cMultiplexer2;
683
684
/**
685
 * @brief   Proximity sensor (I2C #1) driver.
686
 */
687
extern VCNL4020Driver moduleLldProximity1;
688
689
/**
690
 * @brief   Proximity sensor (I2C #2) driver.
691
 */
692
extern VCNL4020Driver moduleLldProximity2;
693
694
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
695
696
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
697
698
#include <alld_PCAL6524.h>
699
#include <alld_AT42QT1050.h>
700
701
/**
702
 * @brief   GPIO extender (I2C #1) driver.
703
 */
704
extern PCAL6524Driver moduleLldGpioExtender1;
705
706
/**
707
 * @brief   GPIO extender (I2C #2) driver.
708
 */
709
extern PCAL6524Driver moduleLldGpioExtender2;
710
711
/**
712
 * @brief   Touch sensor driver.
713
 */
714
extern AT42QT1050Driver moduleLldTouch;
715
716
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
717
718
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
719
720
#include <alld_PCAL6524.h>
721
#include <alld_AT42QT1050.h>
722
723
/**
724
 * @brief   GPIO extender (I2C #1) driver.
725
 */
726
extern PCAL6524Driver moduleLldGpioExtender1;
727
728
/**
729
 * @brief   GPIO extender (I2C #2) driver.
730
 */
731
extern PCAL6524Driver moduleLldGpioExtender2;
732
733
/**
734
 * @brief   Touch sensor driver.
735
 */
736
extern AT42QT1050Driver moduleLldTouch;
737
738
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
739
740
/** @} */
741
742
/*===========================================================================*/
743
/**
744
 * @name Unit tests (UT)
745
 * @{
746
 */
747
/*===========================================================================*/
748
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
749
#include <ut_lld_adc.h>
750
#include <ut_alld_AT24C01B_v1.h>
751
#include <ut_alld_bq241xx_v1.h>
752
#include <ut_alld_bq27500_v1.h>
753
#include <ut_alld_bq27500_v1_bq241xx_v1.h>
754
#include <ut_alld_INA219_v1.h>
755
#include <ut_alld_LED_v1.h>
756
#include <ut_alld_PKxxxExxx_v1.h>
757
#include <ut_alld_TPS6211x_v1.h>
758
#include <ut_alld_TPS6211x_v1_INA219_v1.h>
759
760
/**
761
 * @brief   ADC unit test object.
762
 */
763
extern aos_unittest_t moduleUtAdcVsys;
764
765
/**
766
 * @brief   AT24C01BN-SH-B (EEPROM) unit test object.
767
 */
768
extern aos_unittest_t moduleUtAlldAt24c01b;
769
770
/**
771
 * @brief   BQ24103A (battery charger) unit test object.
772
 */
773
extern aos_unittest_t moduleUtAlldBq24103a;
774
775
/**
776
 * @brief   BQ27500 (fuel gauge) unit test object.
777
 */
778
extern aos_unittest_t moduleUtAlldBq27500;
779
780
/**
781
 * @brief   BQ27500 (fuela gauge) in combination with BQ24103A (battery charger) unit test object.
782
 */
783
extern aos_unittest_t moduleUtAlldBq27500Bq24103a;
784
785
/**
786
 * @brief   INA219 (power monitor) unit test object.
787
 */
788
extern aos_unittest_t moduleUtAlldIna219;
789
790
/**
791
 * @brief   Status LED unit test object.
792
 */
793
extern aos_unittest_t moduleUtAlldLed;
794
795
/**
796
 * @brief   PKLCS1212E4001 (buzzer) unit test object.
797
 */
798
extern aos_unittest_t moduleUtAlldPklcs1212e4001;
799
800
/**
801
 * @brief   TPS62113 (step-down converter) unit test object.
802
 */
803
extern aos_unittest_t moduleUtAlldTps62113;
804
805
/**
806
 * @brief   TPS62113 (step-sown converter) in combination with INA219 (power monitor) unit test object.
807
 */
808
extern aos_unittest_t moduleUtAlldTps62113Ina219;
809
810
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
811
812
#include <ut_alld_MPR121_v1.h>
813
#include <ut_alld_PCA9544A_v1.h>
814
#include <ut_alld_VCNL4020_v1.h>
815
816
/**
817
 * @brief   MPR121 (touch sensor) unit test object.
818
 */
819
extern aos_unittest_t moduleUtAlldMpr121;
820
821
/**
822
 * @brief   PCA9544A (I2C multiplexer) unit test object.
823
 */
824
extern aos_unittest_t moduleUtAlldPca9544a;
825
826
/**
827
 * @brief   VCNL4020 (proximity sensor) unit test object.
828
 */
829
extern aos_unittest_t moduleUtAlldVcnl4020;
830
831
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
832
833
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
834
835
#include <ut_alld_PCAL6524_v1.h>
836
#include <ut_alld_AT42QT1050_v1.h>
837
838
/**
839
 * @brief   PCAL6524 (GPIO extender) unit test object.
840
 */
841
extern aos_unittest_t moduleUtAlldPcal6524;
842
843
/**
844
 * @brief   AT42QT1050 (touch sensor) unit test object.
845
 */
846
extern aos_unittest_t moduleUtAlldAt42qt1050;
847
848
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
849
850
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
851
852
#include <ut_alld_PCAL6524_v1.h>
853
#include <ut_alld_AT42QT1050_v1.h>
854
855
/**
856
 * @brief   PCAL6524 (GPIO extender) unit test object.
857
 */
858
extern aos_unittest_t moduleUtAlldPcal6524;
859
860
/**
861
 * @brief   AT42QT1050 (touch sensor) unit test object.
862
 */
863
extern aos_unittest_t moduleUtAlldAt42qt1050;
864
865
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
866
867
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
868
869
/** @} */
870
871
#endif /* AMIROOS_MODULE_H */
872
873
/** @} */