Repository navigation
drivers/sensors: Add QST QMI8658 6-axis IMU sensor driver - #17363
Conversation
linguini1
left a comment
There was a problem hiding this comment.
This is a nicely formatted PR with a good description, testing and well-written documentation! Nice job!
I think the uORB addition seems fine, but I don't approve of merging this PR with the legacy sensor interface. I think this driver should be uORB-based only.
NuttX is moving to just the uORB interface for sensors. Having multiple interfaces is confusing to users, difficult to maintain and adds more complexity. The way it's implemented in this PR adds many functions as part of the public namespace where they are traditionally private (static) in other driver implementations. It gives users access to device struct contents and register definitions.
Is there a specific use case for the legacy sensor interface? If not, I suggest you move everything from qmi8658_base.c to qmi8658_uorb.c and remove all logic relating to the legacy sensor interface. The only public API for your sensor should be the register function, and possibly a few types if necessary for interacting with the sensor. Everything else should be done through existing uORB APIs/ioctl.
|
Also, if you have some sample code that you used for your example testing app, could you include it in the PR testing description? |
@linguini1 I think char device sensor still important on NuttX because for boards with low resource adding uORB will be too much. This is the same relation with CAN char device and SocketCAN, both implementations should exist to live together peacefully. |
Honestly I disagree. The requirement going forward for all sensor drivers was that they must support uORB, so we have a few drivers already that are uORB capable but do not have a legacy-style version, since most people do not want to do double the work. We definitely can't require people to submit both styles, so I don't think we should be supporting additional legacy drivers unless there's a use-case for them. I think supporting both versions is confusing to users and makes maintenance difficult. I also don't think uORB is that resource-intensive besides the floating point requirement, but it was decided when uORB became a requirement that the If the community still wants to support legacy sensor drivers in addition to uORB that's fine, I will yield, but the drivers will be perpetually out of sync which I think is a problem. Regardless, I still think the implementation in this PR needs changes if both styles are to be kept, since it currently requires shared header and C files that expose private parts of the API which are not exposed in any other sensor drivers on NuttX. |
Yes, I agree that it could generate some drivers only supporting one or other implementation. Same also happens with CAN. It should be nice if uORB was just a wrapper around the char device, this way we could avoid this issue. But I don't know if it is possible. Maybe @xiaoxiang781216 has some suggestion. |
|
|
Ok, I create an issue to let discuss about the possibility to create uORB drivers as a wrap around character drivers. But looking bmi088.c and bmi088_uorb.c as example, I think there is not a simple connection between them, so we will need to find a creative solution for this issue. |
It's currently possible to interact with uORB drivers as though they are character drivers, so I think that approach can be taken. Wrapping character drivers causes more overhead in systems that use uORB. I think the biggest issue with it resource-wise is using floating point numbers, I'm not sure there are really any cases where a small MCU can't run uORB because of its size? It's possible to reduce the buffering it does, although maybe I'm misinformed on all the resources it uses. |
Yes, I think using floating point numbers should be an issue for small MCUs that doesn't have float point support, they will require some functions normally provided by the toolchain library to do math operations. I remember when reducing the size code of NuttX that this operations were some of biggest in the final binary. |
That's the thing, uORB is for exactly that. I think maybe the biggest issue here is allowing users to avoid float usage with uORB. Maybe we can work on that. |
I do not want to block this PR further, but I still hold the following opinion:
-
This PR should not come with the separate character driver interface. As discussed in #17363, the "uORB" version can still be used as a character driver without needing the additional uORB framework overhead. This method is just the new sensor framework, which I've been incorrectly referring to as uORB. In this case,
depends on uORBshould be removed from the Kconfig. The only additional overhead is thefloatdependency, but I don't think that warrants an entire different interface for this contribution. -
This approach publicly exposes a number of functions in the "base" C file, which is an approach that is not taken in other drivers. Typically these functions are static so as to not clutter the namespace. I think that should be considered here by other reviewers.
|
@linguini1 since we don't have a definition how to use uORB sensor drivers only as char dev driver (not fixed point implementation, no CONFIG_SENSOR_UORB to disable not needed parts of the driver), I suggest merging it. Other drivers also implement the base.c idea, normally it is done to isolate I2C, SPI specific functions from the logic driver (please look drivers/sensors/bmi088* for reference). I think the only drawback here is because he didn't implemented the SPI support, but not a big issue. We will need to remove the legacy drivers in the future, so I don't see an issue remove the char device driver from this PR in the future. At least now we will have it available for anyone willing to test/use this sensor. Just my 2 cents! |
|
Okay I have read all of the above comments, thank you folks, looks like we are going uORB as default right? Maybe we should state that explicitly in the documentation about sensors? :-) Regarding the floating point problem, when calculations are not important, for representation only two integers can be used one for integral and other for decimal (i.e. X.Y)? Also depending on the underlying hardware I heard that double may be faster than floating point especially when emulated? Is float type required by uORB or you mean just "floating point" as either float or double or two integers can be used? I did not play with uORB yet sorry :-P We can accept both drivers as @acassis but as @linguini1 mentioned this char driver needs to be fixed first to align with other existing char drivers. |
doc already states that "uorb" approach is "the preferred way": https://nuttx.apache.org/docs/latest/components/drivers/special/sensors.html |
Thanks @raiden00pl :-) I guess we should go the uORB way? Its already done and no remarks to that part right? :-) |
|
@cederom Yes, "uORB" framework is the way to go. We just need a better name for it, because uORB is actually completely optional part for this new sensor framework :) |
|
The reason I'm not explicitly approving this PR is because I still hold the belief that there does not need to be two different interfaces. I don't think we should merge both just to remove the legacy version later. The "uORB" version, as raiden pointed out, does not actually need uORB to work and can be used as a character driver in the unified sensor framework anyways. I don't think there's a justification to merge both just because of int vs float performance, in my opinion. We can fix that at a framework level with fixed point math (sooner rather than later would be good, I might take a look at it). TLDR; while I think the "uORB" portion of this PR looks fine, even if this base.c approach is taken by other drivers, I do not think we should merge the legacy interface because it creates more maintenance work especially if we're just going to remove it later. However, I won't block this PR from merging. |
|
agree with @linguini1 |
|
Ok, I agree, but we need to fix the existing uORB drivers to not have all uORB features when users want to use char device only. |
Regarding single-precision float vs double-precision double vs fixed-point of various types: Performance (speed) really depends on the platform. A microcontroller that has hardware 32-bit (single-precision) float but not hardware 64-bit (double-precision) will probably calculate single-precision much faster than double-precision, because the double would be emulated in software. I think what you're talking about (double being faster) might have something to do with C's argument promotion rules, where a float variable would be implicitly converted to double when calling functions, leading to more code and slower execution for float. Another issue to pay attention to is that double does not always mean double. Sometimes (depending on compiler options and the provided math library) double is actually single. That is, you write double in the code and it silently becomes single in reality. That can take you by surprise if you're not aware of it. Yet another issue to be aware of is that not all floating point units are IEEE754 compliant and floating point implementations (hardware and software) can differ in their precision. I've been bitten by this before. Fixed point comes in many different varieties: you have to choose the range of the whole and fraction parts according to how you'll use the variable but the advantage is that between any two consecutive numbers the fractional resolution is consistent. I don't know whether any of our supported archs have fixed point implementations in hardware. |
|
Thanks @hartmannathan :-) Please take a look at #10644 @raiden00pl created a dedicated issue for this general problem your input will be very valuable over there :-) |
|
@no1wudi it appears the consensus is that the legacy interface portion of this PR should be removed. |
I'll remove it this weekend |
|
Thank you @no1wudi for the updates! :-) |
Add complete driver support for the QST QMI8658 6-axis IMU sensor featuring 3-axis accelerometer and 3-axis gyroscope with I2C interface and uORB integration. Key features implemented: * Full I2C communication with configurable frequency (default 400kHz) * Multiple accelerometer ranges (±2g, ±4g, ±8g, ±16g) and ODR settings * Multiple gyroscope ranges (±16 to ±1024 dps) with high ODR support * Low-pass filter configuration for both sensors * Temperature sensing with 16-bit resolution * Self-test capability for both accelerometer and gyroscope * Calibration-on-demand support with offset registers * FIFO buffer management (framework ready) * Interrupt-driven and polling mode support * Complete uORB integration with sensor_accel and sensor_gyro topics Driver components added: * Core driver implementation (qmi8658_uorb.c) with register operations * Header file with register definitions and scale factors (qmi8658.h) * Kconfig options for driver configuration and polling mode * Build system integration (CMakeLists.txt, Make.defs) * Comprehensive documentation with API reference and usage examples The driver follows NuttX sensor framework conventions and provides robust error handling, mutex protection, and comprehensive debugging support through CONFIG_DEBUG_SENSORS. Signed-off-by: Huang Qi <[email protected]>
Summary
drivers/sensors/directory with both character device and uORB interface options, along with comprehensive documentation and board integration.qmi8658_base.c)qmi8658.c)qmi8658_uorb.c)qmi8658.h)Impact
/dev/imu0) or uORB interface (/dev/uorb/sensor_accel0,/dev/uorb/sensor_gyro0)CONFIG_SENSORS_QMI8658: Enable driver supportCONFIG_SENSORS_QMI8658_UORB: Use uORB interface instead of character deviceCONFIG_SENSORS_QMI8658_POLL: Enable polling mode with configurable intervalCONFIG_QMI8658_I2C_FREQUENCY: Set I2C communication frequency (default 400kHz)Documentation/components/drivers/special/sensors/qmi8658.rst(311 lines)Testing
I confirm that changes are verified on local setup and works as intended: