Skip to content

drivers/sensors: Add QST QMI8658 6-axis IMU sensor driver - #17363

Merged
acassis merged 1 commit into
apache:masterfrom
no1wudi:lc
Nov 30, 2025
Merged

acassis merged 1 commit into
apache:masterfrom
no1wudi:lc

Conversation

@no1wudi

@no1wudi no1wudi commented Nov 22, 2025 •

Copy link
Copy Markdown
Contributor

Summary

  • Why change is necessary: Add comprehensive driver support for the QST QMI8658 6-axis IMU sensor to enable accelerometer and gyroscope functionality in NuttX-based embedded systems.
  • What functional part of the code is being changed: Added new sensor driver in drivers/sensors/ directory with both character device and uORB interface options, along with comprehensive documentation and board integration.
  • How does the change exactly work: The driver implements I2C communication with the QMI8658 sensor, providing:
    • Core I2C register access functions (qmi8658_base.c)
    • Character device interface with ioctl support (qmi8658.c)
    • uORB-based sensor interface for real-time applications (qmi8658_uorb.c)
    • Public API with register definitions and scale factors (qmi8658.h)
    • Complete documentation with usage examples
  • Related NuttX Issue reference: N/A (new feature addition)
  • Related NuttX Apps Issue / Pull Request reference: N/A

Impact

  • Is new feature added? Is existing feature changed?: YES - New QMI8658 6-axis IMU sensor driver added with dual interface support (character device and uORB)
  • Impact on user (will user need to adapt to change?): NO - This is an additive feature that doesn't affect existing functionality. Users can enable the driver via Kconfig options and use either character device (/dev/imu0) or uORB interface (/dev/uorb/sensor_accel0, /dev/uorb/sensor_gyro0)
  • Impact on build (will build process change?): YES - New Kconfig options added:
    • CONFIG_SENSORS_QMI8658: Enable driver support
    • CONFIG_SENSORS_QMI8658_UORB: Use uORB interface instead of character device
    • CONFIG_SENSORS_QMI8658_POLL: Enable polling mode with configurable interval
    • CONFIG_QMI8658_I2C_FREQUENCY: Set I2C communication frequency (default 400kHz)
  • Impact on hardware (will arch(s) / board(s) / driver(s) change?): YES - Added new sensor driver that supports any platform with I2C capability. No specific board changes included in this commit.
  • Impact on documentation (is update required / provided?): YES - Comprehensive documentation added:
    • Documentation/components/drivers/special/sensors/qmi8658.rst (311 lines)
    • Updated sensor framework documentation indices
    • Complete API reference with usage examples
  • Impact on security (any sort of implications?): NO - Driver follows standard NuttX sensor driver patterns with proper I2C communication and mutex protection
  • Impact on compatibility (backward/forward/interoperability?): NO - New driver doesn't affect existing sensor drivers or interfaces
  • Anything else to consider or add?: NO

Testing

I confirm that changes are verified on local setup and works as intended:

nsh> uname -a
NuttX 12.11.0 ae4cc6be5e-dirty Nov 22 2025 23:02:58 xtensa lckfb-szpi-esp32s3
nsh> qmi8658
QMI8658 Sensor Example
Reading 100 samples from /dev/imu0
[001] Accel: (0.002, 0.066, 0.994) g
        Gyro: (1.72, 1.93, -0.33) dps
        Temp: 21.48 °C
[002] Accel: (0.002, 0.066, 0.994) g
        Gyro: (1.72, 1.93, -0.33) dps
        Temp: 21.48 °C
[003] Accel: (0.001, 0.068, 1.000) g
        Gyro: (7.48, 2.98, 0.18) dps
        Temp: 21.19 °C
[004] Accel: (0.001, 0.065, 0.993) g
        Gyro: (1.36, 1.96, 0.09) dps
        Temp: 21.27 °C
[005] Accel: (0.003, 0.064, 0.999) g
        Gyro: (1.19, 1.98, -0.19) dps
        Temp: 21.27 °C
[006] Accel: (0.004, 0.067, 1.000) g
        Gyro: (1.61, 2.77, -0.24) dps
        Temp: 21.27 °C
[007] Accel: (0.004, 0.065, 0.999) g
        Gyro: (1.28, 1.82, -0.05) dps
        Temp: 21.32 °C

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Area: Sensors Sensors issues Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Nov 22, 2025

@linguini1 linguini1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread include/nuttx/sensors/qmi8658.h Resolved
Comment thread include/nuttx/sensors/qmi8658.h Resolved
Comment thread drivers/sensors/Kconfig Resolved
Comment thread drivers/sensors/Kconfig Resolved
Comment thread drivers/sensors/qmi8658_base.h Resolved
@linguini1

Copy link
Copy Markdown
Contributor

Also, if you have some sample code that you used for your example testing app, could you include it in the PR testing description?

@acassis

acassis commented Nov 22, 2025 •

Copy link
Copy Markdown
Contributor

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.

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

acassis
acassis previously approved these changes Nov 22, 2025
@linguini1

Copy link
Copy Markdown
Contributor

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 float dependency was fine.

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.

@acassis

acassis commented Nov 22, 2025

Copy link
Copy Markdown
Contributor

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 float dependency was fine.

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.

@acassis

acassis commented Nov 22, 2025

Copy link
Copy Markdown
Contributor

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 float dependency was fine.
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 or @raiden00pl has some suggestion how we could fix it to have sensors support on low end microcontrollers.

@acassis

acassis commented Nov 22, 2025

Copy link
Copy Markdown
Contributor

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.

@linguini1

Copy link
Copy Markdown
Contributor

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.

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.

@xiaoxiang781216

xiaoxiang781216 commented Nov 23, 2025 •

Copy link
Copy Markdown
Contributor

The major problem of legacy char driver is that userspace can't write the general code to handle the sensor in unified way. For example, we have the following accelerometer sensor legacy char driver:
https://github.com/apache/nuttx/blob/master/drivers/sensors/kxtj9.c
https://github.com/apache/nuttx/blob/master/drivers/sensors/lis2dh.c
https://github.com/apache/nuttx/blob/master/drivers/sensors/lis3dh.c
https://github.com/apache/nuttx/blob/master/drivers/sensors/lis3dsh.c
https://github.com/apache/nuttx/blob/master/drivers/sensors/mpu60x0.c
You have to write the different code to extract the real x/y/z accelerator from them:
https://github.com/apache/nuttx-apps/blob/master/examples/lis3dsh_reader/lis3dsh_reader_main.c#L67-L80
https://github.com/apache/nuttx-apps/blob/master/examples/sensor_fusion/sensor_fusion_main.c#L134-L163
Now, we add a new one into the list.

From the design point of view, the legacy char driver is no much difference that we acccess sensor hardware through i2c/spi directly.
So, whether using uORB is a minor issue comparing that the same type sensor expose the different driver interface.

@acassis

acassis commented Nov 23, 2025

Copy link
Copy Markdown
Contributor

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.

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.

@acassis

acassis commented Nov 23, 2025

Copy link
Copy Markdown
Contributor

The major problem of legacy char driver is that userspace can't write the general code to handle the sensor in unified way. For example, we have the following accelerometer sensor legacy char driver: https://github.com/apache/nuttx/blob/master/drivers/sensors/kxtj9.c https://github.com/apache/nuttx/blob/master/drivers/sensors/lis2dh.c https://github.com/apache/nuttx/blob/master/drivers/sensors/lis3dh.c https://github.com/apache/nuttx/blob/master/drivers/sensors/lis3dsh.c https://github.com/apache/nuttx/blob/master/drivers/sensors/mpu60x0.c You have to write the different code to extract the real x/y/z accelerator from them: https://github.com/apache/nuttx-apps/blob/master/examples/lis3dsh_reader/lis3dsh_reader_main.c#L67-L80 https://github.com/apache/nuttx-apps/blob/master/examples/sensor_fusion/sensor_fusion_main.c#L134-L163 Now, we add a new one into the list.

From the design point of view, the legacy char driver is no much difference that we acccess sensor hardware through i2c/spi directly. So, whether using uORB is a minor issue comparing that the same type sensor expose the different driver interface.

Yes, I think accelerometers and other char devices sensor need a standardization, this way we avoid creating different applications for each sensor.

acassis
acassis previously approved these changes Nov 23, 2025
@linguini1

Copy link
Copy Markdown
Contributor

Yes, I think accelerometers and other char devices sensor need a standardization, this way we avoid creating different applications for each sensor.

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.

@linguini1
linguini1 dismissed their stale review November 23, 2025 21:00

I do not want to block this PR further, but I still hold the following opinion:

  1. 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 uORB should be removed from the Kconfig. The only additional overhead is the float dependency, but I don't think that warrants an entire different interface for this contribution.

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

@acassis

acassis commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

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

@cederom

cederom commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

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.

@raiden00pl

Copy link
Copy Markdown
Member

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? :-)

doc already states that "uorb" approach is "the preferred way": https://nuttx.apache.org/docs/latest/components/drivers/special/sensors.html

@cederom

cederom commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

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? :-)

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? :-)

@raiden00pl

Copy link
Copy Markdown
Member

@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 problem with using float data can be solved as I mentioned here: #10644 (comment)
I'll take care of it one day if someone doesn't do it before me. Support for fixed-point sensor data is important because it allows the implementation of intelligent sensor nodes or sensor hubs on cheap MCUs like Cortex-M0 which don't have FPU.

@linguini1

linguini1 commented Nov 25, 2025 •

Copy link
Copy Markdown
Contributor

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.

@raiden00pl

Copy link
Copy Markdown
Member

agree with @linguini1
We should avoid the old approach to sensors and use only the new framework, otherwise we encourage users to use an approach that is not recommended and basically it's bad from the very beginning

@acassis

acassis commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

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.

@hartmannathan

Copy link
Copy Markdown
Contributor

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

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.

@cederom

cederom commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

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 :-)

@linguini1

Copy link
Copy Markdown
Contributor

@no1wudi it appears the consensus is that the legacy interface portion of this PR should be removed.

@no1wudi

no1wudi commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

@no1wudi it appears the consensus is that the legacy interface portion of this PR should be removed.

I'll remove it this weekend

acassis
acassis previously approved these changes Nov 29, 2025
@cederom

cederom commented Nov 29, 2025

Copy link
Copy Markdown
Contributor

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Area: Sensors Sensors issues Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants