Allow for users to define the sampling period via the sampleper
register on a per instance basis through device-tree properties.
The previous value was hard coded. The same value is now the default
value.
Signed-off-by: Mark Geiger <MarkGeiger@posteo.de>
In lis2dux12_freq_to_odr_val, the loop through the array of possible ODR
frequencies can break sooner than expected if power-mode is
set to High Performance mode and the requested ODR is less than or
equal to 25Hz.
Moreover, move the "odr |= 0x10" statement used for HP mode in the
chip_api set_odr_raw() API, so that we enter the HP mode even when the
ODR is set from DT only.
Signed-off-by: Armando Visconti <armando.visconti@st.com>
Handle `SENSOR_CHAN_ALL` case of the sample_fetch callback of the
lis2dw12 driver. Without this, `sensor_sample_fetch()` does not work
correctly for this device, e.g. rendering the rtio and the sensor shell
unusable.
Signed-off-by: Ruben Völl <ruben.voell@sevenlab.de>
The MAX17055 peripheral allows measuring the current
value (which corresponds to the instantaneous value). Respond to
the `SENSOR_CHAN_CURRENT` command, and retrieve the data
from the `0x0a` device register.
Signed-off-by: Samuel Tardieu <sam@rfc1149.net>
In order to allow decoupling these two operations.
No functional changes, sensor returns same readings through shell.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
As this isn't effectively providing any value to the driver, instead
wastes cycles on every sample-fetch. Scrubbing this simplifies the
code.
Also, remove fix_sign() and replace it for the in-tree helper
sign_extend().
Signed-off-by: Luis Ubieda <luisf@croxel.com>
In order to abstract details of the transport itself, improving
portability.
No functional changes at this point. Driver works the same as far
as my local testing goes.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
The existing driver requires setting multiple attributes in order to
work basic fetch/get reads. Simplify this by allowing the user to set
dts node properties based on the use-case.
As a result, basic settings results in the driver being up and running
from the start, one can just get sensor readings out of the box.
These still can be overriden at run-time if need be.
Signed-off-by: Luis Ubieda <luisf@croxel.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Add the attr_get api. Also rename functions where they implied
accelerometer to imply magnetometer.
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
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>
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>
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>
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>
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>
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>