From 4486ea0473ad7526f59bc4c9332b3444ab2d00c6 Mon Sep 17 00:00:00 2001 From: Florian Vaussard Date: Mon, 1 May 2017 15:22:04 +0200 Subject: [PATCH] pinmux: stm32f4: Clean-up pinmux arrays Clean-up the pinmux arrays as a preparatory work before adding more pinmuxes. This is achieved by the following two actions: - Define the PAD macro to simplify the [x - 1] = y construct - Reorder the declartions by bank / pin to make it easier to locate a pin among a high number of other pins, while minimizing the risk of conflict when two people add a new declaration for two different pins Change-Id: I1ca0cc4f48bcd8cfd35b331e9821935f5c855876 Signed-off-by: Florian Vaussard --- arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c | 50 ++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c b/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c index 711372f582d..3033deeccb7 100644 --- a/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c +++ b/arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c @@ -12,52 +12,48 @@ #include #include -static const stm32_pin_func_t pin_pa9_funcs[] = { - [STM32F4_PINMUX_FUNC_PA9_USART1_TX - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, -}; +#define PAD(AF, func) \ + [AF - 1] = func -static const stm32_pin_func_t pin_pa10_funcs[] = { - [STM32F4_PINMUX_FUNC_PA10_USART1_RX - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, -}; - -static const stm32_pin_func_t pin_pb6_funcs[] = { - [STM32F4_PINMUX_FUNC_PB6_USART1_TX - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, -}; - -static const stm32_pin_func_t pin_pb7_funcs[] = { - [STM32F4_PINMUX_FUNC_PB7_USART1_RX - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, +static const stm32_pin_func_t pin_pa0_funcs[] = { + PAD(STM32F4_PINMUX_FUNC_PA0_PWM2_CH1, STM32F4X_PIN_CONFIG_AF_PUSH_UP), }; static const stm32_pin_func_t pin_pa2_funcs[] = { - [STM32F4_PINMUX_FUNC_PA2_USART2_TX - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, + PAD(STM32F4_PINMUX_FUNC_PA2_USART2_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), }; static const stm32_pin_func_t pin_pa3_funcs[] = { - [STM32F4_PINMUX_FUNC_PA3_USART2_RX - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, + PAD(STM32F4_PINMUX_FUNC_PA3_USART2_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), }; -static const stm32_pin_func_t pin_pa0_funcs[] = { - [STM32F4_PINMUX_FUNC_PA0_PWM2_CH1 - 1] = - STM32F4X_PIN_CONFIG_AF_PUSH_UP, +static const stm32_pin_func_t pin_pa9_funcs[] = { + PAD(STM32F4_PINMUX_FUNC_PA9_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), +}; + +static const stm32_pin_func_t pin_pa10_funcs[] = { + PAD(STM32F4_PINMUX_FUNC_PA10_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP) +}; + +static const stm32_pin_func_t pin_pb6_funcs[] = { + PAD(STM32F4_PINMUX_FUNC_PB6_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), +}; + +static const stm32_pin_func_t pin_pb7_funcs[] = { + PAD(STM32F4_PINMUX_FUNC_PB7_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP), }; /** * @brief pin configuration */ static const struct stm32_pinmux_conf pins[] = { + STM32_PIN_CONF(STM32_PIN_PA0, pin_pa0_funcs), + STM32_PIN_CONF(STM32_PIN_PA2, pin_pa2_funcs), + STM32_PIN_CONF(STM32_PIN_PA3, pin_pa3_funcs), STM32_PIN_CONF(STM32_PIN_PA9, pin_pa9_funcs), STM32_PIN_CONF(STM32_PIN_PA10, pin_pa10_funcs), STM32_PIN_CONF(STM32_PIN_PB6, pin_pb6_funcs), STM32_PIN_CONF(STM32_PIN_PB7, pin_pb7_funcs), - STM32_PIN_CONF(STM32_PIN_PA2, pin_pa2_funcs), - STM32_PIN_CONF(STM32_PIN_PA3, pin_pa3_funcs), - STM32_PIN_CONF(STM32_PIN_PA0, pin_pa0_funcs), }; int stm32_get_pin_config(int pin, int func)