Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.h @ 881a7932

History | View | Annotate | Download (24.779 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
/*===========================================================================*/
31
/**
32
 * @name Module specific functions
33
 * @{
34
 */
35
/*===========================================================================*/
36

    
37
/*
38
 * @brief Makro to store data in the core coupled memory (ccm).
39
 *        Example:
40
 *        int compute_buffer[128] CCM_RAM;
41
 *
42
 * @note The ccm is not connected to any bus system.
43
 */
44
#define CCM_RAM                                 __attribute__((section(".ram4"), aligned(4)))
45

    
46
/*
47
 * @brief Makro to store data in the ethernet memory (eth).
48
 *        Example:
49
 *        int dma_buffer[128] ETH_RAM;
50
 *
51
 * @note The eth is a dedicated memory block with its own DMA controller.
52
 */
53
#define ETH_RAM                                 __attribute__((section(".ram2"), aligned(4)))
54

    
55
/*
56
 * @brief Makro to store data in the backup memory (bckp).
57
 *        Example:
58
 *        int backup_buffer[128] BCKP_RAM;
59
 *
60
 * @note The eth is a dedicated memory block with its own DMA controller.
61
 */
62
#define BCKP_RAM                                __attribute__((section(".ram5"), aligned(4)))
63

    
64
/** @} */
65

    
66
/*===========================================================================*/
67
/**
68
 * @name ChibiOS/HAL configuration
69
 * @{
70
 */
71
/*===========================================================================*/
72
#include <hal.h>
73

    
74
/**
75
 * @brief   ADC driver for reading the system voltage.
76
 */
77
#define MODULE_HAL_ADC_VSYS                     ADCD1
78

    
79
/**
80
 * @brief   Configuration for the ADC.
81
 */
82
extern ADCConversionGroup moduleHalAdcVsysConversionGroup;
83

    
84
/**
85
 * @brief   CAN driver to use.
86
 */
87
#define MODULE_HAL_CAN                          CAND1
88

    
89
/**
90
 * @brief   Configuration for the CAN driver.
91
 */
92
extern CANConfig moduleHalCanConfig;
93

    
94
/**
95
 * @brief   I2C driver to access multiplexer, proximity sensors 1 to 4, power monitors for VIO1.8 and VIO 3.3, and fuel gauge (rear battery).
96
 */
97
#define MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR I2CD1
98

    
99
/**
100
 * @brief   Configuration for the multiplexer, proximity sensors 1 to 4, power monitors for VIO1.8 and VIO 3.3, and fuel gauge (rear battery) I2C driver.
101
 */
102
extern I2CConfig moduleHalI2cProxPm18Pm33GaugeRearConfig;
103

    
104
/**
105
 * @brief   I2C driver to access multiplexer, proximity sensors 5 to 8, power monitors for VSYS4.2, VIO 5.0 and VDD, EEPROM, touch sensor, and fuel gauge (front battery).
106
 */
107
#define MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT I2CD2
108

    
109
/**
110
 * @brief   Configuration for the multiplexer, proximity sensors 1 to 4, power monitors for VIO1.8 and VIO 3.3, and fuel gauge (rear battery) I2C driver.
111
 */
112
extern I2CConfig moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig;
113

    
114
/**
115
 * @brief   PWM driver for the buzzer.
116
 */
117
#define MODULE_HAL_PWM_BUZZER                   PWMD3
118

    
119
/**
120
 * @brief   Configuration of the PWM driver.
121
 */
122
extern PWMConfig moduleHalPwmBuzzerConfig;
123

    
124
/**
125
 * @brief   PWM channeö for the buzzer.
126
 */
127
#define MODULE_HAL_PWM_BUZZER_CHANNEL           1
128

    
129
/**
130
 * @brief   Serial driver of the programmer interface.
131
 */
132
#define MODULE_HAL_PROGIF                       SD1
133

    
134
/**
135
 * @brief   Configuration for the programmer serial interface driver.
136
 */
137
extern SerialConfig moduleHalProgIfConfig;
138

    
139
/**
140
 * @brief   Real-Time Clock driver.
141
 */
142
#define MODULE_HAL_RTC                          RTCD1
143

    
144
/** @} */
145

    
146
/*===========================================================================*/
147
/**
148
 * @name GPIO definitions
149
 * @{
150
 */
151
/*===========================================================================*/
152
#include <amiro-lld.h>
153

    
154
/**
155
 * @brief   SYS_REG_EN output signal GPIO.
156
 */
157
extern ROMCONST apalControlGpio_t moduleGpioSysRegEn;
158

    
159
/**
160
 * @brief   IR_INT1 input signal GPIO.
161
 */
162
extern ROMCONST apalControlGpio_t moduleGpioIrInt1;
163

    
164
/**
165
 * @brief   POWER_EN output signal GPIO.
166
 */
167
extern ROMCONST apalControlGpio_t moduleGpioPowerEn;
168

    
169
/**
170
 * @brief   SYS_UART_DN bidirectional signal GPIO.
171
 */
172
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
173

    
174
/**
175
 * @brief   CHARGE_STAT2A input signal GPIO.
176
 */
177
extern ROMCONST apalControlGpio_t moduleGpioChargeStat2A;
178

    
179
/**
180
 * @brief   GAUGE_BATLOW2 input signal GPIO.
181
 */
182
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2;
183

    
184
/**
185
 * @brief   GAUGE_BATGD2 input signal GPIO.
186
 */
187
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2;
188

    
189
/**
190
 * @brief   LED output signal GPIO.
191
 */
192
extern ROMCONST apalControlGpio_t moduleGpioLed;
193

    
194
/**
195
 * @brief   SYS_UART_UP bidirectional signal GPIO.
196
 */
197
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
198

    
199
/**
200
 * @brief   CHARGE_STAT1A input signal GPIO.
201
 */
202
extern ROMCONST apalControlGpio_t moduleGpioChargeStat1A;
203

    
204
/**
205
 * @brief   GAUGE_BATLOW1 input signal GPIO.
206
 */
207
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1;
208

    
209
/**
210
 * @brief   GAUGE_BATGD1 input signal GPIO.
211
 */
212
extern ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1;
213

    
214
/**
215
 * @brief   CHARG_EN1 output signal GPIO.
216
 */
217
extern ROMCONST apalControlGpio_t moduleGpioChargeEn1;
218

    
219
/**
220
 * @brief   IR_INT2 input signal GPIO.
221
 */
222
extern ROMCONST apalControlGpio_t moduleGpioIrInt2;
223

    
224
/**
225
 * @brief   TOUCH_INT input signal GPIO.
226
 */
227
extern ROMCONST apalControlGpio_t moduleGpioTouchInt;
228

    
229
/**
230
 * @brief   SYS_DONE input signal GPIO.
231
 */
232
extern ROMCONST apalControlGpio_t moduleGpioSysDone;
233

    
234
/**
235
 * @brief   SYS_PROG output signal GPIO.
236
 */
237
extern ROMCONST apalControlGpio_t moduleGpioSysProg;
238

    
239
/**
240
 * @brief   PATH_DC input signal GPIO.
241
 */
242
extern ROMCONST apalControlGpio_t moduleGpioPathDc;
243

    
244
/**
245
 * @brief   SYS_SPI_DIR bidirectional signal GPIO.
246
 */
247
extern ROMCONST apalControlGpio_t moduleGpioSysSpiDir;
248

    
249
/**
250
 * @brief   SYS_SYNC bidirectional signal GPIO.
251
 */
252
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
253

    
254
/**
255
 * @brief   SYS_PD bidirectional signal GPIO.
256
 */
257
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
258

    
259
/**
260
 * @brief   SYS_WARMRST bidirectional signal GPIO.
261
 */
262
extern ROMCONST apalControlGpio_t moduleGpioSysWarmrst;
263

    
264
/**
265
 * @brief   BT_RST output signal GPIO.
266
 */
267
extern ROMCONST apalControlGpio_t moduleGpioBtRst;
268

    
269
/**
270
 * @brief   CHARGE_EN2 output signal GPIO.
271
 */
272
extern ROMCONST apalControlGpio_t moduleGpioChargeEn2;
273

    
274
/** @} */
275

    
276
/*===========================================================================*/
277
/**
278
 * @name AMiRo-OS core configurations
279
 * @{
280
 */
281
/*===========================================================================*/
282

    
283
/**
284
 * @brief   Event flag to be set on a IR_INT1 / CHARGE_STAT1A interrupt.
285
 */
286
#define MODULE_OS_IOEVENTFLAGS_IRINT1           ((eventflags_t)1 << GPIOB_IR_INT1_N)
287

    
288
/**
289
 * @brief   Event flag to be set on a GAUGE_BATLOW1 interrupt.
290
 */
291
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATLOW1     ((eventflags_t)1 << GPIOC_GAUGE_BATLOW1)
292

    
293
/**
294
 * @brief   Event flag to be set on a GAUGE_BATGD1 interrupt.
295
 */
296
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATGD1      ((eventflags_t)1 << GPIOC_GAUGE_BATGD1_N)
297

    
298
/**
299
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
300
 */
301
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        ((eventflags_t)1 << GPIOB_SYS_UART_DN)
302

    
303
/**
304
 * @brief   Event flag to be set on a IR_INT2 / CHARGE_STAT2A interrupt.
305
 */
306
#define MODULE_OS_IOEVENTFLAGS_IRINT2           ((eventflags_t)1 << GPIOC_IR_INT2_N)
307

    
308
/**
309
 * @brief   Event flag to be set on a TOUCH_INT interrupt.
310
 */
311
#define MODULE_OS_IOEVENTFLAGS_TOUCHINT         ((eventflags_t)1 << GPIOC_TOUCH_INT_N)
312

    
313
/**
314
 * @brief   Event flag to be set on a GAUGE_BATLOW2 interrupt.
315
 */
316
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATLOW2     ((eventflags_t)1 << GPIOB_GAUGE_BATLOW2)
317

    
318
/**
319
 * @brief   Event flag to be set on a GAUGE_BATGD2 interrupt.
320
 */
321
#define MODULE_OS_IOEVENTFLAGS_GAUGEBATGD2      ((eventflags_t)1 << GPIOB_GAUGE_BATGD2_N)
322

    
323
/**
324
 * @brief   Event flag to be set on a PATH_DC interrupt.
325
 */
326
#define MODULE_OS_IOEVENTFLAGS_PATHDC           ((eventflags_t)1 << GPIOC_PATH_DC)
327

    
328
/**
329
 * @brief   Event flag to be set on a SYS_SPI_DIR interrupt.
330
 */
331
#define MODULE_OS_IOEVENTFLAGS_SYSSPIDIR        ((eventflags_t)1 << GPIOC_SYS_SPI_DIR)
332

    
333
/**
334
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
335
 */
336
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          ((eventflags_t)1 << GPIOC_SYS_INT_N)
337

    
338
/**
339
 * @brief   Event flag to be set on a SYS_PD interrupt.
340
 */
341
#define MODULE_OS_IOEVENTFLAGS_SYSPD            ((eventflags_t)1 << GPIOC_SYS_PD_N)
342

    
343
/**
344
 * @brief   Event flag to be set on a SYS_WARMRST interrupt.
345
 */
346
#define MODULE_OS_IOEVENTFLAGS_SYSWARMRST       ((eventflags_t)1 << GPIOC_SYS_WARMRST_N)
347

    
348
/**
349
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
350
 */
351
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        ((eventflags_t)1 << GPIOB_SYS_UART_UP)
352

    
353
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
354
/**
355
 * @brief   Shell prompt text.
356
 */
357
extern ROMCONST char* moduleShellPrompt;
358
#endif
359

    
360
/**
361
 * @brief   Interrupt initialization macro.
362
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
363
 */
364
#define MODULE_INIT_INTERRUPTS() {                                            \
365
  /* IR_INT1 */                                                               \
366
  palSetPadCallback(moduleGpioIrInt1.gpio->port, moduleGpioIrInt1.gpio->pad, _intCallback, &moduleGpioIrInt1.gpio->pad); \
367
  palEnablePadEvent(moduleGpioIrInt1.gpio->port, moduleGpioIrInt1.gpio->pad, APAL2CH_EDGE(moduleGpioIrInt1.meta.edge));  \
368
  /* GAUGE_BATLOW2 */                                                         \
369
  palSetPadCallback(moduleGpioGaugeBatLow2.gpio->port, moduleGpioGaugeBatLow2.gpio->pad, _intCallback, &moduleGpioGaugeBatLow2.gpio->pad);  \
370
  palEnablePadEvent(moduleGpioGaugeBatLow2.gpio->port, moduleGpioGaugeBatLow2.gpio->pad, APAL2CH_EDGE(moduleGpioGaugeBatLow2.meta.edge));   \
371
  /* GAUGE_BATGD2 */                                                          \
372
  palSetPadCallback(moduleGpioGaugeBatGd2.gpio->port, moduleGpioGaugeBatGd2.gpio->pad, _intCallback, &moduleGpioGaugeBatGd2.gpio->pad); \
373
  palEnablePadEvent(moduleGpioGaugeBatGd2.gpio->port, moduleGpioGaugeBatGd2.gpio->pad, APAL2CH_EDGE(moduleGpioGaugeBatGd2.meta.edge));  \
374
  /* GAUGE_BATLOW1 */                                                         \
375
  palSetPadCallback(moduleGpioGaugeBatLow1.gpio->port, moduleGpioGaugeBatLow1.gpio->pad, _intCallback, &moduleGpioGaugeBatLow1.gpio->pad);  \
376
  palEnablePadEvent(moduleGpioGaugeBatLow1.gpio->port, moduleGpioGaugeBatLow1.gpio->pad, APAL2CH_EDGE(moduleGpioGaugeBatLow1.meta.edge));   \
377
  /* GAUGE_BATGD1 */                                                          \
378
  palSetPadCallback(moduleGpioGaugeBatGd1.gpio->port, moduleGpioGaugeBatGd1.gpio->pad, _intCallback, &moduleGpioGaugeBatGd1.gpio->pad); \
379
  palEnablePadEvent(moduleGpioGaugeBatGd1.gpio->port, moduleGpioGaugeBatGd1.gpio->pad, APAL2CH_EDGE(moduleGpioGaugeBatGd1.meta.edge));  \
380
  /* IR_INT1 */                                                               \
381
  palSetPadCallback(moduleGpioIrInt2.gpio->port, moduleGpioIrInt2.gpio->pad, _intCallback, &moduleGpioIrInt1.gpio->pad); \
382
  palEnablePadEvent(moduleGpioIrInt2.gpio->port, moduleGpioIrInt2.gpio->pad, APAL2CH_EDGE(moduleGpioIrInt1.meta.edge));  \
383
  /* TOUCH_INT */                                                             \
384
  palSetPadCallback(moduleGpioTouchInt.gpio->port, moduleGpioTouchInt.gpio->pad, _intCallback, &moduleGpioTouchInt.gpio->pad); \
385
  palEnablePadEvent(moduleGpioTouchInt.gpio->port, moduleGpioTouchInt.gpio->pad, APAL2CH_EDGE(moduleGpioTouchInt.meta.edge));  \
386
  /* PATH_DC */                                                               \
387
  palSetPadCallback(moduleGpioPathDc.gpio->port, moduleGpioPathDc.gpio->pad, _intCallback, &moduleGpioPathDc.gpio->pad);  \
388
  palEnablePadEvent(moduleGpioPathDc.gpio->port, moduleGpioPathDc.gpio->pad, APAL2CH_EDGE(moduleGpioPathDc.meta.edge));   \
389
  /* SYS_SPI_DIR */                                                           \
390
  palSetPadCallback(moduleGpioSysSpiDir.gpio->port, moduleGpioSysSpiDir.gpio->pad, _intCallback, &moduleGpioSysSpiDir.gpio->pad); \
391
  palEnablePadEvent(moduleGpioSysSpiDir.gpio->port, moduleGpioSysSpiDir.gpio->pad, APAL2CH_EDGE(moduleGpioSysSpiDir.meta.edge));  \
392
  /* SYS_WARMRST */                                                           \
393
  palSetPadCallback(moduleGpioSysWarmrst.gpio->port, moduleGpioSysWarmrst.gpio->pad, _intCallback, &moduleGpioSysWarmrst.gpio->pad);  \
394
  palEnablePadEvent(moduleGpioSysWarmrst.gpio->port, moduleGpioSysWarmrst.gpio->pad, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));   \
395
}
396

    
397
/**
398
 * @brief   Unit test initialization hook.
399
 */
400
#define MODULE_INIT_TESTS() {                                                 \
401
  /* add unit-test shell commands */                                          \
402
  aosShellAddCommand(&aos.shell, &moduleUtAdcVsys.shellcmd);                  \
403
  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01bn.shellcmd);            \
404
  aosShellAddCommand(&aos.shell, &moduleUtAlldBq24103a.shellcmd);             \
405
  aosShellAddCommand(&aos.shell, &moduleUtAlldBq27500.shellcmd);              \
406
  aosShellAddCommand(&aos.shell, &moduleUtAlldBq27500Bq24103a.shellcmd);      \
407
  aosShellAddCommand(&aos.shell, &moduleUtAlldIna219.shellcmd);               \
408
  aosShellAddCommand(&aos.shell, &moduleUtAlldMpr121.shellcmd);               \
409
  aosShellAddCommand(&aos.shell, &moduleUtAlldPca9544a.shellcmd);             \
410
  aosShellAddCommand(&aos.shell, &moduleUtAlldPklcs1212e4001.shellcmd);       \
411
  aosShellAddCommand(&aos.shell, &moduleUtAlldLed.shellcmd);                  \
412
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113.shellcmd);             \
413
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113Ina219.shellcmd);       \
414
  aosShellAddCommand(&aos.shell, &moduleUtAlldVcnl4020.shellcmd);             \
415
}
416

    
417
/**
418
 * @brief   Periphery communication interfaces initialization hook.
419
 */
420
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
421
  /* serial driver */                                                         \
422
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
423
  /* I2C */                                                                   \
424
  moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed;  \
425
  moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed;  \
426
  moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed;  \
427
  moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed = (BQ27500_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed) ? BQ27500_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed;  \
428
  moduleHalI2cProxPm18Pm33GaugeRearConfig.duty_cycle = (moduleHalI2cProxPm18Pm33GaugeRearConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
429
  i2cStart(&MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR, &moduleHalI2cProxPm18Pm33GaugeRearConfig); \
430
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed; \
431
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed; \
432
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed; \
433
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed = (AT24C01BN_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed) ? AT24C01BN_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed; \
434
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed = (MPR121_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed) ? MPR121_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed; \
435
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed = (BQ27500_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed) ? BQ27500_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed; \
436
  moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.duty_cycle = (moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
437
  i2cStart(&MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT, &moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig);  \
438
  /* ADC */                                                                   \
439
  adcStart(&MODULE_HAL_ADC_VSYS, NULL);                                       \
440
  /* PWM */                                                                   \
441
  pwmStart(&MODULE_HAL_PWM_BUZZER, &moduleHalPwmBuzzerConfig);                \
442
  moduleHalPwmBuzzerConfig.frequency = MODULE_HAL_PWM_BUZZER.clock;           \
443
  pwmStop(&MODULE_HAL_PWM_BUZZER);                                            \
444
  moduleHalPwmBuzzerConfig.period = moduleHalPwmBuzzerConfig.frequency / PKLCS1212E4001_LLD_FREQUENCY_SPEC; \
445
  pwmStart(&MODULE_HAL_PWM_BUZZER, &moduleHalPwmBuzzerConfig);                \
446
}
447

    
448
/**
449
 * @brief   Periphery communication interface deinitialization hook.
450
 */
451
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
452
  /* PWM */                                                                   \
453
  pwmStop(&MODULE_HAL_PWM_BUZZER);                                            \
454
  /* ADC */                                                                   \
455
  adcStop(&MODULE_HAL_ADC_VSYS);                                              \
456
  /* I2C */                                                                   \
457
  i2cStop(&MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR);                          \
458
  i2cStop(&MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT);      \
459
  /* don't stop the serial driver so messages can still be printed */         \
460
}
461

    
462
/** @} */
463

    
464
#if (AMIROOS_CFG_SSSP_ENABLE == true)
465
/*===========================================================================*/
466
/**
467
 * @name Startup Shutdown Synchronization Protocol (SSSP)
468
 * @{
469
 */
470
/*===========================================================================*/
471

    
472
/**
473
 * @brief   PD signal GPIO.
474
 */
475
#define moduleSsspGpioPd                        moduleGpioSysPd
476

    
477
/**
478
 * @brief   SYNC signal GPIO.
479
 */
480
#define moduleSsspGpioSync                       moduleGpioSysSync
481

    
482
/**
483
 * @brief   DN signal GPIO.
484
 */
485
#define moduleSsspGpioDn                        moduleGpioSysUartDn
486

    
487
/**
488
 * @brief   UP signal GPIO.
489
 */
490
#define moduleSsspGpioUp                        moduleGpioSysUartUp
491

    
492
/**
493
 * @brief   Event flags for PD signal events.
494
 */
495
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
496

    
497
/**
498
 * @brief   Event flags for SYNC signal events.
499
 */
500
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
501

    
502
/**
503
 * @brief   Event flags for UP signal events.
504
 */
505
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
506

    
507
/**
508
 * @brief   Event flags for DN signal events.
509
 */
510
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
511

    
512
/** @} */
513

    
514
#endif
515
/*===========================================================================*/
516
/**
517
 * @name Low-level drivers
518
 * @{
519
 */
520
/*===========================================================================*/
521
#include <alld_at24c01bn-sh-b.h>
522
#include <alld_bq24103a.h>
523
#include <alld_bq27500.h>
524
#include <alld_ina219.h>
525
#include <alld_led.h>
526
#include <alld_mpr121.h>
527
#include <alld_pca9544a.h>
528
#include <alld_pklcs1212e4001.h>
529
#include <alld_tps62113.h>
530
#include <alld_vcnl4020.h>
531

    
532
/**
533
 * @brief   EEPROM driver.
534
 */
535
extern AT24C01BNDriver moduleLldEeprom;
536

    
537
/**
538
 * @brief   Battery charger (front battery) driver.
539
 */
540
extern BQ24103ADriver moduleLldBatteryChargerFront;
541

    
542
/**
543
 * @brief   Battery charger (rear battery) driver.
544
 */
545
extern BQ24103ADriver moduleLldBatteryChargerRear;
546

    
547
/**
548
 * @brief   Fuel gauge (front battery) driver.
549
 */
550
extern BQ27500Driver moduleLldFuelGaugeFront;
551

    
552
/**
553
 * @brief   Fuel gauge (rear battery) driver.
554
 */
555
extern BQ27500Driver moduleLldFuelGaugeRear;
556

    
557
/**
558
 * @brief   Power monitor (VDD) driver.
559
 */
560
extern INA219Driver moduleLldPowerMonitorVdd;
561

    
562
/**
563
 * @brief   Power monitor (VIO 1.8) driver.
564
 */
565
extern INA219Driver moduleLldPowerMonitorVio18;
566

    
567
/**
568
 * @brief   Power monitor (VIO 3.3) driver.
569
 */
570
extern INA219Driver moduleLldPowerMonitorVio33;
571

    
572
/**
573
 * @brief   Power monitor (VSYS 4.2) driver.
574
 */
575
extern INA219Driver moduleLldPowerMonitorVsys42;
576

    
577
/**
578
 * @brief   Power monitor (VIO 5.0) driver.
579
 */
580
extern INA219Driver moduleLldPowerMonitorVio50;
581

    
582
/**
583
 * @brief   Status LED driver.
584
 */
585
extern LEDDriver moduleLldStatusLed;
586

    
587
/**
588
 * @brief   Touch sensor driver.
589
 */
590
extern MPR121Driver moduleLldTouch;
591

    
592
/**
593
 * @brief   I2C multiplexer (I2C 1) driver.
594
 */
595
extern PCA9544ADriver moduleLldI2cMultiplexer1;
596

    
597
/**
598
 * @brief   I2C multiplexer (I2C 2) driver.
599
 */
600
extern PCA9544ADriver moduleLldI2cMultiplexer2;
601

    
602
/**
603
 * @brief   Step down converter driver.
604
 * @note    Although there multiple TPS62113, those are completely identical from driver few (share the same signals).
605
 */
606
extern TPS62113Driver moduleLldStepDownConverter;
607

    
608
/**
609
 * @brief   Proximity sensor (I2C 1) driver.
610
 */
611
extern VCNL4020Driver moduleLldProximity1;
612

    
613
/**
614
 * @brief   Proximity sensor (I2C 2) driver.
615
 */
616
extern VCNL4020Driver moduleLldProximity2;
617

    
618
/** @} */
619

    
620
/*===========================================================================*/
621
/**
622
 * @name Unit tests (UT)
623
 * @{
624
 */
625
/*===========================================================================*/
626
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
627
#include <ut_lld_adc.h>
628
#include <ut_alld_at24c01bn-sh-b.h>
629
#include <ut_alld_bq24103a.h>
630
#include <ut_alld_bq27500.h>
631
#include <ut_alld_bq27500_bq24103a.h>
632
#include <ut_alld_ina219.h>
633
#include <ut_alld_led.h>
634
#include <ut_alld_mpr121.h>
635
#include <ut_alld_pca9544a.h>
636
#include <ut_alld_pklcs1212e4001.h>
637
#include <ut_alld_tps62113.h>
638
#include <ut_alld_tps62113_ina219.h>
639
#include <ut_alld_vcnl4020.h>
640

    
641
/**
642
 * @brief   ADC unit test object.
643
 */
644
extern aos_unittest_t moduleUtAdcVsys;
645

    
646
/**
647
 * @brief   AT24C01BN-SH-B (EEPROM) unit test object.
648
 */
649
extern aos_unittest_t moduleUtAlldAt24c01bn;
650

    
651
/**
652
 * @brief   BQ24103A (battery charger) unit test object.
653
 */
654
extern aos_unittest_t moduleUtAlldBq24103a;
655

    
656
/**
657
 * @brief   BQ27500 (fuel gauge) unit test object.
658
 */
659
extern aos_unittest_t moduleUtAlldBq27500;
660

    
661
/**
662
 * @brief   BQ27500 (fuela gauge) in combination with BQ24103A (battery charger) unit test object.
663
 */
664
extern aos_unittest_t moduleUtAlldBq27500Bq24103a;
665

    
666
/**
667
 * @brief   INA219 (power monitor) unit test object.
668
 */
669
extern aos_unittest_t moduleUtAlldIna219;
670

    
671
/**
672
 * @brief   Status LED unit test object.
673
 */
674
extern aos_unittest_t moduleUtAlldLed;
675

    
676
/**
677
 * @brief   MPR121 (touch sensor) unit test object.
678
 */
679
extern aos_unittest_t moduleUtAlldMpr121;
680

    
681
/**
682
 * @brief   PCA9544A (I2C multiplexer) unit test object.
683
 */
684
extern aos_unittest_t moduleUtAlldPca9544a;
685

    
686
/**
687
 * @brief   PKLCS1212E4001 (buzzer) unit test object.
688
 */
689
extern aos_unittest_t moduleUtAlldPklcs1212e4001;
690

    
691
/**
692
 * @brief   TPS62113 (step-down converter) unit test object.
693
 */
694
extern aos_unittest_t moduleUtAlldTps62113;
695

    
696
/**
697
 * @brief   TPS62113 (step-sown converter) in combination with INA219 (power monitor) unit test object.
698
 */
699
extern aos_unittest_t moduleUtAlldTps62113Ina219;
700

    
701
/**
702
 * @brief   VCNL4020 (proximity sensor) unit test object.
703
 */
704
extern aos_unittest_t moduleUtAlldVcnl4020;
705

    
706
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
707

    
708
/** @} */
709

    
710
#endif /* _AMIROOS_MODULE_H_ */
711

    
712
/** @} */