Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.c @ 232ccea6

History | View | Annotate | Download (21.201 KB)

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

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

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

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file
21
 * @brief   Structures and constant for the LightRing v1.2 module.
22
 *
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
I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig = {
51
  /* 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
  /* chip select line port       */ PAL_PORT(LINE_LIGHT_XLAT),
67
  /* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
68
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
69
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
70
};
71

    
72
#if (BOARD_DW1000_CONNECTED == true)
73

    
74
/*! SPI (high speed) configuration for DW1000 */
75
SPIConfig moduleHalSpiUwbHsConfig = {
76
  /* circular buffer mode        */ false,
77
  /* callback function pointer   */ NULL,
78
  /* chip select line port       */ PAL_PORT(LINE_SPI_SS_N),
79
  /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
80
  /* CR1                         */ 0,                                  // 36/2 Mbps
81
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,  // 0
82
};
83
/*! SPI (low speed) configuration for DW1000 */
84
SPIConfig moduleHalSpiUwbLsConfig = {
85
  /* circular buffer mode        */ false,
86
  /* callback function pointer   */ NULL,
87
  /* chip select line port       */ PAL_PORT(LINE_SPI_SS_N),
88
  /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
89
  /* CR1                         */ SPI_CR1_BR_1 | SPI_CR1_BR_0,        // 36/16 Mbps
90
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,  // 0
91
};
92

    
93
#endif /* BOARD_DW1000_CONNECTED == true */
94

    
95

    
96
/*===========================================================================*/
97
/**
98
 * @name GPIO definitions
99
 * @{
100
 */
101
/*===========================================================================*/
102

    
103
/**
104
 * @brief   LIGHT_BANK output signal GPIO.
105
 */
106
static apalGpio_t _gpioLightBlank = {
107
  /* line */ LINE_LIGHT_BLANK,
108
};
109
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
110
  /* GPIO */ &_gpioLightBlank,
111
  /* meta */ {
112
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
113
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
114
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
115
  },
116
};
117

    
118
/**
119
 * @brief   RS232_R_EN_N output signal GPIO.
120
 */
121
static apalGpio_t _gpioRs232En = {
122
  /* line */ LINE_RS232_R_EN_N,
123
};
124
ROMCONST apalControlGpio_t moduleGpioRs232En = {
125
  /* GPIO */ &_gpioRs232En,
126
  /* meta */ {
127
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
128
    /* active state   */ APAL_GPIO_ACTIVE_LOW, //TODO
129
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
130
  },
131
};
132

    
133
/**
134
 * @brief   SW_V33_EN output signal GPIO.
135
 */
136
static apalGpio_t _gpioSwV33En = {
137
  /* line */ LINE_SW_V33_EN,
138
};
139
ROMCONST apalControlGpio_t moduleGpioSwV33En = {
140
  /* GPIO */ &_gpioSwV33En,
141
  /* meta */ {
142
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
143
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
144
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
145
  },
146
};
147

    
148
// The 4.2V switch is disabled due to a hardware bug.
149
///**
150
// * @brief   SW_V42_EN output signal GPIO.
151
// */
152
//static apalGpio_t _gpioSwV42En = {
153
//  /* line */ LINE_SW_V42_EN,
154
//};
155
//ROMCONST apalControlGpio_t moduleGpioSwV42En = {
156
//  /* GPIO */ &_gpioSwV42En,
157
//  /* meta */ {
158
//    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
159
//    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
160
//    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
161
//  },
162
//};
163

    
164
/**
165
 * @brief   SW_V50_EN output signal GPIO.
166
 */
167
static apalGpio_t _gpioSwV50En = {
168
  /* line */ LINE_SW_V50_EN,
169
};
170
ROMCONST apalControlGpio_t moduleGpioSwV50En = {
171
  /* GPIO */ &_gpioSwV50En,
172
  /* meta */ {
173
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
174
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
175
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
176
  },
177
};
178

    
179
/**
180
 * @brief   IO_3 breakout signal GPIO.
181
 */
182
static apalGpio_t _gpioBreakoutIo3 = {
183
  /* line */ LINE_IO_3,
184
};
185
apalControlGpio_t moduleGpioBreakoutIo3 = {
186
  /* GPIO */ &_gpioBreakoutIo3,
187
  /* meta */ {
188
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
189
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
190
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
191
  },
192
};
193

    
194
/**
195
 * @brief   IO_5 breakout signal GPIO.
196
 */
197
static apalGpio_t _gpioBreakoutIo5 = {
198
  /* line */ LINE_IO_5,
199
};
200
apalControlGpio_t moduleGpioBreakoutIo5 = {
201
  /* GPIO */ &_gpioBreakoutIo5,
202
  /* meta */ {
203
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
204
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
205
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
206
  },
207
};
208

    
209
/**
210
 * @brief   IO_6 breakout signal GPIO.
211
 */
212
static apalGpio_t _gpioBreakoutIo6 = {
213
  /* line */ LINE_IO_6,
214
};
215
apalControlGpio_t moduleGpioBreakoutIo6 = {
216
  /* GPIO */ &_gpioBreakoutIo6,
217
  /* meta */ {
218
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
219
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
220
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
221
  },
222
};
223

    
224
/**
225
 * @brief   SYS_UART_DN bidirectional signal GPIO.
226
 */
227
static apalGpio_t _gpioSysUartDn = {
228
  /* line */ LINE_SYS_UART_DN,
229
};
230
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
231
  /* GPIO */ &_gpioSysUartDn,
232
  /* meta */ {
233
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
234
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
235
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
236
  },
237
};
238

    
239
#if (BOARD_DW1000_CONNECTED == true)
240
/**
241
 * @brief   DW1000 interrrupt input signal GPIO.
242
 */
243
static apalGpio_t _gpioDw1000Irqn = {
244
  /* line */  LINE_IO_8,            // (GPIOB, GPIOB_IO_8),
245
};
246
ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
247
  /* GPIO */ &_gpioDw1000Irqn,
248
  /* meta */ {
249
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
250
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
251
    /* interrupt edge */ APAL_GPIO_EDGE_RISING,
252
  },
253
};
254

    
255
/**
256
 * @brief   DW1000 reset output signal GPIO.
257
 */
258
static apalGpio_t _gpioDw1000Reset = {
259
  /* line */ LINE_IO_7,
260
};
261
ROMCONST apalControlGpio_t moduleGpioDw1000Reset = {
262
  /* GPIO */ &_gpioDw1000Reset,
263
  /* meta */ {
264
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
265
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
266
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
267
  },
268
};
269

    
270
/**
271
 * @brief   IO_2 breakout signal GPIO.
272
 */
273
static apalGpio_t _gpioDw1000WakeUp = {
274
  /* line */ LINE_IO_2,
275
};
276
ROMCONST apalControlGpio_t moduleGpioDw1000WakeUp = {
277
  /* GPIO */ &_gpioDw1000WakeUp,
278
  /* meta */ {
279
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
280
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
281
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
282
  },
283
};
284

    
285
/**
286
 * @brief   DW1000 SPI chip select output signal GPIO.
287
 */
288
static apalGpio_t _gpioSpiChipSelect = {
289
  /* line */ LINE_SPI_SS_N,
290
};
291
ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
292
  /* GPIO */ &_gpioSpiChipSelect,
293
  /* meta */ {
294
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
295
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
296
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
297
  },
298
};
299
#else
300
/**
301
 * @brief   IO_8 breakout signal GPIO.
302
 */
303
static apalGpio_t _gpioBreakoutIo8 = {
304
  /* line */ LINE_IO_8,
305
};
306
apalControlGpio_t moduleGpioBreakoutIo8 = {
307
  /* GPIO */ &_gpioBreakoutIo8,
308
  /* meta */ {
309
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
310
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
311
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
312
  },
313
};
314

    
315
/**
316
 * @brief   IO_7 breakout signal GPIO.
317
 */
318
static apalGpio_t _gpioBreakoutIo7 = {
319
  /* line */ LINE_IO_7,
320
};
321
apalControlGpio_t moduleGpioBreakoutIo7 = {
322
  /* GPIO */ &_gpioBreakoutIo7,
323
  /* meta */ {
324
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
325
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
326
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
327
  },
328
};
329

    
330
/**
331
 * @brief   IO_2 breakout signal GPIO.
332
 */
333
static apalGpio_t _gpioBreakoutIo2 = {
334
  /* line */ LINE_IO_2,
335
};
336
apalControlGpio_t moduleGpioBreakoutIo2 = {
337
  /* GPIO */ &_gpioBreakoutIo2,
338
  /* meta */ {
339
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
340
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
341
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
342
  },
343
};
344
#endif  /* BOARD_DW1000_CONNECTED == true */
345

    
346

    
347
/**
348
 * @brief   IO_4 breakout signal GPIO.
349
 */
350
static apalGpio_t _gpioBreakoutIo4 = {
351
  /* line */ LINE_IO_4,
352
};
353
apalControlGpio_t moduleGpioBreakoutIo4 = {
354
  /* GPIO */ &_gpioBreakoutIo4,
355
  /* meta */ {
356
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
357
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
358
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
359
  },
360
};
361

    
362
/**
363
 * @brief   IO_1 breakout signal GPIO.
364
 */
365
static apalGpio_t _gpioBreakoutIo1 = {
366
  /* line */ LINE_IO_1,
367
};
368
apalControlGpio_t moduleGpioBreakoutIo1 = {
369
  /* GPIO */ &_gpioBreakoutIo1,
370
  /* meta */ {
371
    /* direction      */ APAL_GPIO_DIRECTION_UNDEFINED,
372
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
373
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
374
  },
375
};
376

    
377

    
378
/**
379
 * @brief   LED output signal GPIO.
380
 */
381
static apalGpio_t _gpioLed = {
382
  /* line */ LINE_LED,
383
};
384
ROMCONST apalControlGpio_t moduleGpioLed = {
385
  /* GPIO */ &_gpioLed,
386
  /* meta */ {
387
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
388
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
389
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
390
  },
391
};
392

    
393
/**
394
 * @brief   LIGHT_XLAT output signal GPIO.
395
 */
396
static apalGpio_t _gpioLightXlat = {
397
  /* line */ LINE_LIGHT_XLAT,
398
};
399
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
400
  /* GPIO */ &_gpioLightXlat,
401
  /* meta */ {
402
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
403
    /* active state   */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
404
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
405
  },
406
};
407

    
408
/**
409
 * @brief   SW_V18_EN output signal GPIO.
410
 */
411
static apalGpio_t _gpioSwV18En = {
412
  /* line */ LINE_SW_V18_EN,
413
};
414
ROMCONST apalControlGpio_t moduleGpioSwV18En = {
415
  /* GPIO */ &_gpioSwV18En,
416
  /* meta */ {
417
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
418
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
419
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
420
  },
421
};
422

    
423
/**
424
 * @brief   SW_VSYS_EN output signal GPIO.
425
 */
426
static apalGpio_t _gpioSwVsysEn = {
427
  /* line */ LINE_SW_VSYS_EN,
428
};
429
ROMCONST apalControlGpio_t moduleGpioSwVsysEn = {
430
  /* GPIO */ &_gpioSwVsysEn,
431
  /* meta */ {
432
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
433
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
434
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
435
  },
436
};
437

    
438
/**
439
 * @brief   SYS_UART_UP bidirectional signal GPIO.
440
 */
441
static apalGpio_t _gpioSysUartUp = {
442
  /* line */ LINE_SYS_UART_UP,
443
};
444
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
445
  /* GPIO */ &_gpioSysUartUp,
446
  /* meta */ {
447
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
448
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
449
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
450
  },
451
};
452

    
453
/**
454
 * @brief   SYS_PD bidirectional signal GPIO.
455
 */
456
static apalGpio_t _gpioSysPd = {
457
  /* line */ LINE_SYS_PD_N,
458
};
459
ROMCONST apalControlGpio_t moduleGpioSysPd = {
460
  /* GPIO */ &_gpioSysPd,
461
  /* meta */ {
462
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
463
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
464
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
465
  },
466
};
467

    
468
/**
469
 * @brief   SYS_SYNC bidirectional signal GPIO.
470
 */
471
static apalGpio_t _gpioSysSync = {
472
  /* line */ LINE_SYS_INT_N,
473
};
474
ROMCONST apalControlGpio_t moduleGpioSysSync = {
475
  /* GPIO */ &_gpioSysSync,
476
  /* meta */ {
477
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
478
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
479
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
480
  },
481
};
482

    
483
/** @} */
484

    
485
/*===========================================================================*/
486
/**
487
 * @name AMiRo-OS core configurations
488
 * @{
489
 */
490
/*===========================================================================*/
491

    
492
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
493
ROMCONST char* moduleShellPrompt = "LightRing";
494
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
495

    
496
/** @} */
497

    
498
/*===========================================================================*/
499
/**
500
 * @name Startup Shutdown Synchronization Protocol (SSSP)
501
 * @{
502
 */
503
/*===========================================================================*/
504

    
505
/** @} */
506

    
507
/*===========================================================================*/
508
/**
509
 * @name Hardware specific wrappers Functions
510
 * @{
511
 */
512
/*===========================================================================*/
513

    
514
#if (BOARD_DW1000_CONNECTED == true)
515
/*! @brief Manually reset the DW1000 module  */
516
void reset_DW1000(void){
517

    
518
  // Set the pin as output
519
  palSetLineMode(moduleGpioDw1000Reset.gpio->line, APAL_GPIO_DIRECTION_OUTPUT);
520

    
521
  //drive the RSTn pin low
522
  apalGpioWrite(moduleGpioDw1000Reset.gpio, APAL_GPIO_LOW);
523

    
524
  //put the pin back to tri-state ... as input
525
//  palSetLineMode(moduleGpioDw1000Reset.gpio->line, APAL_GPIO_DIRECTION_INPUT); // TODO:
526

    
527
  aosThdMSleep(2);
528
}
529

    
530
/*! @brief entry point to the IRQn event in DW1000 module
531
 *
532
 * */
533
void process_deca_irq(void){
534
  do{
535
    dwt_isr();
536
   //while IRS line active (ARM can only do edge sensitive interrupts)
537
  }while(port_CheckEXT_IRQ() == 1);
538
}
539

    
540
/*! @brief Check the current value of GPIO pin and return the value */
541
apalGpioState_t port_CheckEXT_IRQ(void) {
542
  apalGpioState_t  val;
543
  apalGpioRead(moduleGpioDw1000Irqn.gpio, &val);
544
  return val;
545
}
546

    
547
/*! @brief Manually set the chip select pin of the SPI */
548
void set_SPI_chip_select(void){
549
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH);
550
}
551

    
552
/*! @brief Manually reset the chip select pin of the SPI */
553
void clear_SPI_chip_select(void){
554
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
555
}
556

    
557
/*! @brief Change the SPI speed configuration on the fly */
558
void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
559

    
560
  spiStop(drv->spid);
561

    
562
  if (speedValue == FALSE){
563
    spiStart(drv->spid, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
564
  }
565
  else{
566
    spiStart(drv->spid, &moduleHalSpiUwbHsConfig); // high speed spi configuration
567
  }
568
}
569
#endif /* (BOARD_DW1000_CONNECTED == true) */
570
/** @} */
571

    
572

    
573
/*===========================================================================*/
574
/**
575
 * @name Low-level drivers
576
 * @{
577
 */
578
/*===========================================================================*/
579

    
580
AT24C01BDriver moduleLldEeprom = {
581
  /* I2C driver   */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
582
  /* I2C address  */ 0x00u,
583
};
584

    
585
INA219Driver moduleLldPowerMonitorVled = {
586
  /* I2C Driver       */ &MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT,
587
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
588
  /* current LSB (uA) */ 0x00u,
589
  /* configuration    */ NULL,
590
};
591

    
592
LEDDriver moduleLldStatusLed = {
593
  /* LED enable Gpio */ &moduleGpioLed,
594
};
595

    
596
MIC9404xDriver moduleLldPowerSwitchV18 = {
597
  /* power enable GPIO  */ &moduleGpioSwV18En,
598
};
599

    
600
MIC9404xDriver moduleLldPowerSwitchV33 = {
601
  /* power enable GPIO  */ &moduleGpioSwV33En,
602
};
603

    
604
// The 4.2V switch is disabled due to a hardware bug.
605
//MIC9404xDriver moduleLldPowerSwitchV42 = {
606
//  /* power enable GPIO  */ &moduleGpioSwV42En,
607
//};
608

    
609
MIC9404xDriver moduleLldPowerSwitchV50 = {
610
  /* power enable GPIO  */ &moduleGpioSwV50En,
611
};
612

    
613
MIC9404xDriver moduleLldPowerSwitchVsys = {
614
  /* power enable GPIO  */ &moduleGpioSwVsysEn,
615
};
616

    
617
// TODO: add SNx5C3221E
618

    
619
TLC5947Driver moduleLldLedPwm = {
620
  /* SPI driver         */ &MODULE_HAL_SPI_LIGHT,
621
  /* BLANK signal GPIO  */ &moduleGpioLightBlank,
622
  /* XLAT signal GPIO   */ &moduleGpioLightXlat,
623
};
624

    
625
#if (BOARD_DW1000_CONNECTED == true)
626
DW1000Driver moduleLldDw1000 = {
627
  /* SPI driver         */ &MODULE_HAL_SPI_UWB,
628
  /* ext interrupt      */ &moduleGpioDw1000Irqn,
629
  /* RESET DW1000       */ &moduleGpioDw1000Reset,
630
};
631

    
632
MIC9404xDriver moduleLldPowerSwitchDw1000 = {
633
  /* power enable GPIO  */ &moduleGpioSwVsysEn,
634
};
635
#endif /* (BOARD_DW1000_CONNECTED == true) */
636

    
637
/** @} */
638

    
639
/*===========================================================================*/
640
/**
641
 * @name Tests
642
 * @{
643
 */
644
/*===========================================================================*/
645
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
646

    
647
/*
648
 * AT24C01BN-SH-B (EEPROM)
649
 */
650
#include <module_test_AT24C01B.h>
651
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
652
{
653
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
654
}
655
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
656

    
657
/*
658
 * INA219 (power monitor)
659
 */
660
#include <module_test_INA219.h>
661
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
662
{
663
  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
664
}
665
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
666

    
667
/*
668
 * Status LED
669
 */
670
#include <module_test_LED.h>
671
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
672
{
673
  return moduleTestLedShellCb(stream, argc, argv, NULL);
674
}
675
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
676

    
677
/*
678
 * MIC9404x (power switch)
679
 */
680
#include <module_test_MIC9404x.h>
681
static int _testMic9404xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
682
{
683
  return moduleTestMic9404xShellCb(stream, argc, argv, NULL);
684
}
685
AOS_SHELL_COMMAND(moduleTestMic9404xShellCmd, "test:PowerSwitch", _testMic9404xShellCmdCb);
686

    
687
// TODO: add SNx5C3221E
688

    
689
/*
690
 * TLC5947 (24 channel PWM LED driver)
691
 */
692
#include <module_test_TLC5947.h>
693
static int _testTlc5947ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
694
{
695
  return moduleTestTlc5947ShellCb(stream, argc, argv, NULL);
696
}
697
AOS_SHELL_COMMAND(moduleTestTlc5947ShellCmd, "test:Lights", _testTlc5947ShellCmdCb);
698

    
699
#if (BOARD_DW1000_CONNECTED == true) || defined(__DOXYGEN__)
700
/*
701
 * UwB Driver (DW1000)
702
 */
703
#include <module_test_DW1000.h>
704
static int _testDw1000ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
705
{
706
  return moduleTestDw1000ShellCb(stream, argc, argv, NULL);
707
}
708
AOS_SHELL_COMMAND(moduleTestDw1000ShellCmd, "test:DW1000", _testDw1000ShellCmdCb);
709
#endif /* (BOARD_DW1000_CONNECTED == true) */
710

    
711
/*
712
 * entire module
713
 */
714
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
715
{
716
  (void)argc;
717
  (void)argv;
718

    
719
  int status = AOS_OK;
720
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
721
  aos_testresult_t result_test = {0, 0};
722
  aos_testresult_t result_total = {0, 0};
723

    
724
  /* AT24C01B (EEPROM) */
725
  status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
726
  result_total = aosTestResultAdd(result_total, result_test);
727

    
728
  /* INA219 (power monitor) */
729
  status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
730
  result_total = aosTestResultAdd(result_total, result_test);
731

    
732
  /* Status LED */
733
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
734
  result_total = aosTestResultAdd(result_total, result_test);
735

    
736
  /* MIC9404x (power switch) */
737
  // 1.8V
738
  targv[1] = "1.8V";
739
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
740
  result_total = aosTestResultAdd(result_total, result_test);
741
  // 3.3V
742
  targv[1] = "3.3V";
743
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
744
  result_total = aosTestResultAdd(result_total, result_test);
745
// The 4.2V switch is disabled due to a hardware bug.
746
//  // 4.2V
747
//  targv[1] = "4.2V";
748
//  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
749
//  result_total = aosTestResultAdd(result_total, result_test);
750
  // 5.0V
751
  targv[1] = "5.0V";
752
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
753
  result_total = aosTestResultAdd(result_total, result_test);
754
  //VSYS
755
  targv[1] = "VSYS";
756
  status |= moduleTestMic9404xShellCb(stream, 2, targv, &result_test);
757
  result_total = aosTestResultAdd(result_total, result_test);
758
  targv[1] = "";
759

    
760
  // TODO: add SNx5C3221E
761

    
762
  /* TLC5947 (24 channel PWM LED driver) */
763
  status |= moduleTestTlc5947ShellCb(stream, 0, targv, &result_test);
764
  result_total = aosTestResultAdd(result_total, result_test);
765

    
766
  // print total result
767
  chprintf(stream, "\n");
768
  aosTestResultPrintSummary(stream, &result_total, "entire module");
769

    
770
  return status;
771
}
772
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
773

    
774
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
775

    
776
/** @} */
777
/** @} */