|
28 | 28 | *******************************************************************************
|
29 | 29 | */
|
30 | 30 | #include "PortNames.h"
|
31 |
| -#include "stm32_def.h" |
32 | 31 |
|
33 |
| -// Return GPIO base address |
34 |
| -GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) { |
35 |
| - GPIO_TypeDef* gpioPort = 0; |
36 |
| - switch (port_idx) { |
37 |
| - case PortA: |
38 |
| - gpioPort = (GPIO_TypeDef *)GPIOA_BASE; |
39 |
| - break; |
40 |
| - case PortB: |
41 |
| - gpioPort = (GPIO_TypeDef *)GPIOB_BASE; |
42 |
| - break; |
| 32 | +GPIO_TypeDef * GPIOPort[MAX_NB_PORT] = { |
| 33 | + (GPIO_TypeDef *)GPIOA_BASE, |
| 34 | + (GPIO_TypeDef *)GPIOB_BASE |
43 | 35 | #if defined GPIOC_BASE
|
44 |
| - case PortC: |
45 |
| - gpioPort = (GPIO_TypeDef *)GPIOC_BASE; |
46 |
| - break; |
| 36 | + ,(GPIO_TypeDef *)GPIOC_BASE |
47 | 37 | #endif
|
48 | 38 | #if defined GPIOD_BASE
|
49 |
| - case PortD: |
50 |
| - gpioPort = (GPIO_TypeDef *)GPIOD_BASE; |
51 |
| - break; |
| 39 | + ,(GPIO_TypeDef *)GPIOD_BASE |
52 | 40 | #endif
|
53 | 41 | #if defined GPIOE_BASE
|
54 |
| - case PortE: |
55 |
| - gpioPort = (GPIO_TypeDef *)GPIOE_BASE; |
56 |
| - break; |
| 42 | + ,(GPIO_TypeDef *)GPIOE_BASE |
57 | 43 | #endif
|
58 | 44 | #if defined GPIOF_BASE
|
59 |
| - case PortF: |
60 |
| - gpioPort = (GPIO_TypeDef *)GPIOF_BASE; |
61 |
| - break; |
| 45 | + ,(GPIO_TypeDef *)GPIOF_BASE |
62 | 46 | #endif
|
63 | 47 | #if defined GPIOG_BASE
|
64 |
| - case PortG: |
65 |
| - gpioPort = (GPIO_TypeDef *)GPIOG_BASE; |
66 |
| - break; |
| 48 | + ,(GPIO_TypeDef *)GPIOG_BASE |
67 | 49 | #endif
|
68 | 50 | #if defined GPIOH_BASE
|
69 |
| - case PortH: |
70 |
| - gpioPort = (GPIO_TypeDef *)GPIOH_BASE; |
71 |
| - break; |
| 51 | + ,(GPIO_TypeDef *)GPIOH_BASE |
72 | 52 | #endif
|
73 | 53 | #if defined GPIOI_BASE
|
74 |
| - case PortI: |
75 |
| - gpioPort = (GPIO_TypeDef *)GPIOI_BASE; |
76 |
| - break; |
| 54 | + ,(GPIO_TypeDef *)GPIOI_BASE |
77 | 55 | #endif
|
78 | 56 | #if defined GPIOJ_BASE
|
79 |
| - case PortJ: |
80 |
| - gpioPort = (GPIO_TypeDef *)GPIOJ_BASE; |
81 |
| - break; |
| 57 | + ,(GPIO_TypeDef *)GPIOJ_BASE |
82 | 58 | #endif
|
83 | 59 | #if defined GPIOK_BASE
|
84 |
| - case PortK: |
85 |
| - gpioPort = (GPIO_TypeDef *)GPIOK_BASE; |
86 |
| - break; |
| 60 | + ,(GPIO_TypeDef *)GPIOK_BASE |
87 | 61 | #endif
|
88 |
| - default: |
89 |
| - // wrong port number |
90 |
| - //TBD: error management |
91 |
| - gpioPort = 0; |
92 |
| - break; |
93 |
| - } |
94 |
| - return gpioPort; |
95 |
| -} |
| 62 | +}; |
96 | 63 |
|
97 |
| -// Enable GPIO clock and return GPIO base address |
| 64 | +/* Enable GPIO clock and return GPIO base address */ |
98 | 65 | GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
|
99 | 66 | GPIO_TypeDef* gpioPort = 0;
|
100 | 67 | switch (port_idx) {
|
@@ -173,4 +140,3 @@ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
|
173 | 140 | }
|
174 | 141 | return gpioPort;
|
175 | 142 | }
|
176 |
| - |
0 commit comments