commit 3ed0cc4da52b1c40be56b3f32ea893e7e9e6d904
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Wed Jul 29 11:02:08 2020 +0200

    VL53L1X driver overhauled.

diff --git a/drivers/VL53L1X/v1/alld_VL53L1X.c b/drivers/VL53L1X/v1/alld_VL53L1X.c
index 54287d4..9c55f93 100644
--- a/drivers/VL53L1X/v1/alld_VL53L1X.c
+++ b/drivers/VL53L1X/v1/alld_VL53L1X.c
@@ -1,189 +1,710 @@
+/*
+AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
+Copyright (C) 2016..2019  Thomas Schöpping et al.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file    alld_VL53L1X.c
+ * @brief   ToF sensor function implementations.
+ *
+ * @addtogroup lld_vl53l1x
+ * @{
+ */
+
 #include <alld_VL53L1X.h>
-//#include "vl53l1_platform.h"
 #include <vl53l1_api.h>
-// #include "vl53l1_platform_log.h"
+#include <string.h>
 
+/******************************************************************************/
+/* LOCAL DEFINITIONS                                                          */
+/******************************************************************************/
 
-// #include "stm32xxx_hal.h"
-#include <string.h>
+/**
+ * @brief   I2C communication timeout (in microseconds).
+ * @details Cutsom values can be set via alldconf.h file.
+ */
+#if !defined(VL53L1X_LLD_I2C_TIMEOUT) || defined(__DOXYGEN__)
+# define VL53L1X_LLD_I2C_TIMEOUT               ((apalTime_t)1000)
+#endif
+
+/******************************************************************************/
+/* EXPORTED VARIABLES                                                         */
+/******************************************************************************/
+
+/******************************************************************************/
+/* LOCAL TYPES                                                                */
+/******************************************************************************/
+
+/******************************************************************************/
+/* LOCAL VARIABLES                                                            */
+/******************************************************************************/
+
+/******************************************************************************/
+/* LOCAL FUNCTIONS                                                            */
+/******************************************************************************/
+
+/******************************************************************************/
+/* EXPORTED FUNCTIONS                                                         */
+/******************************************************************************/
+
+/* interface functions for ST API *********************************************/
 
-apalExitStatus_t hello_world(void){
-    return APAL_STATUS_OK;
+/**
+ * @brief   Initialization of communication interface (I2C).
+ * @details Function not supported.
+ *          Initialization must be done by OS or application instead.
+ *
+ * @param[in] pdev              VL53L1X device handle.
+ * @param[in] comms_type        I2C speed class (?).
+ * @param[in] comms_speed_khz   I2C transmission frequency.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_CommsInitialise(VL53L1_Dev_t *pdev, uint8_t comms_type, uint16_t comms_speed_khz)
+{
+  apalDbgAssert(pdev != NULL);
+
+  (void)pdev;
+  (void)comms_type;
+  (void)comms_speed_khz;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
 /**
- * @brief Set the GPIO1 to a specific state.
- * @param[in]   ledp        The LED driver object.
- * @param[in]   led_state   The state to set the LED to.
- * @return                  An indicator whether the call was successful.
+ * @brief   Deinitialization of communication interface (I2C).
+ * @details Function not supported.
+ *          Deinitialization must be done by OS or application instead.
+ *
+ * @param[in] pdev  VL53L1X device handle.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
  */
-apalExitStatus_t vl53l1x_GPIO1_set(const VL53L1XDriver* const vlx, const gpio_lld_state_t state)
+VL53L1_Error VL53L1_CommsClose(VL53L1_Dev_t *pdev)
 {
-  apalDbgAssert(vlx != NULL);
-  
-  return apalControlGpioSet(vlx->xshut, (state == GPIO_LLD_STATE_ON) ? APAL_GPIO_ON : APAL_GPIO_OFF);
+  apalDbgAssert(pdev != NULL);
+
+  (void)pdev;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
+/**
+ * @brief   Transmit multiple bytes of data via I2C.
+ *
+ * @param[in] pdev    Device handle.
+ * @param[in] index   Register address to write to.
+ * @param[in] pdata   Data buffer to be transmitted.
+ * @param[in] count   Number of bytes to transmit.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
+ */
+VL53L1_Error VL53L1_WriteMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count)
+{
+  apalDbgAssert(pdev != NULL);
 
+  // prepare transmit buffer with prepended address bytes.
+  uint8_t txbuf[sizeof(uint16_t) + count];
+  txbuf[0] = index >> 8;
+  txbuf[1] = index & 0xFF;
+  memcpy(&txbuf[2], pdata, count);
 
+  // transmit address and data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
 
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
+}
 
+/**
+ * @brief   Read multiple bytes of data via I2C.
+ *
+ * @param[in]   pdev    Device handle.
+ * @param[in]   index   Register address to read from.
+ * @param[out]  pdata   Data buffer to store read data to.
+ * @param[in]   count   Number of bytes to read.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
+ */
+VL53L1_Error VL53L1_ReadMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count)
+{
+  apalDbgAssert(pdev != NULL);
 
+  // prepare address buffer
+  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
 
-// #define I2C_TIME_OUT_BASE   10
-// #define I2C_TIME_OUT_BYTE   1
+  // transmit address and recieve data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), pdata, count, VL53L1X_LLD_I2C_TIMEOUT);
 
-// #ifdef VL53L1_LOG_ENABLE
-// #define trace_print(level, ...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_PLATFORM, level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
-// #define trace_i2c(...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_NONE, VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__)
-// #endif
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
+}
 
-// #ifndef HAL_I2C_MODULE_ENABLED
-// #warning "HAL I2C module must be enable "
-// #endif
+/**
+ * @brief   Transmit a single byte via I2C.
+ *
+ * @param[in] pdev              Device handle.
+ * @param[in] index             Register address to write to.
+ * @param[in] VL53L1_PRM_00005  Byte to transmit.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
+ */
+VL53L1_Error VL53L1_WrByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t VL53L1_PRM_00005)
+{
+  apalDbgAssert(pdev != NULL);
+
+  // prepare transmit buffer with prepended address bytes.
+  uint8_t txbuf[sizeof(uint16_t) + sizeof(uint8_t)] = {index >> 8, index & 0xFF,
+                                                       VL53L1_PRM_00005};
 
-//extern I2C_HandleTypeDef hi2c1;
-//#define VL53L0X_pI2cHandle    (&hi2c1)
+  // transmit address and data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
 
-/* when not customized by application define dummy one */
-// #ifndef VL53L1_GetI2cBus
-/** This macro can be overloaded by user to enforce i2c sharing in RTOS context
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
+}
+
+/**
+ * @brief   Transmit a 16-bit data word via I2C.
+ *
+ * @param[in] pdev              Device handle.
+ * @param[in] index             Register address to write to.
+ * @param[in] VL53L1_PRM_00005  16-bit data word to transmit.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
  */
-// #   define VL53L1_GetI2cBus(...) (void)0
-// #endif
+VL53L1_Error VL53L1_WrWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t VL53L1_PRM_00005)
+{
+  apalDbgAssert(pdev != NULL);
+
+  // prepare transmit buffer with prepended address bytes.
+  uint8_t txbuf[sizeof(uint16_t) + sizeof(uint16_t)] = {index >> 8, index & 0xFF,
+                                                        (VL53L1_PRM_00005 >> 8) & 0xFF,
+                                                        (VL53L1_PRM_00005 >> 0) & 0xFF};
 
-// #ifndef VL53L1_PutI2cBus
-/** This macro can be overloaded by user to enforce i2c sharing in RTOS context
+  // transmit address and data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
+
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
+}
+
+/**
+ * @brief   Transmit a 32-bit data word via I2C.
+ *
+ * @param[in] pdev              Device handle.
+ * @param[in] index             Register address to write to.
+ * @param[in] VL53L1_PRM_00005  32-bit data word to transmit.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
  */
-// #   define VL53L1_PutI2cBus(...) (void)0
-// #endif
+VL53L1_Error VL53L1_WrDWord(VL53L1_Dev_t *pdev,uint16_t index, uint32_t VL53L1_PRM_00005)
+{
+  apalDbgAssert(pdev != NULL);
+
+  // prepare transmit buffer with prepended address bytes.
+  uint8_t txbuf[sizeof(uint16_t) + sizeof(uint32_t)] = {index >> 8, index & 0xFF,
+                                                        (VL53L1_PRM_00005 >> 24) & 0xFF,
+                                                        (VL53L1_PRM_00005 >> 16) & 0xFF,
+                                                        (VL53L1_PRM_00005 >> 8) & 0xFF,
+                                                        (VL53L1_PRM_00005 >> 0) & 0xFF};
 
-#define I2C_TIME_OUT_BASE   10
-#define I2C_TIME_OUT_BYTE   1
+  // transmit address and data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
 
-uint8_t _I2CBuffer[256] = { 0 };
-uint8_t rx_buf[256];
-uint8_t tx_buf[256];
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
+}
 
-int _I2CWrite(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) {
-    int status = 0;
-    int i2c_time_out = 1000 * (I2C_TIME_OUT_BASE + count * I2C_TIME_OUT_BYTE);
+/**
+ * @brief   Read a single byte via I2C.
+ *
+ * @param[in]   pdev    Device handle.
+ * @param[in]   index   Register address to read from.
+ * @param[out]  pdata   Single byte buffer to store the read data to.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
+ */
+VL53L1_Error VL53L1_RdByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata)
+{
+  apalDbgAssert(pdev != NULL);
 
-    apalExitStatus_t status2 = apalI2CMasterTransmit(Dev->vl53l1x.i2cd, Dev->vl53l1x.addr, pdata, count, rx_buf, 0, 100);
-    return status;
+  // prepare address buffer
+  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
+
+  // transmit address and recieve data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), pdata, 1, VL53L1X_LLD_I2C_TIMEOUT);
+
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
 }
 
-int _I2CRead(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) {
-   int status = 0;
-//   apalI2CMasterReceive(Dev->vl53l1x->i2cd, Dev->vl53l1x->addr, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout)
+/**
+ * @brief   Read a 16-bit data word via I2C.
+ *
+ * @param[in]   pdev    Device handle.
+ * @param[in]   index   Register address to read from.
+ * @param[out]  pdata   16-bit buffer to store the read data to.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
+ */
+VL53L1_Error VL53L1_RdWord(VL53L1_Dev_t *pdev,uint16_t index, uint16_t *pdata)
+{
+  apalDbgAssert(pdev != NULL);
+
+  // prepare address buffer
+  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
+  // prepare receive buffer
+  uint8_t rxbuf[sizeof(uint16_t)];
+
+  // transmit address and recieve data
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), VL53L1X_LLD_I2C_TIMEOUT);
+
+  // fill return value
+  *pdata = (((uint16_t)rxbuf[0]) << 8) &
+           (((uint16_t)rxbuf[1]) << 0);
 
-   return status;
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
 }
 
-// TODO: Needs to be defined
+/**
+ * @brief   Read a 32-bit data word via I2C.
+ *
+ * @param[in]   pdev    Device handle.
+ * @param[in]   index   Register address to read from.
+ * @param[out]  pdata   32-bit buffer to store the read data to.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Transmission was successful.
+ * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
+ * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
+ */
+VL53L1_Error VL53L1_RdDWord(VL53L1_Dev_t *pdev,uint16_t index, uint32_t *pdata)
+{
+  apalDbgAssert(pdev != NULL);
+
+  // prepare address buffer
+  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
+  // prepare receive buffer
+  uint8_t rxbuf[sizeof(uint32_t)];
 
-VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
+  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), VL53L1X_LLD_I2C_TIMEOUT);
 
-    return Status;
+  // fill return value
+  *pdata = (((uint32_t)rxbuf[0]) << 24) &
+           (((uint32_t)rxbuf[1]) << 16) &
+           (((uint32_t)rxbuf[2]) << 8) &
+           (((uint32_t)rxbuf[3]) << 0);
+
+  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
+         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
 }
 
-// the ranging_sensor_comms.dll will take care of the page selection
-VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    return Status;
+/**
+ * @brief   Wait for a specified amount of microseconds.
+ *
+ * @param[in] pdev      Device handle.
+ * @param[in] wait_us   Time to wait in microsecnonds.
+ *
+ * @return  Always returns VL53L1_ERROR_NONE.
+ */
+VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us)
+{
+  (void)pdev;
+
+  apalSleep(wait_us);
+
+  return VL53L1_ERROR_NONE;
 }
 
-VL53L1_Error VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    // printf("Starting to write byte: %X\n", data);
-     int32_t status_int;
+/**
+ * @brief   Wait for a specified amount of milliseconds.
+ *
+ * @param[in] pdev      Device handle.
+ * @param[in] wait_ms   Time to wait in milliseconds.
+ *
+ * @return  Always returns VL53L1_ERROR_NONE.
+ */
+VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms)
+{
+  (void)pdev;
 
-    _I2CBuffer[0] = index>>8;
-    _I2CBuffer[1] = index&0xFF;
-    _I2CBuffer[2] = data;
+  apalSleep(wait_ms * 1000);
 
-    _I2CWrite(Dev, _I2CBuffer, 3);
+  return VL53L1_ERROR_NONE;
+}
 
-    return Status;
+/**
+ * @brief   Retrieve the frequency of a timer?
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[out]  ptimer_freq_hz  Buffer to store the timer frequency to.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz)
+{
+  apalDbgAssert(ptimer_freq_hz != NULL);
+
+  (void)ptimer_freq_hz;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    return Status;
+/**
+ * @brief   Retrieve the current value of a timer?
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[out]  ptimer_count  Buffer to store the current timer value to.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GetTimerValue(int32_t *ptimer_count)
+{
+  apalDbgAssert(ptimer_count != NULL);
+
+  (void)ptimer_count;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    return Status;
+/**
+ * @brief   Set the mode for a GPIO.
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in] pin   GPIO pin to modify.
+ * @param[in] mode  Mode to set for the GPIO.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioSetMode(uint8_t pin, uint8_t mode)
+{
+  (void)pin;
+  (void)mode;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    return Status;
+/**
+ * @brief   Set the output value for a GPIO.
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in] pin     GPIO pin to set.
+ * @param[in] value   Value to set for the GPIO.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioSetValue(uint8_t pin, uint8_t value)
+{
+  (void)pin;
+  (void)value;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    
-    uint8_t indx[2] = { index >> 8, index & 0xFF };
-    apalExitStatus_t status2 = apalI2CMasterTransmit(Dev->vl53l1x.i2cd, Dev->vl53l1x.addr, indx, 2, data, 1, 0);
+/**
+ * @brief   Read the input value of a GPIO.
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in]   pin     GPIO pin to read.
+ * @param[out]  pvalue  Buffer to write the read value to.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioGetValue(uint8_t pin, uint8_t *pvalue)
+{
+  (void)pin;
+  (void)pvalue;
 
-    return Status;
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    return Status;
+/**
+ * @brief   Set to XSHUT GPIO.
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in] value   Value to set the XSHUT GPIO to.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioXshutdown(uint8_t value)
+{
+  (void)value;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data) {
-    VL53L1_Error Status = VL53L1_ERROR_NONE;
-    return Status;
+/**
+ * @brief   Select a GPIO communication interface?
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in] value   Identifier of the interface to select?
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioCommsSelect(uint8_t value)
+{
+  (void)value;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_GetTickCount(
-	uint32_t *ptick_count_ms)
+/**
+ * @brief   Enable power?
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in] value   ?
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioPowerEnable(uint8_t value)
 {
-	VL53L1_Error status  = VL53L1_ERROR_NONE;
-	return status;
+  (void)value;
+
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-//#define trace_print(level, ...) \
-//	_LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_PLATFORM, \
-//	level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+/**
+ * @brief   Enable GPIO interrupt.
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @param[in] fucntion    Callback function to be executed on interrupt.
+ * @param[in] edge_type   Signal edge to trigger an interrupts.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioInterruptEnable(void (*function)(void), uint8_t edge_type)
+{
+  (void)function;
+  (void)edge_type;
 
-//#define trace_i2c(...) \
-//	_LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NONE, \
-//	VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__)
+  return VL53L1_ERROR_NOT_SUPPORTED;
+}
 
-VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz)
+/**
+ * @brief   Disable GPIO interrupt.
+ * @details Function not supported since it is not used by the ST API.
+ * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
+ *
+ * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
+ */
+VL53L1_Error VL53L1_GpioInterruptDisable(void)
 {
-	VL53L1_Error status  = VL53L1_ERROR_NONE;
-	return status;
+  return VL53L1_ERROR_NOT_SUPPORTED;
 }
 
-VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms){
-	VL53L1_Error status  = VL53L1_ERROR_NONE;
-	return status;
+/**
+ * @brief   Retrieve the current system tick count.
+ *
+ * @param[out]  ptime_ms  Buffer to store the current system tick count to.
+ *
+ * @return  Always returns VL53L1_ERROR_NONE.
+ */
+VL53L1_Error VL53L1_GetTickCount(uint32_t *ptime_ms)
+{
+  *ptime_ms = apalGetTime() / 1000;
+
+  return VL53L1_ERROR_NONE;
 }
 
-VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us){
-	VL53L1_Error status  = VL53L1_ERROR_NONE;
-	return status;
+/**
+ * @brief   Wait for a specific register to match a (masked) value.
+ *
+ * @param[in] pdev            Device handle.
+ * @param[in] timeout_ms      Timeout value in milliseconds.
+ * @param[in] index           Register address to check.
+ * @param[in] value           Value to be matched.
+ * @param[in] mask            Mask to apply to the register value.
+ *                            Must not be 0x00.
+ * @param[in] poll_delay_ms   Poll delay in milliseconds.
+ *
+ * @return  Status indicating whether the call was successful.
+ * @retval  VL53L1_ERROR_NONE       Value matched before timeout.
+ * @retval  VL53L1_ERROR_TIME_OUT   Value did not match before timeout occurred.
+ * @retval  VL53L1_ERROR_UNDEFINED  I2C communication failed.
+ */
+VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms)
+{
+  apalDbgAssert(pdev != NULL);
+  apalDbgAssert(mask != 0x00);
+
+  // local variables
+  const apalTime_t starttime = apalGetTime();
+  apalTime_t transmissionstartoffset, transmissionendoffset;
+  apalTime_t remaintime = timeout_ms * 1000;
+  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
+  uint8_t rxbuf[sizeof(uint8_t)];
+
+  // infinite loop will return from within
+  for(;;) {
+    // measure time before transmission
+    transmissionstartoffset = apalGetTime() - starttime;
+
+    // try transmission
+    if (apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), (remaintime < VL53L1X_LLD_I2C_TIMEOUT) ? remaintime : VL53L1X_LLD_I2C_TIMEOUT) < 0) {
+      return VL53L1_ERROR_UNDEFINED;
+    }
+
+    // check returned data
+    if ((rxbuf[0] & mask) == value) {
+      return VL53L1_ERROR_NONE;
+    }
+
+    // measure time after transmission
+    transmissionendoffset = apalGetTime() - starttime;
+
+    // check for timeout and recalculate remaining time
+    if (transmissionendoffset < timeout_ms * 1000) {
+      remaintime = (timeout_ms * 1000) - transmissionendoffset;
+    } else {
+      return VL53L1_ERROR_TIME_OUT;
+    }
+
+    // sleep one poll delay, or the remaining time
+    if (remaintime > (poll_delay_ms * 1000) - (transmissionendoffset - transmissionstartoffset)) {
+      apalSleep((poll_delay_ms * 1000) - (transmissionendoffset - transmissionstartoffset));
+    } else {
+      apalSleep(remaintime);
+      return VL53L1_ERROR_TIME_OUT;
+    }
+
+    // recalculate remaining time
+    remaintime = apalGetTime() - starttime;
+    if (remaintime < timeout_ms * 1000) {
+      remaintime = (timeout_ms * 1000) - remaintime;
+    } else {
+      return VL53L1_ERROR_TIME_OUT;
+    }
+  }
 }
 
-VL53L1_Error VL53L1_WaitValueMaskEx(
-	VL53L1_Dev_t *pdev,
-	uint32_t      timeout_ms,
-	uint16_t      index,
-	uint8_t       value,
-	uint8_t       mask,
-	uint32_t      poll_delay_ms)
+/* driver functions ***********************************************************/
+
+/**
+ * @brief   Read the current activation state of the device.
+ *
+ * @param[in]   vl53l1x   Driver object to check.
+ * @param[out]  state     State of the device.
+ *
+ * @return  Indicator whether the call was successful.
+ */
+apalExitStatus_t vl53l1x_lld_getState(VL53L1XDriver* vl53l1x, vl53l1x_lld_state_t* state)
 {
-	VL53L1_Error status  = VL53L1_ERROR_NONE;
-	return status;
+  apalDbgAssert(vl53l1x != NULL);
+  apalDbgAssert(state != NULL);
+
+  apalControlGpioState_t gpio_state;
+  apalExitStatus_t status = apalControlGpioGet(vl53l1x->Interface.xshut, &gpio_state);
+  *state = gpio_state == APAL_GPIO_ON ? VL53L1X_LLD_STATE_ON : VL53L1X_LLD_STATE_OFF;
+
+  return status;
 }
 
+/**
+ * @brief   Performs initialization procedure according to manual after device
+ *          brought out of reset.
+ *
+ * @param[in,out] vl53l1x   Device to be initialized.
+ *
+ * @return  Indicator whether the call was successful.
+ */
+apalExitStatus_t vl53l1x_lld_init(VL53L1XDriver* vl53l1x)
+{
+  apalDbgAssert(vl53l1x != NULL);
+
+  // local variables
+  apalExitStatus_t status;
+  VL53L1_Error errval;
+
+  // check whether the device is already active
+  {
+    vl53l1x_lld_state_t xshut_state;
+    status = vl53l1x_lld_getState(vl53l1x, &xshut_state);
+    if (status != APAL_STATUS_OK) {
+      return APAL_STATUS_ERROR;
+    }
+    // return warning if the device is already active
+    if (xshut_state == VL53L1X_LLD_STATE_ON) {
+      return APAL_STATUS_WARNING;
+    }
+  }
+
+  // activate the device
+  apalDbgPrintf("apalControlGpioSet()\n");
+  status |= apalControlGpioSet(vl53l1x->Interface.xshut, APAL_GPIO_ON);
+  apalDbgPrintf("\tstatus: %d\n", status);
+
+  // initialize device as described in manual
+  apalDbgPrintf("VL53L1_WaitDeviceBooted()\n");
+  errval = VL53L1_WaitDeviceBooted(vl53l1x);
+  status |= (errval == VL53L1_ERROR_NONE) ? APAL_STATUS_SUCCESS : APAL_STATUS_ERROR;
+  apalDbgPrintf("\tstatus: %d\terrval: %d\n", status, errval);
+  apalDbgPrintf("VL53L1_DataInit()\n");
+  errval = VL53L1_DataInit(vl53l1x);
+  status |= (errval == VL53L1_ERROR_NONE) ? APAL_STATUS_SUCCESS : APAL_STATUS_ERROR;
+  apalDbgPrintf("\tstatus: %d\terrval: %d\n", status, errval);
+  apalDbgPrintf("VL53L1_StaticInit()\n");
+  errval = VL53L1_StaticInit(vl53l1x);
+  status |= (errval == VL53L1_ERROR_NONE) ? APAL_STATUS_SUCCESS : APAL_STATUS_ERROR;
+  apalDbgPrintf("\tstatus: %d\terrval: %d\n", status, errval);
+
+  return status;
+}
 
+/**
+ * @brief   Reset a device by deactivating the XSHUT signal.
+ *
+ * @param[in] vl53l1x   Device to reset.
+ *
+ * @return  Indicator whether the call was successful.
+ */
+apalExitStatus_t vl53l1x_lld_reset(VL53L1XDriver* vl53l1x)
+{
+  return apalControlGpioSet(vl53l1x->Interface.xshut, APAL_GPIO_OFF);
+}
 
+/** @} */
