Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / test / PCAL6524 / module_test_PCAL6524.c @ 96621a83

History | View | Annotate | Download (4.248 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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
#include <amiroos.h>
20

    
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && ((BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X))) || defined(__DOXYGEN__)
22

    
23
#include <module_test_PCAL6524.h>
24
#include <aos_test_PCAL6524.h>
25
#include <string.h>
26

    
27
/******************************************************************************/
28
/* LOCAL DEFINITIONS                                                          */
29
/******************************************************************************/
30

    
31
/******************************************************************************/
32
/* EXPORTED VARIABLES                                                         */
33
/******************************************************************************/
34

    
35
/******************************************************************************/
36
/* LOCAL TYPES                                                                */
37
/******************************************************************************/
38

    
39
/******************************************************************************/
40
/* LOCAL VARIABLES                                                            */
41
/******************************************************************************/
42

    
43
static aos_test_pcal6524data_t _data = {
44
  /* driver   */ NULL,
45
  /* timeout  */ MICROSECONDS_PER_SECOND,
46
};
47

    
48
static AOS_TEST(_test, "PCAL6524", "GPIO extender", moduleTestPcal6524ShellCb, aosTestPcal6524Func, &_data);
49

    
50
/******************************************************************************/
51
/* LOCAL FUNCTIONS                                                            */
52
/******************************************************************************/
53

    
54
/******************************************************************************/
55
/* EXPORTED FUNCTIONS                                                         */
56
/******************************************************************************/
57

    
58
int moduleTestPcal6524ShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result)
59
{
60
  enum {
61
    UNKNOWN,
62
    GPIOEXTENDER1, GPIOEXTENDER2,
63
  } extender = UNKNOWN;
64

    
65
  // evaluate arguments
66
  if (argc == 2) {
67
    if (strcmp(argv[1], "#1") == 0) {
68
      extender = GPIOEXTENDER1;
69
    } else if (strcmp(argv[1], "#2") == 0) {
70
      extender = GPIOEXTENDER2;
71
    }
72
  }
73

    
74
  // handle valid extender
75
  if (extender != UNKNOWN) {
76
    aos_testresult_t res = {0 ,0};
77

    
78
    switch (extender) {
79
      case GPIOEXTENDER1:
80
        _data.pcal6524d = &moduleLldGpioExtender1;
81
        res = aosTestRun(stream, &_test, "I2C bus #1");
82
        _data.pcal6524d = NULL;
83
        break;
84
      case GPIOEXTENDER2:
85
        _data.pcal6524d = &moduleLldGpioExtender2;
86
        res = aosTestRun(stream, &_test, "I2C bus #2");
87
        _data.pcal6524d = NULL;
88
        break;
89
      default:
90
        break;
91
    }
92
    if (result != NULL) {
93
      *result = res;
94
    }
95
    return AOS_OK;
96
  }
97
  // handle invalid arguments
98
  else {
99
    // print help
100
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
101
    chprintf(stream, "Options:\n");
102
    chprintf(stream, "  #1\n");
103
    chprintf(stream, "    Test the GPIO extender for the I2C bus #1.\n");
104
    chprintf(stream, "  #2\n");
105
    chprintf(stream, "    Test the GPIO extender for the I2C bus #2.\n");
106
    if (result != NULL) {
107
      result->passed = 0;
108
      result->failed = 0;
109
    }
110
    return AOS_INVALIDARGUMENTS;
111
  }
112
}
113

    
114
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && ((BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)) */