Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-2 / test / VCNL4020 / module_test_VCNL4020.c @ 96621a83

History | View | Annotate | Download (7.47 KB)

1 4c72a54c Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 96621a83 Thomas Schöpping
Copyright (C) 2016..2020  Thomas Schöpping et al.
4 4c72a54c 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
#include <amiroos.h>
20
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)) || defined(__DOXYGEN__)
22
23
#include <module_test_VCNL4020.h>
24
#include <aos_test_VCNL4020.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_vcnl4020data_t _data = {
44
  /* driver       */ NULL,
45
  /* timeout      */ MICROSECONDS_PER_SECOND,
46 cda14729 Thomas Schöpping
  /* event source */ &aos.events.gpio,
47 4c72a54c Thomas Schöpping
  /* event flags  */ 0,
48
};
49
50
static AOS_TEST(_test, "VCNL4020", "proximity sensor", moduleTestVcnl4020ShellCb, aosTestVcnl4020Func, &_data);
51
52
/******************************************************************************/
53
/* LOCAL FUNCTIONS                                                            */
54
/******************************************************************************/
55
56
static void _disableInterrupt(VCNL4020Driver* vcnl)
57
{
58
  uint8_t intstatus;
59
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, _data.timeout);
60
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, _data.timeout);
61
  if (intstatus) {
62
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, _data.timeout);
63
  }
64
  return;
65
}
66
67
/******************************************************************************/
68
/* EXPORTED FUNCTIONS                                                         */
69
/******************************************************************************/
70
71
int moduleTestVcnl4020ShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result)
72
{
73
  enum {
74
    UNKNOWN,
75
    NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW,
76
  } sensor = UNKNOWN;
77
78
  // evaluate arguments
79
  if (argc == 2) {
80
    if (strcmp(argv[1], "-nne") == 0) {
81
      sensor = NNE;
82
    } else if (strcmp(argv[1], "-ene") == 0) {
83
      sensor = ENE;
84
    } else if (strcmp(argv[1], "-ese") == 0) {
85
      sensor = ESE;
86
    } else if (strcmp(argv[1], "-sse") == 0) {
87
      sensor = SSE;
88
    } else if (strcmp(argv[1], "-ssw") == 0) {
89
      sensor = SSW;
90
    } else if (strcmp(argv[1], "-wsw") == 0) {
91
      sensor = WSW;
92
    } else if (strcmp(argv[1], "-wnw") == 0) {
93
      sensor = WNW;
94
    } else if (strcmp(argv[1], "-nnw") == 0) {
95
      sensor = NNW;
96
    }
97
  }
98
99
  // handle valid sensor
100
  if (sensor != UNKNOWN) {
101
    aos_testresult_t res = {0, 0};
102
    PCA9544ADriver* mux = NULL;
103
    switch (sensor) {
104
      case SSE:
105
      case SSW:
106
      case WSW:
107
      case WNW:
108
        mux = &moduleLldI2cMultiplexer1;
109
        _data.vcnld = &moduleLldProximity1;
110 cda14729 Thomas Schöpping
        _data.evtflags = MODULE_OS_GPIOEVENTFLAG_IRINT2;
111 4c72a54c Thomas Schöpping
        break;
112
      case NNW:
113
      case NNE:
114
      case ENE:
115
      case ESE:
116
        mux = &moduleLldI2cMultiplexer2;
117
        _data.vcnld = &moduleLldProximity2;
118 cda14729 Thomas Schöpping
        _data.evtflags = MODULE_OS_GPIOEVENTFLAG_IRINT1;
119 4c72a54c Thomas Schöpping
        break;
120
      default:
121
        break;
122
    }
123
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, _data.timeout);
124
    _disableInterrupt(_data.vcnld);
125
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, _data.timeout);
126
    _disableInterrupt(_data.vcnld);
127
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, _data.timeout);
128
    _disableInterrupt(_data.vcnld);
129
    pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, _data.timeout);
130
    _disableInterrupt(_data.vcnld);
131
    switch (sensor) {
132
      case NNE:
133
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, _data.timeout);
134
        res = aosTestRun(stream, &_test, "north-northeast sensor (I2C #2)");
135
        break;
136
      case ENE:
137
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, _data.timeout);
138
        res = aosTestRun(stream, &_test, "east-northeast sensor (I2C #2)");
139
        break;
140
      case ESE:
141
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, _data.timeout);
142
        res = aosTestRun(stream, &_test, "east-southeast sensor (I2C #2)");
143
        break;
144
      case SSE:
145
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, _data.timeout);
146
        res = aosTestRun(stream, &_test, "south-southeast sensor (I2C #1)");
147
        break;
148
      case SSW:
149
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, _data.timeout);
150
        res = aosTestRun(stream, &_test, "south-southwest sensor (I2C #1)");
151
        break;
152
      case WSW:
153
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, _data.timeout);
154
        res = aosTestRun(stream, &_test, "west-southwest sensor (I2C #1)");
155
        break;
156
      case WNW:
157
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, _data.timeout);
158
        res = aosTestRun(stream, &_test, "west-northwest sensor (I2C #1)");
159
        break;
160
      case NNW:
161
        pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, _data.timeout);
162
        res = aosTestRun(stream, &_test, "north-northwest sensor (I2C #2)");
163
        break;
164
      default:
165
        break;
166
    }
167
    _data.vcnld = NULL;
168
    _data.evtflags = 0;
169
    if (result != NULL) {
170
      *result = res;
171
    }
172
    return AOS_OK;
173
  }
174
  // handle invalid arguments
175
  else {
176
    // print help
177
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
178
    chprintf(stream, "Options:\n");
179
    chprintf(stream, "  -nne\n");
180
    chprintf(stream, "    Test north-northeast sensor.\n");
181
    chprintf(stream, "  -ene\n");
182
    chprintf(stream, "    Test east-northeast sensor.\n");
183
    chprintf(stream, "  -ese\n");
184
    chprintf(stream, "    Test east-southeast sensor.\n");
185
    chprintf(stream, "  -sse\n");
186
    chprintf(stream, "    Test south-southeast sensor.\n");
187
    chprintf(stream, "  -ssw\n");
188
    chprintf(stream, "    Test south-southwest sensor.\n");
189
    chprintf(stream, "  -wsw\n");
190
    chprintf(stream, "    Test west-southwest sensor.\n");
191
    chprintf(stream, "  -wnw\n");
192
    chprintf(stream, "    Test west-northwest sensor.\n");
193
    chprintf(stream, "  -nnw\n");
194
    chprintf(stream, "    Test north-northwest sensor.\n");
195
    if (result != NULL) {
196
      result->passed = 0;
197
      result->failed = 0;
198
    }
199
    return AOS_INVALIDARGUMENTS;
200
  }
201
}
202
203
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */