drivers: adc: stm32: add support for pinmux
Add support for DT based pinmux configurations. Signed-off-by: Martin Jäger <martin@libre.solar>
This commit is contained in:
parent
6ed13678b8
commit
72d395a897
2 changed files with 29 additions and 10 deletions
|
@ -25,6 +25,7 @@
|
|||
LOG_MODULE_REGISTER(adc_stm32);
|
||||
|
||||
#include <drivers/clock_control/stm32_clock_control.h>
|
||||
#include <pinmux/stm32/pinmux_stm32.h>
|
||||
|
||||
#if !defined(CONFIG_SOC_SERIES_STM32F0X) && \
|
||||
!defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
|
@ -216,11 +217,10 @@ struct adc_stm32_data {
|
|||
|
||||
struct adc_stm32_cfg {
|
||||
ADC_TypeDef *base;
|
||||
|
||||
void (*irq_cfg_func)(void);
|
||||
|
||||
struct stm32_pclken pclken;
|
||||
const struct device *p_dev;
|
||||
const struct soc_gpio_pinctrl *pinctrl;
|
||||
size_t pinctrl_len;
|
||||
};
|
||||
|
||||
static int check_buffer_size(const struct adc_sequence *sequence,
|
||||
|
@ -568,6 +568,12 @@ static int adc_stm32_init(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
/* configure pinmux */
|
||||
if (config->pinctrl_len != 0U) {
|
||||
stm32_dt_pinctrl_configure(config->pinctrl,
|
||||
config->pinctrl_len);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32L4X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32WBX) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32G4X) || \
|
||||
|
@ -710,13 +716,18 @@ static const struct adc_driver_api api_stm32_driver_api = {
|
|||
\
|
||||
static void adc_stm32_cfg_func_##index(void); \
|
||||
\
|
||||
static const struct soc_gpio_pinctrl adc_pins_##index[] = \
|
||||
ST_STM32_DT_INST_PINCTRL(index, 0); \
|
||||
\
|
||||
static const struct adc_stm32_cfg adc_stm32_cfg_##index = { \
|
||||
.base = (ADC_TypeDef *)DT_INST_REG_ADDR(index),\
|
||||
.base = (ADC_TypeDef *)DT_INST_REG_ADDR(index), \
|
||||
.irq_cfg_func = adc_stm32_cfg_func_##index, \
|
||||
.pclken = { \
|
||||
.enr = DT_INST_CLOCKS_CELL(index, bits), \
|
||||
.bus = DT_INST_CLOCKS_CELL(index, bus), \
|
||||
.enr = DT_INST_CLOCKS_CELL(index, bits), \
|
||||
.bus = DT_INST_CLOCKS_CELL(index, bus), \
|
||||
}, \
|
||||
.pinctrl = adc_pins_##index, \
|
||||
.pinctrl_len = ARRAY_SIZE(adc_pins_##index), \
|
||||
}; \
|
||||
static struct adc_stm32_data adc_stm32_data_##index = { \
|
||||
ADC_CONTEXT_INIT_TIMER(adc_stm32_data_##index, ctx), \
|
||||
|
@ -724,7 +735,7 @@ static struct adc_stm32_data adc_stm32_data_##index = { \
|
|||
ADC_CONTEXT_INIT_SYNC(adc_stm32_data_##index, ctx), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_AND_API_INIT(adc_##index, DT_INST_LABEL(index), \
|
||||
DEVICE_AND_API_INIT(adc_##index, DT_INST_LABEL(index), \
|
||||
&adc_stm32_init, \
|
||||
&adc_stm32_data_##index, &adc_stm32_cfg_##index, \
|
||||
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
||||
|
@ -732,10 +743,10 @@ DEVICE_AND_API_INIT(adc_##index, DT_INST_LABEL(index), \
|
|||
\
|
||||
static void adc_stm32_cfg_func_##index(void) \
|
||||
{ \
|
||||
IRQ_CONNECT(DT_INST_IRQN(index), \
|
||||
DT_INST_IRQ(index, priority), \
|
||||
IRQ_CONNECT(DT_INST_IRQN(index), \
|
||||
DT_INST_IRQ(index, priority), \
|
||||
adc_stm32_isr, DEVICE_GET(adc_##index), 0); \
|
||||
irq_enable(DT_INST_IRQN(index)); \
|
||||
irq_enable(DT_INST_IRQN(index)); \
|
||||
}
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(STM32_ADC_INIT)
|
||||
|
|
|
@ -15,6 +15,14 @@ properties:
|
|||
clocks:
|
||||
required: true
|
||||
|
||||
pinctrl-0:
|
||||
type: phandles
|
||||
required: false
|
||||
description: |
|
||||
GPIO pin configuration for ADC input. The phandles are
|
||||
expected to reference pinctrl nodes, e.g.
|
||||
pinctrl-0 = <&adc_in0_pa0 &adc_in1_pa1>;
|
||||
|
||||
interrupts:
|
||||
required: true
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue