Skip to content

Commit 0eebb85

Browse files
Jeppe Odgaardkartben
authored andcommitted
drivers: sensor: ti: tmp11x: add eeprom await function
Move await eeprom programming into function and add poll loop timeout. Signed-off-by: Jeppe Odgaard <[email protected]>
1 parent 72dac16 commit 0eebb85

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

drivers/sensor/ti/tmp11x/tmp11x.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ static bool check_eeprom_bounds(const struct device *dev, off_t offset,
115115
return true;
116116
}
117117

118+
int tmp11x_eeprom_await(const struct device *dev)
119+
{
120+
int res;
121+
uint16_t val;
122+
123+
k_sleep(K_MSEC(EEPROM_MIN_BUSY_MS));
124+
125+
WAIT_FOR((res = tmp11x_reg_read(dev, TMP11X_REG_EEPROM_UL, &val)) != 0 ||
126+
val & TMP11X_EEPROM_UL_BUSY,
127+
100, k_msleep(1));
128+
129+
return res;
130+
}
131+
118132
int tmp11x_eeprom_write(const struct device *dev, off_t offset,
119133
const void *data, size_t len)
120134
{
@@ -139,14 +153,7 @@ int tmp11x_eeprom_write(const struct device *dev, off_t offset,
139153
break;
140154
}
141155

142-
k_sleep(K_MSEC(EEPROM_MIN_BUSY_MS));
143-
144-
do {
145-
res = tmp11x_reg_read(dev, TMP11X_REG_EEPROM_UL, &val);
146-
if (res != 0) {
147-
break;
148-
}
149-
} while (val & TMP11X_EEPROM_UL_BUSY);
156+
res = tmp11x_eeprom_await(dev);
150157
src++;
151158

152159
if (res != 0) {

0 commit comments

Comments
 (0)