IoT-MBBR (masterthesis)
Masterthesis upgrading a Moving Bed BioReactor with extra sensors and cloud connectivity.
VL53L1X_api.c File Reference
#include "VL53L1X_api.h"
#include <string.h>

Go to the source code of this file.

Functions

VL53L1X_ERROR VL53L1X_GetSWVersion (VL53L1X_Version_t *pVersion)
 This function returns the SW driver version. More...
 
VL53L1X_ERROR VL53L1X_SetI2CAddress (uint16_t dev, uint8_t new_address)
 This function sets the sensor I2C address used in case multiple devices application, default address 0x52. More...
 
VL53L1X_ERROR VL53L1X_SensorInit (uint16_t dev)
 This function loads the 135 bytes default values to initialize the sensor. More...
 
VL53L1X_ERROR VL53L1X_ClearInterrupt (uint16_t dev)
 This function clears the interrupt, to be called after a ranging data reading to arm the interrupt for the next data ready event. More...
 
VL53L1X_ERROR VL53L1X_SetInterruptPolarity (uint16_t dev, uint8_t NewPolarity)
 This function programs the interrupt polarity
1=active high (default), 0=active low. More...
 
VL53L1X_ERROR VL53L1X_GetInterruptPolarity (uint16_t dev, uint8_t *pInterruptPolarity)
 This function returns the current interrupt polarity
1=active high (default), 0=active low. More...
 
VL53L1X_ERROR VL53L1X_StartRanging (uint16_t dev)
 This function starts the ranging distance operation
The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready
1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required. More...
 
VL53L1X_ERROR VL53L1X_StopRanging (uint16_t dev)
 This function stops the ranging. More...
 
VL53L1X_ERROR VL53L1X_CheckForDataReady (uint16_t dev, uint8_t *isDataReady)
 This function checks if the new ranging data is available by polling the dedicated register. More...
 
VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs (uint16_t dev, uint16_t TimingBudgetInMs)
 This function programs the timing budget in ms. Predefined values = 15, 20, 33, 50, 100(default), 200, 500. More...
 
VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs (uint16_t dev, uint16_t *pTimingBudget)
 This function returns the current timing budget in ms. More...
 
VL53L1X_ERROR VL53L1X_SetDistanceMode (uint16_t dev, uint16_t DM)
 This function programs the distance mode (1=short, 2=long(default)). Short mode max distance is limited to 1.3 m but better ambient immunity.
Long mode can range up to 4 m in the dark with 200 ms timing budget. More...
 
VL53L1X_ERROR VL53L1X_GetDistanceMode (uint16_t dev, uint16_t *DM)
 This function returns the current distance mode (1=short, 2=long). More...
 
VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs (uint16_t dev, uint32_t InterMeasMs)
 This function programs the Intermeasurement period in ms
Intermeasurement period must be >/= timing budget. This condition is not checked by the API, the customer has the duty to check the condition. Default = 100 ms. More...
 
VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs (uint16_t dev, uint16_t *pIM)
 This function returns the Intermeasurement period in ms. More...
 
VL53L1X_ERROR VL53L1X_BootState (uint16_t dev, uint8_t *state)
 This function returns the boot state of the device (1:booted, 0:not booted) More...
 
VL53L1X_ERROR VL53L1X_GetSensorId (uint16_t dev, uint16_t *sensorId)
 This function returns the sensor id, sensor Id must be 0xEEAC. More...
 
VL53L1X_ERROR VL53L1X_GetDistance (uint16_t dev, uint16_t *distance)
 This function returns the distance measured by the sensor in mm. More...
 
VL53L1X_ERROR VL53L1X_GetSignalPerSpad (uint16_t dev, uint16_t *signalRate)
 This function returns the returned signal per SPAD in kcps/SPAD. With kcps stands for Kilo Count Per Second. More...
 
VL53L1X_ERROR VL53L1X_GetAmbientPerSpad (uint16_t dev, uint16_t *ambPerSp)
 This function returns the ambient per SPAD in kcps/SPAD. More...
 
VL53L1X_ERROR VL53L1X_GetSignalRate (uint16_t dev, uint16_t *signal)
 This function returns the returned signal in kcps. More...
 
VL53L1X_ERROR VL53L1X_GetSpadNb (uint16_t dev, uint16_t *spNb)
 This function returns the current number of enabled SPADs. More...
 
VL53L1X_ERROR VL53L1X_GetAmbientRate (uint16_t dev, uint16_t *ambRate)
 This function returns the ambient rate in kcps. More...
 
VL53L1X_ERROR VL53L1X_GetRangeStatus (uint16_t dev, uint8_t *rangeStatus)
 This function returns the ranging status error
(0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around) More...
 
VL53L1X_ERROR VL53L1X_GetResult (uint16_t dev, VL53L1X_Result_t *pResult)
 This function returns measurements and the range status in a single read access. More...
 
VL53L1X_ERROR VL53L1X_SetOffset (uint16_t dev, int16_t OffsetValue)
 This function programs the offset correction in mm. More...
 
VL53L1X_ERROR VL53L1X_GetOffset (uint16_t dev, int16_t *offset)
 This function returns the programmed offset correction value in mm. More...
 
VL53L1X_ERROR VL53L1X_SetXtalk (uint16_t dev, uint16_t XtalkValue)
 This function programs the xtalk correction value in cps (Count Per Second).
This is the number of photons reflected back from the cover glass in cps. More...
 
VL53L1X_ERROR VL53L1X_GetXtalk (uint16_t dev, uint16_t *xtalk)
 This function returns the current programmed xtalk correction value in cps. More...
 
VL53L1X_ERROR VL53L1X_SetDistanceThreshold (uint16_t dev, uint16_t ThreshLow, uint16_t ThreshHigh, uint8_t Window, uint8_t IntOnNoTarget)
 This function programs the threshold detection mode
Example:
VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100
VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300
VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window
VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window
. More...
 
VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow (uint16_t dev, uint16_t *window)
 This function returns the window detection mode (0=below; 1=above; 2=out; 3=in) More...
 
VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow (uint16_t dev, uint16_t *low)
 This function returns the low threshold in mm. More...
 
VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh (uint16_t dev, uint16_t *high)
 This function returns the high threshold in mm. More...
 
VL53L1X_ERROR VL53L1X_SetROICenter (uint16_t dev, uint8_t ROICenter)
 This function programs the new user ROI center, please to be aware that there is no check in this function. if the ROI center vs ROI size is out of border the ranging function return error #13. More...
 
VL53L1X_ERROR VL53L1X_GetROICenter (uint16_t dev, uint8_t *ROICenter)
 This function returns the current user ROI center. More...
 
VL53L1X_ERROR VL53L1X_SetROI (uint16_t dev, uint16_t X, uint16_t Y)
 This function programs the ROI (Region of Interest)
The ROI position is centered, only the ROI size can be reprogrammed.
The smallest acceptable ROI size = 4
. More...
 
VL53L1X_ERROR VL53L1X_GetROI_XY (uint16_t dev, uint16_t *ROI_X, uint16_t *ROI_Y)
 This function returns width X and height Y. More...
 
VL53L1X_ERROR VL53L1X_SetSignalThreshold (uint16_t dev, uint16_t Signal)
 This function programs a new signal threshold in kcps (default=1024 kcps
. More...
 
VL53L1X_ERROR VL53L1X_GetSignalThreshold (uint16_t dev, uint16_t *signal)
 This function returns the current signal threshold in kcps. More...
 
VL53L1X_ERROR VL53L1X_SetSigmaThreshold (uint16_t dev, uint16_t Sigma)
 This function programs a new sigma threshold in mm (default=15 mm) More...
 
VL53L1X_ERROR VL53L1X_GetSigmaThreshold (uint16_t dev, uint16_t *sigma)
 This function returns the current sigma threshold in mm. More...
 
VL53L1X_ERROR VL53L1X_StartTemperatureUpdate (uint16_t dev)
 This function performs the temperature calibration. It is recommended to call this function any time the temperature might have changed by more than 8 deg C without sensor ranging activity for an extended period. More...
 

Variables

const uint8_t VL51L1X_DEFAULT_CONFIGURATION []
 
static const uint8_t status_rtn [24]
 

Function Documentation

◆ VL53L1X_BootState()

VL53L1X_ERROR VL53L1X_BootState ( uint16_t  dev,
uint8_t *  state 
)

This function returns the boot state of the device (1:booted, 0:not booted)

Definition at line 526 of file VL53L1X_api.c.

527 {
528  VL53L1X_ERROR status = 0;
529  uint8_t tmp = 0;
530 
531  status = VL53L1_RdByte(dev,VL53L1_FIRMWARE__SYSTEM_STATUS, &tmp);
532  *state = tmp;
533  return status;
534 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_FIRMWARE__SYSTEM_STATUS
Definition: VL53L1X_api.h:118
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_CheckForDataReady()

VL53L1X_ERROR VL53L1X_CheckForDataReady ( uint16_t  dev,
uint8_t *  isDataReady 
)

This function checks if the new ranging data is available by polling the dedicated register.

Parameters
isDataReady==0 -> not ready; isDataReady==1 -> ready

Definition at line 291 of file VL53L1X_api.c.

292 {
293  uint8_t Temp;
294  uint8_t IntPol;
295  VL53L1X_ERROR status = 0;
296 
297  status = VL53L1X_GetInterruptPolarity(dev, &IntPol);
298  status = VL53L1_RdByte(dev, GPIO__TIO_HV_STATUS, &Temp);
299  /* Read in the register to check if a new value is available */
300  if (status == 0){
301  if ((Temp & 1) == IntPol)
302  *isDataReady = 1;
303  else
304  *isDataReady = 0;
305  }
306  return status;
307 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
VL53L1X_ERROR VL53L1X_GetInterruptPolarity(uint16_t dev, uint8_t *pInterruptPolarity)
This function returns the current interrupt polarity 1=active high (default), 0=active low...
Definition: VL53L1X_api.c:264
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
#define GPIO__TIO_HV_STATUS
Definition: VL53L1X_api.h:90
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_ClearInterrupt()

VL53L1X_ERROR VL53L1X_ClearInterrupt ( uint16_t  dev)

This function clears the interrupt, to be called after a ranging data reading to arm the interrupt for the next data ready event.

Definition at line 245 of file VL53L1X_api.c.

246 {
247  VL53L1X_ERROR status = 0;
248 
249  status = VL53L1_WrByte(dev, SYSTEM__INTERRUPT_CLEAR, 0x01);
250  return status;
251 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define SYSTEM__INTERRUPT_CLEAR
Definition: VL53L1X_api.h:110

◆ VL53L1X_GetAmbientPerSpad()

VL53L1X_ERROR VL53L1X_GetAmbientPerSpad ( uint16_t  dev,
uint16_t *  ambPerSp 
)

This function returns the ambient per SPAD in kcps/SPAD.

Definition at line 570 of file VL53L1X_api.c.

571 {
572  VL53L1X_ERROR status = 0;
573  uint16_t AmbientRate, SpNb = 1;
574 
575  status = VL53L1_RdWord(dev, RESULT__AMBIENT_COUNT_RATE_MCPS_SD, &AmbientRate);
577  *ambPerSp=(uint16_t) (2000.0 * AmbientRate / SpNb);
578  return status;
579 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0
Definition: VL53L1X_api.h:113
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD
Definition: VL53L1X_api.h:114
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetAmbientRate()

VL53L1X_ERROR VL53L1X_GetAmbientRate ( uint16_t  dev,
uint16_t *  ambRate 
)

This function returns the ambient rate in kcps.

Definition at line 603 of file VL53L1X_api.c.

604 {
605  VL53L1X_ERROR status = 0;
606  uint16_t tmp;
607 
609  *ambRate = tmp*8;
610  return status;
611 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD
Definition: VL53L1X_api.h:114
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetDistance()

VL53L1X_ERROR VL53L1X_GetDistance ( uint16_t  dev,
uint16_t *  distance 
)

This function returns the distance measured by the sensor in mm.

Definition at line 546 of file VL53L1X_api.c.

547 {
548  VL53L1X_ERROR status = 0;
549  uint16_t tmp;
550 
551  status = (VL53L1_RdWord(dev,
553  *distance = tmp;
554  return status;
555 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0
Definition: VL53L1X_api.h:115
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetDistanceMode()

VL53L1X_ERROR VL53L1X_GetDistanceMode ( uint16_t  dev,
uint16_t *  DM 
)

This function returns the current distance mode (1=short, 2=long).

Definition at line 487 of file VL53L1X_api.c.

488 {
489  uint8_t TempDM, status=0;
490 
491  status = VL53L1_RdByte(dev,PHASECAL_CONFIG__TIMEOUT_MACROP, &TempDM);
492  if (TempDM == 0x14)
493  *DM=1;
494  if(TempDM == 0x0A)
495  *DM=2;
496  return status;
497 }
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
#define PHASECAL_CONFIG__TIMEOUT_MACROP
Definition: VL53L1X_api.h:92
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_GetDistanceThresholdHigh()

VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh ( uint16_t  dev,
uint16_t *  high 
)

This function returns the high threshold in mm.

Definition at line 735 of file VL53L1X_api.c.

736 {
737  VL53L1X_ERROR status = 0;
738  uint16_t tmp;
739 
740  status = VL53L1_RdWord(dev,SYSTEM__THRESH_HIGH, &tmp);
741  *high = tmp;
742  return status;
743 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define SYSTEM__THRESH_HIGH
Definition: VL53L1X_api.h:102
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetDistanceThresholdLow()

VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow ( uint16_t  dev,
uint16_t *  low 
)

This function returns the low threshold in mm.

Definition at line 725 of file VL53L1X_api.c.

726 {
727  VL53L1X_ERROR status = 0;
728  uint16_t tmp;
729 
730  status = VL53L1_RdWord(dev,SYSTEM__THRESH_LOW, &tmp);
731  *low = tmp;
732  return status;
733 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define SYSTEM__THRESH_LOW
Definition: VL53L1X_api.h:103
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetDistanceThresholdWindow()

VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow ( uint16_t  dev,
uint16_t *  window 
)

This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)

Definition at line 716 of file VL53L1X_api.c.

717 {
718  VL53L1X_ERROR status = 0;
719  uint8_t tmp;
720  status = VL53L1_RdByte(dev,SYSTEM__INTERRUPT_CONFIG_GPIO, &tmp);
721  *window = (uint16_t)(tmp & 0x7);
722  return status;
723 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
#define SYSTEM__INTERRUPT_CONFIG_GPIO
Definition: VL53L1X_api.h:91
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_GetInterMeasurementInMs()

VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs ( uint16_t  dev,
uint16_t *  pIM 
)

This function returns the Intermeasurement period in ms.

Definition at line 512 of file VL53L1X_api.c.

513 {
514  uint16_t ClockPLL;
515  VL53L1X_ERROR status = 0;
516  uint32_t tmp;
517 
519  *pIM = (uint16_t)tmp;
520  status = VL53L1_RdWord(dev, VL53L1_RESULT__OSC_CALIBRATE_VAL, &ClockPLL);
521  ClockPLL = ClockPLL&0x3FF;
522  *pIM= (uint16_t)(*pIM/(ClockPLL*1.065));
523  return status;
524 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__OSC_CALIBRATE_VAL
Definition: VL53L1X_api.h:117
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
int8_t VL53L1_RdDWord(uint16_t dev, uint16_t index, uint32_t *data)
Read a double word (32 bits) from the I2C bus.
#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD
Definition: VL53L1X_api.h:101
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:78

◆ VL53L1X_GetInterruptPolarity()

VL53L1X_ERROR VL53L1X_GetInterruptPolarity ( uint16_t  dev,
uint8_t *  pInterruptPolarity 
)

This function returns the current interrupt polarity
1=active high (default), 0=active low.

Definition at line 264 of file VL53L1X_api.c.

265 {
266  uint8_t Temp;
267  VL53L1X_ERROR status = 0;
268 
269  status = VL53L1_RdByte(dev, GPIO_HV_MUX__CTRL, &Temp);
270  Temp = Temp & 0x10;
271  *pInterruptPolarity = !(Temp>>4);
272  return status;
273 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
#define GPIO_HV_MUX__CTRL
Definition: VL53L1X_api.h:89
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_GetOffset()

VL53L1X_ERROR VL53L1X_GetOffset ( uint16_t  dev,
int16_t *  offset 
)

This function returns the programmed offset correction value in mm.

Definition at line 658 of file VL53L1X_api.c.

659 {
660  VL53L1X_ERROR status = 0;
661  uint16_t Temp;
662 
664  Temp = Temp<<3;
665  Temp = Temp>>5;
666  *offset = (int16_t)(Temp);
667  return status;
668 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int16_t offset
Definition: VL43L1X.c:52
short int16_t
Typedef defining 16 bit short type. The developer should modify this to suit the platform being deplo...
Definition: vl53l1_types.h:93
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define ALGO__PART_TO_PART_RANGE_OFFSET_MM
Definition: VL53L1X_api.h:86
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetRangeStatus()

VL53L1X_ERROR VL53L1X_GetRangeStatus ( uint16_t  dev,
uint8_t *  rangeStatus 
)

This function returns the ranging status error
(0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)

Definition at line 613 of file VL53L1X_api.c.

614 {
615  VL53L1X_ERROR status = 0;
616  uint8_t RgSt;
617 
618  *rangeStatus = 255;
619  status = VL53L1_RdByte(dev, VL53L1_RESULT__RANGE_STATUS, &RgSt);
620  RgSt = RgSt & 0x1F;
621  if (RgSt < 24)
622  *rangeStatus = status_rtn[RgSt];
623  return status;
624 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__RANGE_STATUS
Definition: VL53L1X_api.h:112
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
static const uint8_t status_rtn[24]
Definition: VL53L1X_api.c:201
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_GetResult()

VL53L1X_ERROR VL53L1X_GetResult ( uint16_t  dev,
VL53L1X_Result_t *  pResult 
)

This function returns measurements and the range status in a single read access.

Definition at line 626 of file VL53L1X_api.c.

627 {
628  VL53L1X_ERROR status = 0;
629  uint8_t Temp[17];
630  uint8_t RgSt = 255;
631 
632  status = VL53L1_ReadMulti(dev, VL53L1_RESULT__RANGE_STATUS, Temp, 17);
633  RgSt = Temp[0] & 0x1F;
634  if (RgSt < 24)
635  RgSt = status_rtn[RgSt];
636  pResult->Status = RgSt;
637  pResult->Ambient = (Temp[7] << 8 | Temp[8]) * 8;
638  pResult->NumSPADs = Temp[3];
639  pResult->SigPerSPAD = (Temp[15] << 8 | Temp[16]) * 8;
640  pResult->Distance = Temp[13] << 8 | Temp[14];
641 
642  return status;
643 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__RANGE_STATUS
Definition: VL53L1X_api.h:112
uint16_t Ambient
Definition: VL53L1X_api.h:142
uint16_t SigPerSPAD
Definition: VL53L1X_api.h:143
uint16_t Distance
Definition: VL53L1X_api.h:141
static const uint8_t status_rtn[24]
Definition: VL53L1X_api.c:201
int8_t VL53L1_ReadMulti(uint16_t dev, uint16_t index, uint8_t *pdata, uint32_t count)
TODO.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98
uint16_t NumSPADs
Definition: VL53L1X_api.h:144

◆ VL53L1X_GetROI_XY()

VL53L1X_ERROR VL53L1X_GetROI_XY ( uint16_t  dev,
uint16_t *  ROI_X,
uint16_t *  ROI_Y 
)

This function returns width X and height Y.

Definition at line 780 of file VL53L1X_api.c.

781 {
782  VL53L1X_ERROR status = 0;
783  uint8_t tmp;
784 
786  *ROI_X = ((uint16_t)tmp & 0x0F) + 1;
787  *ROI_Y = (((uint16_t)tmp & 0xF0) >> 4) + 1;
788  return status;
789 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE
Definition: VL53L1X_api.h:107
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_GetROICenter()

VL53L1X_ERROR VL53L1X_GetROICenter ( uint16_t  dev,
uint8_t *  ROICenter 
)

This function returns the current user ROI center.

Definition at line 752 of file VL53L1X_api.c.

753 {
754  VL53L1X_ERROR status = 0;
755  uint8_t tmp;
756  status = VL53L1_RdByte(dev, ROI_CONFIG__USER_ROI_CENTRE_SPAD, &tmp);
757  *ROICenter = tmp;
758  return status;
759 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
#define ROI_CONFIG__USER_ROI_CENTRE_SPAD
Definition: VL53L1X_api.h:106
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_GetSensorId()

VL53L1X_ERROR VL53L1X_GetSensorId ( uint16_t  dev,
uint16_t *  sensorId 
)

This function returns the sensor id, sensor Id must be 0xEEAC.

Definition at line 536 of file VL53L1X_api.c.

537 {
538  VL53L1X_ERROR status = 0;
539  uint16_t tmp = 0;
540 
541  status = VL53L1_RdWord(dev, VL53L1_IDENTIFICATION__MODEL_ID, &tmp);
542  *sensorId = tmp;
543  return status;
544 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define VL53L1_IDENTIFICATION__MODEL_ID
Definition: VL53L1X_api.h:119
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetSigmaThreshold()

VL53L1X_ERROR VL53L1X_GetSigmaThreshold ( uint16_t  dev,
uint16_t *  sigma 
)

This function returns the current sigma threshold in mm.

Definition at line 822 of file VL53L1X_api.c.

823 {
824  VL53L1X_ERROR status = 0;
825  uint16_t tmp;
826 
827  status = VL53L1_RdWord(dev,RANGE_CONFIG__SIGMA_THRESH, &tmp);
828  *sigma = tmp >> 2;
829  return status;
830 
831 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define RANGE_CONFIG__SIGMA_THRESH
Definition: VL53L1X_api.h:98
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetSignalPerSpad()

VL53L1X_ERROR VL53L1X_GetSignalPerSpad ( uint16_t  dev,
uint16_t *  signalRate 
)

This function returns the returned signal per SPAD in kcps/SPAD. With kcps stands for Kilo Count Per Second.

Definition at line 557 of file VL53L1X_api.c.

558 {
559  VL53L1X_ERROR status = 0;
560  uint16_t SpNb=1, signal;
561 
562  status = VL53L1_RdWord(dev,
564  status = VL53L1_RdWord(dev,
566  *signalRate = (uint16_t) (2000.0*signal/SpNb);
567  return status;
568 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0
Definition: VL53L1X_api.h:113
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0
Definition: VL53L1X_api.h:116
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetSignalRate()

VL53L1X_ERROR VL53L1X_GetSignalRate ( uint16_t  dev,
uint16_t *  signal 
)

This function returns the returned signal in kcps.

Definition at line 581 of file VL53L1X_api.c.

582 {
583  VL53L1X_ERROR status = 0;
584  uint16_t tmp;
585 
586  status = VL53L1_RdWord(dev,
588  *signal = tmp*8;
589  return status;
590 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0
Definition: VL53L1X_api.h:116
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetSignalThreshold()

VL53L1X_ERROR VL53L1X_GetSignalThreshold ( uint16_t  dev,
uint16_t *  signal 
)

This function returns the current signal threshold in kcps.

Definition at line 799 of file VL53L1X_api.c.

800 {
801  VL53L1X_ERROR status = 0;
802  uint16_t tmp;
803 
804  status = VL53L1_RdWord(dev,
806  *signal = tmp <<3;
807  return status;
808 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS
Definition: VL53L1X_api.h:99
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetSpadNb()

VL53L1X_ERROR VL53L1X_GetSpadNb ( uint16_t  dev,
uint16_t *  spNb 
)

This function returns the current number of enabled SPADs.

Definition at line 592 of file VL53L1X_api.c.

593 {
594  VL53L1X_ERROR status = 0;
595  uint16_t tmp;
596 
597  status = VL53L1_RdWord(dev,
599  *spNb = tmp >> 8;
600  return status;
601 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0
Definition: VL53L1X_api.h:113
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetSWVersion()

VL53L1X_ERROR VL53L1X_GetSWVersion ( VL53L1X_Version_t *  pVersion)

This function returns the SW driver version.

Definition at line 206 of file VL53L1X_api.c.

207 {
208  VL53L1X_ERROR Status = 0;
209 
214  return Status;
215 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1X_IMPLEMENTATION_VER_REVISION
Definition: VL53L1X_api.h:76
#define VL53L1X_IMPLEMENTATION_VER_MINOR
Definition: VL53L1X_api.h:74
#define VL53L1X_IMPLEMENTATION_VER_SUB
Definition: VL53L1X_api.h:75
#define VL53L1X_IMPLEMENTATION_VER_MAJOR
Definition: VL53L1X_api.h:73

◆ VL53L1X_GetTimingBudgetInMs()

VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs ( uint16_t  dev,
uint16_t *  pTimingBudget 
)

This function returns the current timing budget in ms.

Definition at line 411 of file VL53L1X_api.c.

412 {
413  uint16_t Temp;
414  VL53L1X_ERROR status = 0;
415 
416  status = VL53L1_RdWord(dev, RANGE_CONFIG__TIMEOUT_MACROP_A_HI, &Temp);
417  switch (Temp) {
418  case 0x001D :
419  *pTimingBudget = 15;
420  break;
421  case 0x0051 :
422  case 0x001E :
423  *pTimingBudget = 20;
424  break;
425  case 0x00D6 :
426  case 0x0060 :
427  *pTimingBudget = 33;
428  break;
429  case 0x1AE :
430  case 0x00AD :
431  *pTimingBudget = 50;
432  break;
433  case 0x02E1 :
434  case 0x01CC :
435  *pTimingBudget = 100;
436  break;
437  case 0x03E1 :
438  case 0x02D9 :
439  *pTimingBudget = 200;
440  break;
441  case 0x0591 :
442  case 0x048F :
443  *pTimingBudget = 500;
444  break;
445  default:
446  status = 1;
447  *pTimingBudget = 0;
448  }
449  return status;
450 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define RANGE_CONFIG__TIMEOUT_MACROP_A_HI
Definition: VL53L1X_api.h:93
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_GetXtalk()

VL53L1X_ERROR VL53L1X_GetXtalk ( uint16_t  dev,
uint16_t *  xtalk 
)

This function returns the current programmed xtalk correction value in cps.

Definition at line 685 of file VL53L1X_api.c.

686 {
687  VL53L1X_ERROR status = 0;
688  uint32_t tmp;
689 
691  *xtalk = (uint16_t)(tmp*1000)>>9; /* * 1000 to convert kcps to cps and >> 9 (7.9 format) */
692  return status;
693 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
uint16_t xtalk
Definition: VL43L1X.c:53
#define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS
Definition: VL53L1X_api.h:83
int8_t VL53L1_RdDWord(uint16_t dev, uint16_t index, uint32_t *data)
Read a double word (32 bits) from the I2C bus.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:78

◆ VL53L1X_SensorInit()

VL53L1X_ERROR VL53L1X_SensorInit ( uint16_t  dev)

This function loads the 135 bytes default values to initialize the sensor.

Parameters
devDevice address
Returns
0:success, != 0:failed

Definition at line 225 of file VL53L1X_api.c.

226 {
227  VL53L1X_ERROR status = 0;
228  uint8_t Addr = 0x00, tmp;
229 
230  for (Addr = 0x2D; Addr <= 0x87; Addr++){
231  status = VL53L1_WrByte(dev, Addr, VL51L1X_DEFAULT_CONFIGURATION[Addr - 0x2D]);
232  }
233  status = VL53L1X_StartRanging(dev);
234  tmp = 0;
235  while(tmp==0){
236  status = VL53L1X_CheckForDataReady(dev, &tmp);
237  }
238  status = VL53L1X_ClearInterrupt(dev);
239  status = VL53L1X_StopRanging(dev);
240  status = VL53L1_WrByte(dev, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
241  status = VL53L1_WrByte(dev, 0x0B, 0); /* start VHV from the previous temperature */
242  return status;
243 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
VL53L1X_ERROR VL53L1X_StopRanging(uint16_t dev)
This function stops the ranging.
Definition: VL53L1X_api.c:283
VL53L1X_ERROR VL53L1X_StartRanging(uint16_t dev)
This function starts the ranging distance operation The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
Definition: VL53L1X_api.c:275
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND
Definition: VL53L1X_api.h:82
VL53L1X_ERROR VL53L1X_CheckForDataReady(uint16_t dev, uint8_t *isDataReady)
This function checks if the new ranging data is available by polling the dedicated register...
Definition: VL53L1X_api.c:291
VL53L1X_ERROR VL53L1X_ClearInterrupt(uint16_t dev)
This function clears the interrupt, to be called after a ranging data reading to arm the interrupt fo...
Definition: VL53L1X_api.c:245
const uint8_t VL51L1X_DEFAULT_CONFIGURATION[]
Definition: VL53L1X_api.c:107
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_SetDistanceMode()

VL53L1X_ERROR VL53L1X_SetDistanceMode ( uint16_t  dev,
uint16_t  DM 
)

This function programs the distance mode (1=short, 2=long(default)). Short mode max distance is limited to 1.3 m but better ambient immunity.
Long mode can range up to 4 m in the dark with 200 ms timing budget.

Definition at line 452 of file VL53L1X_api.c.

453 {
454  uint16_t TB;
455  VL53L1X_ERROR status = 0;
456 
457  status = VL53L1X_GetTimingBudgetInMs(dev, &TB);
458  if (status != 0)
459  return 1;
460  switch (DM) {
461  case 1:
462  status = VL53L1_WrByte(dev, PHASECAL_CONFIG__TIMEOUT_MACROP, 0x14);
463  status = VL53L1_WrByte(dev, RANGE_CONFIG__VCSEL_PERIOD_A, 0x07);
464  status = VL53L1_WrByte(dev, RANGE_CONFIG__VCSEL_PERIOD_B, 0x05);
465  status = VL53L1_WrByte(dev, RANGE_CONFIG__VALID_PHASE_HIGH, 0x38);
466  status = VL53L1_WrWord(dev, SD_CONFIG__WOI_SD0, 0x0705);
467  status = VL53L1_WrWord(dev, SD_CONFIG__INITIAL_PHASE_SD0, 0x0606);
468  break;
469  case 2:
470  status = VL53L1_WrByte(dev, PHASECAL_CONFIG__TIMEOUT_MACROP, 0x0A);
471  status = VL53L1_WrByte(dev, RANGE_CONFIG__VCSEL_PERIOD_A, 0x0F);
472  status = VL53L1_WrByte(dev, RANGE_CONFIG__VCSEL_PERIOD_B, 0x0D);
473  status = VL53L1_WrByte(dev, RANGE_CONFIG__VALID_PHASE_HIGH, 0xB8);
474  status = VL53L1_WrWord(dev, SD_CONFIG__WOI_SD0, 0x0F0D);
475  status = VL53L1_WrWord(dev, SD_CONFIG__INITIAL_PHASE_SD0, 0x0E0E);
476  break;
477  default:
478  status = 1;
479  break;
480  }
481 
482  if (status == 0)
483  status = VL53L1X_SetTimingBudgetInMs(dev, TB);
484  return status;
485 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define RANGE_CONFIG__VCSEL_PERIOD_B
Definition: VL53L1X_api.h:95
#define RANGE_CONFIG__VCSEL_PERIOD_A
Definition: VL53L1X_api.h:94
VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(uint16_t dev, uint16_t *pTimingBudget)
This function returns the current timing budget in ms.
Definition: VL53L1X_api.c:411
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define SD_CONFIG__WOI_SD0
Definition: VL53L1X_api.h:104
#define PHASECAL_CONFIG__TIMEOUT_MACROP
Definition: VL53L1X_api.h:92
#define SD_CONFIG__INITIAL_PHASE_SD0
Definition: VL53L1X_api.h:105
#define RANGE_CONFIG__VALID_PHASE_HIGH
Definition: VL53L1X_api.h:100
VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs(uint16_t dev, uint16_t TimingBudgetInMs)
This function programs the timing budget in ms. Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
Definition: VL53L1X_api.c:309
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_SetDistanceThreshold()

VL53L1X_ERROR VL53L1X_SetDistanceThreshold ( uint16_t  dev,
uint16_t  ThreshLow,
uint16_t  ThreshHigh,
uint8_t  Window,
uint8_t  IntOnNoTarget 
)

This function programs the threshold detection mode
Example:
VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100
VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300
VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window
VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window
.

Parameters
dev: device address
ThreshLow(inmm) : the threshold under which one the device raises an interrupt if Window = 0
ThreshHigh(inmm) : the threshold above which one the device raises an interrupt if Window = 1
Windowdetection mode : 0=below, 1=above, 2=out, 3=in
IntOnNoTarget= 1 (No longer used - just use 1)

Definition at line 695 of file VL53L1X_api.c.

698 {
699  VL53L1X_ERROR status = 0;
700  uint8_t Temp = 0;
701 
702  status = VL53L1_RdByte(dev, SYSTEM__INTERRUPT_CONFIG_GPIO, &Temp);
703  Temp = Temp & 0x47;
704  if (IntOnNoTarget == 0) {
706  (Temp | (Window & 0x07)));
707  } else {
709  ((Temp | (Window & 0x07)) | 0x40));
710  }
711  status = VL53L1_WrWord(dev, SYSTEM__THRESH_HIGH, ThreshHigh);
712  status = VL53L1_WrWord(dev, SYSTEM__THRESH_LOW, ThreshLow);
713  return status;
714 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define SYSTEM__THRESH_HIGH
Definition: VL53L1X_api.h:102
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
#define SYSTEM__THRESH_LOW
Definition: VL53L1X_api.h:103
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define SYSTEM__INTERRUPT_CONFIG_GPIO
Definition: VL53L1X_api.h:91
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_SetI2CAddress()

VL53L1X_ERROR VL53L1X_SetI2CAddress ( uint16_t  dev,
uint8_t  new_address 
)

This function sets the sensor I2C address used in case multiple devices application, default address 0x52.

Definition at line 217 of file VL53L1X_api.c.

218 {
219  VL53L1X_ERROR status = 0;
220 
221  status = VL53L1_WrByte(dev, VL53L1_I2C_SLAVE__DEVICE_ADDRESS, new_address >> 1);
222  return status;
223 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS
Definition: VL53L1X_api.h:81
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.

◆ VL53L1X_SetInterMeasurementInMs()

VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs ( uint16_t  dev,
uint32_t  InterMeasMs 
)

This function programs the Intermeasurement period in ms
Intermeasurement period must be >/= timing budget. This condition is not checked by the API, the customer has the duty to check the condition. Default = 100 ms.

Definition at line 499 of file VL53L1X_api.c.

500 {
501  uint16_t ClockPLL;
502  VL53L1X_ERROR status = 0;
503 
504  status = VL53L1_RdWord(dev, VL53L1_RESULT__OSC_CALIBRATE_VAL, &ClockPLL);
505  ClockPLL = ClockPLL&0x3FF;
507  (uint32_t)(ClockPLL * InterMeasMs * 1.075));
508  return status;
509 
510 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define VL53L1_RESULT__OSC_CALIBRATE_VAL
Definition: VL53L1X_api.h:117
int8_t VL53L1_WrDWord(uint16_t dev, uint16_t index, uint32_t data)
Write a double word (32 bits) to the I2C bus.
int8_t VL53L1_RdWord(uint16_t dev, uint16_t index, uint16_t *data)
Read a word (16 bits) from the I2C bus.
#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD
Definition: VL53L1X_api.h:101
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:78

◆ VL53L1X_SetInterruptPolarity()

VL53L1X_ERROR VL53L1X_SetInterruptPolarity ( uint16_t  dev,
uint8_t  NewPolarity 
)

This function programs the interrupt polarity
1=active high (default), 0=active low.

Definition at line 253 of file VL53L1X_api.c.

254 {
255  uint8_t Temp;
256  VL53L1X_ERROR status = 0;
257 
258  status = VL53L1_RdByte(dev, GPIO_HV_MUX__CTRL, &Temp);
259  Temp = Temp & 0xEF;
260  status = VL53L1_WrByte(dev, GPIO_HV_MUX__CTRL, Temp | (!(NewPolarity & 1)) << 4);
261  return status;
262 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define GPIO_HV_MUX__CTRL
Definition: VL53L1X_api.h:89
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_SetOffset()

VL53L1X_ERROR VL53L1X_SetOffset ( uint16_t  dev,
int16_t  OffsetValue 
)

This function programs the offset correction in mm.

Parameters
OffsetValue:theoffset correction value to program in mm

Definition at line 645 of file VL53L1X_api.c.

646 {
647  VL53L1X_ERROR status = 0;
648  int16_t Temp;
649 
650  Temp = (OffsetValue*4);
652  (uint16_t)Temp);
655  return status;
656 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
short int16_t
Typedef defining 16 bit short type. The developer should modify this to suit the platform being deplo...
Definition: vl53l1_types.h:93
#define MM_CONFIG__INNER_OFFSET_MM
Definition: VL53L1X_api.h:87
#define MM_CONFIG__OUTER_OFFSET_MM
Definition: VL53L1X_api.h:88
#define ALGO__PART_TO_PART_RANGE_OFFSET_MM
Definition: VL53L1X_api.h:86
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_SetROI()

VL53L1X_ERROR VL53L1X_SetROI ( uint16_t  dev,
uint16_t  X,
uint16_t  Y 
)

This function programs the ROI (Region of Interest)
The ROI position is centered, only the ROI size can be reprogrammed.
The smallest acceptable ROI size = 4
.

Parameters
X:ROIWidth; Y=ROI Height

Definition at line 761 of file VL53L1X_api.c.

762 {
763  uint8_t OpticalCenter;
764  VL53L1X_ERROR status = 0;
765 
766  status =VL53L1_RdByte(dev, VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD, &OpticalCenter);
767  if (X > 16)
768  X = 16;
769  if (Y > 16)
770  Y = 16;
771  if (X > 10 || Y > 10){
772  OpticalCenter = 199;
773  }
774  status = VL53L1_WrByte(dev, ROI_CONFIG__USER_ROI_CENTRE_SPAD, OpticalCenter);
776  (Y - 1) << 4 | (X - 1));
777  return status;
778 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE
Definition: VL53L1X_api.h:107
int8_t VL53L1_RdByte(uint16_t dev, uint16_t index, uint8_t *data)
Read a byte (8 bits) from the I2C bus.
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define ROI_CONFIG__USER_ROI_CENTRE_SPAD
Definition: VL53L1X_api.h:106
#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD
Definition: VL53L1X_api.h:120
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_SetROICenter()

VL53L1X_ERROR VL53L1X_SetROICenter ( uint16_t  dev,
uint8_t  ROICenter 
)

This function programs the new user ROI center, please to be aware that there is no check in this function. if the ROI center vs ROI size is out of border the ranging function return error #13.

Definition at line 745 of file VL53L1X_api.c.

746 {
747  VL53L1X_ERROR status = 0;
748  status = VL53L1_WrByte(dev, ROI_CONFIG__USER_ROI_CENTRE_SPAD, ROICenter);
749  return status;
750 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define ROI_CONFIG__USER_ROI_CENTRE_SPAD
Definition: VL53L1X_api.h:106

◆ VL53L1X_SetSigmaThreshold()

VL53L1X_ERROR VL53L1X_SetSigmaThreshold ( uint16_t  dev,
uint16_t  Sigma 
)

This function programs a new sigma threshold in mm (default=15 mm)

Definition at line 810 of file VL53L1X_api.c.

811 {
812  VL53L1X_ERROR status = 0;
813 
814  if(Sigma>(0xFFFF>>2)){
815  return 1;
816  }
817  /* 16 bits register 14.2 format */
818  status = VL53L1_WrWord(dev,RANGE_CONFIG__SIGMA_THRESH,Sigma<<2);
819  return status;
820 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define RANGE_CONFIG__SIGMA_THRESH
Definition: VL53L1X_api.h:98

◆ VL53L1X_SetSignalThreshold()

VL53L1X_ERROR VL53L1X_SetSignalThreshold ( uint16_t  dev,
uint16_t  Signal 
)

This function programs a new signal threshold in kcps (default=1024 kcps
.

Definition at line 791 of file VL53L1X_api.c.

792 {
793  VL53L1X_ERROR status = 0;
794 
796  return status;
797 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS
Definition: VL53L1X_api.h:99

◆ VL53L1X_SetTimingBudgetInMs()

VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs ( uint16_t  dev,
uint16_t  TimingBudgetInMs 
)

This function programs the timing budget in ms. Predefined values = 15, 20, 33, 50, 100(default), 200, 500.

Definition at line 309 of file VL53L1X_api.c.

310 {
311  uint16_t DM;
312  VL53L1X_ERROR status=0;
313 
314  status = VL53L1X_GetDistanceMode(dev, &DM);
315  if (DM == 0)
316  return 1;
317  else if (DM == 1) { /* Short DistanceMode */
318  switch (TimingBudgetInMs) {
319  case 15: /* only available in short distance mode */
321  0x01D);
323  0x0027);
324  break;
325  case 20:
327  0x0051);
329  0x006E);
330  break;
331  case 33:
333  0x00D6);
335  0x006E);
336  break;
337  case 50:
339  0x1AE);
341  0x01E8);
342  break;
343  case 100:
345  0x02E1);
347  0x0388);
348  break;
349  case 200:
351  0x03E1);
353  0x0496);
354  break;
355  case 500:
357  0x0591);
359  0x05C1);
360  break;
361  default:
362  status = 1;
363  break;
364  }
365  } else {
366  switch (TimingBudgetInMs) {
367  case 20:
369  0x001E);
371  0x0022);
372  break;
373  case 33:
375  0x0060);
377  0x006E);
378  break;
379  case 50:
381  0x00AD);
383  0x00C6);
384  break;
385  case 100:
387  0x01CC);
389  0x01EA);
390  break;
391  case 200:
393  0x02D9);
395  0x02F8);
396  break;
397  case 500:
399  0x048F);
401  0x04A4);
402  break;
403  default:
404  status = 1;
405  break;
406  }
407  }
408  return status;
409 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define RANGE_CONFIG__TIMEOUT_MACROP_B_HI
Definition: VL53L1X_api.h:96
VL53L1X_ERROR VL53L1X_GetDistanceMode(uint16_t dev, uint16_t *DM)
This function returns the current distance mode (1=short, 2=long).
Definition: VL53L1X_api.c:487
#define RANGE_CONFIG__TIMEOUT_MACROP_A_HI
Definition: VL53L1X_api.h:93
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
Definition: vl53l1_types.h:88

◆ VL53L1X_SetXtalk()

VL53L1X_ERROR VL53L1X_SetXtalk ( uint16_t  dev,
uint16_t  XtalkValue 
)

This function programs the xtalk correction value in cps (Count Per Second).
This is the number of photons reflected back from the cover glass in cps.

Definition at line 670 of file VL53L1X_api.c.

671 {
672 /* XTalkValue in count per second to avoid float type */
673  VL53L1X_ERROR status = 0;
674 
675  status = VL53L1_WrWord(dev,
677  0x0000);
679  0x0000);
681  (XtalkValue<<9)/1000); /* * << 9 (7.9 format) and /1000 to convert cps to kpcs */
682  return status;
683 }
int8_t VL53L1_WrWord(uint16_t dev, uint16_t index, uint16_t data)
Write a word (16 bits) to the I2C bus.
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
#define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS
Definition: VL53L1X_api.h:83
#define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS
Definition: VL53L1X_api.h:84
#define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS
Definition: VL53L1X_api.h:85

◆ VL53L1X_StartRanging()

VL53L1X_ERROR VL53L1X_StartRanging ( uint16_t  dev)

This function starts the ranging distance operation
The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready
1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.

Definition at line 275 of file VL53L1X_api.c.

276 {
277  VL53L1X_ERROR status = 0;
278 
279  status = VL53L1_WrByte(dev, SYSTEM__MODE_START, 0x40); /* Enable VL53L1X */
280  return status;
281 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define SYSTEM__MODE_START
Definition: VL53L1X_api.h:111

◆ VL53L1X_StartTemperatureUpdate()

VL53L1X_ERROR VL53L1X_StartTemperatureUpdate ( uint16_t  dev)

This function performs the temperature calibration. It is recommended to call this function any time the temperature might have changed by more than 8 deg C without sensor ranging activity for an extended period.

Definition at line 833 of file VL53L1X_api.c.

834 {
835  VL53L1X_ERROR status = 0;
836  uint8_t tmp=0;
837 
838  status = VL53L1_WrByte(dev,VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,0x81); /* full VHV */
839  status = VL53L1_WrByte(dev,0x0B,0x92);
840  status = VL53L1X_StartRanging(dev);
841  while(tmp==0){
842  status = VL53L1X_CheckForDataReady(dev, &tmp);
843  }
844  tmp = 0;
845  status = VL53L1X_ClearInterrupt(dev);
846  status = VL53L1X_StopRanging(dev);
847  status = VL53L1_WrByte(dev, VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND, 0x09); /* two bounds VHV */
848  status = VL53L1_WrByte(dev, 0x0B, 0); /* start VHV from the previous temperature */
849  return status;
850 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
VL53L1X_ERROR VL53L1X_StopRanging(uint16_t dev)
This function stops the ranging.
Definition: VL53L1X_api.c:283
VL53L1X_ERROR VL53L1X_StartRanging(uint16_t dev)
This function starts the ranging distance operation The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
Definition: VL53L1X_api.c:275
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND
Definition: VL53L1X_api.h:82
VL53L1X_ERROR VL53L1X_CheckForDataReady(uint16_t dev, uint8_t *isDataReady)
This function checks if the new ranging data is available by polling the dedicated register...
Definition: VL53L1X_api.c:291
VL53L1X_ERROR VL53L1X_ClearInterrupt(uint16_t dev)
This function clears the interrupt, to be called after a ranging data reading to arm the interrupt fo...
Definition: VL53L1X_api.c:245
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ VL53L1X_StopRanging()

VL53L1X_ERROR VL53L1X_StopRanging ( uint16_t  dev)

This function stops the ranging.

Definition at line 283 of file VL53L1X_api.c.

284 {
285  VL53L1X_ERROR status = 0;
286 
287  status = VL53L1_WrByte(dev, SYSTEM__MODE_START, 0x00); /* Disable VL53L1X */
288  return status;
289 }
int8_t VL53L1X_ERROR
Definition: VL53L1X_api.h:78
int8_t VL53L1_WrByte(uint16_t dev, uint16_t index, uint8_t data)
Write a byte (8 bits) to the I2C bus.
#define SYSTEM__MODE_START
Definition: VL53L1X_api.h:111

Variable Documentation

◆ status_rtn

const uint8_t status_rtn[24]
static
Initial value:
= { 255, 255, 255, 5, 2, 4, 1, 7, 3, 0,
255, 255, 9, 13, 255, 255, 255, 255, 10, 6,
255, 255, 11, 12
}

Definition at line 201 of file VL53L1X_api.c.

◆ VL51L1X_DEFAULT_CONFIGURATION

const uint8_t VL51L1X_DEFAULT_CONFIGURATION[]

Definition at line 107 of file VL53L1X_api.c.