Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / VL53L1X_v1 / aos_test_VL53L1X.c @ e7c4f797

History | View | Annotate | Download (9.418 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
#include <aos_test_VL53L1X.h>
21

    
22
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23

    
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27

    
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31

    
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35

    
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39

    
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43

    
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/*****************************************************************************
47
*/
48

    
49
/**
50
 * @brief   LED test function.
51
 *
52
 * @param[in] stream  Stream for input/output.
53
 * @param[in] test    Test object.
54
 *
55
 * @return            Test result value.
56
 */
57
aos_testresult_t aosTestVL53L1XFunc(BaseSequentialStream* stream, const aos_test_t* test)
58
{
59
//   aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL);
60

    
61
chprintf(stream, "Peter Wurst\n");
62

    
63
  // local variables
64
  aos_testresult_t result = {0,0};
65
//   int32_t status;
66
//     chprintf(stream, "Hello World!\n");
67
// //   aosTestResultInit(&result);
68

    
69
//   VL53L1_Dev_t dev;
70
//   dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x);
71

    
72
//   chprintf(stream, "Toggle PC2...\n");
73
//   chprintf(stream, "On...\n");
74
  /* vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_ON); */
75
//   aosThdSSleep(5);
76
//   chprintf(stream, "off...\n");
77
//   status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_OFF);
78
//   aosThdSSleep(5);
79
//   chprintf(stream, "On...\n");
80
//   status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_ON);
81
//   aosThdSSleep(5);
82
//   chprintf(stream, "Off...\n");
83
//   status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_OFF);
84
//   // status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state);
85
//   if (status == APAL_STATUS_OK) {
86
//       aosTestPassed(stream, &result);
87
//   } else {
88
//     aosTestFailed(stream, &result);
89
//   }p
90

    
91
//   chprintf(stream, "turning off for two seconds...\n");
92
//   state = LED_LLD_STATE_OFF;
93
//   status = led_lld_set(((aos_test_leddata_t*)test->data)->led, state);
94
//   aosThdSSleep(2);
95
//   status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state);
96
//   if (status == APAL_STATUS_OK && state == LED_LLD_STATE_OFF) {
97
//     aosTestPassed(stream, &result);
98
//   } else {
99
//     aosTestFailed(stream, &result);
100
//   }
101

    
102
//   chprintf(stream, "toggling for two seconds...\n");
103
//   status = led_lld_set(((aos_test_leddata_t*)test->data)->led, LED_LLD_STATE_ON);
104
//   for (uint32_t i = 0; i < 2000/100; ++i) {
105
//     status |= led_lld_toggle(((aos_test_leddata_t*)test->data)->led);
106
//     status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state);
107
//     status |= ((uint8_t)state != (i & 0x01u)) ? APAL_STATUS_ERROR : APAL_STATUS_OK;
108
//     aosThdMSleep(100);
109
//   }
110
//   status = led_lld_set(((aos_test_leddata_t*)test->data)->led, LED_LLD_STATE_OFF);
111
//   if (status == APAL_STATUS_OK) {
112
//     aosTestPassed(stream, &result);
113
//   } else {
114
//     aosTestFailed(stream, &result);
115
//   }
116

    
117
//   aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(LEDDriver));
118

    
119
/*
120
  uint8_t byteData, sensorState=0;
121
  uint16_t wordData;
122
  uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
123
  uint16_t Distance;
124
  uint16_t SignalRate;
125
  uint16_t AmbientRate;
126
  uint8_t RangeStatus;
127
  uint8_t dataReady;
128
  int32_t status;
129
  */
130

    
131
    
132
//   aosTestResultInit(&result);
133

    
134
  VL53L1_Dev_t dev;
135
  dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x);
136
  /* vl53l1x_GPIO1_set(&dev.vl53l1x, GPIO_LLD_STATE_ON); */
137

    
138
  // status = VL53L1_RdByte(&dev, 0x010F, &byteData);
139
  // printf("VL53L1X Model_ID: %X\n", byteData);
140
  // status = VL53L1_RdByte(&dev, 0x0110, &byteData);
141
  // printf("VL53L1X Module_Type: %X\n", byteData);
142
  // status = VL53L1_RdWord(&dev, 0x010F, &wordData);
143
  // printf("VL53L1X: %X\n", wordData);
144
  
145
  // activate device
146
  apalControlGpioState_t xshut_state;
147
  apalControlGpioState_t gpio_state;
148
  apalControlGpioGet(dev.vl53l1x.xshut, &xshut_state);
149
  apalControlGpioGet(dev.vl53l1x.gpio1, &gpio_state);
150
  if (xshut_state == APAL_GPIO_OFF) {
151
    chprintf(stream, "XSHUT OFF -> activating\n");
152
    apalControlGpioSet(dev.vl53l1x.xshut, APAL_GPIO_ON);
153
    aosThdSSleep(1);
154
    aosThdUSleep(2 * VL53L1X_LLD_BOOTDURATION);
155
  } else {
156
    chprintf(stream, "XSHUT ON\n");
157
  }
158
  chprintf(stream, "0x%08X | 0x%08X\n", (uint32_t)dev.vl53l1x.i2cd, (uint32_t)(&I2CD3));
159
  chprintf(stream, "0x%02X\n", dev.vl53l1x.xshut);
160
  if (gpio_state == APAL_GPIO_OFF) {
161
    chprintf(stream, "Gpio OFF \n");
162
  }
163

    
164
  uint8_t testBuf[49] = {0};
165
  // Reste device
166
  
167
  // printf("Resetting device! \n");
168
  /* chprintf(stream, "Testif broken!\n"); */
169
  
170
  uint8_t data[4] = {0};
171
  /* Status = VL53L1_RdByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, &i); */
172
  /* apalI2CMasterReceive(dev.vl53l1x.i2cd, dev.vl53l1x.addr, testBuf, 3, 10); */
173
  /* aosThdMSleep(1000); */
174
  /* chprintf(stream, "Start reset!\n"); */
175
  /* apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 3, testBuf, 0, 10); */
176
  chprintf(stream, "Before sleep!\n");
177
  /* apalI2CMasterTransmit() */
178
  /* aosThdMSleep(1000); */
179
  aosThdUSleep(2 * VL53L1X_LLD_BOOTDURATION);
180
  /* 0x002E */
181

    
182
  data[0] =  0x01;
183
  data[1] =  0x0f;
184
  uint8_t stuff[4] = { 0 };
185
  /* data[3] = 0x01; */
186
  chprintf(stream, "End reset!\n");
187
  
188
  apalExitStatus_t res = apalI2CMasterTransmit(dev.vl53l1x.i2cd,  dev.vl53l1x.addr, data, 2, stuff , 0, 10);
189
  
190

    
191
  chprintf(stream, "Res: %d\n", res);
192
  aosThdMSleep(100);
193
  i2cflags_t err =  i2cGetErrors(dev.vl53l1x.i2cd);
194
  chprintf(stream, "Error: %08x\n", err);
195
  aosThdMSleep(100);
196
  /* apalI2CMasterReceive(dev.vl53l1x.i2cd,  dev.vl53l1x.addr, testBuf, 4, 10); */
197
  /* apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 3, testBuf, 0, 10); */
198
  /* /\* VL53L1_RdByte(&dev, VL53L1_IDENTIFICATION__MODEL_ID, &data); *\/ */
199
  chprintf(stream, "0x%02\n", stuff[0]);
200
  chprintf(stream, "0x%02\n", stuff[1]);
201
  chprintf(stream, "0x%02\n", data[0]);
202
  chprintf(stream, "0x%02\n", data[1]);
203
  for(int i = 0; i < 49 ; i++){
204
    chprintf(stream, "0x%02 ", testBuf[i]);
205
  }
206
  chprintf(stream, "\n");
207

    
208
  /* VL53L1_WrByte(&dev, 0x0000, 0x00); */
209
  /* aosThdSSleep(2); */
210
  /* vl53l1_WrByte(&dev, 0x0000, 0x01); */
211

    
212

    
213
  aosTestPassed(stream, &result);
214

    
215

    
216
  return result;
217
}
218

    
219

    
220

    
221
/**
222
 * @brief   Test if I2C was initialized correctly.
223
 *
224
 * @param[in] stream  Stream for input/output.
225
 * @param[in] test    Test object.
226
 *
227
 * @return            Test result value.
228
 */
229
aos_testresult_t aosTestVL53L1Xi2cInit(BaseSequentialStream* stream, const aos_test_t* test)
230
{
231
//   aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL);
232

    
233
  // local variables
234
  aos_testresult_t result = {0,0};
235
  uint8_t byteData, sensorState=0;
236
  uint16_t wordData;
237
  uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
238
  uint16_t Distance;
239
  uint16_t SignalRate;
240
  uint16_t AmbientRate;
241
  uint8_t RangeStatus;
242
  uint8_t dataReady;
243
  int32_t status;
244
    chprintf(stream, "Hello World!\n");
245
//   aosTestResultInit(&result);
246

    
247
  VL53L1_Dev_t dev;
248
  dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x);
249
  // status = VL53L1_RdByte(&dev, 0x010F, &byteData);
250
  // printf("VL53L1X Model_ID: %X\n", byteData);
251
  // status = VL53L1_RdByte(&dev, 0x0110, &byteData);
252
  // printf("VL53L1X Module_Type: %X\n", byteData);
253
  // status = VL53L1_RdWord(&dev, 0x010F, &wordData);
254
  // printf("VL53L1X: %X\n", wordData);
255
  uint8_t testBuf[2] = {0};
256
  // Reste device
257
  printf("Resetting device! \n");
258
  VL53L1_WrByte(&dev, 0x0000, 0x00);
259
  aosThdSSleep(2);
260
  VL53L1_WrByte(&dev, 0x0000, 0x01);
261

    
262

    
263
  aosTestPassed(stream, &result);
264

    
265
  return result;
266
}
267

    
268
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */