-
Notifications
You must be signed in to change notification settings - Fork 7.4k
drivers: sensor: add nooploop tofsens ToF sensor #88494
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
base: main
Are you sure you want to change the base?
drivers: sensor: add nooploop tofsens ToF sensor #88494
Conversation
ad927aa
to
ff663fc
Compare
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.
Copilot reviewed 11 out of 21 changed files in this pull request and generated 1 comment.
Files not reviewed (10)
- drivers/sensor/CMakeLists.txt: Language not supported
- drivers/sensor/Kconfig: Language not supported
- drivers/sensor/nooploop/CMakeLists.txt: Language not supported
- drivers/sensor/nooploop/Kconfig: Language not supported
- drivers/sensor/nooploop/tofsense/CMakeLists.txt: Language not supported
- drivers/sensor/nooploop/tofsense/Kconfig: Language not supported
- samples/sensor/tofsense/CMakeLists.txt: Language not supported
- samples/sensor/tofsense/README.rst: Language not supported
- samples/sensor/tofsense/boards/nucleo_u575zi_q.overlay: Language not supported
- samples/sensor/tofsense/prj.conf: Language not supported
Comments suppressed due to low confidence (2)
drivers/sensor/nooploop/tofsense/tofsense.h:21
- [nitpick] The type name 'tosense_id_t' is inconsistent with the sensor's naming ('tofsense'). Consider renaming it to 'tofsense_id_t' for clarity.
typedef uint8_t tosense_id_t;
drivers/sensor/nooploop/tofsense/tofsense_uart.h:54
- [nitpick] Consider renaming 'tosense_id_t' to 'tofsense_id_t' to align with the sensor’s naming convention.
tosense_id_t id; /* Sensor ID */
samples/sensor/tofsense/src/main.c
Outdated
} | ||
|
||
ret = sensor_channel_get(dev, SENSOR_CHAN_DISTANCE, &value); | ||
printk("distance is %.3lld mm\n", sensor_value_to_milli(&value)); |
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 format specifier '%.3lld' is unconventional for an integer value. Consider using '%lld' for proper formatting.
printk("distance is %.3lld mm\n", sensor_value_to_milli(&value)); | |
printk("distance is %lld mm\n", sensor_value_to_milli(&value)); |
Copilot uses AI. Check for mistakes.
d785929
to
4fc5204
Compare
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.
Copilot reviewed 11 out of 21 changed files in this pull request and generated no comments.
Files not reviewed (10)
- drivers/sensor/CMakeLists.txt: Language not supported
- drivers/sensor/Kconfig: Language not supported
- drivers/sensor/nooploop/CMakeLists.txt: Language not supported
- drivers/sensor/nooploop/Kconfig: Language not supported
- drivers/sensor/nooploop/tofsense/CMakeLists.txt: Language not supported
- drivers/sensor/nooploop/tofsense/Kconfig: Language not supported
- samples/sensor/tofsense/CMakeLists.txt: Language not supported
- samples/sensor/tofsense/README.rst: Language not supported
- samples/sensor/tofsense/boards/nucleo_u575zi_q.overlay: Language not supported
- samples/sensor/tofsense/prj.conf: Language not supported
Comments suppressed due to low confidence (2)
samples/sensor/tofsense/src/main.c:31
- Verify that the return type of sensor_value_to_milli is a 64-bit integer. If it returns a different type, adjust the printf format specifier accordingly.
printk("distance is %.3lld mm\n", sensor_value_to_milli(&value));
drivers/sensor/nooploop/tofsense/tofsense_uart.h:44
- [nitpick] Consider renaming 'dummy1' to 'reserved' to improve code clarity and better indicate that these bits are unused.
uint8_t dummy1: 3;
4fc5204
to
b3ccc76
Compare
Récent force-push to fix Copilote remakes. |
3dc7198
to
3cc390a
Compare
- 0 # TOFSENSE_MODE_ACTIVE | ||
- 1 # TOFSENSE_MODE_QUERY | ||
|
||
enum: [0, 1] |
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.
enum: [0, 1] | |
enum: | |
- 0 | |
- 1 |
3cc390a
to
e0a6d66
Compare
bd5140f
to
03aa60e
Compare
|
||
LOG_MODULE_REGISTER(TOFSense, CONFIG_SENSOR_LOG_LEVEL); | ||
|
||
#ifdef CONFIG_TOFSENSE_BUS_UART |
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.
#ifdef CONFIG_TOFSENSE_BUS_UART |
For large-scale conditional compilation, the code may appear less clean.
You can refer to the approach used in the display/ssd1306.c
, where a union
is employed to encapsulate the device object.
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 did use union where it makes sense to have one structure to represent both bus, but I encapsulated into #ifdef functions that are specific to one. (ex UART flush/clear). For I2C and SPI there are probably more functions that can be unioned... Can you make a suggestion, maybe I don't see what you mean.
03aa60e
to
8a1b100
Compare
Fixed the CI compliance check and twister tests |
@kartben I would like to get more reviews, and I' don't know who to ask. This driver is the first of its kind with both It's working great, and this driver is quite popular in China. The full support of Noopoop lineup could be added easily from then. |
@AlexFabre You can refer to the review suggestions I proposed, as they appear not to have been addressed. |
Hi @rruuaanng sorry I had completely missed your comments... Thanks ! |
8a1b100
to
3bdacf2
Compare
menuconfig TOFSENSE | ||
bool "Nooploop TOFSense ToF sensor" | ||
default y | ||
depends on DT_HAS_NOOPLOOP_TOFSENSE_ENABLED | ||
help | ||
Enable UART/CAN-based driver for the Nooploop TOFSense, | ||
time of flight sensor. | ||
|
||
if TOFSENSE | ||
|
||
config TOFSENSE_BUS_UART | ||
bool "UART TOFSense driver" | ||
default y | ||
depends on $(dt_compat_on_bus,$(DT_COMPAT_NOOPLOOP_TOFSENSE),uart) | ||
depends on UART_INTERRUPT_DRIVEN | ||
select UART | ||
|
||
config TOFSENSE_BUS_CAN | ||
bool "CAN TOFSense driver" | ||
default y | ||
depends on $(dt_compat_any_has_prop,$(DT_COMPAT_NOOPLOOP_TOFSENSE),can-bus) | ||
depends on CAN |
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 isn't the only ToF sensor; need to namespace these Kconfig symbols to indicate it's the Nooploop sensor specifically.
It should also select the bus it needs, not depend on.
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.
TOFSENSE is the product name, and NoopLoop the manufacturer.
Do you suggest to rename the menuconfig entry to NOOPLOOP_TOFSENSE
?
In other sensor's Config, it's usually only the product name.
I took inspiration form this VL53 TOF from ST
default: 1 | ||
required: true |
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.
Need to explain in the description why the default value was selected
https://docs.zephyrproject.org/latest/build/dts/bindings-upstream.html#dt-bindings-default-rules
The property also isn't required if there's a default specified.
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 removed the default
entry, to force the user to input the configured id
value.
default: 0 | ||
required: true |
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.
Need to explain in the description why the default value was selected (not what the value is)
https://docs.zephyrproject.org/latest/build/dts/bindings-upstream.html#dt-bindings-default-rules
The property also isn't required if there's a default specified.
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 removed the default
entry, to force the user to input the configured mode of operation
value.
|
||
active-mode-frequency: | ||
type: int | ||
default: 30 |
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.
Ditto
default: 0 | ||
required: true |
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.
Need to explain in the description why the default value was selected
https://docs.zephyrproject.org/latest/build/dts/bindings-upstream.html#dt-bindings-default-rules
The property also isn't required if there's a default specified.
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 removed the default
entry, to force the user to input the configured id
value.
This sample uses the TOFSense sensor with its factory default settings, on the UART interface. | ||
|
||
References | ||
********** | ||
|
||
- Datasheet: https://ftp.nooploop.com/downloads/tofsense/TOFSense_Datasheet_V3.0_en.pdf | ||
- User manual: https://ftp.nooploop.com/downloads/tofsense/TOFSense_User_Manual_V3.0_en.pdf |
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.
Sensor samples should be agnostic to the specific driver implementation. It's ok to mention specific examples, but the README as currently written assumes the nooploop is the only type of ToF sensor.
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 don't see where I suggest that the TOFSense is the only type of TOF sensor.
It's only one of the NoopLoop products lineup.
I took inspiration from this VL53 TOF sample.
CONFIG_SENSOR=y | ||
CONFIG_UART_INTERRUPT_DRIVEN=y | ||
|
||
CONFIG_CAN=y |
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 can be removed if the driver selects CAN
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.
Thanks, removed
samples/sensor/tofsense/sample.yaml
Outdated
- uart | ||
tags: | ||
- sensors | ||
filter: dt_compat_enabled("nooploop,tofsense") |
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.
Use a generic dt alias 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.
Fixed
samples/sensor/tofsense/src/main.c
Outdated
|
||
int main(void) | ||
{ | ||
const struct device *const dev = DEVICE_DT_GET_ONE(nooploop_tofsense); |
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.
Use a generic dt alias instead of the nooploop compatible.
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.
Fixed
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.
Blocking until I have reviewed the CAN part.
This is not usually how the CAN bus is supposed to be used for integration in Zephyr.
This is similar to how other networking peripherals (e.g. Ethernet) work in Zephyr. |
3bdacf2
to
2882fe3
Compare
Nooploop TOFSense is a packaged TOF (Time of Flight) laser ranging sensor with a UART or CAN interface. It supports two modes of communication: - ACTIVE: The sensor actively output its measured distance at a maximum frequency of 30Hz. - QUERY: The user has to make a request to read the measured distance. It offers 1cm to 8m detection range, with as low as 1mm resolution, ± 1.5cm error, and supports 15 ° ~ 27 ° adjustable FOV. Signed-off-by: Alex Fabre <alex.fabre@rtone.fr>
Provide a demo of the Nooploop TOFSense sensor on a nucleo_u575zi_q board. Signed-off-by: Alex Fabre <alex.fabre@rtone.fr>
2882fe3
to
5f01dc9
Compare
Recent push are related to @MaureenHelm comments. |
|
@henrikbrixandersen do you still plan to make a review ? I'm waiting for it to open another PR for a CAN compatible device, relatively similar to this one on the CAN part. |
Description
Nooploop TOFSense is a TOF-based (Time of Flight) laser ranging sensor that offers UART and CAN communication.
It's quite common in university projects and some pre-industrial prototypes.
Nooploop is specialized in the development of sensor systems and solutions for navigation and positioning.
Official documentation:
Product descriptions:
Implementation remark
I took inspiration from the various sensors that offer two bus communication (most of the time it's SPI & I2C). But because CAN is not declared as a bus in zephyr's dts binding, I had to do differently to handle the bus detection and property handling.
I'm not so proud of it, and it would have been much easier and cleaner if CAN still had it's
bus: can
property incan-controller.yaml
and acan-device.yaml
removed with Zephyr 3.0.0 (#42934 (comment)).Also I provided a demo code for a nucleo board, but I'm not sure what is the common practice regarding samples. I let you tell me if the sample should be kept or should be dropped.