drivers: sensor: stm32_vbat: handle disabled ADCs more gracefully
This commit modifies the STM32 battery voltage sensor driver to handle erroneous usage more gracefully. More precisely, it now fails builds with an explicit error message when the sensor is enabled but the corresponding ADC is not. This can only happen on STM32 series with more than one ADC (e.g., H7). Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
This commit is contained in:
parent
1e0e3a874f
commit
c77d5b8c3b
1 changed files with 8 additions and 5 deletions
|
@ -124,14 +124,17 @@ static int stm32_vbat_init(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STM32_VBAT_GET_ADC_OR_NULL(inst) \
|
#define ASSERT_VBAT_ADC_ENABLED(inst) \
|
||||||
COND_CODE_1(DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(inst), okay), \
|
BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_INST_IO_CHANNELS_CTLR(inst), okay), \
|
||||||
(DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst))), (NULL))
|
"ADC instance '" DT_NODE_FULL_NAME(DT_INST_IO_CHANNELS_CTLR(inst)) "' needed " \
|
||||||
|
"by Vbat sensor '" DT_NODE_FULL_NAME(DT_DRV_INST(inst)) "' is not enabled")
|
||||||
|
|
||||||
#define STM32_VBAT_DEFINE(inst) \
|
#define STM32_VBAT_DEFINE(inst) \
|
||||||
|
ASSERT_VBAT_ADC_ENABLED(inst); \
|
||||||
|
\
|
||||||
static struct stm32_vbat_data stm32_vbat_dev_data_##inst = { \
|
static struct stm32_vbat_data stm32_vbat_dev_data_##inst = { \
|
||||||
.adc = STM32_VBAT_GET_ADC_OR_NULL(inst), \
|
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \
|
||||||
.adc_base = (ADC_TypeDef *)DT_REG_ADDR(DT_INST_IO_CHANNELS_CTLR(0)), \
|
.adc_base = (ADC_TypeDef *)DT_REG_ADDR(DT_INST_IO_CHANNELS_CTLR(inst)), \
|
||||||
.adc_cfg = { \
|
.adc_cfg = { \
|
||||||
.gain = ADC_GAIN_1, \
|
.gain = ADC_GAIN_1, \
|
||||||
.reference = ADC_REF_INTERNAL, \
|
.reference = ADC_REF_INTERNAL, \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue