Commit Graph

2469 Commits

Author SHA1 Message Date
Filip Stojanovic
f0b5911d0a sensor: bme280: Fix bad chip id read after power cycle
Fix an issue where the BME280 sometimes returns an incorrect chip ID
immediately after a power cycle. This causes sensor initialization to fail.

According to the datasheet, the sensor requires a 2 ms start-up delay after
power is applied. This patch introduces a sleep delay to ensure the
required start-up time is respected before reading the chip ID.

Signed-off-by: Filip Stojanovic <filipembedded@gmail.com>
2025-07-09 00:25:33 -05:00
Luis Ubieda
a2acc86429 fix: icm42688: fix: Override FSR settings when high-res is enabled
When IMU is set to stream with High-res mode, the FSR settings are
fixed for ICM42688 at 16g and 2000dps.

Unless this is enforced, the driver will provide incorrect scaling for
readings coming through streaming when the current FS setting is any
different than these.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2025-07-08 13:38:36 -05:00
Armando Visconti
0d7c751bad drivers/sensor: lis2dux12: add 'return' if data has to be dropped
In lis2dux12_read_status_cb() add a return instruction in case of
SENSOR_STREAM_DATA_NOP/SENSOR_STREAM_DATA_DROP.

Fixes: CID 529855

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2025-07-07 16:06:13 -05:00
Armando Visconti
df1832e32d drivers/sensor: lsm6dsv16x: add 'return' if data has to be dropped
In lsm6dsv16x_read_status_cb() add a return instruction in case of
SENSOR_STREAM_DATA_NOP/SENSOR_STREAM_DATA_DROP.

Fixes: CID 529864

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2025-07-07 16:06:13 -05:00
Armando Visconti
79c098a9d9 drivers/sensors: st: fix Null pointer dereferences
Fix Null pointer dereferences in lis2dux12_read_status_cb() and
lsm6dsv16x_read_status_cb().

Fixes: CID 529873
Fixes: CID 529862

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2025-07-07 16:06:13 -05:00
Armando Visconti
1d8bd6bd53 drivers/sensor: lis2dux12: fix uninitialized variable fifo_mode
Set fifo_mode structure to zero and initialize it properly according
to what interrupt event the user has selected.

Fixes: CID 529871
Fixes: CID 529865

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2025-07-07 16:06:13 -05:00
Armando Visconti
5792a429c8 drivers/sensor: lsm6dsv16x: fix unreachable code in decoder_decode()
Fix unreachable code in decoder_decode() as reported by Coverity scan.

Fixes: CID 529878

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2025-07-07 16:06:13 -05:00
Van Petrosyan
960a6f036e sensor: lis2dh: cache CTRL1 on PM_DEVICE_ACTION_TURN_ON
Cache CTRL1 into reg_ctrl1_active_val inside lis2dh_init_chip()
in the PM_DEVICE_ACTION_TURN_ON path.  This prevents the first
runtime-PM RESUME from writing 0x00 to CTRL1 and disabling the sensor
when runtime-PM is enabled.

Fixes: #92196

Signed-off-by: Van Petrosyan <van.petrosyan@sensirion.com>
2025-07-05 11:56:00 -05:00
Gaetan Perrot
9207749e83 drivers: sensor: bma4xx: Avoid potential overflow
Coverity reports a potential integer overflow in the accel_range
computation due to the use of a left shift on an int type.

CID 520269: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)

Even though the register value is constrained to 0–3 by the BMA456 spec,
and no real overflow occurs, an explicit cast to int64_t prevents false
positives and aligns with safe coding practices.

Fixes: #90517

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-04 15:49:09 -05:00
Gaetan Perrot
de1fa4776b drivers: sensor: bmp581: add const qualifier when casting
Add the 'const' qualifier when casting 'dev->config' to 'struct
bmp581_config *' to preserve const-correctness and fix SonarQube warning :

 "A cast shall not remove any const or volatile qualification from the
 type of a pointer or reference."

This improves maintainability by respecting the const contract and resolve
static analysis issues.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-04 13:06:22 -05:00
Gaetan Perrot
032c5301de drivers: sensor: bmp581: fix potential null dereference
Move null check for 'dev' before dereferencing it to access dev->config.

This ensures the check is meaningful and avoids undefined behavior in case
of a null device pointer.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-04 13:06:22 -05:00
Gaetan Perrot
7d5902dd1b drivers: akm09918c: fix null dereference in submit function
Fix a null pointer dereference in akm09918c_submit(), where writeByte_sqe
was dereferenced before checking if it was NULL.

Coverity reported this as CID 516247: the pointer returned by
i2c_rtio_copy_reg_write_byte() may be NULL, and accessing its `flags`
field before checking leads to undefined behavior.

Move the access to writeByte_sqe->flags after confirming both
writeByte_sqe and cb_sqe are valid.

Fixes: CID 516247

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-01 19:03:19 -05:00
Pisit Sawangvonganan
b8a8173c1f drivers: kconfig: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in `Kconfig` files within the `drivers` directory.
Additionally, incorporates a fix recommended by the reviewer.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-07-01 10:58:54 -10:00
Gaetan Perrot
6d0f1aaef8 drivers: sensors: apds9253: remove unnecessary check
gain is an unsigned int so it can't be negative.

Fixes CID 516230

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-06-27 09:04:58 -10:00
Gaetan Perrot
e13f64ac47 drivers: sensor: bmm350: fix redundant return logic in init_chip
Add an explicit log message if setting suspend mode fails during error
handling in bmm350_init_chip(), to improve debuggability.

This addresses Coverity issue CID 520279 (Incorrect expression - CWE-398),
which flagged a conditional block where both branches effectively led to
the same outcome (return -EIO), making it appear redundant.

By adding a log before returning, we clarify the purpose of the condition
and avoid the issue of "identical code for different branches", while
keeping the functional behavior unchanged.

Coverity-CID: 520279

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-06-27 09:04:32 -10:00
Miguel Gazquez
e42cfcf032 drivers: sensor: lsm9ds1: propagate errors in sample_fetch
`lsm9ds1_sample_fetch` did not propagate error codes.
Propagate them.

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
2025-06-27 08:54:42 -10:00
Peter Wang
aa7618ba59 sensor: add nxp_lpadc_temp40 temperature sensor driver
1. add nxp_lpadc_temp40 temperature sensor driver
2. tested with frdm_mcxa166 and frdm_mcxa276 board

Signed-off-by: Peter Wang <chaoyi.wang@nxp.com>
2025-06-27 09:53:28 -05:00
Gaetan Perrot
fae619a916 drivers: sensor: lsm6dsv16x: fix uninitialized struct in enable_wake_int
Zero-initialize lsm6dsv16x_pin_int_route_t to fix Coverity warning.

CID: 516227

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-06-27 10:58:58 +02:00
Bjarki Arge Andreasen
3198db1b12 drivers: sensor: nxp: p3t1755: impl pm device runtime
Implement pm device runtime for p3t1755 sensor.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-06-26 18:51:26 -10:00
Jeppe Odgaard
dffbd4fc88 license: fix copyright owner
Change license owner to Prevas due to initially wrong owner due to company
mix-up during co-development.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-06-26 10:56:48 -05:00
Ryan McClelland
d0d9894070 drivers: sensor: bmm350: expose magnetic reset
This exposes a driver specific function to perform a
magentic reset by the application.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
8cdaf1db99 drivers: sensor: bmm350: run clang-format
Run clang-format on files

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
dc6594997c drivers: sensor: bmm350: nit picky cleanup
There were a lot of places where the return value was sum'ed up
which can be slightly easier to read, but can give an odd return
value in the end. This changes it to just return immediately if
an error is seen.

There was also runtime NULL checking of input arguments that are
rather programmer clown prevention. Change these to asserts.

The return value didn't have a consistant type through the file,
make it consistently an int.

This changes the name of the return value of fix_sign to be
signed_value differenating it from the ret name used elsewhere.

Use the sizeof(buffer) as the argument for reg reads and writes
rather than a hard number.

Some log messages ended with '\n'. Remove all these.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
e636fb2dd1 drivers: sensor: bmm350: add pad ctrl and int ctrl dts config
Add configurations for setting the pad drive strength and the
interrupt active high/low and od/pp.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
d2fdf52d43 drivers: sensor: bmm350: fix handling interrupt race condition
There is a race condition where an interrupt can fire before the
drdy_handler is registered. The drdy_handler will tradionaly
callback the sample get clearing the interrupt... but if it's not
configured and NULL, the interrupt will stay forever latched. Read
the interrupt status to clear the interrupt flag allowing it to
trigger again.

Also, move the serial api function helpers in to the header
allowing them to be used from other c files.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
c7e1f0b3da drivers: sensor: bmm350: fix no averaging val for oversampling
Fix the oversampling value to be 1 from 0 for no oversampling to be
consistant with other sensor drivers.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
b1dac48faa drivers: sensor: bmm350: add default odr/osr
Add a way to define the default odr and osr with devicetree for
the bmm350.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Ryan McClelland
8720b2368e drivers: sensor: bmm350: add attr_get
Add the attr_get api. Also rename functions where they implied
accelerometer to imply magnetometer.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-06-26 10:55:54 -05:00
Miguel Gazquez
d3cae7ee92 drivers: sensors: add driver for the magnetometer in lsm9ds1
This driver supports the magnetometer in the ST lsm9ds1 sensor, on the
I2C bus.
This driver does not support the triggers.
This driver use the stmemsc HAL.

link: https://www.st.com/resource/en/datasheet/lsm9ds1.pdf

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
2025-06-26 10:55:11 -05:00
Oleksii Shcherbyna
35608e295d drivers: fuel_gauge: Fix incorrect variable in bq27xx chem_id switch
The bq27xx driver incorrectly uses the 'val' variable in a switch()
statement that should operate on 'chem_id'. This leads to incorrect
behavior for fuel gauges such as the BQ27427, where the chemical ID
determines how properties are interpreted.

This commit replaces 'switch(val)' with 'switch(chem_id)' to ensure
proper handling of fuel gauge behavior across supported devices.

Signed-off-by: Oleksii Shcherbyna <oleksii.shcherbyna@droid-technologies.com>
2025-06-25 10:49:10 +02:00
Daniel DeGrasse
640958de1d drivers: sensor: npm13xx_charger: fix build warnings from native_sim
Fix the following build warnings highlighted in this driver while
building with clang targeting native_sim:

- exp() expects a double, so passing a float would cause type promotion
- variable declarations within C switch statements are a C23 specific
  extension

Signed-off-by: Daniel DeGrasse <ddegrasse@tenstorrent.com>
2025-06-25 09:51:18 +02:00
Benjamin Cabé
1b93ce7226 drivers: sensor: paj7620: fix return value of paj7620_get_hw_id()
Use a local signed variable to store negative return values instead of
unsigned previously so that errors are actually detected/returned.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-24 20:13:57 -10:00
Jilay Pandya
177e7d2b6a drivers: sensor: uint8_t var cannot be greater than 0xff
SENSOR_XBR818_CLOCKRATE / val->val1 is getting assigned
to uint8_t variable which is causing the logically
dead issue, this commit is a fix for it.

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
2025-06-24 20:08:54 -10:00
Benjamin Cabé
8186e6cc74 drivers: sensor: sht3xd: fix threshold low clear command
Fix copy-paste error causing update to SHT3XD_CMD_WRITE_TH_LOW_CLEAR to
be missing

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-24 20:06:41 -10:00
Alexander Apostolu
8fee98313e drivers: sensor: asahi_kasei: akm09918c: Null check before dereference
cb_sqe could have been NULL before being passed into the callback function,
which expects cb_sqe to be non-NULL.

Add NULL check before the callback function with cb_sqe is called. The
reordering of the callback function after the sqe drop is okay as the
sqe drop is called when cb_sqe is NULL and the callback function isn't
expected to work when cb_sqe is NULL.

Signed-off-by: Alexander Apostolu <apostolu240@gmail.com>
2025-06-24 15:39:46 -05:00
Benjamin Perseghetti
44499df9eb drivers: sensor: icm42688 add asserts to RTIO
Adding asserts to RTIO stream to avoid hardfaults.

Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
2025-06-23 16:29:32 -05:00
Benjamin Perseghetti
4d91f6c3ed drivers: sensor: icm42688 enable fifo-hires in DT
Allow setting fifo-highres from DT, also unify the
naming of all registers and expand to a more complete list.

Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
2025-06-23 16:29:32 -05:00
Benjamin Perseghetti
5c9d6d44f3 drivers: sensor: icm42688 add axis_align in DT
Introduces the ability to set static axis
alignment of a sensor from DT params.

Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
2025-06-23 16:29:32 -05:00
Sergei Ovchinnikov
645159dc26 drivers: npm13xx: add support for nPM1304
Add support for nPM1304 in the npm13xx drivers. The nPM1304 supports
different voltage and current ranges which are handled through the
initialization macros.

Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
2025-06-23 16:19:43 +01:00
Sergei Ovchinnikov
89b8383633 drivers: npm13xx: rename npm1300 to npm13xx
Rename npm1300 to npm13xx in function names, documentation, etc. where
applicable for all the npm13xx drivers

Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
2025-06-23 16:19:43 +01:00
Sergei Ovchinnikov
fb007db50a drivers: npm1300: rename to npm13xx
Rename npm1300 drivers and header files to npm13xx to allow for usage
with other nPM13xx product variants.

Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
2025-06-23 16:19:43 +01:00
Benjamin Cabé
d5af2f7dde drivers: sensors: fxls8974: fix compilation error in fxls8974_transceive
SPI code wasn't tested in CI so this compilation error was missed.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-20 16:23:25 +02:00
Van Petrosyan
04057e15ec sensor: lps22hh: clang-format cleanup
Style-only reformatting, no functional change.

Signed-off-by: Van Petrosyan <van.petrosyan@sensirion.com>
2025-06-18 17:50:22 -04:00
Van Petrosyan
1aa07db0ae sensor: lps22hh: add device power management support
Registers driver with pm_device_driver_init(); implements TURN_ON,
SUSPEND and RESUME.  Sets ODR = 0 on suspend per datasheet

Signed-off-by: Van Petrosyan <van.petrosyan@sensirion.com>
2025-06-18 17:50:22 -04:00
John Shelton
3b2103f5f7 sensor: dht: Fix multi-instance type handling
The DHT driver incorrectly assumes all sensor instances are the same
type as the first instance (dht@0). The data parsing logic uses a
hardcoded check of the devicetree property for instance 0, which
causes incorrect readings when different sensor models (e.g., DHT11
and DHT22) are used together.

This change stores the model type in each per-instance config struct
during initialization. The data parsing logic is updated to use this
per-instance flag, ensuring each sensor is handled correctly
according to its specific model.

Signed-off-by: John Shelton <moosery@gmail.com>
2025-06-18 17:48:58 -04:00
Benjamin Cabé
0f6b3f066a drivers: sensors: add missing const qualifiers
Ensure conversion tables and the like are marked as const to save on
RAM usage.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-18 17:47:18 -04:00
Benjamin Cabé
af6209dbcb drivers: sensors: tdk: icp201xx: fix typo in icp201xx_channel_get
s/pressure/temperature/

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-18 17:44:07 -04:00
Benjamin Cabé
e6bd3b4f3e drivers: sensors: icp101xx: add missing error check
add missing variable assignment causing error code to be ignored

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-18 17:44:07 -04:00
Juraj Lieskovský
7f78eb75dc drivers: sensor: st: qdec_stm32: addition of fractional part
The fractional part of the qdec sensor readout is set to zero (val2 =
0).

Changed the format of the run time data to Q26.6 and adjusted the
assignment of val1 and val2 accordingly.

Signed-off-by: Juraj Lieskovský <lieskovsky.juraj@gmail.com>
2025-06-18 09:26:35 -04:00
Benjamin Cabé
37144c1ffa drivers: sensor: icm42605: fix turn_off_sensor logic
While it would likely not directly cause issues with the current
implementation, the logic of turning off the sensor should be to
actually reset the flags, not to toggle them.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-18 07:39:15 +02:00