From 6d2d34bdad36012165c385c66a3356696f56f1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Mon, 4 Jul 2022 19:33:40 +0200 Subject: [PATCH] drivers: sensor: mpr: Add multi-instance support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move driver to use DT_INST_FOREACH_STATUS_OKAY to add multi-instance support. Signed-off-by: Benjamin Björnsson --- drivers/sensor/mpr/mpr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/sensor/mpr/mpr.c b/drivers/sensor/mpr/mpr.c index c9162473b54..cac15063a24 100644 --- a/drivers/sensor/mpr/mpr.c +++ b/drivers/sensor/mpr/mpr.c @@ -128,11 +128,15 @@ static const struct sensor_driver_api mpr_api_funcs = { .channel_get = mpr_channel_get, }; -static struct mpr_data mpr_data; -static const struct mpr_config mpr_cfg = { - .i2c = I2C_DT_SPEC_INST_GET(0), -}; +#define MPR_DEFINE(inst) \ + static struct mpr_data mpr_data_##inst; \ + \ + static const struct mpr_config mpr_config_##inst = { \ + .i2c = I2C_DT_SPEC_INST_GET(inst), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, mpr_init, NULL, \ + &mpr_data_##inst, &mpr_config_##inst, POST_KERNEL, \ + CONFIG_SENSOR_INIT_PRIORITY, &mpr_api_funcs); \ -DEVICE_DT_INST_DEFINE(0, mpr_init, NULL, &mpr_data, - &mpr_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, - &mpr_api_funcs); +DT_INST_FOREACH_STATUS_OKAY(MPR_DEFINE)