-
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/vl53l1x: VL53L1X ToF ranging sensor added as package #10363
base: master
Are you sure you want to change the base?
Conversation
4afebb6
to
f54431c
Compare
f54431c
to
14043fc
Compare
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
It's waiting for review. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Hi! This is a great PR! Thanks @gschorcht ! I was working on a native VL53L0X, but it was turning into a burden with all this i2c settings that come out of nowhere. I'ḿ not sure if your porting is compatible with my breakbord. Otherwise I can port it in a similar way as you did. Thanks! |
I do have some VL53L0X sensors lying around. I assume those are incompatible, is this right? Update: I ordered two VL53L1X now. So I should be able to review and test this. |
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 haven't seen all files yet, but some comments inline. I can resume review when I have the hardware for testing.
@@ -0,0 +1,11881 @@ | |||
/* |
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.
Would it be easily possible to provide this header via a pkg, similar to the way it is done with the vendor code for STM? But if that is non-trivial to do, I'm very much fine with having a copy in our repo.
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.
This file is part of the ST VL53L1X driver package. Maybe we could pull the package even if it is not used.
drivers/include/vl53l1x.h
Outdated
#if MODULE_VL53L1X_ST_API | ||
VL53L1X_DIST_SHORT = VL53L1_DISTANCEMODE_SHORT, /**< up to 1.3 m */ | ||
VL53L1X_DIST_MEDIUM = VL53L1_DISTANCEMODE_MEDIUM, /**< up to 2 m */ | ||
VL53L1X_DIST_LONG = VL53L1_DISTANCEMODE_LONG, /**< up to 4 m */ | ||
#else | ||
VL53L1X_DIST_SHORT, /**< up to 1.3 m */ | ||
VL53L1X_DIST_MEDIUM, /**< up to 2 m */ | ||
VL53L1X_DIST_LONG, /**< up to 4 m */ | ||
#endif |
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.
Would the be a downside to just unconditionally using the constants which are compatible with the ST API in any case?
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.
These symbols are defined in pkg/driver_vl53l1x_st_api/vl53l1x-st-api/vl53l1_def.h
. They are available only if the ST VL53L1X driver is used by enabling the vl53l1x_st_api
module.
drivers/include/vl53l1x.h
Outdated
*/ | ||
int vl53l1x_read_mm(vl53l1x_t *dev, int16_t *mm); | ||
|
||
#if !MODULE_VL53L1X_BASIC |
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.
#if !MODULE_VL53L1X_BASIC | |
#if !MODULE_VL53L1X_BASIC || DOXYGEN |
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.
It shouldn't be necessary because MODULE_VL53L1X_BASIC
isn't defined when doxygen is executed so that the condition is true.
@maribu Ups, I have to appologize, my plan was to improve the code a bit before because the code is quite old and contains a lot of code style violations 😟 Anyway, thanks for starting the review. |
I'm still on vacation and reviewing larger PRs from my smartphone is cumbersome, also I cannot do testing. But it has a prominent position in my todo list ;) |
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 only did a quick look, but code looks good so far.
#if IS_USED(MODULE_VL53L1X_ST_API) | ||
|
||
EXEC_RET(VL53L1_SetMeasurementTimingBudgetMicroSeconds(&dev->dev, | ||
budget_us)); | ||
#else |
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.
Is there a chance that this would work as C conditionals? That way we can be sure that both ST-API and pololu variant can be compiled without having to provide two test applications. (More instances above and below.)
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.
Hm, there are a lot of defines and symbol mappings dependent on whether the ST API is used or not that I can't imaging that compilation works if we use C conditionals. I can try it, but I'm not optimistic.
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 think there is no chance in this case. The problem is that the ST API is used as a package, so of course the header files with a lot of defines and declarations required during compilation are not available if the package is not used by the driver:
drivers/vl53l1x/vl53l1x.c:525:14: error: implicit declaration of function 'VL53L1_SetMeasurementTimingBudgetMicroSeconds' [-Werror=implicit-function-declaration]
EXEC_RET(VL53L1_SetMeasurementTimingBudgetMicroSeconds(&dev->dev,
^
To solve this problem we would have to pull the package in any case and insert the headers always, even if they are not used by the driver. IMHO, that would be the wrong approach just to use C Conditionals.
Even if we would do it in that way, there would raise another compilation problem because the driver defines some mappings to be able to use same code independent on whether the ST API is used or not. These mappings would result in a conflict if the ST API is used.
I fully agree that the CI coverage is an argument to use C conditionals. But in this case I would prefer to keep the preprocessor conditionals and to provide a second test application. Would it be ok for you?
} | ||
ztimer_sleep(ZTIMER_MSEC, 1); | ||
} | ||
if (timeout == 0) { |
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.
if (timeout == 0) { | |
if (timeout == UINT_MAX) { |
The postdecrement will still kick in, see:
~ $ cat test.c
#include <stdio.h>
int main(void) {
unsigned foo = 3;
while (foo--) { }
printf("foo = %u\n", foo);
return 0;
}
~ $ gcc -o test test.c
~ $ ./test
foo = 4294967295
But IMO it would be more readable to just go for
while (timeout) {
timeout--;
...
instead.
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.
The postdecrement will still kick in, see:
Yeah of course. Good catch. Fixed.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
3e982fa
to
b06ad42
Compare
ecf1139
to
d52ab8f
Compare
Rebased another time to fix the conflicts and updated to be compatible with the |
Contribution description
This PR was originally intended only as an example for the discussion on how to add a device driver as a package. In the meantime I finished the driver. It is fully functional and therefore ready for review.
Overview
This PR adds a device driver for ST VL53L1X Time-of-Flight laser-ranging sensor. The VL53L1X allows accurate and fast ranging up to 4 m and with a frequency of up to 50 Hz.
There are three variants of the driver which differ in functionality and size:
vl53l1x
vl53l1x_st_api
vl53l1x_basic
This
vl53l1x_st_api
variant of the driver uses the ST STSW-IMG007 VL53L1X API as a package (pkg/driver_vl53l1x_st_api
). In this case, the driver is simply a wrapper for the API which provides a driver interface that is compatible with the other driver variants. Since the ST STSW-IMG007 VL53L1X API package is quite complex and very large, this driver variant can only be used when memory requirements are not an issue. It has to be used for best accuracy, for calibration and if threshold interrupts shall be used.The
vl53l1x_std
driver variant (default) 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.The
vl53l1x_basic
driver variant is the smallest driver variant which only provides some basic functions such as the distance measurement and the data-ready interrupt.All driver variants provide SAUL capabilities and data-ready interrupt functionality. However, only the
vl53l1x_st_api
driver variant allows to use threshold interrupts.vl53l1x_basic
vl53l1x_std
(default)vl53l1x_st_api
[1] These functions are available by using the ST VL53L1X API directly.
[2] Reference platform: STM32F411RE
Testing procedure
The driver variants can be tested by using the test application with different modules where the standard variant
vl53l1x_std
is used by default:To use the other driver variants, module
vl53l1x_st_api
or modulevl53l1x_basic
have to be specified at make command line
or
If the configuration parameter
VL53L1X_PARAM_PIN_INT
is defined, e.g.,interrupts are used to get data instead of polling for new data. In the case of driver variant
vl53l1x_st_api
, threshold interrupts are configured.In all cases, the sensor is configured with following default parameters:
Issues/PRs references
Some weeks ago @dylad was providing a sensor driver for the Bosch BME680 gas sensor, see PR #9909. Since the calculations are quite complex, Bosch provides a ready-to-use API. Therefore, he and @aabadie decided that it would be better to add Bosch's BME680 API driver as package.
Since the ST VL53L1X is even more complex, I decided to try it in the same way. This PR is a try to structure a driver as a package.
See also PR #9909