Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlexFabre
Copy link
Contributor

@AlexFabre AlexFabre commented Apr 11, 2025

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 in can-controller.yaml and a can-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.

Copy link

@Copilot Copilot AI left a 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 */

}

ret = sensor_channel_get(dev, SENSOR_CHAN_DISTANCE, &value);
printk("distance is %.3lld mm\n", sensor_value_to_milli(&value));
Copy link
Preview

Copilot AI Apr 11, 2025

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.

Suggested change
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.

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch 2 times, most recently from d785929 to 4fc5204 Compare April 11, 2025 11:55
@kartben kartben requested a review from Copilot April 11, 2025 12:11
Copy link

@Copilot Copilot AI left a 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;

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch from 4fc5204 to b3ccc76 Compare April 12, 2025 07:52
@AlexFabre
Copy link
Contributor Author

Récent force-push to fix Copilote remakes.

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch 2 times, most recently from 3dc7198 to 3cc390a Compare April 14, 2025 08:27
@decsny decsny removed their request for review April 14, 2025 17:00
- 0 # TOFSENSE_MODE_ACTIVE
- 1 # TOFSENSE_MODE_QUERY

enum: [0, 1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enum: [0, 1]
enum:
- 0
- 1

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch from 3cc390a to e0a6d66 Compare April 15, 2025 14:35
@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch 3 times, most recently from bd5140f to 03aa60e Compare May 5, 2025 09:08

LOG_MODULE_REGISTER(TOFSense, CONFIG_SENSOR_LOG_LEVEL);

#ifdef CONFIG_TOFSENSE_BUS_UART
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#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.

Copy link
Contributor Author

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.

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch from 03aa60e to 8a1b100 Compare May 5, 2025 15:28
@AlexFabre
Copy link
Contributor Author

Fixed the CI compliance check and twister tests

@AlexFabre
Copy link
Contributor Author

AlexFabre commented May 6, 2025

@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 UART and CAN support.
As CAN has lost its bus: can property in Zephyr 3, I had to trick to get the bus it's instanced on.

It's working great, and this driver is quite popular in China. The full support of Noopoop lineup could be added easily from then.

@rruuaanng
Copy link
Collaborator

@AlexFabre You can refer to the review suggestions I proposed, as they appear not to have been addressed.

@AlexFabre
Copy link
Contributor Author

Hi @rruuaanng sorry I had completely missed your comments... Thanks !

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch from 8a1b100 to 3bdacf2 Compare May 9, 2025 08:30
Comment on lines 6 to 27
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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines +16 to +22
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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, removed

- uart
tags:
- sensors
filter: dt_compat_enabled("nooploop,tofsense")
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


int main(void)
{
const struct device *const dev = DEVICE_DT_GET_ONE(nooploop_tofsense);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a 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.

@henrikbrixandersen
Copy link
Member

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 in can-controller.yaml and a can-device.yaml removed with Zephyr 3.0.0 (#42934 (comment)).

This is similar to how other networking peripherals (e.g. Ethernet) work in Zephyr.

@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch from 3bdacf2 to 2882fe3 Compare May 12, 2025 15:21
AlexFabre added 2 commits May 13, 2025 15:25
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>
@AlexFabre AlexFabre force-pushed the drivers-sensor-nooploop-add-tofsens-sensor branch from 2882fe3 to 5f01dc9 Compare May 13, 2025 13:48
@AlexFabre
Copy link
Contributor Author

Recent push are related to @MaureenHelm comments.

Copy link

@AlexFabre
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants