VL53L0X API Specification: vl53l0x_i2c_platform.h File Reference

VL53L0X API

vl53l0x_i2c_platform.h File Reference
#include "vl53l0x_def.h" #include <stdint.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

#define I2C   0x01
 
#define SPI   0x00
 
#define COMMS_BUFFER_SIZE   64
 
#define BYTES_PER_WORD   2
 
#define BYTES_PER_DWORD   4
 
#define VL53L0X_MAX_STRING_LENGTH_PLT   256
 

Typedefs

typedef unsigned char bool_t
 Typedef defining . More...
 

Functions

int32_t VL53L0X_comms_initialise (uint8_t comms_type, uint16_t comms_speed_khz)
 Initialise platform comms. More...
 
int32_t VL53L0X_comms_close (void)
 Close platform comms. More...
 
int32_t VL53L0X_cycle_power (void)
 Cycle Power to Device. More...
 
int32_t VL53L0X_write_multi (uint8_t address, uint8_t index, uint8_t *pdata, int32_t count)
 Writes the supplied byte buffer to the device. More...
 
int32_t VL53L0X_read_multi (uint8_t address, uint8_t index, uint8_t *pdata, int32_t count)
 Reads the requested number of bytes from the device. More...
 
int32_t VL53L0X_write_byte (uint8_t address, uint8_t index, uint8_t data)
 Writes a single byte to the device. More...
 
int32_t VL53L0X_write_word (uint8_t address, uint8_t index, uint16_t data)
 Writes a single word (16-bit unsigned) to the device. More...
 
int32_t VL53L0X_write_dword (uint8_t address, uint8_t index, uint32_t data)
 Writes a single dword (32-bit unsigned) to the device. More...
 
int32_t VL53L0X_read_byte (uint8_t address, uint8_t index, uint8_t *pdata)
 Reads a single byte from the device. More...
 
int32_t VL53L0X_read_word (uint8_t address, uint8_t index, uint16_t *pdata)
 Reads a single word (16-bit unsigned) from the device. More...
 
int32_t VL53L0X_read_dword (uint8_t address, uint8_t index, uint32_t *pdata)
 Reads a single dword (32-bit unsigned) from the device. More...
 
int32_t VL53L0X_platform_wait_us (int32_t wait_us)
 Implements a programmable wait in us. More...
 
int32_t VL53L0X_wait_ms (int32_t wait_ms)
 Implements a programmable wait in ms. More...
 
int32_t VL53L0X_set_gpio (uint8_t level)
 Set GPIO value. More...
 
int32_t VL53L0X_get_gpio (uint8_t *plevel)
 Get GPIO value. More...
 
int32_t VL53L0X_release_gpio (void)
 Release force on GPIO. More...
 
int32_t VL53L0X_get_timer_frequency (int32_t *ptimer_freq_hz)
 Get the frequency of the timer used for ranging results time stamps. More...
 
int32_t VL53L0X_get_timer_value (int32_t *ptimer_count)
 Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency()) More...
 

Macro Definition Documentation

#define I2C   0x01

Definition at line 55 of file vl53l0x_i2c_platform.h.

#define SPI   0x00

Definition at line 56 of file vl53l0x_i2c_platform.h.

#define COMMS_BUFFER_SIZE   64

Definition at line 58 of file vl53l0x_i2c_platform.h.

#define BYTES_PER_WORD   2

Definition at line 60 of file vl53l0x_i2c_platform.h.

#define BYTES_PER_DWORD   4

Definition at line 61 of file vl53l0x_i2c_platform.h.

#define VL53L0X_MAX_STRING_LENGTH_PLT   256

Definition at line 63 of file vl53l0x_i2c_platform.h.

Typedef Documentation

typedef unsigned char bool_t

Typedef defining .


The developer shoud modify this to suit the platform being deployed. Typedef defining 8 bit unsigned char type.
The developer shoud modify this to suit the platform being deployed.

Definition at line 51 of file vl53l0x_i2c_platform.h.

Function Documentation

int32_t VL53L0X_comms_initialise ( uint8_t  comms_type,
uint16_t  comms_speed_khz 
)

Initialise platform comms.

Parameters
comms_type- selects between I2C and SPI
comms_speed_khz- unsigned short containing the I2C speed in kHz
Returns
status - status 0 = ok, 1 = error
int32_t VL53L0X_comms_close ( void  )

Close platform comms.

Returns
status - status 0 = ok, 1 = error
int32_t VL53L0X_cycle_power ( void  )

Cycle Power to Device.

Returns
status - status 0 = ok, 1 = error
int32_t VL53L0X_write_multi ( uint8_t  address,
uint8_t  index,
uint8_t pdata,
int32_t  count 
)

Writes the supplied byte buffer to the device.

Wrapper for SystemVerilog Write Multi task

1 Example:
2 
3 uint8_t *spad_enables;
4 
5 int status = VL53L0X_write_multi(RET_SPAD_EN_0, spad_enables, 36);
Parameters
address- uint8_t device address value
index- uint8_t register index value
pdata- pointer to uint8_t buffer containing the data to be written
count- number of bytes in the supplied byte buffer
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_read_multi ( uint8_t  address,
uint8_t  index,
uint8_t pdata,
int32_t  count 
)

Reads the requested number of bytes from the device.

Wrapper for SystemVerilog Read Multi task

1 Example:
2 
3 uint8_t buffer[COMMS_BUFFER_SIZE];
4 
5 int status = status = VL53L0X_read_multi(DEVICE_ID, buffer, 2)
Parameters
address- uint8_t device address value
index- uint8_t register index value
pdata- pointer to the uint8_t buffer to store read data
count- number of uint8_t's to read
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_write_byte ( uint8_t  address,
uint8_t  index,
uint8_t  data 
)

Writes a single byte to the device.

Wrapper for SystemVerilog Write Byte task

1 Example:
2 
3 uint8_t page_number = MAIN_SELECT_PAGE;
4 
5 int status = VL53L0X_write_byte(PAGE_SELECT, page_number);
Parameters
address- uint8_t device address value
index- uint8_t register index value
data- uint8_t data value to write
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_write_word ( uint8_t  address,
uint8_t  index,
uint16_t  data 
)

Writes a single word (16-bit unsigned) to the device.

Manages the big-endian nature of the device (first byte written is the MS byte). Uses SystemVerilog Write Multi task.

1 Example:
2 
3 uint16_t nvm_ctrl_pulse_width = 0x0004;
4 
5 int status = VL53L0X_write_word(NVM_CTRL__PULSE_WIDTH_MSB, nvm_ctrl_pulse_width);
Parameters
address- uint8_t device address value
index- uint8_t register index value
data- uin16_t data value write
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_write_dword ( uint8_t  address,
uint8_t  index,
uint32_t  data 
)

Writes a single dword (32-bit unsigned) to the device.

Manages the big-endian nature of the device (first byte written is the MS byte). Uses SystemVerilog Write Multi task.

1 Example:
2 
3 uint32_t nvm_data = 0x0004;
4 
5 int status = VL53L0X_write_dword(NVM_CTRL__DATAIN_MMM, nvm_data);
Parameters
address- uint8_t device address value
index- uint8_t register index value
data- uint32_t data value to write
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_read_byte ( uint8_t  address,
uint8_t  index,
uint8_t pdata 
)

Reads a single byte from the device.

Uses SystemVerilog Read Byte task.

1 Example:
2 
3 uint8_t device_status = 0;
4 
5 int status = VL53L0X_read_byte(STATUS, &device_status);
Parameters
address- uint8_t device address value
index- uint8_t register index value
pdata- pointer to uint8_t data value
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_read_word ( uint8_t  address,
uint8_t  index,
uint16_t pdata 
)

Reads a single word (16-bit unsigned) from the device.

Manages the big-endian nature of the device (first byte read is the MS byte). Uses SystemVerilog Read Multi task.

1 Example:
2 
3 uint16_t timeout = 0;
4 
5 int status = VL53L0X_read_word(TIMEOUT_OVERALL_PERIODS_MSB, &timeout);
Parameters
address- uint8_t device address value
index- uint8_t register index value
pdata- pointer to uint16_t data value
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_read_dword ( uint8_t  address,
uint8_t  index,
uint32_t pdata 
)

Reads a single dword (32-bit unsigned) from the device.

Manages the big-endian nature of the device (first byte read is the MS byte). Uses SystemVerilog Read Multi task.

1 Example:
2 
3 uint32_t range_1 = 0;
4 
5 int status = VL53L0X_read_dword(RANGE_1_MMM, &range_1);
Parameters
address- uint8_t device address value
index- uint8_t register index value
pdata- pointer to uint32_t data value
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_platform_wait_us ( int32_t  wait_us)

Implements a programmable wait in us.

Wrapper for SystemVerilog Wait in micro seconds task

Parameters
wait_us- integer wait in micro seconds
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_wait_ms ( int32_t  wait_ms)

Implements a programmable wait in ms.

Wrapper for SystemVerilog Wait in milli seconds task

Parameters
wait_ms- integer wait in milli seconds
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_set_gpio ( uint8_t  level)

Set GPIO value.

Parameters
level- input level - either 0 or 1
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_get_gpio ( uint8_t plevel)

Get GPIO value.

Parameters
plevel- uint8_t pointer to store GPIO level (0 or 1)
Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_release_gpio ( void  )

Release force on GPIO.

Returns
status - SystemVerilog status 0 = ok, 1 = error
int32_t VL53L0X_get_timer_frequency ( int32_t ptimer_freq_hz)

Get the frequency of the timer used for ranging results time stamps.

Parameters
[out]ptimer_freq_hz: pointer for timer frequency
Returns
status : 0 = ok, 1 = error
int32_t VL53L0X_get_timer_value ( int32_t ptimer_count)

Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency())

Parameters
[out]ptimer_count: pointer for timer count value
Returns
status : 0 = ok, 1 = error