Skip to content

Commit 6badb7f

Browse files
bbilasnashif
authored andcommitted
drivers: sensors: sht3xd: allow multiple instances
Make this driver multi-instance. Signed-off-by: Bartosz Bilas <[email protected]>
1 parent 3b3961a commit 6badb7f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

drivers/sensor/sht3xd/sht3xd.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,24 @@ static int sht3xd_init(const struct device *dev)
205205
return 0;
206206
}
207207

208-
struct sht3xd_data sht3xd0_driver;
209-
static const struct sht3xd_config sht3xd0_cfg = {
210-
.bus = I2C_DT_SPEC_INST_GET(0),
211208
#ifdef CONFIG_SHT3XD_TRIGGER
212-
.alert_gpio_name = DT_INST_GPIO_LABEL(0, alert_gpios),
209+
#define SHT3XD_TRIGGER_INIT(inst) \
210+
.alert_gpio_name = DT_INST_GPIO_LABEL(inst, alert_gpios), \
211+
.alert_pin = DT_INST_GPIO_PIN(inst, alert_gpios), \
212+
.alert_flags = DT_INST_GPIO_FLAGS(inst, alert_gpios),
213+
#else
214+
#define SHT3XD_TRIGGER_INIT(inst)
213215
#endif
214-
#ifdef CONFIG_SHT3XD_TRIGGER
215-
.alert_pin = DT_INST_GPIO_PIN(0, alert_gpios),
216-
.alert_flags = DT_INST_GPIO_FLAGS(0, alert_gpios),
217-
#endif
218-
};
219216

220-
DEVICE_DT_INST_DEFINE(0, sht3xd_init, NULL,
221-
&sht3xd0_driver, &sht3xd0_cfg,
222-
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
223-
&sht3xd_driver_api);
217+
#define SHT3XD_DEFINE(inst) \
218+
struct sht3xd_data sht3xd0_data_##inst; \
219+
static const struct sht3xd_config sht3xd0_cfg_##inst = { \
220+
.bus = I2C_DT_SPEC_INST_GET(inst), \
221+
SHT3XD_TRIGGER_INIT(inst) \
222+
}; \
223+
DEVICE_DT_INST_DEFINE(inst, sht3xd_init, NULL, \
224+
&sht3xd0_data_##inst, &sht3xd0_cfg_##inst, \
225+
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \
226+
&sht3xd_driver_api);
227+
228+
DT_INST_FOREACH_STATUS_OKAY(SHT3XD_DEFINE)

0 commit comments

Comments
 (0)