Commit graph

2428 commits

Author SHA1 Message Date
Krystof Sadlik
928d025201 drivers: sensor: fxls8974: Added driver for this accelerometer
Added driver for the fxls8974 accelerometer which is present on the
mimxrt1040_evk board.

Signed-off-by: Krystof Sadlik <krystof.sadlik@nxp.com>
2024-08-19 10:00:34 -04:00
Lucas Tamborrino
ca31dbc0bc drivers: sensor: icm42670: Add I2C bus support
Add bus interface so the driver can support both
SPI and I2C bus.

Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
2024-08-16 14:08:44 -04:00
Daniel Kampert
f849140de7 drivers: sensor: Add attribute for gain and resolution
- Add SENSOR_ATTR_GAIN and SENSOR_ATTR_RESOLUTION
- Remove SENSOR_ATTR_GAIN from tsl2540 header

Signed-off-by: Daniel Kampert <DanielKampert@kampis-elektroecke.de>
2024-08-15 10:16:12 +01:00
Jordan Yates
a390f450ec sensor: voltage_divider: don't pulse enable pin
Don't pulse the enable pin on boot if the device is going to immediately
go into suspend mode via `zephyr,pm-device-runtime-auto`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-08-14 12:34:45 -04:00
Armando Visconti
a47b88c09b drivers/sensor/st: iis2iclx: (fix) convert range into mg
Fix the sensor range setting at runtime which is currently returning error,
converting the SI (ms2) value passed thru SENSOR_ATTR_FULL_SCALE in mg (and
not in g) as this is the unit used in the driver internals.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-08-13 14:56:39 +02:00
Armando Visconti
c6f8d37056 drivers/sensor/st: iis2iclx: fix odr setting
Do not fail when requested rate passed in SENSOR_ATTR_SAMPLING_FREQUENCY
is not matching any of the odr values supported by sensor. Instead, round
it up to the next one.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-08-13 14:56:39 +02:00
Juliane Schulze
932306a6e5 drivers: vcnl36825t: fix power consumption issues
- apply correct order to suspend/resume when using continuous mode
- unset LPEN (low-power-enable) bit on suspend (causing excessive
  current draw)
- fix a starting issue which lead to higher power consumption

Signed-off-by: Juliane Schulze <juliane.schulze@deveritec.com>
2024-08-09 09:55:07 +02:00
Robin Carrupt
80aa24ad95 sensor/ntc_thermistor: Corrected the type of adc values to accept 16 bits
The NTC thermistor sensor in drivers/sensor/ntc_thermistor/ntc_thermistor.c
cannot work with a 16-bit ADC.
The voltage becomes negative if the ADC raw value is 0x8000 or higher.

To correct this, I changed the types in the
ntc_thermistor_data struct from int16_t to int32_t.

This also corrects a potential problem at line 53
where we transform an int16_t into an int32_t.

Fixes: #75203
Signed-off-by: Robin Carrupt <robincarrupt@gmail.com>
2024-08-09 09:54:43 +02:00
Konrad Sikora
f3af39b4d7 drivers: sensor: Fix DHT20 build failure with CRC configured
Fixes the build error: 'crc' undeclared for
DHT20 sensor with CONFIG_DHT20_CRC option enabled.

Signed-off-by: Konrad Sikora <kontakt@konradsikora.pl>
2024-08-07 07:14:11 -04:00
Fabian Pflug
ac8e578456 drivers: sensor: tmag5273: Add support for tmag3001
The TMAG3001 is quite similar to the tmag5273 and can be used with just
some small modifications.

Signed-off-by: Fabian Pflug <fabian.pflug@grandcentrix.net>
2024-08-05 16:27:25 +02:00
Mathieu Choplain
94c375ed2f drivers: sensor: stm32_vref: update incorrect comment
The ICACHE must be disabled on STM32H5 series due to documented
behaviour of the flash controller, not to an errata.

For a more technical explaination: (see RM0492 for references)
 -  on STM32H5, the ICACHE block is interposed on C-bus between
    the Cortex-M33 and the FLASH (§2.1.1)
 -  the ICACHE determines if accesses are cacheable or non-cacheable
    based on an AHB attribute; the Cortex-M33 sets this attribute or
    not depending on the MPU configuration (§8.4.6)
 -  when a cacheable access is requested by the Cortex-M33, if the
    requested data is not present in ICACHE (cache miss), a cache line
    refill (128-bit burst read) is performed (§8.4.7)
 -  however, all accesses to OTP and Read-Only regions of the FLASH must
    be done with caching disabled (§7.3.2); indeed, the accesses MUST be
    16 or 32-bit sized - otherwise, the flash interface raises a bus
    error (§7.5.9 / Table 38 "OTP/RO access constraints").

    This is the behaviour that was observed and lead to the introduction
    of ICACHE disable code in 065a8f25e1.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-08-01 16:43:51 +02:00
Mathieu Choplain
c77d5b8c3b drivers: sensor: stm32_vbat: handle disabled ADCs more gracefully
This commit modifies the STM32 battery voltage sensor driver
to handle erroneous usage more gracefully. More precisely,
it now fails builds with an explicit error message when the
sensor is enabled but the corresponding ADC is not. This can
only happen on STM32 series with more than one ADC (e.g., H7).

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-08-01 16:43:51 +02:00
Mathieu Choplain
1e0e3a874f drivers: sensor: stm32_vref: handle disabled ADCs more gracefully
This commit modifies the STM32 internal voltage reference sensor
driver to handle erroneous usage more gracefully. More precisely:
  - driver no longer builds if no ADC node is enabled
  - fail builds with an explicit error message when the sensor
    is enabled but the corresponding ADC is not. This can only
    happen on STM32 series with more than one ADC (e.g., H7).

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-08-01 16:43:51 +02:00
Mathieu Choplain
8d40279644 drivers: sensor: stm32_temp: handle disabled ADCs more gracefully
This commit modifies the STM32 internal temperature sensor driver
to handle erroneous usage more gracefully. More precisely:
 - driver no longer builds if no ADC node is enabled
 - fail builds with an explicit error message when the sensor
   is enabled but the corresponding ADC is not. This can only
   happen on STM32 series with more than one ADC (e.g., H7).

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-08-01 16:43:51 +02:00
Anke Xiao
643e464c76 modules: Kconfig.mcux: remove HAS_MCUX_ACMP
Remove the ‘HAS_MCUX_ACMP’ Kconfig, and also remove it from
driver and soc Kconfig files. It is not needed since we already
depend on 'ACMP' enabled in the dt file, the 'HAS_MCUX_ACMP'
kconfig is a relic of the past before devicetree was stable.

Signed-off-by: Anke Xiao <anke.xiao@nxp.com>
2024-08-01 12:37:23 +02:00
Armando Visconti
8bc00e1420 drivers/sensor: lis2dux12: fix mode when setting odr
In lis2dux12_set_odr(), the call to stmemsc module lis2dux12_mode_set()
API is done with the .fs field left uninitialized, so setting the
underlying device regs in an unproper way.

Suggested-by: Luis Ubieda <luisf@croxel.com>
Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-08-01 12:36:48 +02:00
Miguel Gazquez
26be1da3e7 drivers: sensor: add driver for lsm9ds1 sensor
The LSM9DS1 is a system-in-package featuring
a 3D digital linear acceleration sensor, a 3D digital angular rate
sensor and a 3D digital magnetic sensor.

This driver implements only the linear acceleration sensor and the
angular rate sensor, on the I2C bus.

This driver is without trigger support.

The driver is based on the stmemsc HAL.

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

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
2024-07-29 14:21:24 +02:00
Pieter De Gendt
ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00
Tom Burdick
5474b611cb icm42688: Fix divide by zero potential
There were code paths that could have lead to divide by zero given an
invalid scale setting for accel or gyro. In practice this should be an
invalid setup even before getting to these conversion functions. The
conversion functions now better show all valid values are accounted for
by using CODE_UNREACHABLE in the default case.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-07-27 15:10:27 +03:00
Ian Morris
a6a27aa43e drivers: sensor: tmp116: Add ability to set conversion averaging mode
Adds support for setting the number of conversion results that are
collected and averaged before updating the temperature register.

Signed-off-by: Ian Morris <ian.d.morris@outlook.com>
2024-07-27 10:45:01 +03:00
Armando Visconti
a1f9793e0e drivers/sensor: lis2dux12: fix temperature conversion
Return to sensor_api i/f the temperature in Celsius instead
of the register raw value in LSB.

Fixes #75686

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-07-27 10:37:11 +03:00
Armando Visconti
cf20aa050d drivers/sensor: lis2dux12: fix odr and range
The current implementation assumes that sensor odr and range are
always configured in the Device Tree at compile time which might
not be the case.

Instead, application can set odr and range either at compile time
through the DT or using SENSOR_ATTR_SAMPLING_FREQUENCY and
SENSOR_ATTR_FULL_SCALE attributes at runtime, so each driver instance
must keep trace of the latest values set and use them in the sensor
APIs which require them (e.g. lis2dux12_mode_set).

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-07-27 10:37:11 +03:00
Armando Visconti
2eaec8b779 sensor: lis2dux12: fix SENSOR_ATTR_FULL_SCALE case
When setting the full scale through SENSOR_ATTR_FULL_SCALE the
driver must convert the g value (i.e. one of 2g/4g/8g/16g) to
the corrispondent sensor fs raw value.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-07-27 10:37:11 +03:00
Bjarki Arge Andreasen
ee69e9fadf drivers: sensor: voltage_divider: revert patch
A patch was added to the voltage divider to handle an erroneous
negative voltage reading for the nrfx_saadc which could return
negative voltages even though the ADC mode was single ended.

This has now been patched in the ADC driver.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2024-07-12 19:50:27 +02:00
Luis Ubieda
9c516db69c sensor: coverity-fix: Simplify unsigned comparison
- VEML7700 - Coverity CID 363733, GH: #74759.
- VEML7700 - CID 363719, GH: #74755.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-12 05:56:30 -04:00
Luis Ubieda
00a3be90d7 sensor: icm42688: Use RTIO workq on icm42688_submit
To make its execution path non-blocking from the caller's perspective.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 17:21:05 -04:00
Luis Ubieda
8d0c2f15df sensor: bme280: Use RTIO workq on bme280_submit
To make its execution path non-blocking from the caller's perspective.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 17:21:05 -04:00
Luis Ubieda
5521fc4410 sensor: bma4xx: Use RTIO workq on bma4xx_submit
To make its execution path non-blocking from the caller's perspective.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 17:21:05 -04:00
Luis Ubieda
59e8919da7 sensor: akm09918c: Use RTIO workq on akm09918c_submit
To make its execution path non-blocking from the caller's perspective.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 17:21:05 -04:00
Luis Ubieda
aff6e31ec4 sensor: fallback: Decouple RTIO request using RTIO workqueues service
Incorporate RTIO workqueues to turn sensor_submit_callback into an
asynchronous request.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 17:21:05 -04:00
Luis Ubieda
cc139b85df sensor: Enable RTIO Semaphores for Async API
In order to decouple the read request from its implementation, we need
to be able to yield to potential lower-priority threads, which is not
possible with k_yield() itself. As such, using RTIO Consume semaphore
enables us to achieve this.

This patch also refactors blocking API (sensor_read) to also block upon
consumption, so as not to require RTIO_SUBMIT_SEM enabled.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 17:21:05 -04:00
Jean Nanchen
77f9f0e965 drivers: sensor: maxim: max31865: Fix fault bit clearing
Ensures D1 sets and D5, D3, D2 reset, preventing undefined states.

Signed-off-by: Jean Nanchen <jean.nanchen@gmail.com>
2024-07-09 15:38:19 -04:00
Thomas Stranger
b5d3dea894 drivers: sensor: ds18b20: indicate error for missing response
When multiple devices are on the bus, and no slave matches
the sent rom, the master receives only ones.
This should be handled explicitly and the error reporting
should not rely on the crc mismatch of the scratchpad.

Note: Make sure that the sensor configuration is loaded to the
eeprom (copy scratchpad), otherwise the resolution will not match
the expectations in case a node looses power and recovers.
As in that case the configuration will not be applied again.
Also the sensor may still report the power on reset value
of +85°C just after the sensor powered up.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2024-07-09 15:37:58 -04:00
Thomas Stranger
6fd767d6e4 drivers: sensor: ds18b20: verify scratchpad write
Verify that the scratchpad write was successful by
reading back the configuration.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2024-07-09 15:37:58 -04:00
Thomas Stranger
53e3936a2e drivers: sensor: ds18b20: verify crc of scratchpad.
After each read of the scratchpad the crc of the data
is checked and in case of a mismatch an error is returned.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2024-07-09 15:37:58 -04:00
Thomas Stranger
f4acf390dd drivers: sensor: ds18b20: cleanup header/includes
- Move the content of the header file into the source file,
and drop unnecessary includes.
- Also, drop the bus access function.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2024-07-09 15:37:58 -04:00
Luis Ubieda
95e299ad39 sensor: lis2dux12: fix: CID 363712: Initialize mode-fs
Following the same pattern used in `lis2dux12_sample_fetch_accel`.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 19:05:03 +02:00
Luis Ubieda
05f8b9c54b sensor: lps22hh: Prevent overwriting values that weren't overwritten
Previously both temperature and pressure were updated regardless of
which one was requested.

Fixes CID: 392519, GH: 74779.
Fixes CID: 392497, GH: 74777.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-07-09 11:51:16 +02:00
Jared Kangas
c0fd916fbc drivers: sensor: wsen_itds: fix device ID mismatch return value
During initialization, zero is returned if an unexpected device ID is
read because the returned variable is not written to after a previous
non-zero check. Return -EIO instead to indicate an error occurred.

Detected with the following Coccinelle script:

        @@
        identifier I;
        @@

        *if (I) {
             ...
             return ...;
         }

         if (...) {
             ... when != I
                 when any
        *    return I;
         }

Signed-off-by: Jared Kangas <kangas.jd@gmail.com>
2024-07-09 08:56:04 +02:00
Tom Burdick
983ee54dfd sensors: ICM42688 read/writes chain callbacks
RTIO expects the CHAINED flag to be set when ordering of operations is
important. The callbacks in the icm42688 stream handling were not
chained into, meaning the callbacks would have occured immediately
rather than *after* the SPI reads/writes.

Update all the spi transactions to chain into the desired callbacks in
the driver.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-07-08 17:18:16 -04:00
Armando Visconti
cd7119d292 drivers/sensor/st: ism330dhcx: fix gyro range setting
Fix ism330dhcx_gyro_fs_map[] and ism330dhcx_gyro_fs_sens[] arrays
initialization in order to be able to correctly convert from dps
to register raw value through the array index.

Fix: #72617

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-07-04 08:19:03 +02:00
Armando Visconti
50ad2e05dc drivers/sensor/st: ism330dhcx: fix odr setting
Loop inside the odr array until we find the first
value which is "<=" (amd not "==") the argument.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2024-07-04 08:19:03 +02:00
Ioannis Damigos
6cc5478530 bme280: Update decoder to decode channels correctly
Update bme280 sensor driver decoder to decode
correctly the requested channels.

Fixes issue #74927

Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
2024-06-28 12:22:54 -04:00
Tom Burdick
058253b4b6 icm42688: Follow st's devicetree bindings
Fix the devicetree bindings to actually be used as the default
configuration, following the example set by various ST sensor devices.

This requires sadly dropping enums and using #defines for various
options as well as repeating many numbers, but presumably is the way to
do it given the precedent set by ST with sensors like the lsm6dso.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-06-26 14:13:21 -04:00
Simon Frank
2ca7e41b26 drivers/sensor: lis2mdl: use common SPI duplex option
Driver used a custom SPI duplex option. Replaced with the common one
found in spi-device.yaml.

Signed-off-by: Simon Frank <simon.frank@lohmega.com>
2024-06-26 09:01:13 -04:00
Luis Ubieda
089eaf93ec sensor: lm75: Enforce dependency of int-gpios with Trigger feature
As pointed out on #57586: `LM75_TRIGGER_GLOBAL_THREAD` can't be enabled
without the int-gpios being present in the DTS node. This commit
requires at least one LM75 instance featuring it, otherwise it won't
work.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-06-25 14:16:28 -04:00
Lingao Meng
302422ad9d everywhere: replace double words
import os
import re

common_words = set([
    'about', 'after', 'all', 'also', 'an', 'and',
     'any', 'are', 'as', 'at',
    'be', 'because', 'but', 'by', 'can', 'come',
    'could', 'day', 'do', 'even',
    'first', 'for', 'get', 'give', 'go', 'has',
    'have', 'he', 'her',
    'him', 'his', 'how', 'I', 'in', 'into', 'it',
    'its', 'just',
    'know', 'like', 'look', 'make', 'man', 'many',
    'me', 'more', 'my', 'new',
    'no', 'not', 'now', 'of', 'one', 'only', 'or',
    'other', 'our', 'out',
    'over', 'people', 'say', 'see', 'she', 'so',
    'some', 'take', 'tell', 'than',
    'their', 'them', 'then', 'there', 'these',
    'they', 'think',
    'this', 'time', 'two', 'up', 'use', 'very',
    'want', 'was', 'way',
    'we', 'well', 'what', 'when', 'which', 'who',
    'will', 'with', 'would',
    'year', 'you', 'your'
])

valid_extensions = set([
    'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
    'rst', 'dtsi',
    'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
    'soc', 'cfg'
])

def filter_repeated_words(text):
    # Split the text into lines
    lines = text.split('\n')

    # Combine lines into a single string with unique separator
    combined_text = '/*sep*/'.join(lines)

    # Replace repeated words within a line
    def replace_within_line(match):
        return match.group(1)

    # Regex for matching repeated words within a line
    within_line_pattern =
	re.compile(r'\b(' +
		'|'.join(map(re.escape, common_words)) +
		r')\b\s+\b\1\b')
    combined_text = within_line_pattern.
		sub(replace_within_line, combined_text)

    # Replace repeated words across line boundaries
    def replace_across_lines(match):
        return match.group(1) + match.group(2)

    # Regex for matching repeated words across line boundaries
    across_lines_pattern = re.
		compile(r'\b(' + '|'.join(
			map(re.escape, common_words)) +
			r')\b(\s*[*\/\n\s]*)\b\1\b')
    combined_text = across_lines_pattern.
		sub(replace_across_lines, combined_text)

    # Split the text back into lines
    filtered_text = combined_text.split('/*sep*/')

    return '\n'.join(filtered_text)

def process_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        text = file.read()

    new_text = filter_repeated_words(text)

    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_text)

def process_directory(directory_path):
    for root, dirs, files in os.walk(directory_path):
        dirs[:] = [d for d in dirs if not d.startswith('.')]
        for file in files:
            # Filter out hidden files
            if file.startswith('.'):
                continue
            file_extension = file.split('.')[-1]
            if
	file_extension in valid_extensions:  # 只处理指定后缀的文件
                file_path = os.path.join(root, file)
                print(f"Processed file: {file_path}")
                process_file(file_path)

directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2024-06-25 06:05:35 -04:00
Jordan Yates
07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Maximilian Deubel
71c4526ab3 drivers: sensor: bmm150: Fix setting of attributes
Some functions in the bmm150 driver were depending on a define
that was never used. Changed it to the one that is actually defined.

Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
2024-06-20 12:05:23 -04:00
Luis Ubieda
7cda467cc1 sensor: vcnl36825t: Scrub redundant scaling on meas_timeout_us
Confirming the Proximity Integration is an integer, we don't need to
pre-apply the Scaling factor to then be accounted for when the actual
meas_timeout_us is calculated.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-06-20 12:05:07 -04:00