Skip to content

Commit af27ad5

Browse files
author
Florian Vaussard
committed
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 <florian.vaussard@heig-vd.ch>
1 parent c573a29 commit af27ad5

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

arch/arm/soc/st_stm32/stm32f4/soc_pinmux.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,48 @@
1212
#include <pinmux/stm32/pinmux_stm32.h>
1313
#include <drivers/clock_control/stm32_clock_control.h>
1414

15-
static const stm32_pin_func_t pin_pa9_funcs[] = {
16-
[STM32F4_PINMUX_FUNC_PA9_USART1_TX - 1] =
17-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
15+
#define PAD(AF, func) \
16+
[AF - 1] = func
17+
18+
static const stm32_pin_func_t pin_pa0_funcs[] = {
19+
PAD(STM32F4_PINMUX_FUNC_PA0_PWM2_CH1, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
1820
};
1921

20-
static const stm32_pin_func_t pin_pa10_funcs[] = {
21-
[STM32F4_PINMUX_FUNC_PA10_USART1_RX - 1] =
22-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
22+
static const stm32_pin_func_t pin_pa2_funcs[] = {
23+
PAD(STM32F4_PINMUX_FUNC_PA2_USART2_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
2324
};
2425

25-
static const stm32_pin_func_t pin_pb6_funcs[] = {
26-
[STM32F4_PINMUX_FUNC_PB6_USART1_TX - 1] =
27-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
26+
static const stm32_pin_func_t pin_pa3_funcs[] = {
27+
PAD(STM32F4_PINMUX_FUNC_PA3_USART2_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
2828
};
2929

30-
static const stm32_pin_func_t pin_pb7_funcs[] = {
31-
[STM32F4_PINMUX_FUNC_PB7_USART1_RX - 1] =
32-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
30+
static const stm32_pin_func_t pin_pa9_funcs[] = {
31+
PAD(STM32F4_PINMUX_FUNC_PA9_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
3332
};
3433

35-
static const stm32_pin_func_t pin_pa2_funcs[] = {
36-
[STM32F4_PINMUX_FUNC_PA2_USART2_TX - 1] =
37-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
34+
static const stm32_pin_func_t pin_pa10_funcs[] = {
35+
PAD(STM32F4_PINMUX_FUNC_PA10_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP)
3836
};
3937

40-
static const stm32_pin_func_t pin_pa3_funcs[] = {
41-
[STM32F4_PINMUX_FUNC_PA3_USART2_RX - 1] =
42-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
38+
static const stm32_pin_func_t pin_pb6_funcs[] = {
39+
PAD(STM32F4_PINMUX_FUNC_PB6_USART1_TX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
4340
};
4441

45-
static const stm32_pin_func_t pin_pa0_funcs[] = {
46-
[STM32F4_PINMUX_FUNC_PA0_PWM2_CH1 - 1] =
47-
STM32F4X_PIN_CONFIG_AF_PUSH_UP,
42+
static const stm32_pin_func_t pin_pb7_funcs[] = {
43+
PAD(STM32F4_PINMUX_FUNC_PB7_USART1_RX, STM32F4X_PIN_CONFIG_AF_PUSH_UP),
4844
};
4945

5046
/**
5147
* @brief pin configuration
5248
*/
5349
static const struct stm32_pinmux_conf pins[] = {
50+
STM32_PIN_CONF(STM32_PIN_PA0, pin_pa0_funcs),
51+
STM32_PIN_CONF(STM32_PIN_PA2, pin_pa2_funcs),
52+
STM32_PIN_CONF(STM32_PIN_PA3, pin_pa3_funcs),
5453
STM32_PIN_CONF(STM32_PIN_PA9, pin_pa9_funcs),
5554
STM32_PIN_CONF(STM32_PIN_PA10, pin_pa10_funcs),
5655
STM32_PIN_CONF(STM32_PIN_PB6, pin_pb6_funcs),
5756
STM32_PIN_CONF(STM32_PIN_PB7, pin_pb7_funcs),
58-
STM32_PIN_CONF(STM32_PIN_PA2, pin_pa2_funcs),
59-
STM32_PIN_CONF(STM32_PIN_PA3, pin_pa3_funcs),
60-
STM32_PIN_CONF(STM32_PIN_PA0, pin_pa0_funcs),
6157
};
6258

6359
int stm32_get_pin_config(int pin, int func)

0 commit comments

Comments
 (0)