Official VL53L5CX Linux driver and test applications for linux and android platforms
The following changes have been applied to the official API according to the discussion in link.
-
Updated the
write_read_multi()
function inplatform.cpp
file. Earlier on, it used the address of the sensor as 0x29, even if it was detected on some other bus. But now it has been fixed. -
Updated the
vl53l5cx_comms_init(VL53L5CX_Platform * p_platform)
tovl53l5cx_comms_init(VL53L5CX_Platform * p_platform, char * device, uint16_t address)
, where: -device
: Address of the device eg."/dev/i2c-1"
. Earlier on, it was hardcoded to"/dev/i2c-1"
within this function.address
: The I2C address of the sensor. Earlier on it was assumed that the address was0x29
but now it is configuraable.
-
Updated the
vl53l5cx_set_i2c_address(VL53L5CX_Configuration *p_dev, uint16_t i2c_address)
function invl53l5cx_api.cpp
so that it actually sets the address that is passed to it instead of any bit shifing. Earlier on, lets say if we pass it to set the address to0x40
, it used to set the address to0x20
. -
Updated the
WaitMs(VL53L5CX_Configuration *p_dev, uint32_t time_ms)
toWaitMs(uint32_t time_ms)
, since the other argument was not needed within the function.
The proposed implementation is customized to run on a raspberry pi v3, but can be adapted to run on any linux embedded platform, as far as the VL53L5CX device is connected through I2C Two options are offered to the user
-
- compile and run this driver with a kernel module responsible for handling i2c bus and the interruption. This is the kernel mode
-
- compile and run this driver in a full user mode, where the i2c commnication is handled with the /dev/i2c-1 file descriptor. This is the user mode
Option 1 supports the interruption line of the VL53L5CX but needs a kernel module to be compiled and inserted. Option 2 may be more suitable for simple application, but needs the /dev/i2c-1 to be available which may not be the case on some secured platforms
Note that the following instructions were tested on raspberrypi 3.
refer to raspberrypi official documentation to download the headers matching your kernel version
$ sudo apt-get install raspberrypi-kernel-headers
$ sudo nano /boot/config.txt
--> add or uncomment the following lines at the end of the /boot/config.txt
dtparam=i2c_arm=on
dtparam=i2c1=on
dtparam=i2c1_baudrate=1000000
dtoverlay=stmvl53l5cx
$ cd kernel
$ make dtb
$ sudo reboot
$ nano user/test/Makefile
Enable or disable the STMVL53L5CX_KERNEL cflags option depending on the wished uld driver mode : with a kernel module of fully in user.
$ cd vl53l5cx-driver/user/test
$ make
$ cd kernel
$ make clean
$ make
$ sudo make insert
$ cd user/test
$ ./menu