Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.c @ adcbcf83

History | View | Annotate | Download (18.343 KB)

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

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/**
20
 * @file
21 034cb15a Thomas Schöpping
 * @brief   Structures and constant for the LightRing v1.2 module.
22 9ae7c4f3 Thomas Schöpping
 *
23
 * @addtogroup lightring_module
24
 * @{
25
 */
26
27
#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
CANConfig moduleHalCanConfig = {
46
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
47
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
48
};
49
50 ee884101 Thomas Schöpping
I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig = {
51 9ae7c4f3 Thomas Schöpping
  /* I²C mode   */ OPMODE_I2C,
52
  /* frequency  */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL)
53
  /* duty cycle */ FAST_DUTY_CYCLE_2,
54
};
55
56
SerialConfig moduleHalProgIfConfig = {
57
  /* bit rate */ 115200,
58
  /* CR1      */ 0,
59
  /* CR1      */ 0,
60
  /* CR1      */ 0,
61
};
62
63
SPIConfig moduleHalSpiLightConfig = {
64
  /* circular buffer mode        */ false,
65
  /* callback function pointer   */ NULL,
66 3106e8cc Thomas Schöpping
  /* chip select line port       */ PAL_PORT(LINE_LIGHT_XLAT),
67
  /* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
68 9ae7c4f3 Thomas Schöpping
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
69
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
70
};
71
72
73
/*===========================================================================*/
74
/**
75
 * @name GPIO definitions
76
 * @{
77
 */
78
/*===========================================================================*/
79
80
/**
81
 * @brief   LIGHT_BANK output signal GPIO.
82
 */
83
static apalGpio_t _gpioLightBlank = {
84 3106e8cc Thomas Schöpping
  /* line */ LINE_LIGHT_BLANK,
85 9ae7c4f3 Thomas Schöpping
};
86
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
87
  /* GPIO */ &_gpioLightBlank,
88
  /* meta */ {
89
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
90
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
91
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
92
  },
93
};
94
95
/**
96
 * @brief   RS232_R_EN_N output signal GPIO.
97
 */
98
static apalGpio_t _gpioRs232En = {
99 3106e8cc Thomas Schöpping
  /* line */ LINE_RS232_R_EN_N,
100 9ae7c4f3 Thomas Schöpping
};
101
ROMCONST apalControlGpio_t moduleGpioRs232En = {
102
  /* GPIO */ &_gpioRs232En,
103
  /* meta */ {
104
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
105
    /* active state   */ APAL_GPIO_ACTIVE_LOW, //TODO
106
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
107
  },
108
};
109
110
/**
111
 * @brief   SW_V33_EN output signal GPIO.
112
 */
113
static apalGpio_t _gpioSwV33En = {
114 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V33_EN,
115 9ae7c4f3 Thomas Schöpping
};
116
ROMCONST apalControlGpio_t moduleGpioSwV33En = {
117
  /* GPIO */ &_gpioSwV33En,
118
  /* meta */ {
119
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
120 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
121 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
122
  },
123
};
124
125 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
126
///**
127
// * @brief   SW_V42_EN output signal GPIO.
128
// */
129
//static apalGpio_t _gpioSwV42En = {
130
//  /* line */ LINE_SW_V42_EN,
131
//};
132
//ROMCONST apalControlGpio_t moduleGpioSwV42En = {
133
//  /* GPIO */ &_gpioSwV42En,
134
//  /* meta */ {
135
//    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
136
//    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
137
//    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
138
//  },
139
//};
140 9ae7c4f3 Thomas Schöpping
141
/**
142
 * @brief   SW_V50_EN output signal GPIO.
143
 */
144
static apalGpio_t _gpioSwV50En = {
145 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V50_EN,
146 9ae7c4f3 Thomas Schöpping
};
147
ROMCONST apalControlGpio_t moduleGpioSwV50En = {
148
  /* GPIO */ &_gpioSwV50En,
149
  /* meta */ {
150
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
151 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
152 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
153
  },
154
};
155
156
/**
157
 * @brief   IO_3 breakout signal GPIO.
158
 */
159
static apalGpio_t _gpioBreakoutIo3 = {
160 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_3,
161 9ae7c4f3 Thomas Schöpping
};
162
apalControlGpio_t moduleGpioBreakoutIo3 = {
163
  /* GPIO */ &_gpioBreakoutIo3,
164
  /* meta */ {
165
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
166
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
167
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
168
  },
169
};
170
171
/**
172
 * @brief   IO_5 breakout signal GPIO.
173
 */
174
static apalGpio_t _gpioBreakoutIo5 = {
175 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_5,
176 9ae7c4f3 Thomas Schöpping
};
177
apalControlGpio_t moduleGpioBreakoutIo5 = {
178
  /* GPIO */ &_gpioBreakoutIo5,
179
  /* meta */ {
180
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
181
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
182
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
183
  },
184
};
185
186
/**
187
 * @brief   IO_6 breakout signal GPIO.
188
 */
189
static apalGpio_t _gpioBreakoutIo6 = {
190 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_6,
191 9ae7c4f3 Thomas Schöpping
};
192
apalControlGpio_t moduleGpioBreakoutIo6 = {
193
  /* GPIO */ &_gpioBreakoutIo6,
194
  /* meta */ {
195
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
196
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
197
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
198
  },
199
};
200
201
/**
202
 * @brief   SYS_UART_DN bidirectional signal GPIO.
203
 */
204
static apalGpio_t _gpioSysUartDn = {
205 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_UART_DN,
206 9ae7c4f3 Thomas Schöpping
};
207
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
208
  /* GPIO */ &_gpioSysUartDn,
209
  /* meta */ {
210
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
211
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
212
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
213
  },
214
};
215
216
/**
217
 * @brief   IO_7 breakout signal GPIO.
218
 */
219
static apalGpio_t _gpioBreakoutIo7 = {
220 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_7,
221 9ae7c4f3 Thomas Schöpping
};
222
apalControlGpio_t moduleGpioBreakoutIo7 = {
223
  /* GPIO */ &_gpioBreakoutIo7,
224
  /* meta */ {
225
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
226
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
227
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
228
  },
229
};
230
231
/**
232
 * @brief   IO_8 breakout signal GPIO.
233
 */
234
static apalGpio_t _gpioBreakoutIo8 = {
235 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_8,
236 9ae7c4f3 Thomas Schöpping
};
237
apalControlGpio_t moduleGpioBreakoutIo8 = {
238
  /* GPIO */ &_gpioBreakoutIo8,
239
  /* meta */ {
240
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
241
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
242
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
243
  },
244
};
245
246
/**
247
 * @brief   IO_4 breakout signal GPIO.
248
 */
249
static apalGpio_t _gpioBreakoutIo4 = {
250 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_4,
251 9ae7c4f3 Thomas Schöpping
};
252
apalControlGpio_t moduleGpioBreakoutIo4 = {
253
  /* GPIO */ &_gpioBreakoutIo4,
254
  /* meta */ {
255
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
256
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
257
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
258
  },
259
};
260
261
/**
262
 * @brief   IO_1 breakout signal GPIO.
263
 */
264
static apalGpio_t _gpioBreakoutIo1 = {
265 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_1,
266 9ae7c4f3 Thomas Schöpping
};
267
apalControlGpio_t moduleGpioBreakoutIo1 = {
268
  /* GPIO */ &_gpioBreakoutIo1,
269
  /* meta */ {
270
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
271
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
272
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
273
  },
274
};
275
276
/**
277
 * @brief   IO_2 breakout signal GPIO.
278
 */
279
static apalGpio_t _gpioBreakoutIo2 = {
280 3106e8cc Thomas Schöpping
  /* line */ LINE_IO_2,
281 9ae7c4f3 Thomas Schöpping
};
282
apalControlGpio_t moduleGpioBreakoutIo2 = {
283
  /* GPIO */ &_gpioBreakoutIo2,
284
  /* meta */ {
285
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
286
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
287
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
288
  },
289
};
290
291
/**
292
 * @brief   LED output signal GPIO.
293
 */
294
static apalGpio_t _gpioLed = {
295 3106e8cc Thomas Schöpping
  /* line */ LINE_LED,
296 9ae7c4f3 Thomas Schöpping
};
297
ROMCONST apalControlGpio_t moduleGpioLed = {
298
  /* GPIO */ &_gpioLed,
299
  /* meta */ {
300
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
301
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
302
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
303
  },
304
};
305
306
/**
307 c930aa01 Thomas Schöpping
 * @brief   LIGHT_XLAT output signal GPIO.
308
 */
309
static apalGpio_t _gpioLightXlat = {
310
  /* line */ LINE_LIGHT_XLAT,
311
};
312
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
313
  /* GPIO */ &_gpioLightXlat,
314
  /* meta */ {
315
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
316
    /* active state   */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
317
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
318
  },
319
};
320
321
/**
322 9ae7c4f3 Thomas Schöpping
 * @brief   SW_V18_EN output signal GPIO.
323
 */
324
static apalGpio_t _gpioSwV18En = {
325 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V18_EN,
326 9ae7c4f3 Thomas Schöpping
};
327
ROMCONST apalControlGpio_t moduleGpioSwV18En = {
328
  /* GPIO */ &_gpioSwV18En,
329
  /* meta */ {
330
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
331 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
332 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
333
  },
334
};
335
336
/**
337
 * @brief   SW_VSYS_EN output signal GPIO.
338
 */
339
static apalGpio_t _gpioSwVsysEn = {
340 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_VSYS_EN,
341 9ae7c4f3 Thomas Schöpping
};
342
ROMCONST apalControlGpio_t moduleGpioSwVsysEn = {
343
  /* GPIO */ &_gpioSwVsysEn,
344
  /* meta */ {
345
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
346 ee884101 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
347 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
348
  },
349
};
350
351
/**
352
 * @brief   SYS_UART_UP bidirectional signal GPIO.
353
 */
354
static apalGpio_t _gpioSysUartUp = {
355 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_UART_UP,
356 9ae7c4f3 Thomas Schöpping
};
357
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
358
  /* GPIO */ &_gpioSysUartUp,
359
  /* meta */ {
360
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
361
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
362
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
363
  },
364
};
365
366
/**
367
 * @brief   SYS_PD bidirectional signal GPIO.
368
 */
369
static apalGpio_t _gpioSysPd = {
370 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_PD_N,
371 9ae7c4f3 Thomas Schöpping
};
372
ROMCONST apalControlGpio_t moduleGpioSysPd = {
373
  /* GPIO */ &_gpioSysPd,
374
  /* meta */ {
375
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
376
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
377
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
378
  },
379
};
380
381
/**
382
 * @brief   SYS_SYNC bidirectional signal GPIO.
383
 */
384
static apalGpio_t _gpioSysSync = {
385 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_INT_N,
386 9ae7c4f3 Thomas Schöpping
};
387
ROMCONST apalControlGpio_t moduleGpioSysSync = {
388
  /* GPIO */ &_gpioSysSync,
389
  /* meta */ {
390
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
391
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
392
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
393
  },
394
};
395
396
/** @} */
397
398
/*===========================================================================*/
399
/**
400
 * @name AMiRo-OS core configurations
401
 * @{
402
 */
403
/*===========================================================================*/
404
405
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
406
ROMCONST char* moduleShellPrompt = "LightRing";
407
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
408
409
/** @} */
410
411
/*===========================================================================*/
412
/**
413
 * @name Startup Shutdown Synchronization Protocol (SSSP)
414
 * @{
415
 */
416
/*===========================================================================*/
417
418
/** @} */
419
420
/*===========================================================================*/
421
/**
422
 * @name Low-level drivers
423
 * @{
424
 */
425
/*===========================================================================*/
426
427
AT24C01BDriver moduleLldEeprom = {
428 ee884101 Thomas Schöpping
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
429 9ae7c4f3 Thomas Schöpping
  /* I2C address  */ 0x00u,
430
};
431
432 ee884101 Thomas Schöpping
INA219Driver moduleLldPowerMonitorVled = {
433
  /* I2C Driver       */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
434
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
435
  /* current LSB (uA) */ 0x00u,
436
  /* configuration    */ NULL,
437
};
438
439 c4989d30 Julia Niermann
P9221RDriver moduleQiCharger = {
440
  /* I2C Driver       */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
441
  /* I²C address      */ P9221R_LLD_I2C_ADDR_FIXED,
442
  /* current LSB (uA) */ 0x00u,
443
  /* configuration    */ NULL,
444
};
445
446 ee884101 Thomas Schöpping
LEDDriver moduleLldStatusLed = {
447
  /* LED enable Gpio */ &moduleGpioLed,
448
};
449
450
MIC9404xDriver moduleLldPowerSwitchV18 = {
451
  /* power enable GPIO  */ &moduleGpioSwV18En,
452
};
453
454
MIC9404xDriver moduleLldPowerSwitchV33 = {
455
  /* power enable GPIO  */ &moduleGpioSwV33En,
456
};
457
458 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
459
//MIC9404xDriver moduleLldPowerSwitchV42 = {
460
//  /* power enable GPIO  */ &moduleGpioSwV42En,
461
//};
462 ee884101 Thomas Schöpping
463
MIC9404xDriver moduleLldPowerSwitchV50 = {
464
  /* power enable GPIO  */ &moduleGpioSwV50En,
465
};
466
467
MIC9404xDriver moduleLldPowerSwitchVsys = {
468
  /* power enable GPIO  */ &moduleGpioSwVsysEn,
469
};
470
471 9ae7c4f3 Thomas Schöpping
TLC5947Driver moduleLldLedPwm = {
472
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
473
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
474 c930aa01 Thomas Schöpping
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
475 9ae7c4f3 Thomas Schöpping
};
476
477
/** @} */
478
479
/*===========================================================================*/
480
/**
481
 * @name Unit tests (UT)
482
 * @{
483
 */
484
/*===========================================================================*/
485
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
486 ee884101 Thomas Schöpping
#include <string.h>
487 9ae7c4f3 Thomas Schöpping
488
/*
489
 * EEPROM (AT24C01B)
490
 */
491
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
492
{
493
  (void)argc;
494
  (void)argv;
495
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
496
  return AOS_OK;
497
}
498
static ut_at24c01bdata_t _utAlldAt24c01bData = {
499
  /* driver   */ &moduleLldEeprom,
500
  /* timeout  */ MICROSECONDS_PER_SECOND,
501
};
502
aos_unittest_t moduleUtAlldAt24c01b = {
503
  /* name           */ "AT24C01B",
504
  /* info           */ "1kbit EEPROM",
505
  /* test function  */ utAlldAt24c01bFunc,
506
  /* shell command  */ {
507
    /* name     */ "unittest:EEPROM",
508
    /* callback */ _utShellCmdCb_AlldAt24c01b,
509
    /* next     */ NULL,
510
  },
511
  /* data           */ &_utAlldAt24c01bData,
512
};
513
514
/*
515 ee884101 Thomas Schöpping
 * INA219 (power monitor)
516
 */
517
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
518
{
519
  (void)argc;
520
  (void)argv;
521
  aosUtRun(stream, &moduleUtAlldIna219, "VLED (4.2V)");
522
  return AOS_OK;
523
}
524
static ut_ina219data_t _utIna219Data = {
525
  /* driver           */ &moduleLldPowerMonitorVled,
526
  /* expected voltage */ 4.2f,
527
  /* tolerance        */ 0.2f,
528
  /* timeout */ MICROSECONDS_PER_SECOND,
529
};
530
aos_unittest_t moduleUtAlldIna219 = {
531
  /* name           */ "INA219",
532
  /* info           */ "power monitor",
533
  /* test function  */ utAlldIna219Func,
534
  /* shell command  */ {
535
    /* name     */ "unittest:PowerMonitor",
536
    /* callback */ _utShellCmdCb_AlldIna219,
537
    /* next     */ NULL,
538
  },
539
  /* data           */ &_utIna219Data,
540
};
541
542
/*
543 c4989d30 Julia Niermann
 * P9221R (qi charger)
544
 */
545
static int _utShellCmdCb_AlldP9221r(BaseSequentialStream* stream, int argc, char* argv[])
546
{
547
  (void)argc;
548
  (void)argv;
549
  aosUtRun(stream, &moduleUtAlldP9221r, NULL);
550
  return AOS_OK;
551
}
552
static ut_p9221rdata_t _utP9221rData = {
553 8cbe3240 Julia Niermann
  /* driver           */ &moduleQiCharger, // !!!!
554
  /* x alignment      */ 0.0f,
555
  /* y alignment      */ 0.0f,
556
  /* op freq          */ 0.0f,
557
  /* voltage          */ 0.0f,
558
  /* current          */ 0.0f,
559 c4989d30 Julia Niermann
  /* timeout */ MICROSECONDS_PER_SECOND,
560
};
561
aos_unittest_t moduleUtAlldP9221r = {
562 8cbe3240 Julia Niermann
    /* name           */ "P9221R",
563
    /* info           */ "qi charger",
564
    /* test function  */ utAlldP9221rFunc,
565
    /* shell command  */ {
566
      /* name     */ "unittest:QiCharger",
567
      /* callback */ _utShellCmdCb_AlldP9221r,
568
      /* next     */ NULL,
569
    },
570
    /* data           */ &_utP9221rData,
571
  };
572 c4989d30 Julia Niermann
573
/*
574 ee884101 Thomas Schöpping
 * Status LED
575
 */
576
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
577
{
578
  (void)argc;
579
  (void)argv;
580
  aosUtRun(stream, &moduleUtAlldLed, NULL);
581
  return AOS_OK;
582
}
583
aos_unittest_t moduleUtAlldLed = {
584
  /* name           */ "LED",
585
  /* info           */ NULL,
586
  /* test function  */ utAlldLedFunc,
587
  /* shell command  */ {
588
    /* name     */ "unittest:StatusLED",
589
    /* callback */ _utShellCmdCb_AlldLed,
590
    /* next     */ NULL,
591
  },
592
  /* data           */ &moduleLldStatusLed,
593
};
594
595
/*
596
 * Power switch driver (MIC9404x)
597
 */
598
static int _utShellCmdCb_Mic9404x(BaseSequentialStream* stream, int argc, char* argv[])
599
{
600
  // evaluate arguments
601
  if (argc == 2) {
602
    if (strcmp(argv[1], "1.8V") == 0) {
603
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV18;
604
      aosUtRun(stream, &moduleUtAlldMic9404x, "1.8V");
605
      moduleUtAlldMic9404x.data = NULL;
606
      return AOS_OK;
607
    }
608
    else if (strcmp(argv[1], "3.3V") == 0) {
609
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV33;
610
      aosUtRun(stream, &moduleUtAlldMic9404x, "3.3V");
611
      moduleUtAlldMic9404x.data = NULL;
612
      return AOS_OK;
613
    }
614 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
615
//    else if (strcmp(argv[1], "4.2V") == 0) {
616
//      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV42;
617
//      aosUtRun(stream, &moduleUtAlldMic9404x, "4.2V");
618
//      moduleUtAlldMic9404x.data = NULL;
619
//      return AOS_OK;
620
//    }
621 ee884101 Thomas Schöpping
    else if (strcmp(argv[1], "5.0V") == 0) {
622
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchV50;
623
      aosUtRun(stream, &moduleUtAlldMic9404x, "5.0V");
624
      moduleUtAlldMic9404x.data = NULL;
625
      return AOS_OK;
626
    }
627
    else if (strcmp(argv[1], "VSYS") == 0) {
628
      moduleUtAlldMic9404x.data = &moduleLldPowerSwitchVsys;
629
      aosUtRun(stream, &moduleUtAlldMic9404x, "VSYS");
630
      moduleUtAlldMic9404x.data = NULL;
631
      return AOS_OK;
632
    }
633
  }
634
  // print help
635
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
636
  chprintf(stream, "Options:\n");
637
  chprintf(stream, "  1.8V\n");
638
  chprintf(stream, "    Test power switch for 1.8V supply.\n");
639
  chprintf(stream, "  3.3V\n");
640
  chprintf(stream, "    Test power switch for 3.3V supply.\n");
641 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
642
//  chprintf(stream, "  4.2V\n");
643
//  chprintf(stream, "    Test power switch for 4.2V supply.\n");
644 ee884101 Thomas Schöpping
  chprintf(stream, "  5.0V\n");
645
  chprintf(stream, "    Test power switch for 5.0V supply.\n");
646
  chprintf(stream, "  VSYS\n");
647
  chprintf(stream, "    Test power switch for VSYS supply.\n");
648 916f8d28 Thomas Schöpping
  return AOS_INVALIDARGUMENTS;
649 ee884101 Thomas Schöpping
}
650
aos_unittest_t moduleUtAlldMic9404x = {
651
  /* info           */ "MIC9404x",
652
  /* name           */ "power swicth driver",
653
  /* test function  */ utAlldMic9404xFunc,
654
  /* shell command  */ {
655
    /* name     */ "unittest:PowerSwitch",
656
    /* callback */ _utShellCmdCb_Mic9404x,
657
    /* next     */ NULL,
658
  },
659
  /* data           */ NULL,
660
};
661
662
/*
663 9ae7c4f3 Thomas Schöpping
 * LED PWM driver (TLC5947)
664
 */
665
static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[])
666
{
667
  (void)argc;
668
  (void)argv;
669
  aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
670
  return AOS_OK;
671
}
672
aos_unittest_t moduleUtAlldTlc5947 = {
673
  /* info           */ "TLC5947",
674
  /* name           */ "LED PWM driver",
675
  /* test function  */ utAlldTlc5947Func,
676
  /* shell command  */ {
677
    /* name     */ "unittest:Lights",
678
    /* callback */ _utShellCmdCb_Tlc5947,
679
    /* next     */ NULL,
680
  },
681
  /* data           */ &moduleLldLedPwm,
682
};
683
684
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
685
686
/** @} */
687
/** @} */