Clearing the status register in adxl367_thread_cb() introduces
a one-sample latency since any trigger handler invoking
adxl367_get_accel_data() has to wait until the next sample sets the
DATA_READY bit again. To fix this, identify trigger source by
reading status_copy register in adxl367_thread_cb(). This preserves
the status register contents for verification prior to fetching data.
Signed-off-by: Shiril Tichkule <Shiril.Tichkule@analog.com>
Compress the `struct ina2xx_channels` to only the channels that are
supported. This has the added benefit that trying to access an
unsupported channel (in the driver) is now a compile-time error.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Use `#ifdef`, `#else`, `#endif` to block out implementations, instead
of putting the checks inside an `if`, which results in all the
implementations being indented.
It also makes it much clearer to any user with syntax highlighting
configured, since the unsupported channels are greyed out.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Fix calling `sensor_channel_get` on a channel that is not supported by
the hardware from faulting with a NULL de-reference.
This fixes the following pattern (used by `fuel_guage/composite`):
```
sensor_sample_fetch(dev);
if (sensor_channel_get(dev, chan, val) == -EINVAL) {
printk("Not supported\n");
}
````
Signed-off-by: Jordan Yates <jordan@embeint.com>
This reverts commit ae44e1e7b7.
The only consequence of removing NULL checks is enabling NULL
dereference exceptions. The sensor API is a generic API, a generic
library built on top of that API does not always know which channels a
device supports.
Signed-off-by: Jordan Yates <jordan@embeint.com>
This reverts commit 8340e8c264.
The only consequence of removing NULL checks is enabling NULL
dereference exceptions. The sensor API is a generic API, a generic
library built on top of that API does not always know which channels a
device supports.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Use micro-units when converting readings to struct sensor_value.
The previous implementation used 100000-based scaling for fractional
values, while sensor_value expects 10^-6 units. As a result, converted
magnetic field values were reported as 10x the expected gauss value
instead of gauss, and the incorrect scaling caused apparent jumps in
the reported sensor readings.
Fix the conversions by using 1000000-based scaling and
sensor_value_from_micro().
Signed-off-by: Bernhard Reiter <bernhard.reiter@swarovskioptik.com>
Add driver support for NXP MCUX Quadrature Decoder (QDC) sensor.
The driver provides:
- Position tracking via SENSOR_CHAN_ROTATION channel
- Configurable counts per revolution
- Single phase and normal decoder work modes
- Input filtering with configurable count and sample period
- INPUTMUX integration for flexible signal routing
- Modulo count mode support
Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
There are many lm75 variants differing in temperature resolution.
Typical values are 9, 10, 11, and 12 bit. They all use the same
format (16 bit signed integer with LSB at 1/256 degree C).
Depending on the on the actual variant some of the LSB are not
defined. The new calculation scheme uses all 16 bits independent
on the actual sensor resolution. In the worst this leads to
some pseudo-resolution in case the undefined bits are not
reported as 0 by the sensor.
Signed-off-by: Lutz Dittrich <dittrich@netwake.com>
Update bindings to consume a NVMEM cell instead of raw addresses, and
update the driver to support obtaining calibration data using the NVMEM
subsystem. For backwards compatibility and reduced footprint, the old
mechanism (direct MMIO read) is retained; a Kconfig option is introduced
to allow selecting which mechanism is used.
The sensor binding and SoC DTSI is updated accordingly.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Update bindings to consume a NVMEM cell instead of raw addresses, and
update the driver to support obtaining calibration data using the NVMEM
subsystem. For backwards compatibility and reduced footprint, the old
mechanism (direct MMIO read) is retained; a Kconfig option is introduced
to allow selecting which mechanism is used.
The sensor binding and SoC DTSI is updated accordingly.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
I2C_RTIO, I3C_RTIO and SPI_RTIO should be selected in the driver
itself on the basis of which busses have these devices instances.
Signed-off-by: Armando Visconti <armando.visconti@st.com>
Fix interrupt enable/disable sequence per ADXL345 datasheet
recommendations.
The ADXL345 datasheet (page 19) states: "When initially configuring
the interrupt pins, it is recommended that the functions and interrupt
mapping be done before enabling the interrupts."
Main changes:
1. Remove adxl345_interrupt_config() which incorrectly enabled
interrupts during driver initialization without proper sequencing.
It's not clear to me what was the purpose of this function as all
the required logic (setting gpio interrups, adxl mapping and enabling
happens already in tigger_set).
I checked other drivers and this seems to be the common pattern.
2. Implement proper INT_ENABLE disable/enable sequence in
adxl345_submit_stream() when reconfiguring watermark interrupts:
- Disable watermark interrupt in INT_ENABLE
- Configure interrupt mapping in INT_MAP
- Flush FIFO
- Re-enable watermark interrupt in INT_ENABLE
3. Add datasheet-based comments in adxl345_trigger.c explaining
non-obvious register operations:
- AC/DC coupling modes (ACT_INACT_CTL register)
- INT_MAP routing logic (0=INT1, 1=INT2)
- Interrupt clearing by reading data registers
4. Fix bug in adxl345_trigger_set() where ADXL345_INT_MAP_DATA_RDY_MSK
was hardcoded instead of using the correct int_mask variable.
Fixes#100891
Tested on ebyte_e73_tbb with samples `accel_polling` and `accel_trig`
Signed-off-by: Tobias Kässer <t.kaesser@gmail.com>
Add initial support for Analog Devices ADE7978 isolated energy
metering IC for polyphase shunt meters.
The driver implements the Zephyr sensor API and provides:
- SPI communication (read/write 8/16/32-bit registers)
- Phase A RMS current measurement (SENSOR_CHAN_CURRENT)
- Phase A RMS voltage measurement (SENSOR_CHAN_VOLTAGE)
- Device Tree bindings
This is an initial minimal working implementation. Future enhancements
will include:
- Multi-phase support (Phase B, C, Neutral)
- Active and reactive power measurement
- Interrupt support
- Calibration API
Signed-off-by: Filip Stojanovic <filipembedded@gmail.com>
Use official TDK Invensense driver for icm45686 sensor in tdk_hal module.
Supports icm456xx variants.
Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Correct a bitmask issue on the temperature alert threshold
as per the datasheet (Section 7.5.7.4.2).
Signed-off-by: Jeremy Thompson <jthompson@blackberry.com>
Adds device power manager support to TMAG5273 driver.
Suspending the device will put it into its SLEEP mode, resuming will
restore it to the mode configured in devicetree.
Before communicating with a device in sleep mode, an extra I2C transfer
is needed. Something like this is briefly mentioned in the datasheet,
but without any more specific details. The wake up has also been added
to the init function, even in case PM is disabled.
The device is marked as busy for the whole sample_fetch function.
Signed-off-by: Marek Maškarinec <marek.maskarinec@hardwario.com>
If the clock device (i.e., RCC) failed to initialize, we have bigger
problems than trying to call clock_control_{off,on,configure} on it.
Don't bother checking to save some footprint.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Apply code formatting to the TMAG5170 driver sources.
No functional changes intended.
Signed-off-by: Bernhard Reiter <bernhard.reiter@swarovskioptik.com>
Add full power‑management support to the LPS2XDF sensor family
(LPS22DF, LPS28DFW, ILPS22QS). This integrates the drivers with the
Zephyr PM subsystem and allows deferred initialization through
power domains.
Introduce a power_on() callback in lps2xdf_chip_api and track the
current ODR in lps2xdf_data for suspend/resume handling. Implement
a PM control callback that:
- powers on the chip on PM_DEVICE_ACTION_TURN_ON
- enters power‑down mode by setting ODR=0 on SUSPEND
- restores the previous ODR on RESUME
- performs no action on TURN_OFF
Convert initialization to use pm_device_driver_init() and update
the instantiation macros to use PM_DEVICE_DT_INST_DEFINE.
Update each chip driver (lps22df, lps28dfw, ilps22qs) to provide a
.power_on implementation and store the initial ODR in the driver
data.
This enables proper power‑domain control and low‑power operation for
all LPS2XDF‑based pressure sensors.
Signed-off-by: Zafer SEN <zafersn93@gmail.com>
Add power management (PM) support to the LIS2DW12
accelerometer driver, enabling integration with Zephyr's
PM subsystem and power domains.
Changes:
-Implement lis2dw12_pm_control() callback to handle PM actions:
PM_DEVICE_ACTION_TURN_ON: Performs full chip initialization
PM_DEVICE_ACTION_SUSPEND: Puts device into power-down mode (ODR off)
PM_DEVICE_ACTION_RESUME: Restores previous output data rate
PM_DEVICE_ACTION_TURN_OFF: Supported (no-op)
- Refactor driver initialization:
Extract hardware init sequence into lis2dw12_power_up()
Add lis2dw12_bus_check() for bus readiness verification
Use pm_device_driver_init() for PM lifecycle management
Add PM_DEVICE_DT_INST_DEFINE to device instantiation macro
This enables the LIS2DW12 to be controlled via power domains,
allowing deferred initialization until the device is explicitly turned on,
and proper suspend/resume for power savings.
Signed-off-by: Zafer SEN <zafersn93@gmail.com>
As per Zephyr coding guideline #59, "operands shall not be of an
inappropriate essential type". This makes sure boolean variables are
assigned true/false values, not 1/0.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Combine register address and data in one buffer and use i2c_write_dt()
instead of i2c_burst_write_dt() so the transfer is a single I2C
transaction. Some I2C controllers (e.g. Infineon) split burst write
into two transactions with a STOP in between, which causes failure.
Signed-off-by: Oleksandr Skopets <skopets.sasha@gmail.com>
As per Zephyr coding guideline #59, "operands shall not be of an
inappropriate essential type". This makes sure boolean variables are
initialized and used with proper essential type (true/false).
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The calculation of the sensor value uses the intermediate value of the
function `adc_raw_to_microvolts_dt`. This results in a sensor value
with a resolution that is not below `voltage-divider-scaling` millivolts
which can be too rough for some applications.
Using `adc_raw_to_microvolts_dt` and 64-bit-based scaling improves
the resulting voltage resolution.
Therefore, the public function `voltage_divider_scale64_dt()` is
introduced, which performs the same as `voltage_divider_scale_dt()`.
This decision does not affect implementations that use the current
32-bit implementation of `voltage_divider_scale_dt()`.
Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
Instead of reading calibration data (device-unique, but never changing!)
then multiplying the result with a constant as part of each conversion,
perform the read+multiplication once during init and cache the result.
This notably avoids frequently an ICACHE disable/enable cycle on STM32H5,
which is a somewhat slow operation.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Various fields were stored in the instance data despite being initialized
at compile-time to a constant value.
Move these fields to the instance configuration instead.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Check the return value of adxl372_set_op_mode() in
adxl372_submit_stream() and abort on error.
Fix CID: 516239
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
In sensor_shell_stream.c, cmd_sensor_stream() checks for valid trigger
types, but it is missing SENSOR_TRIG_TIMER option.
Signed-off-by: Brandon Edmonds <bedmonds91@gmail.com>
The current PMS7003 sensor driver in Zephyr only supports reading the
basic PM1.0, PM2.5, and PM10 concentration values.
This update extends the driver to support additional data provided by the
PMS7003 sensor, including:
- Standard particle concentration values (CF=1) for PM1.0, PM2.5, and PM10
- Particle counts for particles greater than or equal to 0.3 µm, 0.5 µm,
1.0 µm, 2.5 µm, 5.0 µm, and 10.0 µm per 0.1 liter of air
Adding support for these readings allows applications to access more
detailed particulate data, improving the sensor’s usability in air quality
monitoring and analysis scenarios.
Signed-off-by: Hanan Arshad <hananarshad619@gmail.com>
Instead of reading calibration data (device-unique, but never changing!)
as part of each conversion, perform the read once and cache the value.
This notably avoids frequently an ICACHE disable/enable cycle on STM32H5,
which is a somewhat slow operation.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Using a union enables accessing the calibration data using member names
instead of an array index, which makes the code more readable.
As long as the layout of struct { T m1; ... T mN; } and array A[N] is the
same (implementation-specific?), usage of the union type as done should
be Standard-compliant: accessing through either member of the union will
use an lvalue with compatible type to the same underlying object, which
is one of the allowed aliasing situations listed in §6.5.7 of N1548.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Various fields were stored in the instance data despite being initialized
at compile-time to a constant value.
Move these fields to the instance configuration instead.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
The raw "12" constant was used in a place where the "CAL_RES" define should
have been used instead.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
When no trigger was chosen case statement fell through to
default which causes the return code to -ENOTSUPP
Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
Add device Self Test procedure. It is required to enable the
per device self-test DT property as well as the LSM6DSV16X_SELF_TEST
configuration.
Signed-off-by: Armando Visconti <armando.visconti@st.com>
INA3221 performs measurements sequentially for all enabled channels (see
datasheet chapter 7.3.1), but the driver was not accounting for this
when calculating the wait time. Additionally, when measuring both bus
and shunt voltages, conversion times should be summed rather than taking
greater value.
Fix by counting enabled channels and multiplying them with per-channel
conversion time. For combined measurement, sum both conversion times
instead of using MAX().
Signed-off-by: Karol Werner <karol@ppkt.eu>
Added a `supported` flag to battery status query so if the
charger does not support the query (returns -ENOTSUP) the
command still returns any other supported queries and
doesn't error out without reporting anything. Any other
errors than -ENOTSUP still cause the request to return
immediately, as was the case before the changes. Tested
on nordic npm 13xx.
Signed-off-by: Jimmy Johnson <catch22@fastmail.net>
The ina2xx channel get helpers assume that channel descriptors are
valid when the driver exposes a given sensor channel.
Checking for NULL channel pointers after they are already
dereferenced does not provide any real safety and can hide
configuration errors.
Drop the late NULL checks and rely on the driver contract that
supported channels must be properly defined.
No functional change intended.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
The INA2xx fetch path assumes valid channel descriptors for all
supported sensor channels.
NULL checks performed after channel data is accessed are ineffective
and misleading, as invalid channel definitions indicate a
configuration error rather than a runtime condition.
Remove the redundant checks and keep the channel handling consistent
with the driver expectations.
No functional change intended.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
To add support for LTR553, we will migrate device-tree
properties to new ones and mark the old ones as deprecated.
We will also refactor variable names accordingly.
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>