Skip to content

Commit c85922f

Browse files
dipakgmxcfriedt
authored andcommitted
drivers: sensor: ti: tmp1075: fix one-shot conversion for shutdown mode
Add missing one-shot conversion logic in sample_fetch when driver is configured for shutdown mode. Previously, the driver would attempt to read temperature without triggering conversion, resulting in stale data. Signed-off-by: Dipak Shetty <[email protected]>
1 parent 91265f0 commit c85922f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/sensor/ti/tmp1075/tmp1075.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ static int tmp1075_reg_write(const struct tmp1075_config *cfg, uint8_t reg, uint
4646
return i2c_write_dt(&cfg->bus, buf, sizeof(buf));
4747
}
4848

49+
static inline uint32_t tmp1075_conv_time_ms(uint8_t cr_idx)
50+
{
51+
switch (cr_idx) {
52+
case 0: /* 00: 27.5 ms */
53+
return 28;
54+
case 1: /* 01: 55 ms */
55+
return 55;
56+
case 2: /* 10: 110 ms */
57+
return 110;
58+
case 3: /* 11: 220 ms */
59+
return 220;
60+
default:
61+
__ASSERT_NO_MSG(false);
62+
return 0;
63+
}
64+
}
65+
4966
#if CONFIG_TMP1075_ALERT_INTERRUPTS
5067
static int set_threshold_attribute(const struct device *dev, uint8_t reg, int16_t value,
5168
const char *error_msg)
@@ -139,6 +156,21 @@ static int tmp1075_sample_fetch(const struct device *dev, enum sensor_channel ch
139156

140157
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP);
141158

159+
if (cfg->shutdown_mode || cfg->one_shot) {
160+
/* Initiate a single temperature conversion */
161+
uint16_t config_reg = drv_data->config_reg;
162+
163+
TMP1075_SET_ONE_SHOT_CONVERSION(config_reg, 1);
164+
165+
if (tmp1075_reg_write(cfg, TMP1075_REG_CONFIG, config_reg) < 0) {
166+
LOG_ERR("Failed to initiate one-shot conversion");
167+
return -EIO;
168+
}
169+
170+
/* Wait for conversion to complete */
171+
k_sleep(K_MSEC(tmp1075_conv_time_ms(cfg->cr)));
172+
}
173+
142174
if (tmp1075_reg_read(cfg, TMP1075_REG_TEMPERATURE, &val) < 0) {
143175
return -EIO;
144176
}

0 commit comments

Comments
 (0)