Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.c @ b85b6b26

History | View | Annotate | Download (48.142 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 84f0ce9e Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 e545e620 Thomas Schöpping

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 53710ca3 Marc Rothmann
/**
20 acc97cbf Thomas Schöpping
 * @file
21 53710ca3 Marc Rothmann
 * @brief   Structures and constant for the PowerManagement module.
22
 *
23
 * @addtogroup powermanagement_module
24
 * @{
25
 */
26
27 e545e620 Thomas Schöpping
#include "module.h"
28
29
/*===========================================================================*/
30
/**
31
 * @name Module specific functions
32
 * @{
33
 */
34
/*===========================================================================*/
35
36
/** @} */
37
38
/*===========================================================================*/
39
/**
40
 * @name ChibiOS/HAL configuration
41
 * @{
42
 */
43
/*===========================================================================*/
44
45
ADCConversionGroup moduleHalAdcVsysConversionGroup = {
46
  /* buffer type        */ true,
47
  /* number of channels */ 1,
48
  /* callback function  */ NULL,
49
  /* error callback     */ NULL,
50
  /* CR1                */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
51
  /* CR2                */ ADC_CR2_SWSTART | ADC_CR2_CONT,
52
  /* SMPR1              */ 0,
53
  /* SMPR2              */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
54
  /* HTR                */ ADC_HTR_HT,
55
  /* LTR                */ 0,
56
  /* SQR1               */ ADC_SQR1_NUM_CH(1),
57
  /* SQR2               */ 0,
58
  /* SQR3               */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
59
};
60
61
CANConfig moduleHalCanConfig = {
62
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
63 933df08e Thomas Schöpping
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1),
64 e545e620 Thomas Schöpping
};
65
66 8be006e0 Thomas Schöpping
I2CConfig moduleHalI2cSrPm18Pm33GaugeRearConfig = {
67 e545e620 Thomas Schöpping
  /* I²C mode   */ OPMODE_I2C,
68
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
69
  /* duty cycle */ FAST_DUTY_CYCLE_2,
70
};
71
72 8be006e0 Thomas Schöpping
I2CConfig moduleHalI2cSrPm42Pm50PmVddEepromGaugeFrontConfig = {
73 e545e620 Thomas Schöpping
  /* I²C mode   */ OPMODE_I2C,
74
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
75
  /* duty cycle */ FAST_DUTY_CYCLE_2,
76
};
77
78
PWMConfig moduleHalPwmBuzzerConfig = {
79
  /* frequency              */ 1000000,
80
  /* period                 */ 0,
81
  /* callback               */ NULL,
82
  /* channel configurations */ {
83
    /* channel 0              */ {
84
      /* mode                   */ PWM_OUTPUT_DISABLED,
85
      /* callback               */ NULL
86
    },
87
    /* channel 1              */ {
88
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
89
      /* callback               */ NULL
90
    },
91 4a0e2139 Julian L
    /* channel 2  f            */ {
92 e545e620 Thomas Schöpping
      /* mode                   */ PWM_OUTPUT_DISABLED,
93
      /* callback               */ NULL
94
    },
95
    /* channel 3              */ {
96
      /* mode                   */ PWM_OUTPUT_DISABLED,
97
      /* callback               */ NULL
98
    },
99
  },
100
  /* TIM CR2 register       */ 0,
101 7de0cc90 Thomas Schöpping
#if (STM32_PWM_USE_ADVANCED == TRUE)
102 e545e620 Thomas Schöpping
  /* TIM BDTR register      */ 0,
103 7de0cc90 Thomas Schöpping
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */
104 e545e620 Thomas Schöpping
  /* TIM DIER register      */ 0,
105
};
106
107
SerialConfig moduleHalProgIfConfig = {
108
  /* bit rate */ 115200,
109
  /* CR1      */ 0,
110
  /* CR1      */ 0,
111
  /* CR1      */ 0,
112
};
113
114
/** @} */
115
116
/*===========================================================================*/
117
/**
118
 * @name GPIO definitions
119
 * @{
120
 */
121
/*===========================================================================*/
122
123 1e5f7648 Thomas Schöpping
/**
124
 * @brief   SYS_REG_EN output signal GPIO.
125
 */
126
static apalGpio_t _gpioSysRegEn = {
127 e545e620 Thomas Schöpping
  /* port */ GPIOA,
128
  /* pad  */ GPIOA_SYS_REG_EN,
129
};
130 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleSysRegEn = {
131 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysRegEn,
132
  /* meta */ {
133
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
134
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
135
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
136
  },
137
};
138 e545e620 Thomas Schöpping
139 1e5f7648 Thomas Schöpping
/**
140
 * @brief   IR_INT1 input signal GPIO.
141
 */
142
static apalGpio_t _gpioIrInt1 = {
143 e545e620 Thomas Schöpping
  /* port */ GPIOB,
144
  /* pad  */ GPIOB_IR_INT1_N,
145
};
146 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt1 = {
147 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioIrInt1,
148
  /* meta */ {
149
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
150 8be006e0 Thomas Schöpping
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
151 1e5f7648 Thomas Schöpping
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
152
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
153 8be006e0 Thomas Schöpping
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
154 bffb3465 Thomas Schöpping
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
155
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
156 8be006e0 Thomas Schöpping
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
157 bffb3465 Thomas Schöpping
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
158
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
159 7de0cc90 Thomas Schöpping
#else /* (BOARD_SENSORRING == ?) */
160 8be006e0 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
161
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
162 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == ?) */
163 1e5f7648 Thomas Schöpping
  },
164
};
165 e545e620 Thomas Schöpping
166 1e5f7648 Thomas Schöpping
/**
167
 * @brief   POWER_EN output signal GPIO.
168
 */
169
static apalGpio_t _gpioPowerEn = {
170 e545e620 Thomas Schöpping
  /* port */ GPIOB,
171
  /* pad  */ GPIOB_POWER_EN,
172
};
173 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
174 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPowerEn,
175
  /* meta */ {
176
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
177
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
178
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
179
  },
180
};
181 e545e620 Thomas Schöpping
182 1e5f7648 Thomas Schöpping
/**
183
 * @brief   SYS_UART_DN bidirectional signal GPIO.
184
 */
185
static apalGpio_t _gpioSysUartDn = {
186 e545e620 Thomas Schöpping
  /* port */ GPIOB,
187
  /* pad  */ GPIOB_SYS_UART_DN,
188
};
189 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
190 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysUartDn,
191
  /* meta */ {
192
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
193
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
194
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
195
  },
196
};
197 e545e620 Thomas Schöpping
198 1e5f7648 Thomas Schöpping
/**
199
 * @brief   CHARGE_STAT2A input signal GPIO.
200
 */
201
static apalGpio_t _gpioChargeStat2A = {
202 e545e620 Thomas Schöpping
  /* port */ GPIOB,
203
  /* pad  */ GPIOB_CHARGE_STAT2A,
204
};
205 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioChargeStat2A = {
206 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioChargeStat2A,
207
  /* meta */ {
208
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
209 ddf34c3d Thomas Schöpping
    /* active state   */ BQ241xx_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
210 1e5f7648 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
211
  },
212
};
213 e545e620 Thomas Schöpping
214 1e5f7648 Thomas Schöpping
/**
215
 * @brief   GAUGE_BATLOW2 input signal GPIO.
216
 */
217
static apalGpio_t _gpioGaugeBatLow2 = {
218 e545e620 Thomas Schöpping
  /* port */ GPIOB,
219
  /* pad  */ GPIOB_GAUGE_BATLOW2,
220
};
221 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2 = {
222 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGaugeBatLow2,
223
  /* meta */ {
224
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
225
    /* active state   */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
226
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
227
  },
228
};
229 e545e620 Thomas Schöpping
230 1e5f7648 Thomas Schöpping
/**
231
 * @brief   GAUGE_BATGD2 input signal GPIO.
232
 */
233
static apalGpio_t _gpioGaugeBatGd2 = {
234 e545e620 Thomas Schöpping
  /* port */ GPIOB,
235
  /* pad  */ GPIOB_GAUGE_BATGD2_N,
236
};
237 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2 = {
238 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGaugeBatGd2,
239
  /* meta */ {
240
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
241
    /* active state   */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
242
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
243
  },
244
};
245 e545e620 Thomas Schöpping
246 1e5f7648 Thomas Schöpping
/**
247
 * @brief   LED output signal GPIO.
248
 */
249
static apalGpio_t _gpioLed = {
250 e545e620 Thomas Schöpping
  /* port */ GPIOB,
251
  /* pad  */ GPIOB_LED,
252
};
253 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
254 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioLed,
255
  /* meta */ {
256
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
257
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
258
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
259
  },
260
};
261 e545e620 Thomas Schöpping
262 1e5f7648 Thomas Schöpping
/**
263
 * @brief   SYS_UART_UP bidirectional signal GPIO.
264
 */
265
static apalGpio_t _gpioSysUartUp = {
266 e545e620 Thomas Schöpping
  /* port */ GPIOB,
267
  /* pad  */ GPIOB_SYS_UART_UP,
268
};
269 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
270 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysUartUp,
271
  /* meta */ {
272
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
273
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
274
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
275
  },
276
};
277 e545e620 Thomas Schöpping
278 1e5f7648 Thomas Schöpping
/**
279
 * @brief   CHARGE_STAT1A input signal GPIO.
280
 */
281
static apalGpio_t _gpioChargeStat1A = {
282 e545e620 Thomas Schöpping
  /* port */ GPIOC,
283
  /* pad  */ GPIOC_CHARGE_STAT1A,
284
};
285 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioChargeStat1A = {
286 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioChargeStat1A,
287
  /* meta */ {
288
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
289 ddf34c3d Thomas Schöpping
    /* active state   */ BQ241xx_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
290 1e5f7648 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
291
  },
292
};
293 e545e620 Thomas Schöpping
294 1e5f7648 Thomas Schöpping
/**
295
 * @brief   GAUGE_BATLOW1 input signal GPIO.
296
 */
297
static apalGpio_t _gpioGaugeBatLow1 = {
298 e545e620 Thomas Schöpping
  /* port */ GPIOC,
299
  /* pad  */ GPIOC_GAUGE_BATLOW1,
300
};
301 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGaugeBatLow1 = {
302 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGaugeBatLow1,
303
  /* meta */ {
304
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
305
    /* active state   */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
306
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
307
  },
308
};
309 e545e620 Thomas Schöpping
310 1e5f7648 Thomas Schöpping
/**
311
 * @brief   GAUGE_BATGD1 input signal GPIO.
312
 */
313
static apalGpio_t _gpioGaugeBatGd1 = {
314 e545e620 Thomas Schöpping
  /* port */ GPIOC,
315
  /* pad  */ GPIOC_GAUGE_BATGD1_N,
316
};
317 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGaugeBatGd1 = {
318 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGaugeBatGd1,
319
  /* meta */ {
320
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
321
    /* active state   */ BQ27500_LLD_BATGOOD_ACTIVE_STATE,
322
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
323
  },
324
};
325 e545e620 Thomas Schöpping
326 1e5f7648 Thomas Schöpping
/**
327
 * @brief   CHARG_EN1 output signal GPIO.
328
 */
329
static apalGpio_t _gpioChargeEn1 = {
330 e545e620 Thomas Schöpping
  /* port */ GPIOC,
331
  /* pad  */ GPIOC_CHARGE_EN1_N,
332
};
333 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioChargeEn1 = {
334 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioChargeEn1,
335
  /* meta */ {
336
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
337 ddf34c3d Thomas Schöpping
    /* active state   */ BQ241xx_LLD_ENABLED_GPIO_ACTIVE_STATE,
338 1e5f7648 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
339
  },
340
};
341 e545e620 Thomas Schöpping
342 1e5f7648 Thomas Schöpping
/**
343
 * @brief   IR_INT2 input signal GPIO.
344
 */
345
static apalGpio_t _gpioIrInt2 = {
346 e545e620 Thomas Schöpping
  /* port */ GPIOC,
347
  /* pad  */ GPIOC_IR_INT2_N,
348
};
349 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt2 = {
350 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioIrInt2,
351
  /* meta */ {
352
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
353 8be006e0 Thomas Schöpping
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
354 1e5f7648 Thomas Schöpping
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
355
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
356 8be006e0 Thomas Schöpping
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
357 bffb3465 Thomas Schöpping
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
358
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
359 8be006e0 Thomas Schöpping
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
360 bffb3465 Thomas Schöpping
    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
361
    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
362 7de0cc90 Thomas Schöpping
#else /* (BOARD_SENSORRING == ?) */
363 8be006e0 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
364
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
365 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == ?) */
366 1e5f7648 Thomas Schöpping
  },
367
};
368 e545e620 Thomas Schöpping
369 1e5f7648 Thomas Schöpping
/**
370
 * @brief   TOUCH_INT input signal GPIO.
371
 */
372
static apalGpio_t _gpioTouchInt = {
373 e545e620 Thomas Schöpping
  /* port */ GPIOC,
374
  /* pad  */ GPIOC_TOUCH_INT_N,
375
};
376 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioTouchInt = {
377 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioTouchInt,
378
  /* meta */ {
379
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
380 8be006e0 Thomas Schöpping
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)
381 1e5f7648 Thomas Schöpping
    /* active state   */ (MPR121_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
382
    /* interrupt edge */ MPR121_LLD_INT_EDGE,
383 8be006e0 Thomas Schöpping
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
384 bffb3465 Thomas Schöpping
    /* active state   */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
385
    /* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
386 8be006e0 Thomas Schöpping
#elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
387 bffb3465 Thomas Schöpping
    /* active state   */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
388
    /* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
389 7de0cc90 Thomas Schöpping
#else /* (BOARD_SENSORRING == ?) */
390 8be006e0 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
391
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
392 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == ?) */
393 1e5f7648 Thomas Schöpping
  },
394
};
395 e545e620 Thomas Schöpping
396 1e5f7648 Thomas Schöpping
/**
397
 * @brief   SYS_DONE input signal GPIO.
398
 */
399
static apalGpio_t _gpioSysDone = {
400 e545e620 Thomas Schöpping
  /* port */ GPIOC,
401
  /* pad  */ GPIOC_SYS_DONE,
402
};
403 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysDone = {
404 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysDone,
405
  /* meta */ {
406
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
407
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
408
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
409
  },
410
};
411 e545e620 Thomas Schöpping
412 1e5f7648 Thomas Schöpping
/**
413
 * @brief   SYS_PROG output signal GPIO.
414
 */
415
static apalGpio_t _gpioSysProg = {
416 e545e620 Thomas Schöpping
  /* port */ GPIOC,
417
  /* pad  */ GPIOC_SYS_PROG_N,
418
};
419 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysProg = {
420 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysProg,
421
  /* meta */ {
422
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
423
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
424
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
425
  },
426
};
427 e545e620 Thomas Schöpping
428 1e5f7648 Thomas Schöpping
/**
429
 * @brief   PATH_DC input signal GPIO.
430
 */
431
static apalGpio_t _gpioPathDc = {
432 e545e620 Thomas Schöpping
  /* port */ GPIOC,
433
  /* pad  */ GPIOC_PATH_DC,
434
};
435 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDc = {
436 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPathDc,
437
  /* meta */ {
438
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
439
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
440
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
441
  },
442
};
443 e545e620 Thomas Schöpping
444 1e5f7648 Thomas Schöpping
/**
445
 * @brief   SYS_SPI_DIR bidirectional signal GPIO.
446
 */
447
static apalGpio_t _gpioSysSpiDir = {
448 e545e620 Thomas Schöpping
  /* port */ GPIOC,
449
  /* pad  */ GPIOC_SYS_SPI_DIR,
450
};
451 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysSpiDir = {
452 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysSpiDir,
453
  /* meta */ {
454
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
455
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
456
    /* interrupt edge */ APAL_GPIO_EDGE_FALLING,
457
  },
458
};
459 e545e620 Thomas Schöpping
460 1e5f7648 Thomas Schöpping
/**
461
 * @brief   SYS_SYNC bidirectional signal GPIO.
462
 */
463
static apalGpio_t _gpioSysSync = {
464 e545e620 Thomas Schöpping
  /* port */ GPIOC,
465
  /* pad  */ GPIOC_SYS_INT_N,
466
};
467 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysSync = {
468 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysSync,
469
  /* meta */ {
470
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
471
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
472
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
473
  },
474
};
475 e545e620 Thomas Schöpping
476 1e5f7648 Thomas Schöpping
/**
477
 * @brief   SYS_PD bidirectional signal GPIO.
478
 */
479
static apalGpio_t _gpioSysPd = {
480 e545e620 Thomas Schöpping
  /* port */ GPIOC,
481
  /* pad  */ GPIOC_SYS_PD_N,
482
};
483 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysPd = {
484 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysPd,
485
  /* meta */ {
486
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
487
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
488
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
489
  },
490
};
491 e545e620 Thomas Schöpping
492 1e5f7648 Thomas Schöpping
/**
493
 * @brief   SYS_WARMRST bidirectional signal GPIO.
494
 */
495
static apalGpio_t _gpioSysWarmrst = {
496 e545e620 Thomas Schöpping
  /* port */ GPIOC,
497
  /* pad  */ GPIOC_SYS_WARMRST_N,
498
};
499 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
500 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysWarmrst,
501
  /* meta */ {
502
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
503
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
504
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
505
  },
506
};
507 e545e620 Thomas Schöpping
508 1e5f7648 Thomas Schöpping
/**
509
 * @brief   BT_RST output signal GPIO.
510
 */
511
static apalGpio_t _gpioBtRst = {
512 e545e620 Thomas Schöpping
  /* port */ GPIOC,
513
  /* pad  */ GPIOC_BT_RST,
514
};
515 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioBtRst = {
516 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioBtRst,
517
  /* meta */ {
518
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
519
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
520
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
521
  },
522
};
523 e545e620 Thomas Schöpping
524 1e5f7648 Thomas Schöpping
/**
525
 * @brief   CHARGE_EN2 output signal GPIO.
526
 */
527
static apalGpio_t _gpioChargeEn2 = {
528 e545e620 Thomas Schöpping
  /* port */ GPIOD,
529
  /* pad  */ GPIOD_CHARGE_EN2_N,
530
};
531 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioChargeEn2 = {
532 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioChargeEn2,
533
  /* meta */ {
534
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
535 ddf34c3d Thomas Schöpping
    /* active state   */ BQ241xx_LLD_ENABLED_GPIO_ACTIVE_STATE,
536 1e5f7648 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
537
  },
538
};
539 e545e620 Thomas Schöpping
540
/** @} */
541
542
/*===========================================================================*/
543
/**
544
 * @name AMiRo-OS core configurations
545
 * @{
546
 */
547
/*===========================================================================*/
548
549 2dd2e257 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
550 acc97cbf Thomas Schöpping
ROMCONST char* moduleShellPrompt = "PowerManagement";
551 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
552 6b53f6bf Thomas Schöpping
553
/** @} */
554
555
/*===========================================================================*/
556
/**
557
 * @name Startup Shutdown Synchronization Protocol (SSSP)
558
 * @{
559
 */
560
/*===========================================================================*/
561
562 e545e620 Thomas Schöpping
/** @} */
563
564
/*===========================================================================*/
565
/**
566
 * @name Low-level drivers
567
 * @{
568
 */
569
/*===========================================================================*/
570
571 ddf34c3d Thomas Schöpping
AT24C01BDriver moduleLldEeprom = {
572 8be006e0 Thomas Schöpping
  /* I2C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
573 ddf34c3d Thomas Schöpping
  /* I2C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
574 e545e620 Thomas Schöpping
};
575
576 ddf34c3d Thomas Schöpping
BQ241xxDriver moduleLldBatteryChargerFront = {
577 1e5f7648 Thomas Schöpping
  /* charge enable GPIO */ &moduleGpioChargeEn1,
578
  /* charge status GPIO */ &moduleGpioChargeStat1A,
579 e545e620 Thomas Schöpping
};
580
581 ddf34c3d Thomas Schöpping
BQ241xxDriver moduleLldBatteryChargerRear = {
582 1e5f7648 Thomas Schöpping
  /* charge enable GPIO */ &moduleGpioChargeEn2,
583
  /* charge status GPIO */ &moduleGpioChargeStat2A,
584 e545e620 Thomas Schöpping
};
585
586
BQ27500Driver moduleLldFuelGaugeFront = {
587 8be006e0 Thomas Schöpping
  /* I2C driver         */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
588 1e5f7648 Thomas Schöpping
  /* battery low GPIO   */ &moduleGpioGaugeBatLow1,
589
  /* battery good GPIO  */ &moduleGpioGaugeBatGd1,
590 e545e620 Thomas Schöpping
};
591
592
BQ27500Driver moduleLldFuelGaugeRear = {
593 8be006e0 Thomas Schöpping
  /* I2C driver         */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
594 1e5f7648 Thomas Schöpping
  /* battery low GPIO   */ &moduleGpioGaugeBatLow2,
595
  /* battery good GPIO  */ &moduleGpioGaugeBatGd2,
596 e545e620 Thomas Schöpping
};
597
598
INA219Driver moduleLldPowerMonitorVdd = {
599 8be006e0 Thomas Schöpping
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
600 e545e620 Thomas Schöpping
  /* I²C address      */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
601
  /* current LSB (uA) */ 0x00u,
602
  /* configuration    */ NULL,
603
};
604
605
INA219Driver moduleLldPowerMonitorVio18 = {
606 8be006e0 Thomas Schöpping
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
607 e545e620 Thomas Schöpping
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
608
  /* current LSB (uA) */ 0x00u,
609
  /* configuration    */ NULL,
610
};
611
612
INA219Driver moduleLldPowerMonitorVio33 = {
613 8be006e0 Thomas Schöpping
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
614 e545e620 Thomas Schöpping
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
615
  /* current LSB (uA) */ 0x00u,
616
  /* configuration    */ NULL,
617
};
618
619
INA219Driver moduleLldPowerMonitorVsys42 = {
620 8be006e0 Thomas Schöpping
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
621 e545e620 Thomas Schöpping
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
622
  /* current LSB (uA) */ 0x00u,
623
  /* configuration    */ NULL,
624
};
625
626
INA219Driver moduleLldPowerMonitorVio50 = {
627 8be006e0 Thomas Schöpping
  /* I2C Driver       */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
628 e545e620 Thomas Schöpping
  /* I²C address      */ INA219_LLD_I2C_ADDR_A1,
629
  /* current LSB (uA) */ 0x00u,
630
  /* configuration    */ NULL,
631
};
632
633
LEDDriver moduleLldStatusLed = {
634 1e5f7648 Thomas Schöpping
  /* LED GPIO */ &moduleGpioLed,
635 e545e620 Thomas Schöpping
};
636
637 ddf34c3d Thomas Schöpping
TPS6211xDriver moduleLldStepDownConverter = {
638 8be006e0 Thomas Schöpping
  /* Power enable GPIO */ &moduleGpioPowerEn,
639
};
640
641
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
642
643 e545e620 Thomas Schöpping
MPR121Driver moduleLldTouch = {
644 8be006e0 Thomas Schöpping
  /* I²C Driver */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
645 e545e620 Thomas Schöpping
};
646
647
PCA9544ADriver moduleLldI2cMultiplexer1 = {
648 8be006e0 Thomas Schöpping
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
649 e545e620 Thomas Schöpping
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
650
};
651
652
PCA9544ADriver moduleLldI2cMultiplexer2 = {
653 8be006e0 Thomas Schöpping
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
654 e545e620 Thomas Schöpping
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
655
};
656
657
VCNL4020Driver moduleLldProximity1 = {
658 8be006e0 Thomas Schöpping
  /* I²C Driver */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
659 e545e620 Thomas Schöpping
};
660
661
VCNL4020Driver moduleLldProximity2 = {
662 8be006e0 Thomas Schöpping
  /* I²C Driver */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
663 e545e620 Thomas Schöpping
};
664
665 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
666 8be006e0 Thomas Schöpping
667
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
668 bffb3465 Thomas Schöpping
669
PCAL6524Driver moduleLldGpioExtender1 = {
670
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
671
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
672
};
673
674
PCAL6524Driver moduleLldGpioExtender2 = {
675
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
676
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
677
};
678
679
AT42QT1050Driver moduleLldTouch = {
680
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
681
  /* I²C address  */ AT42QT1050_LLD_I2C_ADDRSEL_LOW,
682
};
683
684 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
685 8be006e0 Thomas Schöpping
686
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
687 bffb3465 Thomas Schöpping
688
PCAL6524Driver moduleLldGpioExtender1 = {
689
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
690
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
691
};
692
693
PCAL6524Driver moduleLldGpioExtender2 = {
694
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
695
  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
696
};
697
698
AT42QT1050Driver moduleLldTouch = {
699
  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
700
  /* I²C address  */ AT42QT1050_LLD_I2C_ADDRSEL_LOW,
701
};
702
703 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
704 8be006e0 Thomas Schöpping
705 e545e620 Thomas Schöpping
/** @} */
706
707
/*===========================================================================*/
708
/**
709
 * @name Unit tests (UT)
710
 * @{
711
 */
712
/*===========================================================================*/
713
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
714
#include <string.h>
715
716 8be006e0 Thomas Schöpping
/*
717
 * ADC
718
 */
719 e545e620 Thomas Schöpping
static int _utShellCmdCb_Adc(BaseSequentialStream* stream, int argc, char* argv[])
720
{
721
  (void)argc;
722
  (void)argv;
723
  aosUtRun(stream, &moduleUtAdcVsys, NULL);
724
  return AOS_OK;
725
}
726
static ut_adcdata_t _utAdcVsysData = {
727
  /* driver               */ &MODULE_HAL_ADC_VSYS,
728
  /* ADC conversion group */ &moduleHalAdcVsysConversionGroup,
729
};
730
aos_unittest_t moduleUtAdcVsys = {
731
  /* name           */ "ADC",
732
  /* info           */ "VSYS",
733
  /* test function  */ utAdcFunc,
734
  /* shell command  */ {
735
    /* name     */ "unittest:ADC",
736
    /* callback */ _utShellCmdCb_Adc,
737
    /* next     */ NULL,
738
  },
739
  /* data           */ &_utAdcVsysData,
740
};
741
742 8be006e0 Thomas Schöpping
/*
743 ddf34c3d Thomas Schöpping
 * AT24C01B (EEPROM)
744 8be006e0 Thomas Schöpping
 */
745 ddf34c3d Thomas Schöpping
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
746 e545e620 Thomas Schöpping
{
747
  (void)argc;
748
  (void)argv;
749 ddf34c3d Thomas Schöpping
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
750 e545e620 Thomas Schöpping
  return AOS_OK;
751
}
752 ddf34c3d Thomas Schöpping
static ut_at24c01bdata_t _utAlldAt24c01bData = {
753 e545e620 Thomas Schöpping
  /* driver   */ &moduleLldEeprom,
754
  /* timeout  */ MICROSECONDS_PER_SECOND,
755
};
756 ddf34c3d Thomas Schöpping
aos_unittest_t moduleUtAlldAt24c01b = {
757
  /* name           */ "AT24C01B",
758 e545e620 Thomas Schöpping
  /* info           */ "1kbit EEPROM",
759 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldAt24c01bFunc,
760 e545e620 Thomas Schöpping
  /* shell command  */ {
761
    /* name     */ "unittest:EEPROM",
762 ddf34c3d Thomas Schöpping
    /* callback */ _utShellCmdCb_AlldAt24c01b,
763 e545e620 Thomas Schöpping
    /* next     */ NULL,
764
  },
765 ddf34c3d Thomas Schöpping
  /* data           */ &_utAlldAt24c01bData,
766 e545e620 Thomas Schöpping
};
767
768 8be006e0 Thomas Schöpping
/*
769 ddf34c3d Thomas Schöpping
 * bq24103a (battery charger)
770 8be006e0 Thomas Schöpping
 */
771 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldBq24103a(BaseSequentialStream* stream, int argc, char* argv[])
772
{
773
  // local variables
774
  bool print_help = false;
775
776
  // evaluate argument
777
  if (argc == 2) {
778
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
779
      moduleUtAlldBq24103a.data = &moduleLldBatteryChargerFront;
780
      aosUtRun(stream, &moduleUtAlldBq24103a, "front battery");
781
      moduleUtAlldBq24103a.data = NULL;
782
    }
783
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
784
      moduleUtAlldBq24103a.data = &moduleLldBatteryChargerRear;
785
      aosUtRun(stream, &moduleUtAlldBq24103a, "rear battery");
786
      moduleUtAlldBq24103a.data = NULL;
787
    }
788
    else {
789
      print_help = true;
790
    }
791
  } else {
792
    print_help = true;
793
  }
794
795
  // print help or just return
796
  if (print_help) {
797
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
798
    chprintf(stream, "Options:\n");
799
    chprintf(stream, "  --front, -f\n");
800
    chprintf(stream, "    Test the front battery charger.\n");
801
    chprintf(stream, "  --rear, -r\n");
802
    chprintf(stream, "    Test the rear battery charger.\n");
803
    return AOS_INVALID_ARGUMENTS;
804
  } else {
805
    return AOS_OK;
806
  }
807
}
808
aos_unittest_t moduleUtAlldBq24103a = {
809 ddf34c3d Thomas Schöpping
  /* name           */ "bq24103a",
810 e545e620 Thomas Schöpping
  /* info           */ "battery charger",
811 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldBq241xxFunc,
812 e545e620 Thomas Schöpping
  /* shell command  */ {
813
    /* name     */ "unittest:BatteryCharger",
814
    /* callback */ _utShellCmdCb_AlldBq24103a,
815
    /* next     */ NULL,
816
  },
817
  /* data           */ NULL,
818
};
819
820 8be006e0 Thomas Schöpping
/*
821 ddf34c3d Thomas Schöpping
 * bq27500 (fuel gauge)
822 8be006e0 Thomas Schöpping
 */
823 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldBq27500(BaseSequentialStream* stream, int argc, char* argv[])
824
{
825
  // evaluate arguments
826
  if (argc == 2) {
827
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
828
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeFront;
829
      aosUtRun(stream, &moduleUtAlldBq27500, "front battery");
830
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
831
      return AOS_OK;
832
    }
833
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
834
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeRear;
835
      aosUtRun(stream, &moduleUtAlldBq27500, "rear battery");
836
      ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
837
      return AOS_OK;
838
    }
839
  }
840
  // print help
841
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
842
  chprintf(stream, "Options:\n");
843
  chprintf(stream, "  --front, -f\n");
844
  chprintf(stream, "    Test the front battery fuel gauge.\n");
845
  chprintf(stream, "  --rear, -r\n");
846
  chprintf(stream, "    Test the rear battery fuel gauge.\n");
847
  return AOS_INVALID_ARGUMENTS;
848
}
849
static ut_bq27500data_t _utAlldBq27500Data = {
850
  /* driver   */ NULL,
851
  /* timeout  */ MICROSECONDS_PER_SECOND,
852
};
853
aos_unittest_t moduleUtAlldBq27500 = {
854 ddf34c3d Thomas Schöpping
  /* name           */ "bq27500",
855 e545e620 Thomas Schöpping
  /* info           */ "fuel gauge",
856
  /* test function  */ utAlldBq27500Func,
857
  /* shell command  */ {
858
    /* name     */ "unittest:FuelGauge",
859
    /* callback */ _utShellCmdCb_AlldBq27500,
860
    /* next     */ NULL,
861
  },
862
  /* data           */ &_utAlldBq27500Data,
863
};
864
865 8be006e0 Thomas Schöpping
/*
866 ddf34c3d Thomas Schöpping
 * bq27500 (fuel gauge) in combination with bq24103a (battery charger)
867 8be006e0 Thomas Schöpping
 */
868 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldBq27500Bq24103a(BaseSequentialStream* stream, int argc, char* argv[])
869
{
870
  // evaluate arguments
871
  if (argc == 2) {
872
    if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) {
873 ddf34c3d Thomas Schöpping
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeFront;
874
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq241xx = &moduleLldBatteryChargerFront;
875 e545e620 Thomas Schöpping
      aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "front battery");
876 ddf34c3d Thomas Schöpping
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
877
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq241xx = NULL;
878 e545e620 Thomas Schöpping
      return AOS_OK;
879
    }
880
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) {
881 ddf34c3d Thomas Schöpping
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeRear;
882
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq241xx = &moduleLldBatteryChargerRear;
883 e545e620 Thomas Schöpping
      aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "rear battery");
884 ddf34c3d Thomas Schöpping
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
885
      ((ut_bq27500bq241xxdata_t*)moduleUtAlldBq27500Bq24103a.data)->bq241xx = NULL;
886 e545e620 Thomas Schöpping
      return AOS_OK;
887
    }
888
  }
889
  // print help
890
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
891
  chprintf(stream, "Options:\n");
892
  chprintf(stream, "  --front, -f\n");
893
  chprintf(stream, "    Test the front battery fuel gauge and charger.\n");
894
  chprintf(stream, "  --rear, -r\n");
895
  chprintf(stream, "    Test the rear battery fuel gauge and charger.\n");
896
  return AOS_INVALID_ARGUMENTS;
897
}
898 ddf34c3d Thomas Schöpping
static ut_bq27500bq241xxdata_t _utAlldBq27500Bq24103aData= {
899
  /* bq27500 driver   */ NULL,
900
  /* bq24103a driver  */ NULL,
901 e545e620 Thomas Schöpping
  /* timeout          */ MICROSECONDS_PER_SECOND,
902
};
903
aos_unittest_t moduleUtAlldBq27500Bq24103a = {
904
  /* name           */ "BQ27500 & BQ24103A",
905
  /* info           */ "fuel gauge & battery charger",
906 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldBq27500Bq241xxFunc,
907 e545e620 Thomas Schöpping
  /* shell command  */ {
908
    /* name     */ "unittest:FuelGauge&BatteryCharger",
909
    /* callback */ _utShellCmdCb_AlldBq27500Bq24103a,
910
    /* next     */ NULL,
911
  },
912
  /* data           */ &_utAlldBq27500Bq24103aData,
913
};
914
915 8be006e0 Thomas Schöpping
/*
916
 * INA219 (power monitor)
917
 */
918 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
919
{
920
  // evaluate arguments
921
  if (argc == 2) {
922
    if (strcmp(argv[1], "VDD") == 0) {
923
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVdd;
924
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f;
925
      aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
926
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
927
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
928
      return AOS_OK;
929
    }
930
    else if (strcmp(argv[1], "VIO1.8") == 0) {
931
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio18;
932
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 1.8f;
933
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (1.8V)");
934
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
935
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
936
      return AOS_OK;
937
    }
938
    else if (strcmp(argv[1], "VIO3.3") == 0) {
939
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio33;
940
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f;
941
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (3.3V)");
942
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
943
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
944
      return AOS_OK;
945
    }
946
    else if (strcmp(argv[1], "VSYS4.2") == 0) {
947
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVsys42;
948
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 4.2f;
949
      aosUtRun(stream, &moduleUtAlldIna219, "VSYS (4.2V)");
950
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
951
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
952
      return AOS_OK;
953
    }
954
    else if (strcmp(argv[1], "VIO5.0") == 0) {
955
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio50;
956
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 5.0f;
957
      aosUtRun(stream, &moduleUtAlldIna219, "VIO (5.0V)");
958
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
959
      ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f;
960
      return AOS_OK;
961
    }
962
  }
963
  // print help
964
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
965
  chprintf(stream, "Options:\n");
966
  chprintf(stream, "  VDD\n");
967
  chprintf(stream, "    Test VDD (3.3V) power monitor.\n");
968
  chprintf(stream, "  VIO1.8\n");
969
  chprintf(stream, "    Test VIO 1.8V power monitor.\n");
970
  chprintf(stream, "  VIO3.3\n");
971
  chprintf(stream, "    Test VIO 3.3V power monitor.\n");
972
  chprintf(stream, "  VSYS4.2\n");
973
  chprintf(stream, "    Test VSYS 4.2V power monitor.\n");
974
  chprintf(stream, "  VIO5.0\n");
975
  chprintf(stream, "    Test VIO 5.0V power monitor.\n");
976
  return AOS_INVALID_ARGUMENTS;
977
}
978
static ut_ina219data_t _utAlldIna219Data = {
979
  /* driver           */ NULL,
980
  /* expected voltage */ 0.0f,
981
  /* tolerance        */ 0.05f,
982
  /* timeout          */ MICROSECONDS_PER_SECOND,
983
};
984
aos_unittest_t moduleUtAlldIna219 = {
985
  /* name           */ "INA219",
986
  /* info           */ "power monitor",
987
  /* test function  */ utAlldIna219Func,
988
  /* shell command  */ {
989
    /* name     */ "unittest:PowerMonitor",
990
    /* callback */ _utShellCmdCb_AlldIna219,
991
    /* next     */ NULL,
992
  },
993
  /* data           */ &_utAlldIna219Data,
994
};
995
996 8be006e0 Thomas Schöpping
/*
997
 * Status LED
998
 */
999 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
1000
{
1001
  (void)argc;
1002
  (void)argv;
1003
  aosUtRun(stream, &moduleUtAlldLed, NULL);
1004
  return AOS_OK;
1005
}
1006
aos_unittest_t moduleUtAlldLed = {
1007
  /* name           */ "LED",
1008
  /* info           */ NULL,
1009
  /* test function  */ utAlldLedFunc,
1010
  /* shell command  */ {
1011
    /* name     */ "unittest:StatusLED",
1012
    /* callback */ _utShellCmdCb_AlldLed,
1013
    /* next     */ NULL,
1014
  },
1015
  /* data           */ &moduleLldStatusLed,
1016
};
1017
1018 8be006e0 Thomas Schöpping
/*
1019
 * PKLCS1212E4001 (buzzer)
1020
 */
1021 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldPklcs1212e4001(BaseSequentialStream* stream, int argc, char* argv[])
1022
{
1023
  (void)argc;
1024
  (void)argv;
1025
  aosUtRun(stream, &moduleUtAlldPklcs1212e4001, NULL);
1026
  return AOS_OK;
1027
}
1028 ddf34c3d Thomas Schöpping
static ut_pkxxxexxx_t _utAlldPklcs1212e4001Data = {
1029 e545e620 Thomas Schöpping
  /* PWM driver   */ &MODULE_HAL_PWM_BUZZER,
1030
  /* PWM channel  */ MODULE_HAL_PWM_BUZZER_CHANNEL
1031
};
1032
aos_unittest_t moduleUtAlldPklcs1212e4001 = {
1033
  /* name           */ "PKLCS1212E4001",
1034
  /* info           */ "buzzer",
1035 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldPkxxxexxxFunc,
1036 e545e620 Thomas Schöpping
  /* shell command  */ {
1037
    /* name     */ "unittest:Buzzer",
1038
    /* callback */ _utShellCmdCb_AlldPklcs1212e4001,
1039
    /* next     */ NULL,
1040
  },
1041
  /* data           */ &_utAlldPklcs1212e4001Data,
1042
};
1043
1044 8be006e0 Thomas Schöpping
/*
1045 ddf34c3d Thomas Schöpping
 * TPS62113 (step-down converter)
1046 8be006e0 Thomas Schöpping
 */
1047 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
1048
{
1049
  // Although there are four TPS62113 on the PCB, they all share the same input signal.
1050
  // A sa result, no additional shell arguments need to be evaluated.
1051
  (void)argc;
1052
  (void)argv;
1053
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
1054
  return AOS_OK;
1055
}
1056
aos_unittest_t moduleUtAlldTps62113 = {
1057
  /* name           */ "TPS62113",
1058
  /* info           */ "step-down converter",
1059 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldTps6211xFunc,
1060 e545e620 Thomas Schöpping
  /* shell command  */ {
1061
    /* name     */ "unittest:StepDownConverter",
1062
    /* callback */ _utShellCmdCb_AlldTps62113,
1063
    /* next     */ NULL,
1064
  },
1065
  /* data           */ &moduleLldStepDownConverter,
1066
};
1067
1068 8be006e0 Thomas Schöpping
/*
1069
 * TPS62113 (step-donw converter) in combination with INA219 (power monitor)
1070
 */
1071 e545e620 Thomas Schöpping
static int _utShellCmdCb_AlldTps62113Ina219(BaseSequentialStream* stream, int argc, char* argv[])
1072
{
1073
  (void)argc;
1074
  (void)argv;
1075
  aosUtRun(stream, &moduleUtAlldTps62113Ina219, "VSYS (4.2V)");
1076
  return AOS_OK;
1077
}
1078 ddf34c3d Thomas Schöpping
static ut_tps6211xina219data_t _utAlldTps62113Ina219Data = {
1079 e545e620 Thomas Schöpping
  /* TPS62113 */ &moduleLldStepDownConverter,
1080
  /* INA219   */ &moduleLldPowerMonitorVsys42,
1081
  /* timeout  */ MICROSECONDS_PER_SECOND,
1082
};
1083
aos_unittest_t moduleUtAlldTps62113Ina219 = {
1084
  /* name           */ "TPS62113 & INA219",
1085
  /* info           */ "step-down converter & power monitor",
1086 ddf34c3d Thomas Schöpping
  /* test function  */ utAlldTps6211xIna219Func,
1087 e545e620 Thomas Schöpping
  /* shell command  */ {
1088
    /* name     */ "unittest:StepDownConverter&PowerMonitor",
1089
    /* callback */ _utShellCmdCb_AlldTps62113Ina219,
1090
    /* next     */ NULL,
1091
  },
1092
  /* data           */ &_utAlldTps62113Ina219Data,
1093
};
1094
1095 8be006e0 Thomas Schöpping
#if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
1096
1097
/*
1098
 * MPR121 (touch sensor)
1099
 */
1100
static int _utShellCmdCb_AlldMpr121(BaseSequentialStream* stream, int argc, char* argv[])
1101
{
1102
  (void)argc;
1103
  (void)argv;
1104
  aosUtRun(stream, &moduleUtAlldMpr121, NULL);
1105
  return AOS_OK;
1106
}
1107
static ut_mpr121data_t _utAlldMpr121Data= {
1108
  /* MPR121 driver  */ &moduleLldTouch,
1109
  /* timeout        */ MICROSECONDS_PER_SECOND,
1110
  /* event source   */ &aos.events.io,
1111
  /* event flags    */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
1112
};
1113
aos_unittest_t moduleUtAlldMpr121 = {
1114
  /* name           */ "MPR121",
1115
  /* info           */ "touch sensor",
1116
  /* test function  */ utAlldMpr121Func,
1117
  /* shell command  */ {
1118
    /* name     */ "unittest:Touch",
1119
    /* callback */ _utShellCmdCb_AlldMpr121,
1120
    /* next     */ NULL,
1121
  },
1122
  /* data           */ &_utAlldMpr121Data,
1123
};
1124
1125
/*
1126
 * PCA9544A (I2C multiplexer)
1127
 */
1128
static int _utShellCmdCb_AlldPca5944a(BaseSequentialStream* stream, int argc, char* argv[])
1129
{
1130
  // evaluate arguments
1131
  if (argc == 2) {
1132
    if (strcmp(argv[1], "#1") == 0) {
1133
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer1;
1134
      aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #1");
1135
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
1136
      return AOS_OK;
1137
    }
1138
    else if (strcmp(argv[1], "#2") == 0) {
1139
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer2;
1140
      aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #2");
1141
      ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
1142
      return AOS_OK;
1143
    }
1144
  }
1145
  // print help
1146
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
1147
  chprintf(stream, "Options:\n");
1148
  chprintf(stream, "  #1\n");
1149
  chprintf(stream, "    Test the multiplexer on the I2C bus #1.\n");
1150
  chprintf(stream, "  #2\n");
1151
  chprintf(stream, "    Test the multiplexer on the I2C bus #2.\n");
1152
  return AOS_INVALID_ARGUMENTS;
1153
}
1154
static ut_pca9544adata_t _utAlldPca9544aData = {
1155
  /* driver   */ NULL,
1156
  /* timeout  */ MICROSECONDS_PER_SECOND,
1157
};
1158
aos_unittest_t moduleUtAlldPca9544a = {
1159
  /* name           */ "PCA9544A",
1160
  /* info           */ "I2C multiplexer",
1161
  /* test function  */ utAlldPca9544aFunc,
1162
  /* shell command  */ {
1163
    /* name     */ "unittest:I2CMultiplexer",
1164
    /* callback */ _utShellCmdCb_AlldPca5944a,
1165
    /* next     */ NULL,
1166
  },
1167
  /* data           */ &_utAlldPca9544aData,
1168
};
1169
1170
/*
1171
 * VCNL4020 (proximity sensor)
1172
 */
1173 e545e620 Thomas Schöpping
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
1174
{
1175
  uint8_t intstatus;
1176
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1177
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1178
  if (intstatus) {
1179
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1180
  }
1181
  return;
1182
}
1183
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
1184
{
1185
  enum {
1186
    UNKNOWN,
1187
    NNE, ENE, ESE, SSE, SSW,WSW,WNW, NNW,
1188
  } sensor = UNKNOWN;
1189
  // evaluate arguments
1190
  if (argc == 2) {
1191
    if (strcmp(argv[1], "-nne") == 0) {
1192
      sensor = NNE;
1193
    } else if (strcmp(argv[1], "-ene") == 0) {
1194
      sensor = ENE;
1195
    } else if (strcmp(argv[1], "-ese") == 0) {
1196
      sensor = ESE;
1197
    } else if (strcmp(argv[1], "-sse") == 0) {
1198
      sensor = SSE;
1199
    } else if (strcmp(argv[1], "-ssw") == 0) {
1200
      sensor = SSW;
1201
    } else if (strcmp(argv[1], "-wsw") == 0) {
1202
      sensor = WSW;
1203
    } else if (strcmp(argv[1], "-wnw") == 0) {
1204
      sensor = WNW;
1205
    } else if (strcmp(argv[1], "-nnw") == 0) {
1206
      sensor = NNW;
1207
    }
1208
  }
1209
  if (sensor != UNKNOWN) {
1210
    PCA9544ADriver* mux = NULL;
1211
    switch (sensor) {
1212
      case SSE:
1213
      case SSW:
1214
      case WSW:
1215
      case WNW:
1216
        mux = &moduleLldI2cMultiplexer1;
1217
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity1;
1218 1e5f7648 Thomas Schöpping
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = MODULE_OS_IOEVENTFLAGS_IRINT2;
1219 e545e620 Thomas Schöpping
        break;
1220
      case NNW:
1221
      case NNE:
1222
      case ENE:
1223
      case ESE:
1224
        mux = &moduleLldI2cMultiplexer2;
1225
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity2;
1226 1e5f7648 Thomas Schöpping
        ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = MODULE_OS_IOEVENTFLAGS_IRINT1;
1227 e545e620 Thomas Schöpping
        break;
1228
      default:
1229
        break;
1230
    }
1231
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1232
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1233
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1234
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1235
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1236
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1237
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1238
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
1239
    switch (sensor) {
1240
      case NNE:
1241
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1242
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northeast sensor");
1243
        break;
1244
      case ENE:
1245
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1246
        aosUtRun(stream, &moduleUtAlldVcnl4020, "east-northeast sensor");
1247
        break;
1248
      case ESE:
1249
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1250
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-southeast sensor");
1251
        break;
1252
      case SSE:
1253
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1254
        aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southeast sensor");
1255
        break;
1256
      case SSW:
1257
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1258
        aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southwest sensor");
1259
        break;
1260
      case WSW:
1261
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1262
        aosUtRun(stream, &moduleUtAlldVcnl4020, "west-southwest sensor");
1263
        break;
1264
      case WNW:
1265
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1266
        aosUtRun(stream, &moduleUtAlldVcnl4020, "west-northwest sensor");
1267
        break;
1268
      case NNW:
1269
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
1270
        aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northwest sensor");
1271
        break;
1272
      default:
1273
        break;
1274
    }
1275
    ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = NULL;
1276
    ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = 0;
1277
    return AOS_OK;
1278
  }
1279
  // print help
1280
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
1281
  chprintf(stream, "Options:\n");
1282
  chprintf(stream, "  -nne\n");
1283
  chprintf(stream, "    Test north-northeast sensor.\n");
1284
  chprintf(stream, "  -ene\n");
1285
  chprintf(stream, "    Test east-northeast sensor.\n");
1286
  chprintf(stream, "  -ese\n");
1287
  chprintf(stream, "    Test east-southeast sensor.\n");
1288
  chprintf(stream, "  -sse\n");
1289
  chprintf(stream, "    Test south-southeast sensor.\n");
1290
  chprintf(stream, "  -ssw\n");
1291
  chprintf(stream, "    Test south-southwest sensor.\n");
1292
  chprintf(stream, "  -wsw\n");
1293
  chprintf(stream, "    Test west-southwest sensor.\n");
1294
  chprintf(stream, "  -wnw\n");
1295
  chprintf(stream, "    Test west-northwest sensor.\n");
1296
  chprintf(stream, "  -nnw\n");
1297
  chprintf(stream, "    Test north-northwest sensor.\n");
1298
  return AOS_INVALID_ARGUMENTS;
1299
}
1300
static ut_vcnl4020data_t _utAlldVcnl4020Data = {
1301
  /* driver       */ NULL,
1302
  /* timeout      */ MICROSECONDS_PER_SECOND,
1303 6b53f6bf Thomas Schöpping
  /* event source */ &aos.events.io,
1304 e545e620 Thomas Schöpping
  /* event flags  */ 0,
1305
};
1306
aos_unittest_t moduleUtAlldVcnl4020 = {
1307
  /* name           */ "VCNL4020",
1308
  /* info           */ "proximity sensor",
1309
  /* test function  */ utAlldVcnl4020Func,
1310
  /* shell command  */ {
1311
    /* name     */ "unittest:Proximity",
1312
    /* callback */ _utShellCmdCb_AlldVcnl4020,
1313
    /* next     */ NULL,
1314
  },
1315
  /* data           */ &_utAlldVcnl4020Data,
1316
};
1317
1318 df20c2fc Julian L
static ut_rtcandata_t _utLldRtCanData = {
1319
    /*operation */ NULL
1320
};
1321
1322
static int _utShellCmdCb_LldRtCan(BaseSequentialStream* stream, int argc, char* argv[])
1323
{
1324
    if(argc == 2 ){
1325
        if (strcmp(argv[1], "send") == 0) {
1326
            ((ut_rtcandata_t*)moduleUtLldRtCan.data)->operation = "send";
1327
            aosUtRun(stream, &moduleUtLldRtCan,NULL);
1328
            return AOS_OK;
1329
        }else if(strcmp(argv[1], "receive") == 0){
1330
            ((ut_rtcandata_t*)moduleUtLldRtCan.data)->operation = "receive";
1331
            aosUtRun(stream, &moduleUtLldRtCan,NULL);
1332
            return AOS_OK;
1333
        }
1334
    }
1335
    return AOS_INVALID_ARGUMENTS;
1336
}
1337
aos_unittest_t moduleUtLldRtCan = {
1338
  /* name           */ "RTCAN",
1339
  /* info           */ NULL,
1340
  /* test function  */ utLldRtCanFunc,
1341
  /* shell command  */ {
1342
    /* name     */ "unittest:rtcan",
1343
    /* callback */ _utShellCmdCb_LldRtCan,
1344
    /* next     */ NULL,
1345
  },
1346
  /* data           */&_utLldRtCanData,
1347
};
1348 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */
1349 8be006e0 Thomas Schöpping
1350
1351
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
1352 bffb3465 Thomas Schöpping
1353
/*
1354
 * PCAL6524 (GPIO extender)
1355
 */
1356
static int _utShellCmdCb_AlldPcal6524(BaseSequentialStream* stream, int argc, char* argv[])
1357
{
1358
  // evaluate arguments
1359
  if (argc == 2) {
1360
    if (strcmp(argv[1], "#1") == 0) {
1361
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender1;
1362
      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #1");
1363
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
1364
      return AOS_OK;
1365
    }
1366
    else if (strcmp(argv[1], "#2") == 0) {
1367
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender2;
1368
      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #2");
1369
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
1370
      return AOS_OK;
1371
    }
1372
  }
1373
  // print help
1374
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
1375
  chprintf(stream, "Options:\n");
1376
  chprintf(stream, "  #1\n");
1377
  chprintf(stream, "    Test the GPIO extender on the I2C bus #1.\n");
1378
  chprintf(stream, "  #2\n");
1379
  chprintf(stream, "    Test the GPIO extender on the I2C bus #2.\n");
1380
  return AOS_INVALID_ARGUMENTS;
1381
}
1382
static ut_pcal6524data_t _utAlldPcal6524Data = {
1383
  /* driver   */ NULL,
1384
  /* timeout  */ MICROSECONDS_PER_SECOND,
1385
};
1386
aos_unittest_t moduleUtAlldPcal6524 = {
1387
  /* name           */ "PCAL6524",
1388
  /* info           */ "GPIO extender",
1389
  /* test function  */ utAlldPcal6524Func,
1390
  /* shell command  */ {
1391
    /* name     */ "unittest:GPIOExtender",
1392
    /* callback */ _utShellCmdCb_AlldPcal6524,
1393
    /* next     */ NULL,
1394
  },
1395
  /* data           */ &_utAlldPcal6524Data,
1396
};
1397
1398
/*
1399
 * AT42QT1050 (touch sensor)
1400
 */
1401
static int _utShellCmdCb_AlldAt42qt1050(BaseSequentialStream* stream, int argc, char* argv[])
1402
{
1403
  (void)argc;
1404
  (void)argv;
1405
  aosUtRun(stream, &moduleUtAlldAt42qt1050, NULL);
1406
  return AOS_OK;
1407
}
1408 052ee695 Felix Wittenfeld
static ut_at42qt1050data_t _utAlldAt42qt1050Data= {
1409 bffb3465 Thomas Schöpping
  /* AT42QT1050 driver  */ &moduleLldTouch,
1410
  /* timeout            */ MICROSECONDS_PER_SECOND,
1411
  /* event source       */ &aos.events.io,
1412
  /* event flags        */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
1413
};
1414
aos_unittest_t moduleUtAlldAt42qt1050 = {
1415
  /* name           */ "AT42QT1050",
1416
  /* info           */ "touch sensor",
1417
  /* test function  */ utAlldAt42qt1050Func,
1418
  /* shell command  */ {
1419
    /* name     */ "unittest:Touch",
1420
    /* callback */ _utShellCmdCb_AlldAt42qt1050,
1421
    /* next     */ NULL,
1422
  },
1423 052ee695 Felix Wittenfeld
  /* data           */ &_utAlldAt42qt1050Data,
1424 bffb3465 Thomas Schöpping
};
1425
1426 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) */
1427 8be006e0 Thomas Schöpping
1428
#if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
1429 bffb3465 Thomas Schöpping
1430
/*
1431
 * PCAL6524 (GPIO extender)
1432
 */
1433
static int _utShellCmdCb_AlldPcal6524(BaseSequentialStream* stream, int argc, char* argv[])
1434
{
1435
  // evaluate arguments
1436
  if (argc == 2) {
1437
    if (strcmp(argv[1], "#1") == 0) {
1438
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender1;
1439
      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #1");
1440
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
1441
      return AOS_OK;
1442
    }
1443
    else if (strcmp(argv[1], "#2") == 0) {
1444
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender2;
1445
      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #2");
1446
      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
1447
      return AOS_OK;
1448
    }
1449
  }
1450
  // print help
1451
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
1452
  chprintf(stream, "Options:\n");
1453
  chprintf(stream, "  #1\n");
1454
  chprintf(stream, "    Test the GPIO extender on the I2C bus #1.\n");
1455
  chprintf(stream, "  #2\n");
1456
  chprintf(stream, "    Test the GPIO extender on the I2C bus #2.\n");
1457
  return AOS_INVALID_ARGUMENTS;
1458
}
1459
static ut_pcal6524data_t _utAlldPcal6524Data = {
1460
  /* driver   */ NULL,
1461
  /* timeout  */ MICROSECONDS_PER_SECOND,
1462
};
1463
aos_unittest_t moduleUtAlldPcal6524 = {
1464
  /* name           */ "PCAL6524",
1465
  /* info           */ "GPIO extender",
1466
  /* test function  */ utAlldPcal6524Func,
1467
  /* shell command  */ {
1468
    /* name     */ "unittest:GPIOExtender",
1469
    /* callback */ _utShellCmdCb_AlldPcal6524,
1470
    /* next     */ NULL,
1471
  },
1472
  /* data           */ &_utAlldPcal6524Data,
1473
};
1474
1475
/*
1476
 * AT42QT1050 (touch sensor)
1477
 */
1478
static int _utShellCmdCb_AlldAt42qt1050(BaseSequentialStream* stream, int argc, char* argv[])
1479
{
1480
  (void)argc;
1481
  (void)argv;
1482
  aosUtRun(stream, &moduleUtAlldAt42qt1050, NULL);
1483
  return AOS_OK;
1484
}
1485 052ee695 Felix Wittenfeld
static ut_at42qt1050data_t _utAlldAt42qt1050Data= {
1486 bffb3465 Thomas Schöpping
  /* AT42QT1050 driver  */ &moduleLldTouch,
1487
  /* timeout            */ MICROSECONDS_PER_SECOND,
1488
  /* event source       */ &aos.events.io,
1489
  /* event flags        */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
1490
};
1491
aos_unittest_t moduleUtAlldAt42qt1050 = {
1492
  /* name           */ "AT42QT1050",
1493
  /* info           */ "touch sensor",
1494
  /* test function  */ utAlldAt42qt1050Func,
1495
  /* shell command  */ {
1496
    /* name     */ "unittest:Touch",
1497
    /* callback */ _utShellCmdCb_AlldAt42qt1050,
1498
    /* next     */ NULL,
1499
  },
1500 052ee695 Felix Wittenfeld
  /* data           */ &_utAlldAt42qt1050Data,
1501 bffb3465 Thomas Schöpping
};
1502
1503 7de0cc90 Thomas Schöpping
#endif /* (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) */
1504 8be006e0 Thomas Schöpping
1505 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
1506 e545e620 Thomas Schöpping
1507
/** @} */
1508 53710ca3 Marc Rothmann
/** @} */