-
Notifications
You must be signed in to change notification settings - Fork 2k
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: add driver for ST VL6180X ranging and ambient light sensor #10462
Changes from all commits
51bf9d4
add625a
afb5e04
9897dcc
0bee1dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) 2018 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_vl6180x | ||
* @ingroup sys_auto_init_saul | ||
* @brief Auto initialization of ST VL6180X Ranging and Ambient Light Sensor | ||
* @author Gunar Schorcht <[email protected]> | ||
* @file | ||
*/ | ||
|
||
#ifdef MODULE_VL6180X | ||
|
||
#include "assert.h" | ||
#include "log.h" | ||
#include "saul_reg.h" | ||
#include "vl6180x.h" | ||
#include "vl6180x_params.h" | ||
|
||
/** | ||
* @brief Define the number of configured sensors | ||
*/ | ||
#define VL6180X_NUM ARRAY_SIZE(vl6180x_params) | ||
|
||
/** | ||
* @brief Allocate memory for the device descriptors | ||
*/ | ||
static vl6180x_t vl6180x_devs[VL6180X_NUM]; | ||
|
||
/** | ||
* @brief Memory for the SAUL registry entries | ||
*/ | ||
static saul_reg_t saul_entries[VL6180X_NUM * 2]; | ||
|
||
/** | ||
* @brief Define the number of saul info | ||
*/ | ||
#define VL6180X_INFO_NUM ARRAY_SIZE(vl6180x_saul_info) | ||
|
||
/** | ||
* @brief Reference the driver structs | ||
*/ | ||
extern saul_driver_t vl6180x_saul_als_driver; | ||
extern saul_driver_t vl6180x_saul_rng_driver; | ||
|
||
void auto_init_vl6180x(void) | ||
{ | ||
assert(VL6180X_INFO_NUM == VL6180X_NUM); | ||
|
||
for (unsigned i = 0; i < VL6180X_NUM; i++) { | ||
LOG_DEBUG("[auto_init_saul] initializing vl6180x #%u\n", i); | ||
|
||
if (vl6180x_init(&vl6180x_devs[i], &vl6180x_params[i]) != VL6180X_OK) { | ||
LOG_ERROR("[auto_init_saul] error initializing vl6180x #%u\n", i); | ||
continue; | ||
} | ||
|
||
saul_entries[(i * 2)].dev = &(vl6180x_devs[i]); | ||
saul_entries[(i * 2)].name = vl6180x_saul_info[i].name; | ||
saul_entries[(i * 2)].driver = &vl6180x_saul_als_driver; | ||
saul_reg_add(&(saul_entries[(i * 2)])); | ||
|
||
saul_entries[(i * 2) + 1].dev = &(vl6180x_devs[i]); | ||
saul_entries[(i * 2) + 1].name = vl6180x_saul_info[i].name; | ||
saul_entries[(i * 2) + 1].driver = &vl6180x_saul_rng_driver; | ||
saul_reg_add(&(saul_entries[(i * 2) + 1])); | ||
} | ||
} | ||
|
||
#else | ||
typedef int dont_be_pedantic; | ||
#endif /* MODULE_VL6180X */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
# 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. | ||
# | ||
|
||
menuconfig MODULE_VL6180X | ||
bool "VL6180X Ranging and Ambient Light Sensing (ALS) module" | ||
depends on TEST_KCONFIG | ||
depends on HAS_PERIPH_I2C | ||
select MODULE_PERIPH_I2C | ||
select MODULE_ZTIMER_MSEC | ||
help | ||
Driver for the ST VL6180X Ranging and Ambient Light Sensing (ALS) module | ||
|
||
if MODULE_VL6180X | ||
|
||
config MODULE_VL6180X_RNG | ||
bool "Ranging enabled" | ||
|
||
config VL6180X_RNG_MAX_TIME | ||
int "Ranging maximum convergence time [ms]" | ||
range 1 63 | ||
default 50 | ||
depends on MODULE_VL6180X_RNG | ||
|
||
config MODULE_VL6180X_ALS | ||
bool "Ambient light sensing (ALS) enabled" | ||
|
||
if MODULE_VL6180X_ALS | ||
|
||
config VL6180X_ALS_INT_TIME | ||
int "ALS integration time [ms]" | ||
range 0 511 | ||
default 100 | ||
|
||
choice VL6180X_ALS_GAIN | ||
bool "ALS analogue light channel gain" | ||
default VL6180X_ALS_GAIN_1 | ||
|
||
config VL6180X_ALS_GAIN_1 | ||
bool "ALS gain setting 1 (actual analogue gain of 1.01)" | ||
config VL6180X_ALS_GAIN_1_25 | ||
bool "ALS gain setting 1.25 (actual analogue gain of 1.28)" | ||
config VL6180X_ALS_GAIN_1_67 | ||
bool "ALS gain setting 1.67 (actual analogue gain of 1.72)" | ||
config VL6180X_ALS_GAIN_2_5 | ||
bool "ALS gain setting 2.5 (actual analogue gain of 2.60)" | ||
config VL6180X_ALS_GAIN_5 | ||
bool "ALS gain setting 5 (actual analogue gain of 5.21)" | ||
config VL6180X_ALS_GAIN_10 | ||
bool "ALS gain setting 10 (actual analogue gain of 10.32)" | ||
config VL6180X_ALS_GAIN_20 | ||
bool "ALS gain setting 20 (actual analogue gain of 20)" | ||
config VL6180X_ALS_GAIN_40 | ||
bool "ALS gain setting 40 (actual analogue gain of 40)" | ||
|
||
endchoice | ||
|
||
config VL6180X_ALS_LUX_RES | ||
int "ALS lux resolution [lux/count*1000]" | ||
range 1 320 | ||
default 320 | ||
help | ||
ALS lux resolution is used to convert count values from ambient | ||
light sensing to lux values. It is specified as lux/count*1000. | ||
The factory calibrated lux resolution is 0.32 lux/count. | ||
|
||
endif # MODULE_VL6180X_ALS | ||
|
||
config VL6180X_MEAS_PERIOD | ||
int "Measurement period in continuous mode [10 ms]" | ||
range 0 255 | ||
default 20 | ||
help | ||
The measurement period is defined as multiple of 10 ms. It is used for | ||
both range measurements and ambient light sensing (ALS) in | ||
continuous mode. | ||
The measurement period also controls the measurement mode used after | ||
sensor initialization. If the measurement period is 0, the single-shot | ||
mode is used for both the range and ALS measurements, and functions | ||
vl6180x_rng_start_single and vl6180x_als_start_single have to be used | ||
to start a single measurement. Otherwise the continuous mode is | ||
used for both measurements which are started immediatly after sensor | ||
initialization. | ||
|
||
config MODULE_VL6180X_IRQ | ||
bool "Support for interrupts" | ||
depends on HAS_PERIPH_GPIO_IRQ | ||
select MODULE_PERIPH_GPIO_IRQ | ||
help | ||
Interrupts can be used either when new sensor data are ready to be | ||
read or when sensor values exceed configured thresholds. | ||
If interrupt handling is enabled, the interrupt signal | ||
(sensor pin GPIO1) has to be connected to a MCU GPIO pin which | ||
has to be defined in the board definition by VL6180X_PARAM_INT_PIN. | ||
|
||
if MODULE_VL6180X_IRQ | ||
|
||
choice | ||
bool "Ranging interrupt mode" | ||
depends on MODULE_VL6180X_RNG | ||
default VL6180X_RNG_INT_DRDY | ||
help | ||
Interrupt defines the interrupt that is enabled for ranging. | ||
|
||
config VL6180X_RNG_INT_DRDY | ||
bool "Data Ready" | ||
help | ||
Interrupt is triggered when new ranging data are ready to be read | ||
|
||
config VL6180X_RNG_INT_LOW | ||
bool "Level Low" | ||
help | ||
Interrupt is triggered when ranging values are below lower threshold | ||
|
||
config VL6180X_RNG_INT_HIGH | ||
bool "Level High" | ||
help | ||
Interrupt is triggered when ranging values are above upper threshold | ||
|
||
config VL6180X_RNG_INT_OUT | ||
bool "Out of Window" | ||
help | ||
Interrupt is triggered when ranging values are below the lower | ||
threshold or above the upper threshold (out of threshold window) | ||
|
||
endchoice | ||
|
||
config VL6180X_RNG_THRESH_LOW | ||
int "Ranging lower threshold [mm]" | ||
depends on VL6180X_RNG_INT_LOW || VL6180X_RNG_INT_OUT | ||
range 0 255 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it make sense to have 255 here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. The sensor allows to set the thresholds to 255 even if it doesn't make sense. But if you think it makes more sense to limit the values at user level, I can change it to 100. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the hardware allows I think we can stay as it then. |
||
default 20 | ||
help | ||
Interrupt is triggered when ranging values are below this threshold | ||
|
||
config VL6180X_RNG_THRESH_HIGH | ||
int "Ranging upper threshold [mm]" | ||
depends on VL6180X_RNG_INT_HIGH || VL6180X_RNG_INT_OUT | ||
range 0 255 | ||
dylad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default 90 | ||
help | ||
Interrupt is triggered when ranging values are above this threshold | ||
|
||
choice | ||
bool "ALS interrupt mode" | ||
depends on MODULE_VL6180X_ALS | ||
default VL6180X_ALS_INT_DRDY | ||
help | ||
Interrupt defines the interrupt that is enabled for ALS. | ||
|
||
config VL6180X_ALS_INT_DRDY | ||
bool "Data Ready" | ||
help | ||
Interrupt is triggered when new ALS data are ready to be read | ||
|
||
config VL6180X_ALS_INT_LOW | ||
bool "Level Low" | ||
help | ||
Interrupt is triggered when ALS values are below lower threshold | ||
|
||
config VL6180X_ALS_INT_HIGH | ||
bool "Level High" | ||
help | ||
Interrupt is triggered when ALS values are above upper threshold | ||
|
||
config VL6180X_ALS_INT_OUT | ||
bool "Out of Window" | ||
help | ||
Interrupt is triggered when ALS values are below the lower | ||
threshold or above the upper threshold (out of threshold window) | ||
|
||
endchoice | ||
|
||
config VL6180X_ALS_THRESH_LOW | ||
int "ALS lower threshold [counts]" | ||
depends on VL6180X_ALS_INT_LOW || VL6180X_ALS_INT_OUT | ||
range 0 65535 | ||
default 50 | ||
help | ||
Interrupt is triggered when ALS values are below this threshold | ||
|
||
config VL6180X_ALS_THRESH_HIGH | ||
int "ALS upper threshold [counts]" | ||
depends on VL6180X_ALS_INT_HIGH || VL6180X_ALS_INT_OUT | ||
range 0 65535 | ||
default 2000 | ||
help | ||
Interrupt is triggered when ALS values are above this threshold | ||
|
||
endif # MODULE_VL6180X_IRQ | ||
|
||
config MODULE_VL6180X_SHUTDOWN | ||
bool "Support for power-down and power-up" | ||
depends on HAS_PERIPH_GPIO | ||
select MODULE_PERIPH_GPIO | ||
help | ||
Enable the power-down and power-up functions. If power-down and | ||
power-up functions are enabled by module, the shutdown signal | ||
(sensor pin GPIO0/CE) has to be connected to a MCU GPIO pin which | ||
has to be defined in the board definition by VL6180X_PARAM_SHUTDOWN_PIN. | ||
|
||
config MODULE_VL6180X_CONFIG | ||
bool "Configuration of the sensor at runtime" | ||
help | ||
Enables the functions that can be used to reconfigure the sensor at | ||
runtime. | ||
|
||
endif # MODULE_VL6180X |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ifneq (,$(filter vl6180x_irq_%,$(USEMODULE))) | ||
USEMODULE += vl6180x_irq | ||
endif | ||
|
||
ifneq (,$(filter vl6180x,$(USEMODULE))) | ||
FEATURES_REQUIRED += periph_i2c | ||
USEMODULE += ztimer_msec | ||
endif | ||
|
||
ifneq (,$(filter vl6180x_shutdown,$(USEMODULE))) | ||
FEATURES_REQUIRED += periph_gpio | ||
endif | ||
|
||
ifneq (,$(filter vl6180x_irq,$(USEMODULE))) | ||
FEATURES_REQUIRED += periph_gpio | ||
FEATURES_REQUIRED += periph_gpio_irq | ||
endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# include variants of VL6180x drivers as pseudomodules | ||
PSEUDOMODULES += vl6180x_rng | ||
PSEUDOMODULES += vl6180x_als | ||
PSEUDOMODULES += vl6180x_irq | ||
PSEUDOMODULES += vl6180x_shutdown | ||
PSEUDOMODULES += vl6180x_config | ||
|
||
USEMODULE_INCLUDES_vl6180x:= $(LAST_MAKEFILEDIR)/include | ||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_vl6180x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit puzzled by the RNG abbreviation. I find it a bit disturbing at first glance.
I am not asking for a change here but I am wondering what other think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, could be misinterpreted as random number generator. I din't think about it, I was just looking for short wording.