drivers: pwm: pwm_stm32: add macro for using DT_INST_PARENT()
Make device init more readable by adding a macro Suggested-by: Francois Ramu <francois.ramu@st.com> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
This commit is contained in:
parent
35f380510c
commit
63fa033d11
1 changed files with 15 additions and 12 deletions
|
@ -722,27 +722,29 @@ static int pwm_stm32_init(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PWM(index) DT_INST_PARENT(index)
|
||||||
|
|
||||||
#ifdef CONFIG_PWM_CAPTURE
|
#ifdef CONFIG_PWM_CAPTURE
|
||||||
#define IRQ_CONNECT_AND_ENABLE_BY_NAME(index, name) \
|
#define IRQ_CONNECT_AND_ENABLE_BY_NAME(index, name) \
|
||||||
{ \
|
{ \
|
||||||
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_INST_PARENT(index), name, irq), \
|
IRQ_CONNECT(DT_IRQ_BY_NAME(PWM(index), name, irq), \
|
||||||
DT_IRQ_BY_NAME(DT_INST_PARENT(index), name, priority), \
|
DT_IRQ_BY_NAME(PWM(index), name, priority), \
|
||||||
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
|
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
|
||||||
irq_enable(DT_IRQ_BY_NAME(DT_INST_PARENT(index), name, irq)); \
|
irq_enable(DT_IRQ_BY_NAME(PWM(index), name, irq)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IRQ_CONNECT_AND_ENABLE_DEFAULT(index) \
|
#define IRQ_CONNECT_AND_ENABLE_DEFAULT(index) \
|
||||||
{ \
|
{ \
|
||||||
IRQ_CONNECT(DT_IRQN(DT_INST_PARENT(index)), \
|
IRQ_CONNECT(DT_IRQN(PWM(index)), \
|
||||||
DT_IRQ(DT_INST_PARENT(index), priority), \
|
DT_IRQ(PWM(index), priority), \
|
||||||
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
|
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
|
||||||
irq_enable(DT_IRQN(DT_INST_PARENT(index))); \
|
irq_enable(DT_IRQN(PWM(index))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IRQ_CONFIG_FUNC(index) \
|
#define IRQ_CONFIG_FUNC(index) \
|
||||||
static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
|
static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
|
||||||
{ \
|
{ \
|
||||||
COND_CODE_1(DT_IRQ_HAS_NAME(DT_INST_PARENT(index), cc), \
|
COND_CODE_1(DT_IRQ_HAS_NAME(PWM(index), cc), \
|
||||||
(IRQ_CONNECT_AND_ENABLE_BY_NAME(index, cc)), \
|
(IRQ_CONNECT_AND_ENABLE_BY_NAME(index, cc)), \
|
||||||
(IRQ_CONNECT_AND_ENABLE_DEFAULT(index)) \
|
(IRQ_CONNECT_AND_ENABLE_DEFAULT(index)) \
|
||||||
); \
|
); \
|
||||||
|
@ -756,10 +758,11 @@ static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
|
||||||
|
|
||||||
#define DT_INST_CLK(index, inst) \
|
#define DT_INST_CLK(index, inst) \
|
||||||
{ \
|
{ \
|
||||||
.bus = DT_CLOCKS_CELL(DT_INST_PARENT(index), bus), \
|
.bus = DT_CLOCKS_CELL(PWM(index), bus), \
|
||||||
.enr = DT_CLOCKS_CELL(DT_INST_PARENT(index), bits) \
|
.enr = DT_CLOCKS_CELL(PWM(index), bits) \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define PWM_DEVICE_INIT(index) \
|
#define PWM_DEVICE_INIT(index) \
|
||||||
static struct pwm_stm32_data pwm_stm32_data_##index; \
|
static struct pwm_stm32_data pwm_stm32_data_##index; \
|
||||||
IRQ_CONFIG_FUNC(index) \
|
IRQ_CONFIG_FUNC(index) \
|
||||||
|
@ -767,9 +770,9 @@ static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
|
||||||
PINCTRL_DT_INST_DEFINE(index); \
|
PINCTRL_DT_INST_DEFINE(index); \
|
||||||
\
|
\
|
||||||
static const struct pwm_stm32_config pwm_stm32_config_##index = { \
|
static const struct pwm_stm32_config pwm_stm32_config_##index = { \
|
||||||
.timer = (TIM_TypeDef *)DT_REG_ADDR(DT_INST_PARENT(index)), \
|
.timer = (TIM_TypeDef *)DT_REG_ADDR(PWM(index)), \
|
||||||
.prescaler = DT_PROP(DT_INST_PARENT(index), st_prescaler), \
|
.prescaler = DT_PROP(PWM(index), st_prescaler), \
|
||||||
.countermode = DT_PROP(DT_INST_PARENT(index), st_countermode), \
|
.countermode = DT_PROP(PWM(index), st_countermode), \
|
||||||
.pclken = DT_INST_CLK(index, timer), \
|
.pclken = DT_INST_CLK(index, timer), \
|
||||||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
|
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
|
||||||
CAPTURE_INIT(index) \
|
CAPTURE_INIT(index) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue