Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.h @ f38aba21

History | View | Annotate | Download (30.593 KB)

1
/*
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 channel 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   SYS_REG_EN output signal GPIO.
190
 */
191
extern ROMCONST apalControlGpio_t moduleGpioSysRegEn;
192

    
193
/**
194
 * @brief   IR_INT1 input signal GPIO.
195
 */
196
extern ROMCONST apalControlGpio_t moduleGpioIrInt1;
197

    
198
/**
199
 * @brief   POWER_EN output signal GPIO.
200
 */
201
extern ROMCONST apalControlGpio_t moduleGpioPowerEn;
202

    
203
/**
204
 * @brief   SYS_UART_DN bidirectional signal GPIO.
205
 */
206
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
207

    
208
/**
209
 * @brief   CHARGE_STAT2A input signal GPIO.
210
 */
211
extern ROMCONST apalControlGpio_t moduleGpioChargeStat2A;
212

    
213
/**
214
 * @brief   GAUGE_BATLOW2 input signal GPIO.
215
 */
216
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2;
217

    
218
/**
219
 * @brief   GAUGE_BATGD2 input signal GPIO.
220
 */
221
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2;
222

    
223
/**
224
 * @brief   LED output signal GPIO.
225
 */
226
extern ROMCONST apalControlGpio_t moduleGpioLed;
227

    
228
/**
229
 * @brief   SYS_UART_UP bidirectional signal GPIO.
230
 */
231
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
232

    
233
/**
234
 * @brief   CHARGE_STAT1A input signal GPIO.
235
 */
236
extern ROMCONST apalControlGpio_t moduleGpioChargeStat1A;
237

    
238
/**
239
 * @brief   GAUGE_BATLOW1 input signal GPIO.
240
 */
241
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1;
242

    
243
/**
244
 * @brief   GAUGE_BATGD1 input signal GPIO.
245
 */
246
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1;
247

    
248
/**
249
 * @brief   CHARGE_EN1 output signal GPIO.
250
 */
251
extern ROMCONST apalControlGpio_t moduleGpioChargeEn1;
252

    
253
/**
254
 * @brief   IR_INT2 input signal GPIO.
255
 */
256
extern ROMCONST apalControlGpio_t moduleGpioIrInt2;
257

    
258
/**
259
 * @brief   TOUCH_INT input signal GPIO.
260
 */
261
extern ROMCONST apalControlGpio_t moduleGpioTouchInt;
262

    
263
/**
264
 * @brief   SYS_DONE input signal GPIO.
265
 */
266
extern ROMCONST apalControlGpio_t moduleGpioSysDone;
267

    
268
/**
269
 * @brief   SYS_PROG output signal GPIO.
270
 */
271
extern ROMCONST apalControlGpio_t moduleGpioSysProg;
272

    
273
/**
274
 * @brief   PATH_DC input signal GPIO.
275
 */
276
extern ROMCONST apalControlGpio_t moduleGpioPathDc;
277

    
278
/**
279
 * @brief   SYS_SPI_DIR bidirectional signal GPIO.
280
 */
281
extern ROMCONST apalControlGpio_t moduleGpioSysSpiDir;
282

    
283
/**
284
 * @brief   SYS_SYNC bidirectional signal GPIO.
285
 */
286
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
287

    
288
/**
289
 * @brief   SYS_PD bidirectional signal GPIO.
290
 */
291
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
292

    
293
/**
294
 * @brief   SYS_WARMRST bidirectional signal GPIO.
295
 */
296
extern ROMCONST apalControlGpio_t moduleGpioSysWarmrst;
297

    
298
/**
299
 * @brief   BT_RST output signal GPIO.
300
 */
301
extern ROMCONST apalControlGpio_t moduleGpioBtRst;
302

    
303
/**
304
 * @brief   CHARGE_EN2 output signal GPIO.
305
 */
306
extern ROMCONST apalControlGpio_t moduleGpioChargeEn2;
307

    
308
/** @} */
309

    
310
/*===========================================================================*/
311
/**
312
 * @name AMiRo-OS core configurations
313
 * @{
314
 */
315
/*===========================================================================*/
316

    
317
/**
318
 * @brief   Event flag to be set on a IR_INT1 / CHARGE_STAT1A interrupt.
319
 */
320
#define MODULE_OS_IOEVENTFLAGS_IRINT1           AOS_IOEVENT_FLAG(PAL_PAD(LINE_IR_INT1_N))
321

    
322
/**
323
 * @brief   Event flag to be set on a GAUGE_BATLOW1 interrupt.
324
 */
325
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATLOW1     AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATLOW1))
326

    
327
/**
328
 * @brief   Event flag to be set on a GAUGE_BATGD1 interrupt.
329
 */
330
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATGD1      AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATGD1_N))
331

    
332
/**
333
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
334
 */
335
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_DN))
336

    
337
/**
338
 * @brief   Event flag to be set on a IR_INT2 / CHARGE_STAT2A interrupt.
339
 */
340
#define MODULE_OS_IOEVENTFLAGS_IRINT2           AOS_IOEVENT_FLAG(PAL_PAD(LINE_IR_INT2_N))
341

    
342
/**
343
 * @brief   Event flag to be set on a TOUCH_INT interrupt.
344
 */
345
#define MODULE_OS_IOEVENTFLAGS_TOUCHINT         AOS_IOEVENT_FLAG(PAL_PAD(LINE_TOUCH_INT_N))
346

    
347
/**
348
 * @brief   Event flag to be set on a GAUGE_BATLOW2 interrupt.
349
 */
350
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATLOW2     AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATLOW2))
351

    
352
/**
353
 * @brief   Event flag to be set on a GAUGE_BATGD2 interrupt.
354
 */
355
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATGD2      AOS_IOEVENT_FLAG(PAL_PAD(LINE_GAUGE_BATGD2_N))
356

    
357
/**
358
 * @brief   Event flag to be set on a PATH_DC interrupt.
359
 */
360
#define MODULE_OS_IOEVENTFLAGS_PATHDC           AOS_IOEVENT_FLAG(PAL_PAD(LINE_PATH_DC))
361

    
362
/**
363
 * @brief   Event flag to be set on a SYS_SPI_DIR interrupt.
364
 */
365
#define MODULE_OS_IOEVENTFLAGS_SYSSPIDIR        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_SPI_DIR))
366

    
367
/**
368
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
369
 */
370
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
371

    
372
/**
373
 * @brief   Event flag to be set on a SYS_PD interrupt.
374
 */
375
#define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
376

    
377
/**
378
 * @brief   Event flag to be set on a SYS_WARMRST interrupt.
379
 */
380
#define MODULE_OS_IOEVENTFLAGS_SYSWARMRST       AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_WARMRST_N))
381

    
382
/**
383
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
384
 */
385
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
386

    
387
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
388
/**
389
 * @brief   Shell prompt text.
390
 */
391
extern ROMCONST char* moduleShellPrompt;
392
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
393

    
394
/**
395
 * @brief   Interrupt initialization macro.
396
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
397
 */
398
#define MODULE_INIT_INTERRUPTS() {                                            \
399
  /* IR_INT1 */                                                               \
400
  palSetLineCallback(moduleGpioIrInt1.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioIrInt1.gpio->line);  \
401
  palEnableLineEvent(moduleGpioIrInt1.gpio->line, APAL2CH_EDGE(moduleGpioIrInt1.meta.edge));                  \
402
  /* GAUGE_BATLOW2 */                                                         \
403
  palSetLineCallback(moduleGpioGaugeBatLow2.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioGaugeBatLow2.gpio->line);  \
404
  palEnableLineEvent(moduleGpioGaugeBatLow2.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatLow2.meta.edge));                  \
405
  /* GAUGE_BATGD2 */                                                          \
406
  palSetLineCallback(moduleGpioGaugeBatGd2.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioGaugeBatGd2.gpio->line);  \
407
  palEnableLineEvent(moduleGpioGaugeBatGd2.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatGd2.meta.edge));                  \
408
  /* GAUGE_BATLOW1 */                                                         \
409
  palSetLineCallback(moduleGpioGaugeBatLow1.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioGaugeBatLow1.gpio->line);  \
410
  palEnableLineEvent(moduleGpioGaugeBatLow1.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatLow1.meta.edge));                  \
411
  /* GAUGE_BATGD1 */                                                          \
412
  palSetLineCallback(moduleGpioGaugeBatGd1.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioGaugeBatGd1.gpio->line);  \
413
  palEnableLineEvent(moduleGpioGaugeBatGd1.gpio->line, APAL2CH_EDGE(moduleGpioGaugeBatGd1.meta.edge));                  \
414
  /* IR_INT2 */                                                               \
415
  palSetLineCallback(moduleGpioIrInt2.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioIrInt2.gpio->line);  \
416
  palEnableLineEvent(moduleGpioIrInt2.gpio->line, APAL2CH_EDGE(moduleGpioIrInt2.meta.edge));                  \
417
  /* TOUCH_INT */                                                             \
418
  palSetLineCallback(moduleGpioTouchInt.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioTouchInt.gpio->line);  \
419
  palEnableLineEvent(moduleGpioTouchInt.gpio->line, APAL2CH_EDGE(moduleGpioTouchInt.meta.edge));                  \
420
  /* PATH_DC */                                                               \
421
  palSetLineCallback(moduleGpioPathDc.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioPathDc.gpio->line);  \
422
  palEnableLineEvent(moduleGpioPathDc.gpio->line, APAL2CH_EDGE(moduleGpioPathDc.meta.edge));                  \
423
  /* SYS_SPI_DIR */                                                           \
424
  palSetLineCallback(moduleGpioSysSpiDir.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioSysSpiDir.gpio->line);  \
425
  palEnableLineEvent(moduleGpioSysSpiDir.gpio->line, APAL2CH_EDGE(moduleGpioSysSpiDir.meta.edge));                  \
426
  /* SYS_WARMRST */                                                           \
427
  palSetLineCallback(moduleGpioSysWarmrst.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioSysWarmrst.gpio->line);  \
428
  palEnableLineEvent(moduleGpioSysWarmrst.gpio->line, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));                  \
429
}
430

    
431
/**
432
 * @brief   Test initialization hook.
433
 */
434
#define MODULE_INIT_TESTS() {                                                 \
435
  /* add unit-test shell commands */                                          \
436
  aosShellAddCommand(&aos.shell, &moduleTestAdcShellCmd);                     \
437
  aosShellAddCommand(&aos.shell, &moduleTestAt24c01bShellCmd);                \
438
  aosShellAddCommand(&aos.shell, &moduleTestBq241xxShellCmd);                 \
439
  aosShellAddCommand(&aos.shell, &moduleTestBq27500ShellCmd);                 \
440
  aosShellAddCommand(&aos.shell, &moduleTestBq27500Bq241xxShellCmd);          \
441
  aosShellAddCommand(&aos.shell, &moduleTestIna219ShellCmd);                  \
442
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
443
  aosShellAddCommand(&aos.shell, &moduleTestPkxxxexxxShellCmd);               \
444
  aosShellAddCommand(&aos.shell, &moduleTestTps6211xShellCmd);                \
445
  aosShellAddCommand(&aos.shell, &moduleTestTps6211xIna219ShellCmd);          \
446
  MODULE_INIT_TEST_SENSORRING();                                              \
447
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
448
}
449
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
450
  #define MODULE_INIT_TEST_SENSORRING() {                                     \
451
    aosShellAddCommand(&aos.shell, &moduleTestPca9544aShellCmd);              \
452
    aosShellAddCommand(&aos.shell, &moduleTestMpr121ShellCmd);                \
453
    aosShellAddCommand(&aos.shell, &moduleTestVcnl4020ShellCmd);              \
454
  }
455
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
456
  #define MODULE_INIT_TEST_SENSORRING() {                                     \
457
    aosShellAddCommand(&aos.shell, &moduleTestPcal6524ShellCmd);              \
458
    aosShellAddCommand(&aos.shell, &moduleTestAt42qt1050ShellCmd);            \
459
  }
460
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
461
  #define MODULE_INIT_TEST_SENSORRING() {                                     \
462
    aosShellAddCommand(&aos.shell, &moduleTestPcal6524ShellCmd);              \
463
    aosShellAddCommand(&aos.shell, &moduleTestAt42qt1050ShellCmd);            \
464
  }
465
#else /* (BOARD_SENSORRING == ?) */
466
  #define MODULE_INIT_TEST_SENSORRING()         {}
467
#endif /* (BOARD_SENSORRING == ?) */
468

    
469
/**
470
 * @brief   Periphery communication interfaces initialization hook.
471
 */
472
#define MODULE_INIT_PERIPHERY_IF() {                                          \
473
  MODULE_INIT_PERIPHERY_IF_SENSORRING();                                      \
474
  /* serial driver */                                                         \
475
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
476
  /* I2C */                                                                   \
477
  moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
478
  moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (BQ27500_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? BQ27500_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
479
  moduleHalI2cSrPm18Pm33GaugeRearConfig.duty_cycle = (moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
480
  i2cStart(&MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR, &moduleHalI2cSrPm18Pm33GaugeRearConfig); \
481
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
482
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
483
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (BQ27500_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? BQ27500_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
484
  moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.duty_cycle = (moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
485
  i2cStart(&MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT, &moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig);  \
486
  /* ADC */                                                                   \
487
  adcStart(&MODULE_HAL_ADC_VSYS, NULL);                                       \
488
  /* PWM */                                                                   \
489
  pwmStart(&MODULE_HAL_PWM_BUZZER, &moduleHalPwmBuzzerConfig);                \
490
  moduleHalPwmBuzzerConfig.frequency = MODULE_HAL_PWM_BUZZER.clock;           \
491
  pwmStop(&MODULE_HAL_PWM_BUZZER);                                            \
492
  moduleHalPwmBuzzerConfig.period = moduleHalPwmBuzzerConfig.frequency / PKxxxExxx_LLD_FREQUENCY_SPEC; \
493
  pwmStart(&MODULE_HAL_PWM_BUZZER, &moduleHalPwmBuzzerConfig);                \
494
}
495
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
496
  #define MODULE_INIT_PERIPHERY_IF_SENSORRING() {                             \
497
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
498
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
499
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
500
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
501
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (MPR121_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? MPR121_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed; \
502
  }
503
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
504
  #define MODULE_INIT_PERIPHERY_IF_SENSORRING() {                             \
505
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
506
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
507
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (AT42QT1050_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? AT42QT1050_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
508
  }
509
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
510
  #define MODULE_INIT_PERIPHERY_IF_SENSORRING() {                             \
511
    moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm18Pm33GaugeRearConfig.clock_speed;  \
512
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (PCAL6524_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? PCAL6524_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
513
    moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed = (AT42QT1050_LLD_I2C_MAXFREQUENCY < moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed) ? AT42QT1050_LLD_I2C_MAXFREQUENCY : moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig.clock_speed;  \
514
  }
515
#else /* (BOARD_SENSORRING == ?) */
516
  #define MODULE_INIT_PERIPHERY_IF_SENSORRING() {}
517
#endif /* (BOARD_SENSORRING == ?) */
518

    
519
/**
520
 * @brief   Periphery communication interface deinitialization hook.
521
 */
522
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
523
  /* PWM */                                                                   \
524
  pwmStop(&MODULE_HAL_PWM_BUZZER);                                            \
525
  /* ADC */                                                                   \
526
  adcStop(&MODULE_HAL_ADC_VSYS);                                              \
527
  /* I2C */                                                                   \
528
  i2cStop(&MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR);                            \
529
  i2cStop(&MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT);              \
530
  /* don't stop the serial driver so messages can still be printed */         \
531
}
532

    
533
/** @} */
534

    
535
/*===========================================================================*/
536
/**
537
 * @name Startup Shutdown Synchronization Protocol (SSSP)
538
 * @{
539
 */
540
/*===========================================================================*/
541

    
542
/**
543
 * @brief   PD signal GPIO.
544
 */
545
#define moduleSsspGpioPd                        moduleGpioSysPd
546

    
547
/**
548
 * @brief   SYNC signal GPIO.
549
 */
550
#define moduleSsspGpioSync                       moduleGpioSysSync
551

    
552
/**
553
 * @brief   DN signal GPIO.
554
 */
555
#define moduleSsspGpioDn                        moduleGpioSysUartDn
556

    
557
/**
558
 * @brief   UP signal GPIO.
559
 */
560
#define moduleSsspGpioUp                        moduleGpioSysUartUp
561

    
562
/**
563
 * @brief   Event flags for PD signal events.
564
 */
565
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
566

    
567
/**
568
 * @brief   Event flags for SYNC signal events.
569
 */
570
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
571

    
572
/**
573
 * @brief   Event flags for UP signal events.
574
 */
575
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
576

    
577
/**
578
 * @brief   Event flags for DN signal events.
579
 */
580
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
581

    
582
/** @} */
583

    
584
/*===========================================================================*/
585
/**
586
 * @name Low-level drivers
587
 * @{
588
 */
589
/*===========================================================================*/
590
#include <alld_AT24C01B.h>
591
#include <alld_bq241xx.h>
592
#include <alld_bq27500.h>
593
#include <alld_INA219.h>
594
#include <alld_LED.h>
595
#include <alld_PKxxxExxx.h>
596
#include <alld_TPS6211x.h>
597

    
598
/**
599
 * @brief   EEPROM driver.
600
 */
601
extern AT24C01BDriver moduleLldEeprom;
602

    
603
/**
604
 * @brief   Battery charger (front battery) driver.
605
 */
606
extern BQ241xxDriver moduleLldBatteryChargerFront;
607

    
608
/**
609
 * @brief   Battery charger (rear battery) driver.
610
 */
611
extern BQ241xxDriver moduleLldBatteryChargerRear;
612

    
613
/**
614
 * @brief   Fuel gauge (front battery) driver.
615
 */
616
extern BQ27500Driver moduleLldFuelGaugeFront;
617

    
618
/**
619
 * @brief   Fuel gauge (rear battery) driver.
620
 */
621
extern BQ27500Driver moduleLldFuelGaugeRear;
622

    
623
/**
624
 * @brief   Power monitor (VDD) driver.
625
 */
626
extern INA219Driver moduleLldPowerMonitorVdd;
627

    
628
/**
629
 * @brief   Power monitor (VIO 1.8) driver.
630
 */
631
extern INA219Driver moduleLldPowerMonitorVio18;
632

    
633
/**
634
 * @brief   Power monitor (VIO 3.3) driver.
635
 */
636
extern INA219Driver moduleLldPowerMonitorVio33;
637

    
638
/**
639
 * @brief   Power monitor (VSYS 4.2) driver.
640
 */
641
extern INA219Driver moduleLldPowerMonitorVsys42;
642

    
643
/**
644
 * @brief   Power monitor (VIO 5.0) driver.
645
 */
646
extern INA219Driver moduleLldPowerMonitorVio50;
647

    
648
/**
649
 * @brief   Status LED driver.
650
 */
651
extern LEDDriver moduleLldStatusLed;
652

    
653
/**
654
 * @brief   Step down converter driver.
655
 * @note    Although there multiple TPS6211x, those are completely identical from driver few (share the same signals).
656
 */
657
extern TPS6211xDriver moduleLldStepDownConverter;
658

    
659
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
660

    
661
#include <alld_MPR121.h>
662
#include <alld_PCA9544A.h>
663
#include <alld_VCNL4020.h>
664

    
665
/**
666
 * @brief   Touch sensor driver.
667
 */
668
extern MPR121Driver moduleLldTouch;
669

    
670
/**
671
 * @brief   I2C multiplexer (I2C #1) driver.
672
 */
673
extern PCA9544ADriver moduleLldI2cMultiplexer1;
674

    
675
/**
676
 * @brief   I2C multiplexer (I2C #2) driver.
677
 */
678
extern PCA9544ADriver moduleLldI2cMultiplexer2;
679

    
680
/**
681
 * @brief   Proximity sensor (I2C #1) driver.
682
 */
683
extern VCNL4020Driver moduleLldProximity1;
684

    
685
/**
686
 * @brief   Proximity sensor (I2C #2) driver.
687
 */
688
extern VCNL4020Driver moduleLldProximity2;
689

    
690
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
691

    
692
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
693

    
694
#include <alld_PCAL6524.h>
695
#include <alld_AT42QT1050.h>
696

    
697
/**
698
 * @brief   GPIO extender (I2C #1) driver.
699
 */
700
extern PCAL6524Driver moduleLldGpioExtender1;
701

    
702
/**
703
 * @brief   GPIO extender (I2C #2) driver.
704
 */
705
extern PCAL6524Driver moduleLldGpioExtender2;
706

    
707
/**
708
 * @brief   Touch sensor driver.
709
 */
710
extern AT42QT1050Driver moduleLldTouch;
711

    
712
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
713

    
714
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
715

    
716
#include <alld_PCAL6524.h>
717
#include <alld_AT42QT1050.h>
718

    
719
/**
720
 * @brief   GPIO extender (I2C #1) driver.
721
 */
722
extern PCAL6524Driver moduleLldGpioExtender1;
723

    
724
/**
725
 * @brief   GPIO extender (I2C #2) driver.
726
 */
727
extern PCAL6524Driver moduleLldGpioExtender2;
728

    
729
/**
730
 * @brief   Touch sensor driver.
731
 */
732
extern AT42QT1050Driver moduleLldTouch;
733

    
734
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
735

    
736
/** @} */
737

    
738
/*===========================================================================*/
739
/**
740
 * @name Tests
741
 * @{
742
 */
743
/*===========================================================================*/
744
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
745

    
746
/**
747
 * @brief   ADC test command.
748
 */
749
extern aos_shellcommand_t moduleTestAdcShellCmd;
750

    
751
/**
752
 * @brief   AT24C01BN-SH-B (EEPROM) test command.
753
 */
754
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
755

    
756
/**
757
 * @brief   bq24103a (battery charger) test command.
758
 */
759
extern aos_shellcommand_t moduleTestBq241xxShellCmd;
760

    
761
/**
762
 * @brief   bq27500 (fuel gauge) test command.
763
 */
764
extern aos_shellcommand_t moduleTestBq27500ShellCmd;
765

    
766
/**
767
 * @brief   bq27500 (fuel gauge) in combination with bq24103a (battery charger) test command.
768
 */
769
extern aos_shellcommand_t moduleTestBq27500Bq241xxShellCmd;
770

    
771
/**
772
 * @brief   INA219 (power monitor) test command.
773
 */
774
extern aos_shellcommand_t moduleTestIna219ShellCmd;
775

    
776
/**
777
 * @brief   Status LED test command.
778
 */
779
extern aos_shellcommand_t moduleTestLedShellCmd;
780

    
781
/**
782
 * @brief   PKLCS1212E4001 (buzzer) test command.
783
 */
784
extern aos_shellcommand_t moduleTestPkxxxexxxShellCmd;
785

    
786
/**
787
 * @brief   TPS62113 (step-down converter) test command.
788
 */
789
extern aos_shellcommand_t moduleTestTps6211xShellCmd;
790

    
791
/**
792
 * @brief   TPS62113 (step-sown converter) in combination with INA219 (power monitor) test command.
793
 */
794
extern aos_shellcommand_t moduleTestTps6211xIna219ShellCmd;
795

    
796
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
797

    
798
/**
799
 * @brief   MPR121 (touch sensor) test command.
800
 */
801
extern aos_shellcommand_t moduleTestMpr121ShellCmd;
802

    
803
/**
804
 * @brief   PCA9544A (I2C multiplexer) test command.
805
 */
806
extern aos_shellcommand_t moduleTestPca9544aShellCmd;
807

    
808
/**
809
 * @brief   VCNL4020 (proximity sensor) test command.
810
 */
811
extern aos_shellcommand_t moduleTestVcnl4020ShellCmd;
812

    
813
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
814

    
815
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
816

    
817
/**
818
 * @brief   PCAL6524 (GPIO extender) test command.
819
 */
820
extern aos_shellcommand_t moduleTestPcal6524ShellCmd;
821

    
822
/**
823
 * @brief   AT42QT1050 (touch sensor) test command.
824
 */
825
extern aos_shellcommand_t moduleTestAt42qt1050ShellCmd;
826

    
827
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
828

    
829
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
830

    
831
/**
832
 * @brief   PCAL6524 (GPIO extender) test command.
833
 */
834
extern aos_shellcommand_t moduleTestPcal6524ShellCmd;
835

    
836
/**
837
 * @brief   AT42QT1050 (touch sensor) test command.
838
 */
839
extern aos_shellcommand_t moduleTestAt42qt1050ShellCmd;
840

    
841
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
842

    
843
/**
844
 * @brief   Entire module test command.
845
 */
846
extern aos_shellcommand_t moduleTestAllShellCmd;
847

    
848
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
849

    
850
/** @} */
851

    
852
#endif /* AMIROOS_MODULE_H */
853

    
854
/** @} */