commit c368a7653aea662f10bd6661493f26b162f0a821
Author: Andre Raming <araming@techfak.uni-bielefeld.de>
Date:   Mon Apr 29 15:28:09 2019 +0200

    added changes

diff --git a/include/VL53L0X/v1/Api_vl53l0x/core/inc/vl53l0x_api.h b/include/VL53L0X/v1/Api_vl53l0x/core/inc/vl53l0x_api.h
index 03f34a9..83e3712 100644
--- a/include/VL53L0X/v1/Api_vl53l0x/core/inc/vl53l0x_api.h
+++ b/include/VL53L0X/v1/Api_vl53l0x/core/inc/vl53l0x_api.h
@@ -55,8 +55,6 @@ extern "C"
 
 
 
-#define USE_I2C_2V8
-
 /** @defgroup VL53L0X_cut11_group VL53L0X cut1.1 Function Definition
  *  @brief    VL53L0X cut1.1 Function Definition
  *  @{
diff --git a/include/VL53L0X/v1/Api_vl53l0x/platform/inc/vl53l0x_platform.h b/include/VL53L0X/v1/Api_vl53l0x/platform/inc/vl53l0x_platform.h
index e60b027..9a420ed 100644
--- a/include/VL53L0X/v1/Api_vl53l0x/platform/inc/vl53l0x_platform.h
+++ b/include/VL53L0X/v1/Api_vl53l0x/platform/inc/vl53l0x_platform.h
@@ -68,7 +68,7 @@ typedef struct {
     VL53L0X_DevData_t Data;               /*!< embed ST Ewok Dev  data as "Data"*/
 
     /*!< user specific field */
-    uint16_t   I2cDevAddr;                /*!< i2c device address user specific field */
+    uint16_t  I2cDevAddr;                /*!< i2c device address user specific field */
     uint8_t   comms_type;                /*!< Type of comms : VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI */
     uint16_t  comms_speed_khz;           /*!< Comms speed [kHz] : typically 400kHz for I2C           */
 
diff --git a/source/VL53L0X/v1/alld_VL53L0X_v1.c b/source/VL53L0X/v1/alld_VL53L0X_v1.c
index 871934d..1a142eb 100644
--- a/source/VL53L0X/v1/alld_VL53L0X_v1.c
+++ b/source/VL53L0X/v1/alld_VL53L0X_v1.c
@@ -55,17 +55,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* LOCAL FUNCTIONS                                                            */
 /******************************************************************************/
 
-/******************************************************************************/
-/* EXPORTED FUNCTIONS                                                         */
-/******************************************************************************/
-
-/* general single register access */
-
-
 void print_pal_error(VL53L0X_Error Status){
     char buf[VL53L0X_MAX_STRING_LENGTH];
     VL53L0X_GetPalErrorString(Status, buf);
-    chprintf((BaseSequentialStream*)&SD1,"\t\tAPI Status: %i : %s\n", Status, buf);
+    apalDbgPrintf("\t\tAPI Status: %i : %s\n", Status, buf);
 }
 
 
@@ -81,16 +74,26 @@ void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementDat
     RangeStatus = pRangingMeasurementData->RangeStatus;
 
     VL53L0X_GetRangeStatusString(RangeStatus, buf);
-    chprintf((BaseSequentialStream*)&SD1,"Range Status: %i : %s\n", RangeStatus, buf);
+    apalDbgPrintf("Range Status: %i : %s\n", RangeStatus, buf);
 
 }
 
 
+/******************************************************************************/
+/* EXPORTED FUNCTIONS                                                         */
+/******************************************************************************/
+
+/* general single register access */
+
+
+
+
+
 /**
  * @brief vl53l0x_lld_init useses the Vl53L0X functions so init the sensor. This function are VL53L0X_DataInit (performs the device initialization)
  * and VL53L0X_StaticInit (allows to load device settings specific for a given use case). These two function need 40 ms to perform.
  *
- * @param[in] vl53l0x
+ * @param[in] vl53l0x driver with i2cadress, vl53l0x_data and more.
  * @return
  */
 
@@ -99,16 +102,20 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
 {
 
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
 
     VL53L0X_DeviceInfo_t DeviceInfo;
 
 
     if(status == VL53L0X_ERROR_NONE)
         {
-            chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_DataInit\n");
+            apalDbgPrintf("Call of VL53L0X_DataInit\n");
             status = VL53L0X_DataInit(&(vl53l0x->vl53l0x_dev)); // Data initialization
+
             print_pal_error(status);
-        }
+        }else{
+        status_driver = APAL_STATUS_ERROR;
+    }
 
 
     if(status == VL53L0X_ERROR_NONE)
@@ -116,20 +123,22 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
            status = VL53L0X_GetDeviceInfo(&(vl53l0x->vl53l0x_dev), &DeviceInfo);
            if(status == VL53L0X_ERROR_NONE)
            {
-               chprintf((BaseSequentialStream*)&SD1,"VL53L0X_GetDeviceInfo:\n");
-               chprintf((BaseSequentialStream*)&SD1,"\tDevice Name : %s\n", DeviceInfo.Name);
-               chprintf((BaseSequentialStream*)&SD1,"\tDevice Type : %s\n", DeviceInfo.Type);
-               chprintf((BaseSequentialStream*)&SD1,"\tDevice ID : %s\n", DeviceInfo.ProductId);
-               chprintf((BaseSequentialStream*)&SD1,"\tProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
-           chprintf((BaseSequentialStream*)&SD1,"\tProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
+               apalDbgPrintf("VL53L0X_GetDeviceInfo:\n");
+               apalDbgPrintf("\tDevice Name : %s\n", DeviceInfo.Name);
+               apalDbgPrintf("\tDevice Type : %s\n", DeviceInfo.Type);
+               apalDbgPrintf("\tDevice ID : %s\n", DeviceInfo.ProductId);
+               apalDbgPrintf("\tProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
+           apalDbgPrintf("\tProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
 
            if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) {
-               chprintf((BaseSequentialStream*)&SD1,"Error expected cut 1.1 but found cut %d.%d\n",
+               apalDbgPrintf("Error expected cut 1.1 but found cut %d.%d\n",
                           DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor);
                    status = VL53L0X_ERROR_NOT_SUPPORTED;
                }
            }
            print_pal_error(status);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
@@ -141,9 +150,11 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
 
     if(status == VL53L0X_ERROR_NONE)
     {
-        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_StaticInit\n");
+        apalDbgPrintf("Call of VL53L0X_StaticInit\n");
         status = VL53L0X_StaticInit(&(vl53l0x->vl53l0x_dev)); // Device Initialization
        print_pal_error(status);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
@@ -163,16 +174,19 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
     {
         // only test
        status = VL53L0X_GetReferenceSpads(&(vl53l0x->vl53l0x_dev), &refSpadCount, &isApertureSpads);
-       chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_GetReferenceSpads with refSpadCount:%lu and isApertureSpads:%u \n", refSpadCount, isApertureSpads);
+       apalDbgPrintf("Call of VL53L0X_GetReferenceSpads with refSpadCount:%lu and isApertureSpads:%u \n", refSpadCount, isApertureSpads);
 
-        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_PerformRefSpadManagement\n");
+        apalDbgPrintf("Call of VL53L0X_PerformRefSpadManagement\n");
         status |= VL53L0X_PerformRefSpadManagement(&(vl53l0x->vl53l0x_dev),
                 &refSpadCount, &isApertureSpads); // Device Initialization
-        chprintf((BaseSequentialStream*)&SD1,"\trefSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
+        apalDbgPrintf("\trefSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
         print_pal_error(status);
         if(status == -6){
+            status_driver = APAL_STATUS_ERROR;
             status  = VL53L0X_ERROR_NONE;
         }
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
@@ -183,13 +197,16 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
     // if the user has previously performed a calibration and stored the two parameters in the Host memory we can use VL53L0X_SetRefCalibration
     if(status == VL53L0X_ERROR_NONE)
     {
-        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_PerformRefCalibration\n");
+        apalDbgPrintf("Call of VL53L0X_PerformRefCalibration\n");
         status = VL53L0X_PerformRefCalibration(&(vl53l0x->vl53l0x_dev),
                 &VhvSettings, &PhaseCal); // Device Initialization
         print_pal_error(status);
         if(status == -6){
             status  = VL53L0X_ERROR_NONE;
+            status_driver = APAL_STATUS_ERROR;
         }
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
@@ -208,12 +225,16 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
     if (status == VL53L0X_ERROR_NONE) {
         status = VL53L0X_SetLimitCheckEnable(&(vl53l0x->vl53l0x_dev),
                 VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
     // why are no values seet?? with VL53L0X_SetLimitCheckValue
     if (status == VL53L0X_ERROR_NONE) {
         status = VL53L0X_SetLimitCheckEnable(&(vl53l0x->vl53l0x_dev),
                 VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
@@ -223,24 +244,28 @@ apalExitStatus_t vl53l0x_lld_init(VL53L0XDriver* vl53l0x)
     if (status == VL53L0X_ERROR_NONE) {
         status = VL53L0X_SetLimitCheckEnable(&(vl53l0x->vl53l0x_dev),
                 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
     if (status == VL53L0X_ERROR_NONE) {
         status = VL53L0X_SetLimitCheckValue(&(vl53l0x->vl53l0x_dev),
                 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
                 (FixPoint1616_t)(1.5*0.023*65536));
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
     /* end static init and some tests */
 
 
-    return status;
+    return status_driver;
 
 
 }
 
 
 /**
- * @brief vl53l0x_lld_set_mode set one of the thre possible modes.
+ * @brief vl53l0x_lld_set_mode set one of the thre possible modes. Same as VL53L0X_SetDeviceMode and VL53L0X_SetGpioConfig.
  * @param vl53l0x[in]
  * @param mode[in] one of the VL53L0X_DeviceModes, VL53L0X_DEVICEMODE_SINGLE_RANGING == 0, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING == 1,
  *                  VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING == 3
@@ -259,23 +284,28 @@ apalExitStatus_t vl53l0x_lld_set_mode(VL53L0XDriver* vl53l0x, VL53L0X_DeviceMode
     uint32_t ThresholdLow;
     uint32_t ThresholdHigh;
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
 
     if(status == VL53L0X_ERROR_NONE)
     {
 
         // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
-        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_SetDeviceMode\n");
+        apalDbgPrintf("Call of VL53L0X_SetDeviceMode\n");
         status = VL53L0X_SetDeviceMode(&(vl53l0x->vl53l0x_dev), mode); // Setup in single ranging mode
         print_pal_error(status);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
     if(status == VL53L0X_ERROR_NONE)
     {
         // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
-        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_SetGpioConfig\n");
-        status = VL53L0X_SetGpioConfig(&(vl53l0x->vl53l0x_dev), 0, mode, interrupt, VL53L0X_INTERRUPTPOLARITY_LOW);
+        apalDbgPrintf("Call of VL53L0X_SetGpioConfig\n");
+        status = VL53L0X_SetGpioConfig(&(vl53l0x->vl53l0x_dev), 0, mode, interrupt, VL53L0X_INTERRUPTPOLARITY_HIGH);
         print_pal_error(status);
+    }else{
+        status_driver = APAL_STATUS_ERROR;
     }
 
 
@@ -285,7 +315,7 @@ apalExitStatus_t vl53l0x_lld_set_mode(VL53L0XDriver* vl53l0x, VL53L0X_DeviceMode
         // multiplication with 65536 is imported, no clue why!
         // 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!
         if(mode == VL53L0X_DEVICEMODE_SINGLE_RANGING && (low > 254 || high > 254)){
-            chprintf((BaseSequentialStream*)&SD1,"Device mode is VL53L0X_DEVICEMODE_SINGLE_RANGING and therefore we get no Interrupt if the interrupt "
+            apalDbgPrintf("Device mode is VL53L0X_DEVICEMODE_SINGLE_RANGING and therefore we get no Interrupt if the interrupt "
                                                  "threshold is bigger than 254 mm\n");
         }
 
@@ -295,12 +325,16 @@ apalExitStatus_t vl53l0x_lld_set_mode(VL53L0XDriver* vl53l0x, VL53L0X_DeviceMode
 
 
         // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
-        chprintf((BaseSequentialStream*)&SD1,"Call of VL53L0X_SetInterruptThresholds\n");
+        apalDbgPrintf("Call of VL53L0X_SetInterruptThresholds\n");
         status = VL53L0X_SetInterruptThresholds(&(vl53l0x->vl53l0x_dev),interrupt,ThresholdLow ,ThresholdHigh);
         print_pal_error(status);
+        if(status != VL53L0X_ERROR_NONE)
+        {
+            status_driver = APAL_STATUS_ERROR;
+        }
     }
 
-    return status;
+    return status_driver;
 
 
 
@@ -413,31 +447,44 @@ apalExitStatus_t vl53l0x_lld_set_mode(VL53L0XDriver* vl53l0x, VL53L0X_DeviceMode
 apalExitStatus_t vl53l0x_lld_start_measurement(VL53L0XDriver* vl53l0x)
 {
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
     status = VL53L0X_StartMeasurement(&(vl53l0x->vl53l0x_dev));
 
     if(status == VL53L0X_ERROR_NONE)
     {
         // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
-        chprintf((BaseSequentialStream*)&SD1,"Successful startet measurement\n");
+        apalDbgPrintf("Successful startet measurement\n");
         print_pal_error(status);
     }else{
-        chprintf((BaseSequentialStream*)&SD1,"Error in startet measurement\n");
+        apalDbgPrintf("Error in startet measurement\n");
         print_pal_error(status);
+        status_driver = APAL_STATUS_ERROR;
     }
 
-    return status;
+    return status_driver;
 
 }
 
 
 
+/**
+ * @brief vl53l0x_lld_stop_measurement, stops a measurement when the measurement were started with vl53l0x_lld_start_measurement
+ * @param vl53l0x[in]
+ * @return
+ */
 apalExitStatus_t vl53l0x_lld_stop_measurement(VL53L0XDriver* vl53l0x)
 {
 
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
     status = VL53L0X_StopMeasurement(&(vl53l0x->vl53l0x_dev));
+    if(status != VL53L0X_ERROR_NONE)
+    {
+        print_pal_error(status);
+        status_driver = APAL_STATUS_ERROR;
+    }
 
-    return status;
+    return status_driver;
 }
 
 /**
@@ -461,27 +508,32 @@ apalExitStatus_t vl53l0x_lld_perform_mesaurement(VL53L0XDriver* vl53l0x, uint16_
     VL53L0X_RangingMeasurementData_t    RangingMeasurementData;
     VL53L0X_RangingMeasurementData_t   *pRangingMeasurementData    = &RangingMeasurementData;
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
 
     status = VL53L0X_PerformSingleMeasurement(&(vl53l0x->vl53l0x_dev));
 
     if (status == VL53L0X_ERROR_NONE)
         status = VL53L0X_GetRangingMeasurementData(&(vl53l0x->vl53l0x_dev),
             pRangingMeasurementData);
+    else
+        status_driver = APAL_STATUS_ERROR;
 
 
     if (status == VL53L0X_ERROR_NONE)
         status = VL53L0X_ClearInterruptMask(&(vl53l0x->vl53l0x_dev), 0);
+    else
+        status_driver = APAL_STATUS_ERROR;
 
 
 
     data[0] = RangingMeasurementData.RangeMilliMeter;
-    //chprintf((BaseSequentialStream*)&SD1, "Measured distance: %i\n\n", RangingMeasurementData.RangeMilliMeter);
+    //apalDbgPrintf( "Measured distance: %i\n\n", RangingMeasurementData.RangeMilliMeter);
 
 
     //TODO write millimeter to data
     //data = &RangingMeasurementData.RangeMilliMeter;
 
-    return status;
+    return status_driver;
 }
 
 /**
@@ -493,6 +545,7 @@ apalExitStatus_t vl53l0x_lld_perform_mesaurement(VL53L0XDriver* vl53l0x, uint16_
 apalExitStatus_t vl53l0x_lld_CheckRangingDataReady(VL53L0XDriver* vl53l0x, uint8_t *pMeasurementDataReady)
 {
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
 
     uint8_t sysRangeStatusRegister;
     uint8_t interruptConfig;
@@ -518,8 +571,15 @@ apalExitStatus_t vl53l0x_lld_CheckRangingDataReady(VL53L0XDriver* vl53l0x, uint8
         }
     }
 
+    if(status != VL53L0X_ERROR_NONE)
+    {
+        print_pal_error(status);
+        status_driver = APAL_STATUS_ERROR;
+    }
+
+
     //LOG_FUNCTION_END(status);
-    return status;
+    return status_driver;
 }
 
 /**
@@ -531,12 +591,19 @@ apalExitStatus_t vl53l0x_lld_CheckRangingDataReady(VL53L0XDriver* vl53l0x, uint8
 apalExitStatus_t vl53l0x_lld_getRangingData(VL53L0XDriver* vl53l0x, VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
 {
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
     status = VL53L0X_GetRangingMeasurementData(&(vl53l0x->vl53l0x_dev),
         pRangingMeasurementData);
 
     status |= VL53L0X_ClearInterruptMask(&(vl53l0x->vl53l0x_dev), 0);
 
-    return status;
+    if(status != VL53L0X_ERROR_NONE)
+    {
+        print_pal_error(status);
+        status_driver = APAL_STATUS_ERROR;
+    }
+
+    return status_driver;
 }
 
 
@@ -551,8 +618,15 @@ apalExitStatus_t vl53l0x_lld_set_address(VL53L0XDriver* vl53l0x, uint8_t new_add
 {
 
     VL53L0X_Error status = VL53L0X_ERROR_NONE;
+    apalExitStatus_t status_driver = APAL_STATUS_OK;
     status = VL53L0X_SetDeviceAddress(&(vl53l0x->vl53l0x_dev), new_address );
-    return status;
+    if(status != VL53L0X_ERROR_NONE)
+    {
+        print_pal_error(status);
+        status_driver = APAL_STATUS_ERROR;
+    }
+
+    return status_driver;
 }
 
 
@@ -644,24 +718,6 @@ VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev) {
 }
 
 
-//#define VL53L0X_POLLINGDELAY_LOOPNB  250
-//int32_t VL53L0X_PollingDelay(VL53L0X_DEV Dev){
-//    int32_t status = VL53L0X_ERROR_NONE;
-//    //LOG_FUNCTION_START("");
-
-////    const DWORD cTimeout_ms = 1;
-//    usleep(1000);
-
-////    HANDLE hEvent = CreateEvent(0, TRUE, FALSE, 0);
-////    if(hEvent != NULL)
-////    {
-////        WaitForSingleObject(hEvent,cTimeout_ms);
-////    }
-
-//    //LOG_FUNCTION_END(status);
-//    return status;
-//}
-
 
 /*============================================================================*/
 /* threshold register access                                                  */
