sensor: adc_cmp: npcx: use BUILD_ASSERT to check `thr-sel` value
This CL uses BUILD_ASSERT macro to check whether `thr-sel` is out of range instead of using NPCX series definitions. Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
parent
a6496e056b
commit
0d59aa1ab4
|
@ -251,20 +251,23 @@ static const struct sensor_driver_api adc_cmp_npcx_api = {
|
||||||
.channel_get = adc_cmp_npcx_channel_get,
|
.channel_get = adc_cmp_npcx_channel_get,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NPCX_ADC_CMP_INIT(inst) \
|
#define NPCX_ADC_CMP_INIT(inst) \
|
||||||
static struct adc_cmp_npcx_data adc_cmp_npcx_data_##inst; \
|
static struct adc_cmp_npcx_data adc_cmp_npcx_data_##inst; \
|
||||||
static const struct adc_cmp_npcx_config adc_cmp_npcx_config_##inst = {\
|
static const struct adc_cmp_npcx_config adc_cmp_npcx_config_##inst = { \
|
||||||
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \
|
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \
|
||||||
.chnsel = DT_INST_IO_CHANNELS_INPUT(inst), \
|
.chnsel = DT_INST_IO_CHANNELS_INPUT(inst), \
|
||||||
.th_sel = DT_INST_STRING_TOKEN_OR(inst, thr_sel, inst), \
|
.th_sel = DT_INST_STRING_TOKEN_OR(inst, thr_sel, inst), \
|
||||||
.thr_mv = DT_INST_PROP_OR(inst, threshold_mv, \
|
.thr_mv = DT_INST_PROP_OR(inst, threshold_mv, \
|
||||||
ADC_CMP_NPCX_UNDEFINED), \
|
ADC_CMP_NPCX_UNDEFINED), \
|
||||||
.comparison = DT_INST_STRING_TOKEN_OR(inst, \
|
.comparison = DT_INST_STRING_TOKEN_OR(inst, \
|
||||||
comparison, ADC_CMP_NPCX_UNDEFINED) \
|
comparison, ADC_CMP_NPCX_UNDEFINED) \
|
||||||
}; \
|
}; \
|
||||||
SENSOR_DEVICE_DT_INST_DEFINE(inst, adc_cmp_npcx_init, NULL, \
|
SENSOR_DEVICE_DT_INST_DEFINE(inst, adc_cmp_npcx_init, NULL, \
|
||||||
&adc_cmp_npcx_data_##inst, \
|
&adc_cmp_npcx_data_##inst, \
|
||||||
&adc_cmp_npcx_config_##inst, POST_KERNEL, \
|
&adc_cmp_npcx_config_##inst, POST_KERNEL, \
|
||||||
CONFIG_SENSOR_INIT_PRIORITY, \
|
CONFIG_SENSOR_INIT_PRIORITY, \
|
||||||
&adc_cmp_npcx_api);
|
&adc_cmp_npcx_api); \
|
||||||
|
BUILD_ASSERT(DT_INST_STRING_TOKEN_OR(inst, thr_sel, inst) < \
|
||||||
|
DT_PROP(DT_INST_IO_CHANNELS_CTLR(inst), threshold_count), \
|
||||||
|
"Exceed the number of threshold detectors adc supports");
|
||||||
DT_INST_FOREACH_STATUS_OKAY(NPCX_ADC_CMP_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(NPCX_ADC_CMP_INIT)
|
||||||
|
|
|
@ -17,11 +17,9 @@ enum npcx_adc_cmp_thrctl {
|
||||||
ADC_CMP_NPCX_THRCTL1,
|
ADC_CMP_NPCX_THRCTL1,
|
||||||
ADC_CMP_NPCX_THRCTL2,
|
ADC_CMP_NPCX_THRCTL2,
|
||||||
ADC_CMP_NPCX_THRCTL3,
|
ADC_CMP_NPCX_THRCTL3,
|
||||||
#if !defined(CONFIG_SOC_SERIES_NPCX7)
|
|
||||||
ADC_CMP_NPCX_THRCTL4,
|
ADC_CMP_NPCX_THRCTL4,
|
||||||
ADC_CMP_NPCX_THRCTL5,
|
ADC_CMP_NPCX_THRCTL5,
|
||||||
ADC_CMP_NPCX_THRCTL6,
|
ADC_CMP_NPCX_THRCTL6,
|
||||||
#endif
|
|
||||||
ADC_CMP_NPCX_THRCTL_COUNT,
|
ADC_CMP_NPCX_THRCTL_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue