drivers/sensors: add SGP30 uORB driver #1

Open
mojito02 wants to merge 1 commits from mojito02/nuttx:sgp30-uorb-driver into dev
First-time contributor

Changes

 drivers/sensors/sgp30_uorb.c   | new file (617 lines)
 drivers/sensors/sgp30.c        | +50   (add sgp30_measure_for_service)
 include/nuttx/sensors/sgp30.h  | +52   (quality enum, snapshot struct, decls)
 drivers/sensors/Kconfig        | +19   (SENSORS_SGP30_UORB and friends)
 drivers/sensors/Make.defs      | +4
 drivers/sensors/CMakeLists.txt | +6/-1

All changes to existing files are pure additions; no existing function is
modified or removed, so current users of the character-device driver are
unaffected.

Summary

Add a uORB-based driver for the Sensirion SGP30 air quality sensor
(CO2eq / TVOC), complementing the existing character-device driver
(sgp30.c).

The existing sgp30.c exposes the SGP30 through a POSIX character
device. This patch adds sgp30_uorb.c, which registers the sensor with
the uORB sensor framework (SENSOR_TYPE_CO2 and SENSOR_TYPE_TVOC).

The two interfaces are mutually exclusive and selected by
CONFIG_SENSORS_SGP30_UORB, following the same pattern already used by
the BMP180 driver (bmp180.c / bmp180_uorb.c).

Why

The SGP30 differs from most environmental sensors in that it requires a
sustained 1 Hz measurement cadence to maintain its internal baseline
compensation. A character device that only measures inside read()
cannot guarantee that cadence, so readings degrade when the application
polls irregularly.

This driver runs a dedicated sampling thread at a configurable interval
(CONFIG_SENSORS_SGP30_POLL_INTERVAL, default 1 s) and publishes to
uORB, so any number of consumers can subscribe without affecting the
sensor's timing requirements.

Implementation notes

  • Two uORB lower halves are registered: SENSOR_TYPE_CO2 and
    SENSOR_TYPE_TVOC
  • A sampling thread keeps the required 1 Hz cadence independently of
    consumers
  • Readings are exposed through a snapshot structure carrying a quality
    state (warming up / valid / saturated / stale / I/O error), so
    consumers can distinguish "sensor still warming up" from "sensor
    failed"
  • Consecutive I/O failures beyond a threshold trigger a re-initialisation
    of the sensor rather than leaving it permanently stuck

Testing

Tested on an Allwinner R528 board with an SGP30 on I2C (address 0x58):

  • Both uORB topics publish at the expected 1 Hz cadence
  • Values validated against the datasheet ranges
  • Warm-up → valid state transition observed on cold start

Notes

The driver contains no platform-specific code; it depends only on
standard NuttX interfaces (i2c_master, sensors/sensor.h, kthread,
mutex). The existing character-device driver and its Kconfig options
are left unchanged, so current users are unaffected.

合并请求描述

[简要描述本次合并请求的目的和主要内容]

相关Issue

关联Issue编号:#{Issue编号}

变更内容

1. 增强了xxx

## Changes ``` drivers/sensors/sgp30_uorb.c | new file (617 lines) drivers/sensors/sgp30.c | +50 (add sgp30_measure_for_service) include/nuttx/sensors/sgp30.h | +52 (quality enum, snapshot struct, decls) drivers/sensors/Kconfig | +19 (SENSORS_SGP30_UORB and friends) drivers/sensors/Make.defs | +4 drivers/sensors/CMakeLists.txt | +6/-1 ``` All changes to existing files are **pure additions**; no existing function is modified or removed, so current users of the character-device driver are unaffected. ## Summary Add a uORB-based driver for the Sensirion SGP30 air quality sensor (CO2eq / TVOC), complementing the existing character-device driver (`sgp30.c`). The existing `sgp30.c` exposes the SGP30 through a POSIX character device. This patch adds `sgp30_uorb.c`, which registers the sensor with the uORB sensor framework (`SENSOR_TYPE_CO2` and `SENSOR_TYPE_TVOC`). The two interfaces are mutually exclusive and selected by `CONFIG_SENSORS_SGP30_UORB`, following the same pattern already used by the BMP180 driver (`bmp180.c` / `bmp180_uorb.c`). ## Why The SGP30 differs from most environmental sensors in that it requires a sustained 1 Hz measurement cadence to maintain its internal baseline compensation. A character device that only measures inside `read()` cannot guarantee that cadence, so readings degrade when the application polls irregularly. This driver runs a dedicated sampling thread at a configurable interval (`CONFIG_SENSORS_SGP30_POLL_INTERVAL`, default 1 s) and publishes to uORB, so any number of consumers can subscribe without affecting the sensor's timing requirements. ## Implementation notes - Two uORB lower halves are registered: `SENSOR_TYPE_CO2` and `SENSOR_TYPE_TVOC` - A sampling thread keeps the required 1 Hz cadence independently of consumers - Readings are exposed through a snapshot structure carrying a quality state (warming up / valid / saturated / stale / I/O error), so consumers can distinguish "sensor still warming up" from "sensor failed" - Consecutive I/O failures beyond a threshold trigger a re-initialisation of the sensor rather than leaving it permanently stuck ## Testing Tested on an Allwinner R528 board with an SGP30 on I2C (address 0x58): - Both uORB topics publish at the expected 1 Hz cadence - Values validated against the datasheet ranges - Warm-up → valid state transition observed on cold start ## Notes The driver contains no platform-specific code; it depends only on standard NuttX interfaces (`i2c_master`, `sensors/sensor.h`, `kthread`, `mutex`). The existing character-device driver and its Kconfig options are left unchanged, so current users are unaffected. ## 合并请求描述 [简要描述本次合并请求的目的和主要内容] ## 相关Issue 关联Issue编号:#{Issue编号} ## 变更内容 ### 1. 增强了xxx
mojito02 added 1 commit 2026-07-29 13:06:28 +08:00
875440afd8 drivers/sensors: add SGP30 uORB driver
Signed-off-by: mojito02 <1786365650@qq.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b mojito02-sgp30-uorb-driver dev
git pull sgp30-uorb-driver

Step 2:

Merge the changes and update on Gitea.
git checkout dev
git merge --no-ff mojito02-sgp30-uorb-driver
git push origin dev
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: openvela/nuttx#1
No description provided.