Skip to content

Commit aeae605

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 8d202cb commit aeae605

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/sensor/tdk/icm42x70/icm42x70.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,17 @@ 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+
if (hires) {
491+
conv_val = (25 * 1000000) + ((int64_t)raw_val * 1000000 / 128);
492+
} else {
493+
conv_val = (25 * 1000000) + ((int64_t)raw_val * 1000000 / 2);
494+
}
495+
491496
val->val1 = conv_val / 1000000;
492497
val->val2 = conv_val % 1000000;
493498
}
@@ -530,7 +535,15 @@ static int icm42x70_channel_get(const struct device *dev, enum sensor_channel ch
530535
icm42670_convert_gyro(val, data->gyro_z, data->gyro_fs);
531536
#endif
532537
} else if (chan == SENSOR_CHAN_DIE_TEMP) {
533-
icm42x70_convert_temp(val, data->temp);
538+
/* see datasheet section 15.9 for details */
539+
if (IS_ENABLED(CONFIG_ICM42X70_TRIGGER)) {
540+
icm42x70_convert_temp(val, data->temp, data->driver.fifo_highres_enabled);
541+
} else {
542+
/* The temperature data read in non-fifo mode is of 2-bytes;
543+
* which is same as FIFO with high resolution temp data.
544+
*/
545+
icm42x70_convert_temp(val, data->temp, true);
546+
}
534547
#ifdef CONFIG_TDK_APEX
535548
} else if ((enum sensor_channel_tdk_apex)chan == SENSOR_CHAN_APEX_MOTION) {
536549
if (cfg->apex == TDK_APEX_PEDOMETER) {

0 commit comments

Comments
 (0)