Revision c368a765

View differences:

include/VL53L0X/v1/Api_vl53l0x/core/inc/vl53l0x_api.h
55 55

  
56 56

  
57 57

  
58
#define USE_I2C_2V8
59

  
60 58
/** @defgroup VL53L0X_cut11_group VL53L0X cut1.1 Function Definition
61 59
 *  @brief    VL53L0X cut1.1 Function Definition
62 60
 *  @{
include/VL53L0X/v1/Api_vl53l0x/platform/inc/vl53l0x_platform.h
68 68
    VL53L0X_DevData_t Data;               /*!< embed ST Ewok Dev  data as "Data"*/
69 69

  
70 70
    /*!< user specific field */
71
    uint16_t   I2cDevAddr;                /*!< i2c device address user specific field */
71
    uint16_t  I2cDevAddr;                /*!< i2c device address user specific field */
72 72
    uint8_t   comms_type;                /*!< Type of comms : VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI */
73 73
    uint16_t  comms_speed_khz;           /*!< Comms speed [kHz] : typically 400kHz for I2C           */
74 74

  
source/VL53L0X/v1/alld_VL53L0X_v1.c
55 55
/* LOCAL FUNCTIONS                                                            */
56 56
/******************************************************************************/
57 57

  
58
/******************************************************************************/
59
/* EXPORTED FUNCTIONS                                                         */
60
/******************************************************************************/
61

  
62
/* general single register access */
63

  
64

  
65 58
void print_pal_error(VL53L0X_Error Status){
66 59
    char buf[VL53L0X_MAX_STRING_LENGTH];
67 60
    VL53L0X_GetPalErrorString(Status, buf);
68
    chprintf((BaseSequentialStream*)&SD1,"\t\tAPI Status: %i : %s\n", Status, buf);
61
    apalDbgPrintf("\t\tAPI Status: %i : %s\n", Status, buf);
69 62
}
70 63

  
71 64

  
......
81 74
    RangeStatus = pRangingMeasurementData->RangeStatus;
82 75

  
83 76
    VL53L0X_GetRangeStatusString(RangeStatus, buf);
84
    chprintf((BaseSequentialStream*)&SD1,"Range Status: %i : %s\n", RangeStatus, buf);
77
    apalDbgPrintf("Range Status: %i : %s\n", RangeStatus, buf);
85 78

  
86 79
}
87 80

  
88 81

  
82
/******************************************************************************/
83
/* EXPORTED FUNCTIONS                                                         */
84
/******************************************************************************/
85

  
86
/* general single register access */
87

  
88

  
89

  
90

  
91

  
89 92
/**
90 93
 * @brief vl53l0x_lld_init useses the Vl53L0X functions so init the sensor. This function are VL53L0X_DataInit (performs the device initialization)
91 94
 * and VL53L0X_StaticInit (allows to load device settings specific for a given use case). These two function need 40 ms to perform.
92 95
 *
93
 * @param[in] vl53l0x
96
 * @param[in] vl53l0x driver with i2cadress, vl53l0x_data and more.
94 97
 * @return
95 98
 */
96 99

  
......
99 102
{
100 103

  
101 104
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
105
    apalExitStatus_t status_driver = APAL_STATUS_OK;
102 106

  
103 107
    VL53L0X_DeviceInfo_t DeviceInfo;
104 108

  
105 109

  
106 110
    if(status == VL53L0X_ERROR_NONE)
107 111
        {
108
            chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_DataInit\n");
112
            apalDbgPrintf("Call of VL53L0X_DataInit\n");
109 113
            status = VL53L0X_DataInit(&(vl53l0x->vl53l0x_dev)); // Data initialization
114

  
110 115
            print_pal_error(status);
111
        }
116
        }else{
117
        status_driver = APAL_STATUS_ERROR;
118
    }
112 119

  
113 120

  
114 121
    if(status == VL53L0X_ERROR_NONE)
......
116 123
           status = VL53L0X_GetDeviceInfo(&(vl53l0x->vl53l0x_dev), &DeviceInfo);
117 124
           if(status == VL53L0X_ERROR_NONE)
118 125
           {
119
               chprintf((BaseSequentialStream*)&SD1,"VL53L0X_GetDeviceInfo:\n");
120
               chprintf((BaseSequentialStream*)&SD1,"\tDevice Name : %s\n", DeviceInfo.Name);
121
               chprintf((BaseSequentialStream*)&SD1,"\tDevice Type : %s\n", DeviceInfo.Type);
122
               chprintf((BaseSequentialStream*)&SD1,"\tDevice ID : %s\n", DeviceInfo.ProductId);
123
               chprintf((BaseSequentialStream*)&SD1,"\tProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
124
           chprintf((BaseSequentialStream*)&SD1,"\tProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
126
               apalDbgPrintf("VL53L0X_GetDeviceInfo:\n");
127
               apalDbgPrintf("\tDevice Name : %s\n", DeviceInfo.Name);
128
               apalDbgPrintf("\tDevice Type : %s\n", DeviceInfo.Type);
129
               apalDbgPrintf("\tDevice ID : %s\n", DeviceInfo.ProductId);
130
               apalDbgPrintf("\tProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
131
           apalDbgPrintf("\tProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
125 132

  
126 133
           if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) {
127
               chprintf((BaseSequentialStream*)&SD1,"Error expected cut 1.1 but found cut %d.%d\n",
134
               apalDbgPrintf("Error expected cut 1.1 but found cut %d.%d\n",
128 135
                          DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor);
129 136
                   status = VL53L0X_ERROR_NOT_SUPPORTED;
130 137
               }
131 138
           }
132 139
           print_pal_error(status);
140
    }else{
141
        status_driver = APAL_STATUS_ERROR;
133 142
    }
134 143

  
135 144

  
......
141 150

  
142 151
    if(status == VL53L0X_ERROR_NONE)
143 152
    {
144
        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_StaticInit\n");
153
        apalDbgPrintf("Call of VL53L0X_StaticInit\n");
145 154
        status = VL53L0X_StaticInit(&(vl53l0x->vl53l0x_dev)); // Device Initialization
146 155
       print_pal_error(status);
156
    }else{
157
        status_driver = APAL_STATUS_ERROR;
147 158
    }
148 159

  
149 160

  
......
163 174
    {
164 175
        // only test
165 176
       status = VL53L0X_GetReferenceSpads(&(vl53l0x->vl53l0x_dev), &refSpadCount, &isApertureSpads);
166
       chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_GetReferenceSpads with refSpadCount:%lu and isApertureSpads:%u \n", refSpadCount, isApertureSpads);
177
       apalDbgPrintf("Call of VL53L0X_GetReferenceSpads with refSpadCount:%lu and isApertureSpads:%u \n", refSpadCount, isApertureSpads);
167 178

  
168
        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_PerformRefSpadManagement\n");
179
        apalDbgPrintf("Call of VL53L0X_PerformRefSpadManagement\n");
169 180
        status |= VL53L0X_PerformRefSpadManagement(&(vl53l0x->vl53l0x_dev),
170 181
                &refSpadCount, &isApertureSpads); // Device Initialization
171
        chprintf((BaseSequentialStream*)&SD1,"\trefSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
182
        apalDbgPrintf("\trefSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
172 183
        print_pal_error(status);
173 184
        if(status == -6){
185
            status_driver = APAL_STATUS_ERROR;
174 186
            status  = VL53L0X_ERROR_NONE;
175 187
        }
188
    }else{
189
        status_driver = APAL_STATUS_ERROR;
176 190
    }
177 191

  
178 192

  
......
183 197
    // if the user has previously performed a calibration and stored the two parameters in the Host memory we can use VL53L0X_SetRefCalibration
184 198
    if(status == VL53L0X_ERROR_NONE)
185 199
    {
186
        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_PerformRefCalibration\n");
200
        apalDbgPrintf("Call of VL53L0X_PerformRefCalibration\n");
187 201
        status = VL53L0X_PerformRefCalibration(&(vl53l0x->vl53l0x_dev),
188 202
                &VhvSettings, &PhaseCal); // Device Initialization
189 203
        print_pal_error(status);
190 204
        if(status == -6){
191 205
            status  = VL53L0X_ERROR_NONE;
206
            status_driver = APAL_STATUS_ERROR;
192 207
        }
208
    }else{
209
        status_driver = APAL_STATUS_ERROR;
193 210
    }
194 211

  
195 212

  
......
208 225
    if (status == VL53L0X_ERROR_NONE) {
209 226
        status = VL53L0X_SetLimitCheckEnable(&(vl53l0x->vl53l0x_dev),
210 227
                VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
228
    }else{
229
        status_driver = APAL_STATUS_ERROR;
211 230
    }
212 231

  
213 232
    // why are no values seet?? with VL53L0X_SetLimitCheckValue
214 233
    if (status == VL53L0X_ERROR_NONE) {
215 234
        status = VL53L0X_SetLimitCheckEnable(&(vl53l0x->vl53l0x_dev),
216 235
                VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
236
    }else{
237
        status_driver = APAL_STATUS_ERROR;
217 238
    }
218 239

  
219 240

  
......
223 244
    if (status == VL53L0X_ERROR_NONE) {
224 245
        status = VL53L0X_SetLimitCheckEnable(&(vl53l0x->vl53l0x_dev),
225 246
                VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1);
247
    }else{
248
        status_driver = APAL_STATUS_ERROR;
226 249
    }
227 250

  
228 251
    if (status == VL53L0X_ERROR_NONE) {
229 252
        status = VL53L0X_SetLimitCheckValue(&(vl53l0x->vl53l0x_dev),
230 253
                VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
231 254
                (FixPoint1616_t)(1.5*0.023*65536));
255
    }else{
256
        status_driver = APAL_STATUS_ERROR;
232 257
    }
233 258
    /* end static init and some tests */
234 259

  
235 260

  
236
    return status;
261
    return status_driver;
237 262

  
238 263

  
239 264
}
240 265

  
241 266

  
242 267
/**
243
 * @brief vl53l0x_lld_set_mode set one of the thre possible modes.
268
 * @brief vl53l0x_lld_set_mode set one of the thre possible modes. Same as VL53L0X_SetDeviceMode and VL53L0X_SetGpioConfig.
244 269
 * @param vl53l0x[in]
245 270
 * @param mode[in] one of the VL53L0X_DeviceModes, VL53L0X_DEVICEMODE_SINGLE_RANGING == 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING == 1,
246 271
 *                  VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING == 3
......
259 284
    uint32_t ThresholdLow;
260 285
    uint32_t ThresholdHigh;
261 286
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
287
    apalExitStatus_t status_driver = APAL_STATUS_OK;
262 288

  
263 289
    if(status == VL53L0X_ERROR_NONE)
264 290
    {
265 291

  
266 292
        // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
267
        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_SetDeviceMode\n");
293
        apalDbgPrintf("Call of VL53L0X_SetDeviceMode\n");
268 294
        status = VL53L0X_SetDeviceMode(&(vl53l0x->vl53l0x_dev), mode); // Setup in single ranging mode
269 295
        print_pal_error(status);
296
    }else{
297
        status_driver = APAL_STATUS_ERROR;
270 298
    }
271 299

  
272 300

  
273 301
    if(status == VL53L0X_ERROR_NONE)
274 302
    {
275 303
        // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
276
        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_SetGpioConfig\n");
277
        status = VL53L0X_SetGpioConfig(&(vl53l0x->vl53l0x_dev), 0, mode, interrupt, VL53L0X_INTERRUPTPOLARITY_LOW);
304
        apalDbgPrintf("Call of VL53L0X_SetGpioConfig\n");
305
        status = VL53L0X_SetGpioConfig(&(vl53l0x->vl53l0x_dev), 0, mode, interrupt, VL53L0X_INTERRUPTPOLARITY_HIGH);
278 306
        print_pal_error(status);
307
    }else{
308
        status_driver = APAL_STATUS_ERROR;
279 309
    }
280 310

  
281 311

  
......
285 315
        // multiplication with 65536 is imported, no clue why!
286 316
        // in single ranging high and low must be below 255, otherwise there will be no interrupt. In the other two modes the ranging is a few ms slower!
287 317
        if(mode == VL53L0X_DEVICEMODE_SINGLE_RANGING && (low > 254 || high > 254)){
288
            chprintf((BaseSequentialStream*)&SD1,"Device mode is VL53L0X_DEVICEMODE_SINGLE_RANGING and therefore we get no Interrupt if the interrupt "
318
            apalDbgPrintf("Device mode is VL53L0X_DEVICEMODE_SINGLE_RANGING and therefore we get no Interrupt if the interrupt "
289 319
                                                 "threshold is bigger than 254 mm\n");
290 320
        }
291 321

  
......
295 325

  
296 326

  
297 327
        // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
298
        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_SetInterruptThresholds\n");
328
        apalDbgPrintf("Call of VL53L0X_SetInterruptThresholds\n");
299 329
        status = VL53L0X_SetInterruptThresholds(&(vl53l0x->vl53l0x_dev),interrupt,ThresholdLow ,ThresholdHigh);
300 330
        print_pal_error(status);
331
        if(status != VL53L0X_ERROR_NONE)
332
        {
333
            status_driver = APAL_STATUS_ERROR;
334
        }
301 335
    }
302 336

  
303
    return status;
337
    return status_driver;
304 338

  
305 339

  
306 340

  
......
413 447
apalExitStatus_t vl53l0x_lld_start_measurement(VL53L0XDriver* vl53l0x)
414 448
{
415 449
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
450
    apalExitStatus_t status_driver = APAL_STATUS_OK;
416 451
    status = VL53L0X_StartMeasurement(&(vl53l0x->vl53l0x_dev));
417 452

  
418 453
    if(status == VL53L0X_ERROR_NONE)
419 454
    {
420 455
        // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
421
        chprintf((BaseSequentialStream*)&SD1,"Successful startet measurement\n");
456
        apalDbgPrintf("Successful startet measurement\n");
422 457
        print_pal_error(status);
423 458
    }else{
424
        chprintf((BaseSequentialStream*)&SD1,"Error in startet measurement\n");
459
        apalDbgPrintf("Error in startet measurement\n");
425 460
        print_pal_error(status);
461
        status_driver = APAL_STATUS_ERROR;
426 462
    }
427 463

  
428
    return status;
464
    return status_driver;
429 465

  
430 466
}
431 467

  
432 468

  
433 469

  
470
/**
471
 * @brief vl53l0x_lld_stop_measurement, stops a measurement when the measurement were started with vl53l0x_lld_start_measurement
472
 * @param vl53l0x[in]
473
 * @return
474
 */
434 475
apalExitStatus_t vl53l0x_lld_stop_measurement(VL53L0XDriver* vl53l0x)
435 476
{
436 477

  
437 478
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
479
    apalExitStatus_t status_driver = APAL_STATUS_OK;
438 480
    status = VL53L0X_StopMeasurement(&(vl53l0x->vl53l0x_dev));
481
    if(status != VL53L0X_ERROR_NONE)
482
    {
483
        print_pal_error(status);
484
        status_driver = APAL_STATUS_ERROR;
485
    }
439 486

  
440
    return status;
487
    return status_driver;
441 488
}
442 489

  
443 490
/**
......
461 508
    VL53L0X_RangingMeasurementData_t    RangingMeasurementData;
462 509
    VL53L0X_RangingMeasurementData_t   *pRangingMeasurementData    = &RangingMeasurementData;
463 510
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
511
    apalExitStatus_t status_driver = APAL_STATUS_OK;
464 512

  
465 513
    status = VL53L0X_PerformSingleMeasurement(&(vl53l0x->vl53l0x_dev));
466 514

  
467 515
    if (status == VL53L0X_ERROR_NONE)
468 516
        status = VL53L0X_GetRangingMeasurementData(&(vl53l0x->vl53l0x_dev),
469 517
            pRangingMeasurementData);
518
    else
519
        status_driver = APAL_STATUS_ERROR;
470 520

  
471 521

  
472 522
    if (status == VL53L0X_ERROR_NONE)
473 523
        status = VL53L0X_ClearInterruptMask(&(vl53l0x->vl53l0x_dev), 0);
524
    else
525
        status_driver = APAL_STATUS_ERROR;
474 526

  
475 527

  
476 528

  
477 529
    data[0] = RangingMeasurementData.RangeMilliMeter;
478
    //chprintf((BaseSequentialStream*)&SD1, "Measured distance: %i\n\n", RangingMeasurementData.RangeMilliMeter);
530
    //apalDbgPrintf( "Measured distance: %i\n\n", RangingMeasurementData.RangeMilliMeter);
479 531

  
480 532

  
481 533
    //TODO write millimeter to data
482 534
    //data = &RangingMeasurementData.RangeMilliMeter;
483 535

  
484
    return status;
536
    return status_driver;
485 537
}
486 538

  
487 539
/**
......
493 545
apalExitStatus_t vl53l0x_lld_CheckRangingDataReady(VL53L0XDriver* vl53l0x, uint8_t *pMeasurementDataReady)
494 546
{
495 547
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
548
    apalExitStatus_t status_driver = APAL_STATUS_OK;
496 549

  
497 550
    uint8_t sysRangeStatusRegister;
498 551
    uint8_t interruptConfig;
......
518 571
        }
519 572
    }
520 573

  
574
    if(status != VL53L0X_ERROR_NONE)
575
    {
576
        print_pal_error(status);
577
        status_driver = APAL_STATUS_ERROR;
578
    }
579

  
580

  
521 581
    //LOG_FUNCTION_END(status);
522
    return status;
582
    return status_driver;
523 583
}
524 584

  
525 585
/**
......
531 591
apalExitStatus_t vl53l0x_lld_getRangingData(VL53L0XDriver* vl53l0x, VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
532 592
{
533 593
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
594
    apalExitStatus_t status_driver = APAL_STATUS_OK;
534 595
    status = VL53L0X_GetRangingMeasurementData(&(vl53l0x->vl53l0x_dev),
535 596
        pRangingMeasurementData);
536 597

  
537 598
    status |= VL53L0X_ClearInterruptMask(&(vl53l0x->vl53l0x_dev), 0);
538 599

  
539
    return status;
600
    if(status != VL53L0X_ERROR_NONE)
601
    {
602
        print_pal_error(status);
603
        status_driver = APAL_STATUS_ERROR;
604
    }
605

  
606
    return status_driver;
540 607
}
541 608

  
542 609

  
......
551 618
{
552 619

  
553 620
    VL53L0X_Error status = VL53L0X_ERROR_NONE;
621
    apalExitStatus_t status_driver = APAL_STATUS_OK;
554 622
    status = VL53L0X_SetDeviceAddress(&(vl53l0x->vl53l0x_dev), new_address );
555
    return status;
623
    if(status != VL53L0X_ERROR_NONE)
624
    {
625
        print_pal_error(status);
626
        status_driver = APAL_STATUS_ERROR;
627
    }
628

  
629
    return status_driver;
556 630
}
557 631

  
558 632

  
......
644 718
}
645 719

  
646 720

  
647
//#define VL53L0X_POLLINGDELAY_LOOPNB  250
648
//int32_t VL53L0X_PollingDelay(VL53L0X_DEV Dev){
649
//    int32_t status = VL53L0X_ERROR_NONE;
650
//    //LOG_FUNCTION_START("");
651

  
652
////    const DWORD cTimeout_ms = 1;
653
//    usleep(1000);
654

  
655
////    HANDLE hEvent = CreateEvent(0, TRUE, FALSE, 0);
656
////    if(hEvent != NULL)
657
////    {
658
////        WaitForSingleObject(hEvent,cTimeout_ms);
659
////    }
660

  
661
//    //LOG_FUNCTION_END(status);
662
//    return status;
663
//}
664

  
665 721

  
666 722
/*============================================================================*/
667 723
/* threshold register access                                                  */

Also available in: Unified diff