Skip to content

Commit e38f335

Browse files
drivers: sensor: tdk: icm42x70: update temperature data processing
Update the temperature data processing to handle different data sizes based on FIFO configuration. The temperature sensor data size and conversion formula vary depending on the FIFO mode: 1. FIFO disabled: Uses 20-bit data format 2. FIFO enabled (standard resolution): 16-bit data 3. FIFO enabled (high resolution): 20-bit data The implementation now: - Uses the 'fifo_highres_enabled' flag to determine the correct data size - Applies the appropriate conversion formula based on the resolution mode - Handles all three possible FIFO configurations - Ensures accurate temperature readings in all modes Signed-off-by: Shreehari HK <[email protected]>
1 parent 36bc2f3 commit e38f335

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/sensor/tdk/icm42x70/icm42x70.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,21 @@ static void icm42x70_convert_accel(struct sensor_value *val, int16_t raw_val, ui
482482
val->val2 = conv_val % 1000000;
483483
}
484484

485-
static void icm42x70_convert_temp(struct sensor_value *val, int16_t raw_val)
485+
static void icm42x70_convert_temp(struct sensor_value *val, int16_t raw_val, bool hires)
486486
{
487487
int64_t conv_val;
488488

489489
/* see datasheet section 15.9 for details */
490-
conv_val = 25 * 1000000 + ((int64_t)raw_val * 1000000 / 2);
490+
#ifdef CONFIG_ICM42X70_TRIGGER
491+
if (!hires) {
492+
conv_val = (25 * 1000000) + ((int64_t)raw_val * 1000000 / 2);
493+
} else {
494+
#else
495+
{
496+
#endif
497+
conv_val = (25 * 1000000) + ((int64_t)raw_val * 1000000 / 128);
498+
}
499+
491500
val->val1 = conv_val / 1000000;
492501
val->val2 = conv_val % 1000000;
493502
}
@@ -530,7 +539,7 @@ static int icm42x70_channel_get(const struct device *dev, enum sensor_channel ch
530539
icm42670_convert_gyro(val, data->gyro_z, data->gyro_fs);
531540
#endif
532541
} else if (chan == SENSOR_CHAN_DIE_TEMP) {
533-
icm42x70_convert_temp(val, data->temp);
542+
icm42x70_convert_temp(val, data->temp, data->driver.fifo_highres_enabled);
534543
#ifdef CONFIG_TDK_APEX
535544
} else if ((enum sensor_channel_tdk_apex)chan == SENSOR_CHAN_APEX_MOTION) {
536545
if (cfg->apex == TDK_APEX_PEDOMETER) {

0 commit comments

Comments
 (0)