Commit graph zephyr/drivers/sensor
Author SHA1 Message Date
Gobi M
cd2c862c85 drivers: sensor: bme280: return error on pressure compensation failure
Avoid silently reporting an invalid pressure value when pressure
compensation encounters a division-by-zero condition.

Use the existing return value 0 from bme280_compensate_press() to
detect a compensation failure in bme280_sample_fetch_helper(), Log an
error, and return -EIO instead of storing an invalid pressure reading.

This ensures callers to receive an appropriate error when pressure
compensation cannot be completed successfully.

Signed-off-by: Gobi M <gobi@aerlync.com>
2026-07-13 16:17:05 -05:00
Mathieu Choplain
23c84fa1ef drivers: *: stm32: replace COND_CODE_1() chains with COND_CASE_1()
The COND_CASE_1() allows writing chained/nested COND_CODE_1() checks in
a simpler way. Replace such patterns in the STM32 drivers with this new
utility macro.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-12 20:02:10 -04:00
Ryan McClelland
ff07e42fba drivers: sensor: bmi08x: gyro: fix timestamps in FIFO stream
Add gyro_odr to the encoded header so the decoder knows the sample
rate. Fix base_timestamp_ns to reflect the time of the first FIFO
sample (trigger_time - (N-1)*period) and add timestamp_delta per
sample, matching the lsm6dsv16x reference implementation.

Fixes: #98720
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
(cherry picked from commit 396a5615ee758c156fc340b3e2a496b6d1590ffc)
2026-07-07 17:41:40 -04:00
Ryan McClelland
b458174118 drivers: sensor: bmi08x: accel: fix timestamps in FIFO stream
Add accel_odr to the encoded header so the decoder knows the sample
rate. Fix base_timestamp_ns to reflect the time of the first FIFO
sample (trigger_time - (N-1)*period) and add timestamp_delta per
sample, matching the lsm6dsv16x reference implementation.

Fixes: #98720
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
(cherry picked from commit 674f1aff9143bbd8191eff4844fd5d84c938e421)
2026-07-07 17:41:40 -04:00
Ryan McClelland
78f1218532 drivers: sensor: adxl372: fix base_timestamp_ns to first sample time
Adjust base_timestamp_ns backward from the trigger timestamp by
(N-1)*period so it reflects the time of the first FIFO sample,
matching the lsm6dsv16x reference implementation.

Fixes: #98720
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
(cherry picked from commit 6fa8569d5ded7c6a2578ea3b30a5033861224497)
2026-07-07 17:41:31 -04:00
Ryan McClelland
6547604b18 drivers: sensor: adxl355: fix base_timestamp_ns to first sample time
Adjust base_timestamp_ns backward from the trigger timestamp by
(N-1)*period so it reflects the time of the first FIFO sample,
matching the lsm6dsv16x reference implementation.

Fixes: #98720
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
(cherry picked from commit beb67e32e8e91250ec1ed877c89e4b140fd95673)
2026-07-07 17:41:20 -04:00
Ryan McClelland
576586e9fa drivers: sensor: adxl345: fix base_timestamp_ns to first sample time
Adjust base_timestamp_ns backward from the trigger timestamp by
(N-1)*period so it reflects the time of the first FIFO sample,
matching the lsm6dsv16x reference implementation.

Fixes: #98720
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
(cherry picked from commit 31e23771424d99a99392a94ae459be836d91dc3c)
2026-07-07 17:41:12 -04:00
Ryan McClelland
1f4adc265c drivers: sensor: bma4xx: fix base_timestamp_ns to first sample time
Record base_timestamp_ns as the time of the first sample in the FIFO
by adjusting backward from the trigger timestamp using the total frame
count and ODR period, matching the lsm6dsv16x reference implementation.

Fixes: #98720
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
(cherry picked from commit 36386844a6a0da009cca6bc730034f849e4b9dcf)
2026-07-07 17:41:04 -04:00
Matthias Alleman
c37125204c drivers: sensor: lis2dh: Add down event int to any motion configuration
Lis2dh interrupts were only fired for up events. Fixed it by adding
down event enable bits to the ANYM_CFG.

Signed-off-by: Matthias Alleman <matthias.alleman@basalte.be>
2026-07-06 11:29:30 -04:00
Mathieu Choplain
4175bed67f drivers: sensor: st: stm32_vbat: add broader VDDCORE support
Extend the VBAT driver to support VDDCORE channel on more STM32 series:
- STM32H7R/S
- STM32MP2
- STM32N6
- STM32U3

This is achieved by using different LL APIs which seem more portable
(with the exception of STM32H5 series on which they are not available!)

Adding actual DTSI nodes for the sensors will be done in other commits.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-07-03 13:58:15 -04:00
Felix Wang
a961b551c5 drivers: sensor: nxp: add MCUX eQDC driver
Add a sensor driver for the NXP MCUX Enhanced Quadrature Decoder (EQDC)
using the fsl_eqdc HAL. The PHASEA/PHASEB decoder inputs are routed
through the on-chip INPUTMUX, described by an "inputmux-connections"
phandle-array following the nxp,inputmux convention.

The driver exposes SENSOR_CHAN_ROTATION, SENSOR_CHAN_RPM,
SENSOR_CHAN_ENCODER_COUNT and SENSOR_CHAN_ENCODER_REVOLUTIONS; the last
channel is added to the sensor API. Velocity uses the EQDC period
measurement (POSDH/POSDPERH), so a prescaler keeps the 16-bit period
counter from saturating at the sample rate.

A single-phase-mode property selects single-phase decode (one count per
PHASEA pulse, with the direction taken from PHASEB) instead of the
default quadrature X4 decoding, with the counts-per-revolution scaling
adjusted accordingly.

Co-authored-by: bnina-ayoub <ouba.bnina@gmail.com>
Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2026-07-03 10:05:43 +02:00
Tomas Groth Christensen
bfdbdae877 driver: sensor: maxim: Add support for Max31826 temperature sensor
Based on the DS18B20 driver. Only the temperature sensor functionality is
exposed by this driver, not eeprom access nor parasite power configuration.

Signed-off-by: Tomas Groth Christensen <tgc@foss.dk>
2026-07-02 21:32:05 -04:00
Nicolas Belin
e9f4c9c95f drivers: sensor: flow_meter: add initial driver
Add Hall-effect pulse-output flow meter driver. An ISR increments a
64-bit pulse counter implemented as two 32-bit atomics (low word and
high word) with wraparound detection.

Volume thresholds are stored as a snapshot of the low pulse counter at
arm time plus a delta in pulses. The ISR fires when the unsigned 32-bit
difference (current - snapshot) reaches the delta, which is inherently
wraparound-safe. Sub-pulse thresholds are clamped to one pulse. The
threshold trigger is one-shot: it disarms on firing or when a NULL
handler is registered. Work is deferred to the system workqueue to avoid
running the handler in ISR context.

SENSOR_CHAN_VOLUME reports accumulated volume in liters since boot.
SENSOR_CHAN_FLOW_RATE reports instantaneous flow in L/min, computed at
sample_fetch time from the delta pulse count and elapsed time since the
previous fetch. SENSOR_ATTR_CALIBRATION provides a runtime override for
the pulses-per-liter calibration value. An optional power GPIO can be
asserted at init to enable the sensor module.

Signed-off-by: Nicolas Belin <nbelin@baylibre.com>
2026-07-02 12:58:57 -04:00
Nicolas Belin
ea25f77271 include: drivers: sensor: add SENSOR_CHAN_VOLUME channel
Add SENSOR_CHAN_VOLUME for sensors that report accumulated flow volume in
liters.

Signed-off-by: Nicolas Belin <nbelin@baylibre.com>
2026-07-02 12:58:57 -04:00
Jordan Yates
5b4b30456c sensor: st: lps22hh: one-shot mode unless CONFIG_LPS22HH_TRIGGER
Transition the driver over to one-shot operation by default unless
`CONFIG_LPS22HH_TRIGGER` is enabled to actually make use of periodic
measurements. By using one-shot mode and polling on the status register,
this fixes the following code flow, which is currently broken due to
no periodic samples being available immediately after resuming.
```
pm_device_runtime_get(dev);
sensor_sample_fetch(dev);
sensor_channel_get(dev, ...);
pm_device_runtime_put(dev);
```

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-07-01 14:31:41 -04:00
Etienne Carriere
b0b25c35c9 drivers: use <> to include Zephyr headers instead of ""
Use <> operator to include a Zephyr header file instead of "" that
is intended to local header files, not header files relative to
specifically defined search paths.

This change was made running the sed shell command below:
$ sed -i -E 's/#include "zephyr\/([^"]+)\.h"/#include <zephyr\/\1.h>/g' \
    `grep -rsl "#include \"zephyr/" drivers/`

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2026-06-30 06:49:18 -04:00
Michael Zimmermann
e10af22991 tree-wide: replace usages of k_work_q thread with thread_id
The `thread` field is not initialized, if it's being animated via
k_work_queue_run instead of k_work_queue_start.

Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
2026-06-29 22:17:45 -04:00
Noah Luskey
0c7a90ce4c drivers: sensor: ti: ina2xx: fix INA228 SHUNT_CAL integer truncation
INA228_DRIVER_INIT sets CAL with
`.cal = (INA237_DT_CAL(inst) * 16)`, where INA237_DT_CAL ends in
`/ 10000000ULL`. C operator precedence runs the divide before the
*16, so the truncation residual gets amplified 16x — and for small
current_lsb * rshunt products (e.g. 191 nA LSB, 5 mOhm shunt) the
numerator is below 1e10 and CAL collapses to 0, leaving the CURRENT
register stuck at zero (datasheet section 8.1.2).

Replace both CAL macros with a single parameterized
INA2XX_DT_CAL(inst, scaling) so the *16 (folded into
INA228_CAL_SCALING) happens inside the product, and the divide is the
last operation. INA237 path is functionally unchanged.

Signed-off-by: Noah Luskey <luskey@meta.com>
2026-06-23 08:35:58 +02:00
Jan Carlo Roleda
5e610f91f0 tests: drivers: sensor: Add ADT7420 Emulated Driver Tests
Adds Driver emulation tests to validate configuration,
data fetching and temperature edge case checks.

Signed-off-by: Jan Carlo Roleda <jancarlo.roleda@analog.com>
2026-06-22 20:31:12 -04:00
Jan Carlo Roleda
f62e280b20 drivers: sensor: adi: Fix ADT7420 negative temperature decoding
Fixes a computation issue that causes negative temperature values
to be erroneously parsed from the device driver.

Signed-off-by: Jan Carlo Roleda <jancarlo.roleda@analog.com>
2026-06-22 20:31:12 -04:00
Anas Nashif
ea1fbf3588 driver: fix various typos
Fixed various typos under drivers/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-17 10:12:27 -04:00
Jilay Pandya
b70f8bf048 drivers: max30101 replace a bunch of BUILD_ASSERTs
use min-len/max-len for asserting the correct length of the
array, drop corresponding build asserts

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-17 08:02:10 +02:00
Armando Visconti
2b61140427 drivers: sensors: st: fix shub using 8-bit i2c_addr
Init the sensorhub targets using 8-bit i2c_addr for those drivers
when their STMEMSC API requires it.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2026-06-16 23:15:38 +02:00
Albert Jakieła
2c497f5705 sensor: pac194x: add support for individual channel fetch
Previously, the `pac194x_sample_fetch` function would always read data
from all enabled physical channels over the I2C bus, regardless of which
specific sensor channel was actually requested by the caller. This commit
updates the fetch routine to respect the requested channel.

Signed-off-by: Albert Jakieła <jakiela@google.com>
2026-06-13 08:34:26 +02:00
Albert Jakieła
fa95c398aa sensor: pac194x: Add microchip,refresh-mode property
Add microchip,refresh-mode property to Mictochip PAC194X/195X.
This property allows configuring the sensor's refresh behavior
directly from the devicetree.

Signed-off-by: Albert Jakieła <jakiela@google.com>
2026-06-13 08:34:26 +02:00
Alban Chauvel
0e987ec1ef drivers: sensor: max30101: limit slot values in Multi-LED mode
In Multi-LED mode, nothing prevents sending an incorrect slot to the chip.
One could unintentionally send a "reserved" slot code, which could result
in unexpected behavior. Values must be between 0 (time slot disabled)
and 3 (Green LED channel). For the MAX30102, the max value should be 2.
This fix limits the sensor binding using min/max properties and simplifies
the translate map generation by testing if the time slot is not disabled.

Signed-off-by: Alban Chauvel <a.chauvel@catie.fr>
2026-06-11 15:02:39 -04:00
Alban Chauvel
7f416f74cc drivers: sensor: max30101: fix slot handling in Multi-LED mode
The MAX30101 sensor driver does not correctly support the Multi-LED mode.
If a user sets four LEDs in the "led-slot" binding property, the fourth
measurement in the FIFO will be lost. Fix it by separating the number
of slots available in each FIFO sample (four) from the number of LED
channels available (three for the MAX30101, two for the MAX30102).

Signed-off-by: Alban Chauvel <a.chauvel@catie.fr>
2026-06-11 15:02:39 -04:00
Fabrice DJIATSA
079748ab9c drivers: sensor: st: add GPIO Kconfig selection for some sensors
Add conditional GPIO selects for ST sensor drivers when their
bindings expose *-gpios properties, including properties inherited
from included common binding files.
This aligns Kconfig GPIO dependencies with devicetree binding data.

Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
2026-06-08 19:00:53 +02:00
Benjamin Cabé
3353896942 drivers: sensor: apds9960: move register definitions to private header
Drop all the symbols that were incorrectly part of the public header
and move them to a driver-internal header.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-06-03 08:27:19 +02:00
Dan Mangum
7daea21650 drivers: sensor: ntc_thermistor: make tdk ntcg generic
Uses generic nomenclature for TDK ntcg series NTC thermistors, which use a
naming scheme that indicates their resistance (R25) and beta (B25/85)
values. Compensation tables are identical for parts with the same
resistance and beta values.

Signed-off-by: Dan Mangum <georgedanielmangum@gmail.com>
2026-06-02 20:19:47 -04:00
Camille BAUD
16b8db7fbf drivers: bflb: Convert EFUSEs to OTP
Use new OTP API instead of syscon

Signed-off-by: Camille BAUD <mail@massdriver.space>
2026-06-02 20:19:36 -04:00
Jilay Pandya
6bf48124db drivers: pixart,pat9136 use min/max
use min/max for resolution in range [0,199]
drop the corresponding BUILD_ASSERT

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
Jilay Pandya
242e4d6a70 drivers: nxp,mcux-qdc use min/max
use min/max instead of BUILD_ASSERT for counts-per-revolution
and filter-sample-period

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
Jilay Pandya
d2a8f1ea09 drivers: brcm,afbr-s50 use min for odr
use min in odr and drop corresponding BUILD_ASSERT

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
Jilay Pandya
d095fe0f8b drivers: bosch,bmp581 use min/max
replace BUILD_ASSERT for fifo-watermark with min/max in bindings
replace all enums with min/max with their corresponding ranges

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
Jilay Pandya
d691521415 drivers: bosch,bmi08x use min/max
use min/max for fifo-watermark in bosch,bmi08x-gyro.yaml
and bosch,bmi08x-accel.yaml
drop BUILD_ASSERT in bmi08x_gyro.c

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
Jilay Pandya
ec317572a3 drivers: adi,adxl355 use min/max instead of valid range
use min/max in bindings instead of BUILD_ASSERT for
fifo-watermark

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
Jilay Pandya
8fdd43698f drivers: adi,adxl345 use min/max
use min/max instead of BUILD_ASSERT for fifo-watermark

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2026-06-02 20:22:38 +02:00
JuHyun Kim
d910a649ae drivers: sensor: icm45686: Change default interrupt drive
Fixed default interrupt drive from Open Drain to Push pull.
Fixes #108987

Signed-off-by: JuHyun Kim <jh.kim@tdk.com>
2026-06-01 18:05:01 -05:00
Benjamin Cabé
bef55f207d drivers: sensor: tmp108: move alert masks to driver header
TMP108/AS6212 status alert bit masks are driver-internal. Move them from
the public header into tmp108.h.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-06-01 12:42:21 -04:00
Benjamin Cabé
8b89c95ee3 drivers: sensor: ti_hdc302x: move status register macros to driver
Status register bit macros are driver-internal and only used in
ti_hdc302x.c. Remove them from the public header.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-06-01 12:42:21 -04:00
Armando Visconti
ca2992379c drivers/sensor: lsm6dsv16x: add int-gpio-config attribute in DT
Add the possibility to configure the interrupt gpio in one of the
two possiblities:

      - GPIO_INT_EDGE_TO_ACTIVE
      - GPIO_INT_LEVEL_ACTIVE

Default is GPIO_INT_EDGE_TO_ACTIVE, which matches with old fixed
configuration.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2026-05-31 13:41:03 +02:00
Raffael Rostagno
9b0c9a2a3a drivers: tsens: esp32: Sleep retention
Add sleep retention support for die temp driver. When peripheral
power down is enabled for light sleep, register data is lost,
so REGDMA backup is needed to mantein peripheral operational.

Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
2026-05-29 22:05:37 +02:00
Sudarshan Iyengar
111a1ba43f drivers: sensor: bmi323: Add I2C bus support
Add I2C bus support to the BMI323 sensor driver. The BMI323
supports I2C communication with a dummy byte offset protocol
where 2 dummy bytes precede actual data in read operations.

Changes:
- Add bmi323_i2c.c/.h with I2C read/write and chip ID validation
- Add BMI323_BUS_I2C Kconfig option
- Update BMI323_DEVICE_BUS macro to handle I2C bus type
- Add bosch,bmi323-i2c.yaml device tree binding

The I2C implementation handles the dummy byte offset required
by the BMI323 when reading registers over I2C.

Signed-off-by: Sudarshan Iyengar <sudarshan.iyengar@alifsemi.com>
2026-05-29 22:05:08 +02:00
Sudarshan Iyengar
792718a5a3 drivers: sensor: bmi323: add RTIO async API support
Add Real-Time I/O (RTIO) asynchronous sensor API support to the
BMI323 driver. This enables non-blocking sensor reads with
kernel-managed buffering.

Features added:
- RTIO submit and decode operations for accel, gyro, and temp channels
- Q31 fixed-point format encoding for consistent sensor data scaling
- Unified sample fetch implementation shared between sync and async paths
- Decoder API with timestamped frame headers

The driver now supports both blocking (sensor_sample_fetch) and
non-blocking (sensor_read) operation modes when CONFIG_SENSOR_ASYNC_API
is enabled.

Signed-off-by: Sudarshan Iyengar <sudarshan.iyengar@alifsemi.com>
Assisted-by: GPTCodex:GPT-5.4
2026-05-29 22:05:08 +02:00
Sudarshan Iyengar
87421d3d8a drivers: sensor: bme680: Add RTIO support
Add Real-Time I/O (RTIO) support to the BME680 sensor driver to enable
asynchronous sensor operations. This implementation follows the pattern
established by other Bosch sensor drivers in Zephyr.

Changes include:
- Add bme680_async.c implementing the sensor async API submit function
  using RTIO lock free queues asynchronous read operations
- Add bme680_decoder.c implementing the sensor decoder API for
  Q31-format data conversion of temperature, pressure, humidity, and
  gas resistance channels
- Add RTIO encoded data structures (bme680_encoded_data, bme680_reading)
  to bme680.h with proper bit-packed flags for channel presence
- Update CMakeLists.txt to conditionally build async sources when
  CONFIG_SENSOR_ASYNC_API is enabled

The driver supports fetching temperature, pressure, humidity, and gas
resistance channels via the RTIO interface.

Signed-off-by: Sudarshan Iyengar <sudarshan.iyengar@alifsemi.com>
Assisted-by: Claude:claude-opus-4.6
2026-05-29 10:31:46 -05:00
Kurtis Dinelle
6b7302e454 drivers: sensor: tmp451: add TMP451 temperature sensor driver
Add support for the TI TMP451 remote and local temperature sensor.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Kurtis Dinelle <kurtisdinelle@gmail.com>
2026-05-27 08:35:06 +02:00
Maksim Salau
cce752f808 sensor: Add more device checks to shell-battery
The battery alias is verified to be a sensor device before use.
Also the commit fixes incorrect use of `argv[1]` instead of `dev->name`.

Signed-off-by: Maksim Salau <maksim.salau@gmail.com>
2026-05-23 17:14:36 -07:00
Aaron Kim
0d4f781476 drivers: sensor: tad2144: Add tad2144 support
Use official TDK Invensense driver for tad2144 sensor in tdk_hal module.

Signed-off-by: Aaron Kim <aaron.kim@tdk.com>
2026-05-22 21:55:54 +02:00
Nick Ward
74ff7d3913 drivers: sensor: use shell_print for command output
shell_info is intended for informational side-notes, not for printing
command result data. Use shell_print instead, consistent with other
Zephyr driver shell implementations (rtc_shell, gpio_shell, i2c_shell,
eeprom_shell).

Signed-off-by: Nick Ward <nix.ward@gmail.com>
Assisted-by: Claude:claude-sonnet-4-6
2026-05-21 17:04:13 -04:00