Commit graph

2428 commits

Author SHA1 Message Date
Luis Ubieda
51ad3d34bd sensor: vcnl36825t: fix: Address CID 347083
Coverity found this legitimate issue: the datasheet specifies PS_IT
being 2-bits long (1, 2, 4, 8) and this driver assumes more steps are
available. Remove extraneous fields so the Proximity integration
setting fits in the expected 16-bit value.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-06-20 12:05:07 -04:00
Tom Burdick
694428947a sensors: Fix shell missing channel types
The shell tries to decode all channel types and sequential channel
indexes. Unfortunately when swapping to channel specs we forgot to reset
the channel index for the next channel type to look at.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-06-18 14:55:27 -04:00
Gerson Fernando Budke
0561d74d31 drivers: counter: sam: Add qdec as tc special mode
The current atmel,sam-tc-qdec sensor implementation shared the timer
counter node. This create issues when users wants define both modes.
The current proposal changes the qdec dedinition to be a child of
tc and refactor all the chain of definitions.

Fixes #71312

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2024-06-17 17:47:42 -04:00
Trent Piepho
971227180b drivers/sensor: si7006: Switch to undef DT_DRV_COMPAT
This style is used in sensor drivers.  It's more complicated than the
other way, which is used in different drivers that are not sensor
drivers.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-06-15 04:42:31 -04:00
Trent Piepho
0f219e1e6d drivers/sensor: si7006: Fix math for calculating sensor values
The existing code rounded the result to an integer, then multiplied that
integer by 1000000 to get micro-degrees or micro-percent, and then
divided by 1000000 to get whole degrees/percent and took the modulus to
get fractional degrees/percent.

Obviously, multiplying and then dividing an integer by the same value
has no effect!

The result is the humidity and temperature were always rounded down to
the nearest integer.

Fix this to properly keep the fractional component.  This is done in a
way that avoids any integer divisions, which are slow on all CPUs, but
especially most microcontrollers, e.g. Cortex-M, lack any integer
division instruction.

Avoiding the base 10 math does not require more code.  One just needs to
think in binary and use binary fractions instead of base 10 fractions.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-06-15 04:42:31 -04:00
Trent Piepho
88649dad1a drivers/sensor: si7006: Mask off low two bits of data reads
The low two bits are not part of the data, but rather "status" bits that
should be masked off.

This is documented in the HTU21D datasheet Edition 8, date 05/2017, pp.
15, and Sensirion SHT21 datasheet version 6, date 10/2022, §6 (wording
exactly the same):

"The two status bits, the last bits of LSB, must be set to ‘0’ before
calculating physical values."

Also Silicon Labs Si7006 example driver code:
        /* Swap the bytes and clear the status bits */
        return ((data.byte[0] * 256) + data.byte[1]) & ~3;

Since these are the LSBs, it has only a small effect and might not have
been noticed despite being wrong.

While editing this code, switch to using the Zephyr endian conversion
functions intead of a written out conversion.

Add error code to error log message.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-06-15 04:42:31 -04:00
Trent Piepho
c7b3b13119 drivers/sensor: si7006: Clean up headers
Some, like stdio.h, don't belong here at all and aren't needed.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-06-15 04:42:31 -04:00
Trent Piepho
d7e03dd148 drivers/sensor: si7006: Support SHT21 and HTU21D
These three sensor types are all largely compatible.  The SHT21 and
HTU21D can be supported by this driver by sending command 0xE3 instead
of 0xE0 to read the temperature.

Mention the sensor names in bindings and Kconfig to help those looking
for support to find it.  There have been at least five PRs attempting to
add SHT21 and/or HTU21D support that did not realize the Si7006 is the
same.

As mentioned in PR #22862, the Sensirion SH21 is the original.  The dts
bindings are adjusted (in a backward compatible way!) to make the sht21
the base binding and si7006 is derived from that.

Examples of dts compatibles:

TE Connectivity née Measurement Sepcialties HTU21D:
compatible = "meas,htu21d", "sensirion,sht21";

Sensirion SHT21:
compatible = "sensirion,sht21";

Silicon Labs Si7006
compatible = "silabs,si7006";

Silicon Labs Si7021
compatible = "silabs,si7021", "silabs,si7006";

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-06-15 04:42:31 -04:00
Trent Piepho
6817ac34b6 drivers/sensor: si7006: Remove unused struct device field
Use was removed but the field itself wasn't deleted.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-06-15 04:42:31 -04:00
Benjamin Lemouzy
5c8937fbac drivers: sensor: lm75: add alert threshold support
Add SENSOR_ATTR_ALERT and SENSOR_ATTR_HYSTERESIS attributes support.
The code is heavily inspired by the one for lm77 sensor.

Signed-off-by: Benjamin Lemouzy <blemouzy@centralp.fr>
2024-06-14 18:48:32 -04:00
Robert Hancock
2d171efcec drivers: sensors: Add driver for LM95234 temperature sensor
Add a driver for the National/TI LM95234 Quad Remote Diode and Local
Temperature Sensor with SMBus Interface and TruTherm Technology.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
2024-06-14 19:34:01 +02:00
Tom Burdick
3b94af2b5c sensors: Submit call returns void
The integer return of sensor_submit should be void as the call is
asynchronous and the response is meant to be delivered using RTIO APIs
signaling that the submission completed with error or success.

Change the function signature to void and fix all uses of the submit
API, fixing some bugs in the process.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-06-14 19:13:02 +02:00
Krystian Dolatowski
317abcc589 sensor: fix fallthrough on sample_channel_get on AQI
fixed fallthrough on getting channel AQI value from ENS160

Signed-off-by: Krystian Dolatowski <kryqpl1@gmail.com>
2024-06-12 18:16:29 -04:00
Lauren Murphy
f9db6ed414 drivers: sensor: update bme280 to new async api
Updates BME280 driver to new async API.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2024-06-11 20:28:24 -05:00
Juliane Schulze
3c1590cbad drivers: tmag5273: fix documentation of tmag5273_check_device_status
Typos and invalid doxygen documentation.

Signed-off-by: Juliane Schulze <juliane.schulze@deveritec.com>
2024-06-11 19:47:02 -04:00
Juliane Schulze
7ddbdb23df drivers: tmag5273: remove unneccessary check
If an immediate return on error is used, an additional result check in
sample_fetch can be neglected. Since they are now treated as errors,
also changed logging type.

Signed-off-by: Juliane Schulze <juliane.schulze@deveritec.com>
2024-06-11 19:47:02 -04:00
Glenn Andrews
d5b653a805 Driver: Sensor: HTS221: Remove log message when trigger disabled
My students are using a disco_l475_iot1 board with HTS221 sensor.
When logging is enabled, the following log message is always emitted:
"HTS221: Cannot enable trigger without drdy-gpios"

This message is confusing to my students as they are not using the
HTS221 sensor in their projects. However since HTS221 is enabled in
the devicetree it gets initialized on boot and the log message
appears.

It doesn't seem necessary to tell people that they haven't enabled
CONFIG_HTS221_TRIGGER at log level INF. I'd be amenable to changing
this to LOG_DBG, but I don't think it needs to exist at all.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2024-06-11 19:43:36 -04:00
Thomas Stranger
34cac05775 drivers: sensor: sensirion: shtcx: remove chip property
Removes the dts "chip" property, the compatible should be used instead.

Any existing dts should be converted from something like:

test_i2c_shtc3: shtc3@70 {
	compatible = "sensirion,shtcx";
	reg = <0x70>;
	chip = "shtc3";
	measure-mode = "normal";
	clock-stretching;
};

to something like:

test_i2c_shtc3: shtc3@70 {
	compatible = "sensirion,shtc3", "sensirion,shtcx";
	reg = <0x70>;
	measure-mode = "normal";
	clock-stretching;
};

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2024-06-11 20:12:15 +03:00
Nick Ward
49d09ecb28 sensor: current_amp: fix fractional value
It needs to be x1000

Also correct the units used in the log

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-06-11 20:11:53 +03:00
Chris Friedt
2bc722a97e posix: deprecate POSIX_FNMATCH GETOPT GETENTROPY
The functions fnmatch(), getopt(), getentropy()
and others are grouped into the standard Option Group
POSIX_C_LIB_EXT.

The getentropy() function is currently in-draft for
Issue 8 as of 2021.

https://www.opengroup.org/austin/docs/austin_1110.pdf

Not surprisingly, the POSIX_C_LIB_EXT Option Group
also includes the highly debated strnlen() function.

Moving that function will be deferred until later.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Braissant
61536c1096 drivers/sensor: lps22hh: Enable fetching individual sensor channels
Add the possibility to fetch specific sensor channels independently,
either pressure data with SENSOR_CHAN_PRESS or temperature data
with SENSOR_CHAN_AMBIENT_TEMP.
Additionally, the option to fetch both channels simultaneously remains
available using SENSOR_CHAN_ALL, thus not breaking any samples.

Signed-off-by: Chris Braissant <chrisbraissant@gmail.com>
2024-06-04 16:38:00 +02:00
Aurelien Jarno
371f22b937 drivers: sensor: st: add driver for the STM32 Digital Temperature Sensor
This add basic support for the STM32 Digital Temperature Sensor found
notably on the STM32H7 series. It work in interrupt mode and support
basic power device management.

It does not support the more advanced features like using the
temperature threshold, triggers from LPTIM or using the LSE clock in
during sleep or stop.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2024-06-04 16:37:19 +02:00
Florian Weber
8f852551e0 drivers: sensor: akm09918c: fix decoder api define
Decoder api was not defined and lead to build error
if it is used in userland.
Fix that by adding necessary DT_DRV_COMPAT #define
in akm09918c sensor decoder.

Signed-off-by: Florian Weber <florian.weber@live.de>
2024-06-02 00:43:08 +02:00
Zhaoxiang Jin
0507021009 drivers: sensor/nxp: Add NXP LPCMP driver
Add NXP LPCMP driver

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2024-05-31 09:51:29 -05:00
Jordan Yates
b9c9426b62 sensor: bme680: simplify conversion logic
Read less data from the sensor and use standard zephyr functions for
extracting integers from byte arrays.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-30 02:06:19 -07:00
Jordan Yates
b67185b90d sensor: bme680: fix fetch API conformance
`sensor_sample_fetch` is documented to read all of a sensor's active
channels and block until complete. The previous implementation read
the result from the previous call and triggered the next sample.

As a result the first call always failed, and subsequent calls would
return data one sampling period old.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-30 02:06:19 -07:00
Tom Burdick
d2ccc91d7d sensors: Add a blocking sensor_read call
Rename the current sensor_read to sensor_read_async_pool and create a
new blocking sensor_read helper.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-05-30 09:00:43 +02:00
Juliane Schulze
90d8941b54 vcnl36825t: allow "force"-mode only if low-power mode is inactive
Behavior of "force"-mode as described in datasheet cannot be achieved if
low-power mode is enabled. After triggering a sampling, the sensor will
not sample again for the period specified in measurement-time.

Signed-off-by: Juliane Schulze <juliane.schulze@deveritec.com>
2024-05-29 10:47:44 -07:00
Ethan Lu
9baf77dd39 sensor: ms5837: fix compensate parameters for 30BA variant
The previous parameters seems wrong if we refer to:
https://www.te.com/usa-en/product-CAT-BLPS0017.html

Signed-off-by: Ethan Lu <ethan@cpdesign.com.au>
2024-05-29 07:34:51 +02:00
Margherita Milani
885d271e57 drivers: sensor: si7006: fix redundant include in si7006
Remove redundant include of `zephyr/logging/log.h` in si7006.c.

Signed-off-by: Margherita Milani <margherita.milani@amarulasolutions.com>
2024-05-29 07:31:53 +02:00
Yong Cong Sin
bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Yong Cong Sin
e993e994ea sensors: add new channel SENSOR_CHAN_POS_DXYZ
Add new channel: `SENSOR_CHAN_POS_DXYZ`, so that it is
consistent with other 3-axis channels.

Updated pytest, `sensor_shell` & `fake_sensor` accordingly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin
4e7168028b sensors: shell: use SENSOR_CHANNEL_3_AXIS whenever possible
Instead of specifying 3 axis channels manually, use
`SENSOR_CHANNEL_3_AXIS` instead.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin
eb37b8620b sensor_shell: fix hang when device is not a sensor
If `CONFIG_SENSOR_INFO` is enabled, use the `sensor_info`
section to validate that the argument is a sensor before using,
otherwise the shell command will hang the application.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin
e879cd0502 sensor_shell: fix assertion due to NULL pointer deref
The `SENSOR_CHAN_VSHUNT` was added in #60717 but was never
added to the `sensor_channel_name[SENSOR_CHAN_COMMON_COUNT]`
table. Since the length of `sensor_channel_name` is fixed to
`SENSOR_CHAN_COMMON_COUNT`, this means that the index at
`SENSOR_CHAN_VSHUNT` points to `NULL`. When we use the
`sensor get` command for anything bigger than
`SENSOR_CHAN_VSHUNT`, we will deref that `NULL` pointer
when we do `strcmp` in the for-loop of `parse_named_int`.

Fix this by defining `SENSOR_CHAN_VSHUNT` in the table.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-24 07:49:27 -04:00
Yong Cong Sin
c211cb347e drivers: sensor: rtio: use catch-remaining for decoding
As new channels are added to the `enum sensor_channel`, some
of the newer channel aren't updated in the whitelist of rtio
decoder.

Instead of specifying every channel in the list, do:
1. Verify that the `channel` is valid
2. cherry-pick the channels that require special handling, i.e.
   1. `three_axis_data`
   2. `byte_data`
   3. `uint64_data`
3. handle the remaining `channel` in the default case as
   `q31_data`

to make sure that all channels are handled.

Updated the pytest to get channel 32, previously nothing would
happen for this channel as there isn't a decoder for it, now
it would return:

```
channel type=32((null))
```

the channel name is NULL because it wasn't added to the channel
name look up table in the sensor_shell.c, that is being fixed
in #72815.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-21 20:55:47 -04:00
Aurelien Jarno
2194331431 drivers: sensor: stm32_temp/vbat/vref: ensure the ADC is not suspended
The STM32 temperature, battery and voltage reference sensors needs to
write the ADC common registers to enable the corresponding ADC features.
For that we need to ensure that the ADC is not suspended by using the
pm_device_runtime_get/put methods.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2024-05-21 20:53:32 -04:00
Henrik Brix Andersen
59402fd82e drivers: sensor: nxp: kinetis: temp: fix memset() length
Use the correct buffer size when calling memset().

Fixes: #73093

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-05-21 16:41:58 -04:00
Henrik Brix Andersen
0a49b788a4 drivers: sensors: nxp: kinetis: temp: select CONFIG_ADC
The NXP Kinetis temperature sensor depends on CONFIG_ADC. Make the driver
Kconfig select CONFIG_ADC to get better CI coverage (enabling the driver
when CONFIG_SENSOR is enabled without depending on CONFIG_ADC=y).

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2024-05-21 16:41:58 -04:00
Aurelien Jarno
52935edc5c drivers: sensor: stm32_temp: use sensor_value_from_float()
The temperature being computed using a float variable, use
sensor_value_from_float() instead of sensor_value_from_double(). This
saves some flash.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2024-05-20 20:39:01 -04:00
Yong Cong Sin
1e196f0f75 sensor: sensor_shell: print something when trig command succeeds
Print something to the shell when the `trig` command
completed successfully.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-20 22:56:11 +03:00
Juliane Schulze
72b20315ea drivers: set LIS2DH default trigger mode to "EDGE_BOTH"
Previous value just activated the ability to trigger for both edges,
without (de)-activating the gpio. This caused an assrtion error in GPIO.h.

Fixes #71227

Signed-off-by: Juliane Schulze <juliane.schulze@deveritec.com>
2024-05-20 18:05:01 +02:00
Jeppe Odgaard
0b94ab7704 drivers: sensors: add veaa_x_3 proportional pressure regulator sensor
Add driver for Festo VEAA-X-3 series proportional pressure regulator.

The driver assumes that the maximum ADC value matches the maximum
output from the device, and that the maximum DAC value matches the
maximum input value for the device. External hardware is probably
required between the ADC/DAC and the device.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2024-05-18 15:56:09 +03:00
Björn Stenberg
63c8b950e5 voltage_divider: Add support for single-ended 16-bit ADC
Unless configured as differential, the raw ADC data is unsigned.

Includes workaround for #71119.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2024-05-18 15:55:02 +03:00
Yong Cong Sin
5f1e1c7b34 drivers: sensor: sensor_shell: fix infinite loop when doing sensor get
Should increment `ch.chan_idx` instead of `channel_idx`,
otherwise we will be stucked in the loop forever.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-17 14:34:09 +02:00
Yong Cong Sin
b0394425e1 drivers: sensor: st: vbat: check for ADC nodes
The vbat driver requires the adc node to be enabled:

```c
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst))
```

Update its Kconfig to depend on `DT_HAS_ST_STM32_ADC_ENABLED`,
which is the `"st,stm32-adc"` compat that all ST ADC bindings
include, this will guarantee that at least one ADC node is
enabled, but not necessarily the ADC used by the vbat node.

To make sure that it at least compiles, we init the `adc`
pointer only if the specified ADC node is enabled, otherwise
it will points to `NULL`.

Finally, check if the `adc` points to `NULL` in
`stm32_vbat_init`. We are not relying on the existing
`device_is_ready` check because `DEVICE_DT_GET` will not
return `NULL` if the ADC is enabled. `adc == NULL` means
that the ADC node is not enabled in the devicetree.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-17 11:39:19 +02:00
Tom Burdick
b249535093 sensors: Add channel specifier
Use a structured channel specifier rather than a single enum when
specifying channels to read in the new read/decoder API.

Replaces usages of a seperate channel and channel_index parameter
where previously used with a struct sensor_chan_spec.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2024-05-17 09:30:18 +02:00
Jeppe Odgaard
c9f53d3374 drivers: sensor: add Innovative Sensor Technology TSic xx6 driver
Add driver for TSic 206/306/316/506F/516/716 temperature sensor.
The driver uses PWM capture driver to read a single wire with
Manchester-like encoding.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2024-05-16 18:57:24 -04:00
Jordan Yates
7ddbe9d4bd sensor: voltage_divider: fix power-gpio
`CONFIG_PM_DEVICE` being disabled does not mean that the `power-gpio`
does not need to be controlled.

Additionally, not having a `power-gpio` property does not mean that
power management is not supported, just that is has no work to do.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-16 18:55:45 -04:00
Jordan Yates
d725666b2c sensor: convert ADC depends on to select
When a sensor that depends on an ADC is enabled in devicetree, enable
the ADC subsystem. ADC is roughly equivalent to a bus for these sensors
(the mechanism through which data is transferred), which had the same
conversion applied in #48707.

The same benefits apply here, namely removing the need for the following
pattern in board `.kconfig` files:
```
configdefault ADC
    default y if SENSOR
```

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-16 13:31:32 +02:00