drivers: sensor: stm32_temp: Add multi-instance support

Move driver to use DT_INST_FOREACH_STATUS_OKAY to add
multi-instance support.

Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
Benjamin Björnsson 2022-07-11 23:31:06 +02:00 committed by Carles Cufí
parent 7b6ca29941
commit 05a6c0fe68

View file

@ -6,6 +6,7 @@
*/
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/adc.h>
#include <zephyr/logging/log.h>
@ -134,30 +135,33 @@ static int stm32_temp_init(const struct device *dev)
return 0;
}
static const struct stm32_temp_config stm32_temp_dev_config = {
#if HAS_CALIBRATION
.cal1_addr = (uint16_t *)DT_INST_PROP(0, ts_cal1_addr),
.cal2_addr = (uint16_t *)DT_INST_PROP(0, ts_cal2_addr),
.cal1_temp = DT_INST_PROP(0, ts_cal1_temp),
.cal2_temp = DT_INST_PROP(0, ts_cal2_temp),
.cal_vrefanalog = DT_INST_PROP(0, ts_cal_vrefanalog),
#else
.avgslope = DT_INST_PROP(0, avgslope),
.v25_mv = DT_INST_PROP(0, v25),
.is_ntc = DT_INST_PROP(0, ntc)
#endif
};
#define STM32_TEMP_DEFINE(inst) \
static struct stm32_temp_data stm32_temp_dev_data_##inst = { \
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \
.adc_cfg = { \
.gain = ADC_GAIN_1, \
.reference = ADC_REF_INTERNAL, \
.acquisition_time = ADC_ACQ_TIME_MAX, \
.channel_id = DT_INST_IO_CHANNELS_INPUT(inst), \
.differential = 0 \
}, \
}; \
\
static const struct stm32_temp_config stm32_temp_dev_config_##inst = { \
COND_CODE_1(HAS_CALIBRATION, \
(.cal1_addr = (uint16_t *)DT_INST_PROP(inst, ts_cal1_addr), \
.cal2_addr = (uint16_t *)DT_INST_PROP(inst, ts_cal2_addr), \
.cal1_temp = DT_INST_PROP(inst, ts_cal1_temp), \
.cal2_temp = DT_INST_PROP(inst, ts_cal2_temp), \
.cal_vrefanalog = DT_INST_PROP(inst, ts_cal_vrefanalog),), \
(.avgslope = DT_INST_PROP(inst, avgslope), \
.v25_mv = DT_INST_PROP(inst, v25), \
.is_ntc = DT_INST_PROP(inst, ntc))) \
}; \
\
DEVICE_DT_INST_DEFINE(inst, stm32_temp_init, NULL, \
&stm32_temp_dev_data_##inst, &stm32_temp_dev_config_##inst, \
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \
&stm32_temp_driver_api); \
static struct stm32_temp_data stm32_temp_dev_data = {
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(0)),
.adc_cfg = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_MAX,
.channel_id = DT_INST_IO_CHANNELS_INPUT(0),
.differential = 0
},
};
DEVICE_DT_INST_DEFINE(0, stm32_temp_init, NULL, &stm32_temp_dev_data, &stm32_temp_dev_config,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &stm32_temp_driver_api);
DT_INST_FOREACH_STATUS_OKAY(STM32_TEMP_DEFINE)