Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/vl53l1x: VL53L1X ToF ranging sensor added as package #10363

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
55b315f
drivers/vl53l1x: add driver for ST VL53L1X sensor
gschorcht Dec 12, 2021
31cbc2a
pkg/driver_vl53l1x_st_api: vendor API used by vl53l1x driver
gschorcht Dec 12, 2021
b85d14e
drivers/vl53l1x: SAUL integration
gschorcht Dec 12, 2021
7df6f4a
tests/driver_vl53l1x: add test app for vl53l1x driver
gschorcht Dec 12, 2021
2812f88
driver/vl53l1x: add Kconfig
gschorcht Dec 12, 2021
b4e47ea
fixup! drivers/vl53l1x: add driver for ST VL53L1X sensor
gschorcht Dec 13, 2022
39ce37c
fixup! drivers/vl53l1x: SAUL integration
gschorcht Dec 13, 2022
a61ebaa
fixup! pkg/driver_vl53l1x_st_api: vendor API used by vl53l1x driver
gschorcht Dec 13, 2022
963837a
fixup! pkg/driver_vl53l1x_st_api: vendor API used by vl53l1x driver
gschorcht Dec 14, 2022
3f7f28a
fixup! drivers/vl53l1x: add driver for ST VL53L1X sensor
gschorcht Dec 14, 2022
ca6ca0e
fixup! drivers/vl53l1x: add driver for ST VL53L1X sensor
gschorcht Dec 15, 2022
23a0cb2
fixup! tests/driver_vl53l1x: add test app for vl53l1x driver
gschorcht Dec 15, 2022
9947675
fixup! driver/vl53l1x: add Kconfig
gschorcht Dec 15, 2022
e2abaf0
tests/driver_vl53l1x: add test app for vl53l1x_st_api driver
gschorcht Dec 15, 2022
4682545
fixup! driver/vl53l1x: add Kconfig
gschorcht Dec 15, 2022
6e9ed3a
fixup! tests/driver_vl53l1x: add test app for vl53l1x_st_api driver
gschorcht Dec 15, 2022
0c1209f
fixup! tests/driver_vl53l1x: add test app for vl53l1x driver
gschorcht Sep 10, 2023
d52ab8f
fixup! tests/driver_vl53l1x: add test app for vl53l1x_st_api driver
gschorcht Sep 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ rsource "tsl2561/Kconfig"
rsource "tsl4531x/Kconfig"
rsource "vcnl40x0/Kconfig"
rsource "veml6070/Kconfig"
rsource "vl53l1x/Kconfig"
rsource "vl6180x/Kconfig"
endmenu # Sensor Device Drivers

Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ ifneq (,$(filter vcnl40%0,$(USEMODULE)))
USEMODULE += vcnl40x0
endif

ifneq (,$(filter vl53l1x_%,$(USEMODULE)))
USEMODULE += vl53l1x
endif

ifneq (,$(filter vl6180x_%,$(USEMODULE)))
USEMODULE += vl6180x
endif
Expand Down
604 changes: 604 additions & 0 deletions drivers/include/vl53l1x.h

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions drivers/saul/init_devs/auto_init_vl53l1x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2021 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
*/

/*
* @ingroup drivers_vl53l1x
* @ingroup sys_auto_init_saul
* @brief Auto initialization of ST VL53L1X Time-of-Flight (ToF) ranging sensor
* @author Gunar Schorcht <[email protected]>
* @file
*/

#ifdef MODULE_VL53L1X

#include "assert.h"
#include "log.h"
#include "saul_reg.h"
#include "vl53l1x.h"
#include "vl53l1x_params.h"

/**
* @brief Define the number of configured sensors
*/
#define VL53L1X_NUM (sizeof(vl53l1x_params) / sizeof(vl53l1x_params[0]))

/**
* @brief Allocate memory for the device descriptors
*/
static vl53l1x_t vl53l1x_devs[VL53L1X_NUM];

/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[VL53L1X_NUM];

/**
* @brief Define the number of saul info
*/
#define VL53L1X_INFO_NUM (sizeof(vl53l1x_saul_info) / sizeof(vl53l1x_saul_info[0]))

/**
* @brief Reference the driver structs
*/
extern saul_driver_t vl53l1x_saul_driver;

void auto_init_vl53l1x(void)
{
assert(VL53L1X_INFO_NUM == VL53L1X_NUM);

for (unsigned i = 0; i < VL53L1X_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing vl53l1x #%u\n", i);

if (vl53l1x_init(&vl53l1x_devs[i], &vl53l1x_params[i]) != VL53L1X_OK) {
LOG_ERROR("[auto_init_saul] error initializing vl53l1x #%u\n", i);
continue;
}

saul_entries[i].dev = &(vl53l1x_devs[i]);
saul_entries[i].name = vl53l1x_saul_info[i].name;
saul_entries[i].driver = &vl53l1x_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}

#else
typedef int dont_be_pedantic;
#endif /* MODULE_VL53L1X */
4 changes: 4 additions & 0 deletions drivers/saul/init_devs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ void saul_init_devs(void)
extern void auto_init_veml6070(void);
auto_init_veml6070();
}
if (IS_USED(MODULE_VL53L1X)) {
extern void auto_init_vl53l1x(void);
auto_init_vl53l1x();
}
if (IS_USED(MODULE_VL6180X)) {
extern void auto_init_vl6180x(void);
auto_init_vl6180x();
Expand Down
79 changes: 79 additions & 0 deletions drivers/vl53l1x/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (c) 2020 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_VL53L1X
bool "VL53L1X Time-of-Flight (ToF) ranging sensor"
depends on HAS_PERIPH_GPIO
depends on HAS_PERIPH_GPIO_IRQ
depends on HAS_PERIPH_I2C
depends on TEST_KCONFIG
select MODULE_PERIPH_GPIO
select MODULE_PERIPH_GPIO_IRQ
select MODULE_PERIPH_I2C
select MODULE_ZTIMER_MSEC

if MODULE_VL53L1X

choice
bool "Driver variant"
default MODULE_VL53L1X_STD

config MODULE_VL53L1X_BASIC
bool "Basic functionality"
help
This is the smallest driver variant that only provides some basic
functions such as the distance measurement and the data-ready interrupt.

config MODULE_VL53L1X_STD
bool "Standard functionality"
help
This driver variant is a compromise of size and functionality. It
provides the application with most functionality of the sensor. The
driver can be used when memory requirements are important and most
of the functionality should be used.

config MODULE_VL53L1X_ST_API
bool "Full functionality using the ST VL53L1X Full API"
select PACKAGE_DRIVER_VL53L1X_ST_API
help
This driver variant uses ST STSW-IMG007 VL53L1X API as package. In
this case, the driver is simply a wrapper for the API which provides
a driver interface that is compatible with other driver variants.
Additionally, it provides access to the complete functionality
of the sensor by using API functions directly. This is for example
necessary to configure and use threshold interrupts, or to calibrate
the sensor.

endchoice

choice
bool "Distance mode"
default VL53L1X_DIST_LONG
depends on MODULE_VL53L1X_STD || MODULE_VL53L1X_ST_API

config VL53L1X_DIST_SHORT
bool "Short - up to 1.3 m"
config VL53L1X_DIST_MEDIUM
bool "Medium - up to 2 m"
config VL53L1X_DIST_LONG
bool "Long - up to 4 m"

endchoice

config VL53L1X_PARAM_TIMING_BUDGET
int "Timing budget [us]"
default 50000
range 20000 1000000
depends on MODULE_VL53L1X_STD || MODULE_VL53L1X_ST_API

config VL53L1X_PARAM_PERIOD
int "Inter-measurement period [ms]"
default 100
range 20 1000
depends on MODULE_VL53L1X_STD || MODULE_VL53L1X_ST_API

endif # MODULE_VL53L1X
1 change: 1 addition & 0 deletions drivers/vl53l1x/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
17 changes: 17 additions & 0 deletions drivers/vl53l1x/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ifneq (,$(filter vl53l1x_st_api,$(USEMODULE)))
USEMODULE += driver_vl53l1x_st_api_platform
USEMODULE += ztimer_usec
USEPKG += driver_vl53l1x_st_api
endif

ifeq (,$(filter vl53l1x_%,$(USEMODULE)))
# use vl53l1x_std if no `vl53l1x_*` driver variant is explicitly specified
USEMODULE += vl53l1x_std
endif

ifneq (,$(filter vl53l1x,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_i2c
USEMODULE += ztimer_msec
endif
7 changes: 7 additions & 0 deletions drivers/vl53l1x/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# include variants of VL53L1X drivers as pseudo modules
PSEUDOMODULES += vl53l1x_basic
PSEUDOMODULES += vl53l1x_st_api
PSEUDOMODULES += vl53l1x_std

USEMODULE_INCLUDES_vl53l1x := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_vl53l1x)
153 changes: 153 additions & 0 deletions drivers/vl53l1x/include/vl53l1x_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2021 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_vl53l1x
* @brief Default configuration for ST VL53L1X Time-of-Flight (ToF) ranging sensor
* @author Gunar Schorcht <[email protected]>
* @file
* @{
*/

#ifndef VL53L1X_PARAMS_H
#define VL53L1X_PARAMS_H

#include "board.h"
#include "saul_reg.h"
#include "vl53l1x.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Default hardware configuration parameters
* @{
*/

/**
* @brief Default device is I2C_DEV(0)
*/
#ifndef VL53L1X_PARAM_DEV
#define VL53L1X_PARAM_DEV I2C_DEV(0)
#endif

/**
* @brief Default I2C VDDIO voltage: 2.8 V
*/
#ifndef VL53L1X_PARAM_VDDIO_2V8
#define VL53L1X_PARAM_VDDIO_2V8 (true)
#endif

/**
* @brief Default interrupt pin: not used
*/
#ifndef VL53L1X_PARAM_PIN_INT
#define VL53L1X_PARAM_PIN_INT (GPIO_UNDEF)
#endif

/**
* @brief Default shutdown pin: not used
*/
#ifndef VL53L1X_PARAM_PIN_SHUTDOWN
#define VL53L1X_PARAM_PIN_SHUTDOWN (GPIO_UNDEF)
#endif
/** @} */

/**
* @name Default sensor configuration parameters
* @{
*/

#if !DOXYGEN

/* Mapping of Kconfig defines to the respective driver enumeration values */
#ifdef CONFIG_VL53L1X_DIST_SHORT
#define CONFIG_VL53L1X_PARAM_DISTANCE_MODE (VL53L1X_DIST_SHORT)
#elif CONFIG_VL53L1X_DIST_MEDIUM
#define CONFIG_VL53L1X_PARAM_DISTANCE_MODE (VL53L1X_DIST_MEDIUM)
#elif CONFIG_VL53L1X_DIST_LONG
#define CONFIG_VL53L1X_PARAM_DISTANCE_MODE (VL53L1X_DIST_LONG)
#endif

#endif /* !DOXYGEN */

/**
* @brief Default inter-measurement period [ms]: 100 ms
*/
#ifndef CONFIG_VL53L1X_PARAM_PERIOD
#define CONFIG_VL53L1X_PARAM_PERIOD (100)
#endif

/**
* @brief Default Timing budget [us]: 50 ms
*/
#ifndef CONFIG_VL53L1X_PARAM_TIMING_BUDGET
#define CONFIG_VL53L1X_PARAM_TIMING_BUDGET (50000)
#endif

/**
* @brief Default distance mode: long
*/
#ifndef CONFIG_VL53L1X_PARAM_DISTANCE_MODE
#define CONFIG_VL53L1X_PARAM_DISTANCE_MODE (VL53L1X_DIST_LONG)
#endif
/**@}*/

/**
* @brief Default VL53L1X configuration parameter set
*/
#ifndef VL53L1X_PARAMS
#if !IS_USED(MODULE_VL53L1X_BASIC)
#define VL53L1X_PARAMS { \
.i2c_dev = VL53L1X_PARAM_DEV, \
.vddio_2v8 = VL53L1X_PARAM_VDDIO_2V8, \
.pin_int = VL53L1X_PARAM_PIN_INT, \
.pin_shutdown = VL53L1X_PARAM_PIN_SHUTDOWN, \
.budget = CONFIG_VL53L1X_PARAM_TIMING_BUDGET, \
.period = CONFIG_VL53L1X_PARAM_PERIOD, \
.mode = CONFIG_VL53L1X_PARAM_DISTANCE_MODE, \
}
#else /* !IS_USED(MODULE_VL53L1X_BASIC) */
#define VL53L1X_PARAMS { \
.i2c_dev = VL53L1X_PARAM_DEV, \
.vddio_2v8 = VL53L1X_PARAM_VDDIO_2V8, \
.pin_int = VL53L1X_PARAM_PIN_INT, \
}
#endif /* !IS_USED(MODULE_VL53L1X_BASIC) */
#endif /* VL53L1X_PARAMS */

/**
* @brief Default SAUL device information
*/
#ifndef VL53L1X_SAUL_INFO
#define VL53L1X_SAUL_INFO { .name = "vl53l1x" }
#endif

/**
* @brief Allocate some memory to store the default configuration
*/
static const vl53l1x_params_t vl53l1x_params[] =
{
VL53L1X_PARAMS
};

/**
* @brief Additional meta information to keep in the SAUL registry
*/
static const saul_reg_info_t vl53l1x_saul_info[] =
{
VL53L1X_SAUL_INFO
};

#ifdef __cplusplus
}
#endif

#endif /* VL53L1X_PARAMS_H */
/** @} */
Loading