1 /**
2   ******************************************************************************
3   * @file    stm32u0xx_hal_gpio_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of GPIO HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2023 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32U0xx_HAL_GPIO_EX_H
21 #define STM32U0xx_HAL_GPIO_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32u0xx_hal_def.h"
29 
30 /** @addtogroup STM32U0xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup GPIOEx GPIOEx
35   * @brief GPIO Extended HAL module driver
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 /* Exported constants --------------------------------------------------------*/
41 /** @defgroup GPIOEx_Exported_Constants GPIOEx Exported Constants
42   * @{
43   */
44 
45 /** @defgroup GPIOEx_Alternate_function_selection GPIOEx Alternate function selection
46   * @{
47   */
48 
49 /**
50   * @brief   AF 0 selection
51   */
52 #define GPIO_AF0_MCO           ((uint8_t)0x00)  /*!< MCO (MCO1) Alternate Function mapping */
53 #define GPIO_AF0_OSC_EN        ((uint8_t)0x00)  /*!< OSC (By pass and Enable) Alternate Function mapping */
54 #define GPIO_AF0_OSC32_EN      ((uint8_t)0x00)  /*!< OSC32 (By pass and Enable) Alternate Function mapping */
55 #define GPIO_AF0_SWD           ((uint8_t)0x00)  /*!< SWD (SWDIO/SWDCLK)  Alternate Function mapping */
56 #define GPIO_AF0_MCO2          ((uint8_t)0x00)  /*!< MCO (MCO2) Alternate Function mapping */
57 #define GPIO_AF0_RTC           ((uint8_t)0x00)  /*!< RTC (OUT2/REFIN) Alternate Function mapping */
58 
59 /**
60   * @brief   AF 1 selection
61   */
62 #define GPIO_AF1_IR            ((uint8_t)0x01)  /*!< IR Alternate Function mapping */
63 #define GPIO_AF1_TIM1          ((uint8_t)0x01)  /*!< TIM1 Alternate Function mapping */
64 #define GPIO_AF1_TIM2          ((uint8_t)0x01)  /*!< TIM2 Alternate Function mapping */
65 #define GPIO_AF1_LPTIM1        ((uint8_t)0x01)  /*!< LPTIM1 Alternate Function mapping */
66 #define GPIO_AF1_OSC_EN        ((uint8_t)0x01)  /*!< OSC (By pass and Enable) Alternate Function mapping */
67 
68 /**
69   * @brief   AF 2 selection
70   */
71 #define GPIO_AF2_LPTIM1        ((uint8_t)0x02)  /*!< LPTIM1 Alternate Function mapping */
72 #if defined(LPTIM3)
73 #define GPIO_AF2_LPTIM3        ((uint8_t)0x02)  /*!< LPTIM3 Alternate Function mapping */
74 #endif /* LPTIM3 */
75 #if defined(I2C4)
76 #define GPIO_AF2_I2C4          ((uint8_t)0x02)  /*!< I2C4 Alternate Function mapping */
77 #endif /* I2C4 */
78 #define GPIO_AF2_TIM2          ((uint8_t)0x02)  /*!< TIM2 Alternate Function mapping */
79 #define GPIO_AF2_TIM3          ((uint8_t)0x02)  /*!< TIM3 Alternate Function mapping */
80 #define GPIO_AF2_TIM1          ((uint8_t)0x02)  /*!< TIM3 Alternate Function mapping */
81 
82 /**
83   * @brief   AF 3 selection
84   */
85 #define GPIO_AF3_I2C2          ((uint8_t)0x03)  /*!< I2C2 Alternate Function mapping */
86 #define GPIO_AF3_MCO2          ((uint8_t)0x03)  /*!< MCO (MCO2) Alternate Function mapping */
87 #define GPIO_AF3_USART2        ((uint8_t)0x03)  /*!< USART2 Alternate Function mapping */
88 #if defined(I2C4)
89 #define GPIO_AF3_I2C4          ((uint8_t)0x03)  /*!< I2C4 Alternate Function mapping */
90 #endif /* I2C4 */
91 
92 /**
93   * @brief   AF 4 selection
94   */
95 #define GPIO_AF4_I2C3          ((uint8_t)0x04)  /*!< I2C3 Alternate Function mapping */
96 #define GPIO_AF4_I2C1          ((uint8_t)0x04)  /*!< I2C1 Alternate Function mapping */
97 #if defined(LPTIM3)
98 #define GPIO_AF4_LPTIM3        ((uint8_t)0x04)  /*!< LPTIM3 Alternate Function mapping */
99 #endif /* LPTIM3 */
100 #define GPIO_AF4_I2C2          ((uint8_t)0x04)  /*!< I2C2 Alternate Function mapping */
101 #if defined(I2C4)
102 #define GPIO_AF4_I2C4          ((uint8_t)0x04)  /*!< I2C4 Alternate Function mapping */
103 #endif /* I2C4 */
104 
105 /**
106   * @brief   AF 5 selection
107   */
108 #define GPIO_AF5_SPI1          ((uint8_t)0x05)  /*!< SPI1 Alternate Function mapping */
109 #define GPIO_AF5_I2C2          ((uint8_t)0x05)  /*!< I2C2 Alternate Function mapping */
110 #define GPIO_AF5_SPI2          ((uint8_t)0x05)  /*!< SPI2 Alternate Function mapping */
111 
112 /**
113   * @brief   AF 6 selection
114   */
115 #define GPIO_AF6_SPI2          ((uint8_t)0x06)  /*!< SPI2 Alternate Function mapping */
116 #if defined (SPI3)
117 #define GPIO_AF6_SPI3          ((uint8_t)0x06)  /*!< SPI3 Alternate Function mapping */
118 #endif /* SPI3 */
119 #define GPIO_AF6_COMP1         ((uint8_t)0x06)  /*!< COMP1 Alternate Function mapping */
120 #if defined(LPUART3)
121 #define GPIO_AF6_LPUART3       ((uint8_t)0x06)  /*!< LPUART3 Alternate Function mapping */
122 #endif /* LPUART3 */
123 
124 /**
125   * @brief   AF 7 selection
126   */
127 #define GPIO_AF7_USART1        ((uint8_t)0x07)  /*!< USART1 Alternate Function mapping */
128 #define GPIO_AF7_USART2        ((uint8_t)0x07)  /*!< USART2 Alternate Function mapping */
129 #define GPIO_AF7_USART3        ((uint8_t)0x07)  /*!< USART3 Alternate Function mapping */
130 
131 /**
132   * @brief   AF 8 selection
133   */
134 #define GPIO_AF8_USART4        ((uint8_t)0x08)  /*!< USART4 Alternate Function mapping  */
135 #define GPIO_AF8_LPUART1       ((uint8_t)0x08)  /*!< LPUART1 Alternate Function mapping */
136 #define GPIO_AF8_LPUART2       ((uint8_t)0x08)  /*!< LPUART2 Alternate Function mapping */
137 #if defined(LPUART3)
138 #define GPIO_AF8_LPUART3       ((uint8_t)0x08)  /*!< LPUART3 Alternate Function mapping */
139 #endif /* LPUART3 */
140 
141 /**
142   * @brief   AF 9 selection
143   */
144 #define GPIO_AF9_TSC           ((uint8_t)0x09)  /*!< TSC Alternate Function mapping */
145 
146 /**
147   * @brief   AF 10 selection
148   */
149 #define GPIO_AF10_LPUART2      ((uint8_t)0x0A)  /*!< LPUART2 Alternate Function mapping */
150 #if defined(USB_DRD_FS)
151 #define GPIO_AF10_USB          ((uint8_t)0x0A)  /*!< USB Alternate Function mapping */
152 #endif /* USB_DRD_FS */
153 #if defined(CRS)
154 #define GPIO_AF10_CRS          ((uint8_t)0x0A)  /*!< CRS Alternate Function mapping */
155 #endif /* CRS */
156 
157 /**
158   * @brief   AF 11 selection
159   */
160 #if defined(LCD)
161 #define GPIO_AF11_LCD         ((uint8_t)0x0B)  /*!< LCD Alternate Function mapping */
162 #endif /* LCD */
163 
164 /**
165   * @brief   AF 12 selection
166   */
167 #define GPIO_AF12_COMP1       ((uint8_t)0x0C)  /*!< COMP1 Alternate Function mapping */
168 #if defined(COMP2)
169 #define GPIO_AF12_COMP2       ((uint8_t)0x0C)  /*!< COMP2 Alternate Function mapping */
170 #endif /* COMP2 */
171 #if defined(LCD)
172 #define GPIO_AF12_LCD         ((uint8_t)0x0C)  /*!< LCD Alternate Function mapping */
173 #endif /* LCD */
174 
175 /**
176   * @brief   AF 13 selection
177   */
178 
179 /**
180   * @brief   AF 14 selection
181   */
182 #define GPIO_AF14_LPTIM1      ((uint8_t)0x0E)  /*!< LPTIM1 Alternate Function mapping */
183 #define GPIO_AF14_LPTIM2      ((uint8_t)0x0E)  /*!< LPTIM2 Alternate Function mapping */
184 #if defined(LPTIM3)
185 #define GPIO_AF14_LPTIM3      ((uint8_t)0x0E)  /*!< LPTIM3 Alternate Function mapping */
186 #endif /* LPTIM3 */
187 #define GPIO_AF14_TIM2        ((uint8_t)0x0E)  /*!< TIM2 Alternate Function mapping   */
188 #define GPIO_AF14_TIM15       ((uint8_t)0x0E)  /*!< TIM15 Alternate Function mapping  */
189 #define GPIO_AF14_TIM16       ((uint8_t)0x0E)  /*!< TIM16 Alternate Function mapping  */
190 
191 /**
192   * @brief   AF 15 selection
193   */
194 #define GPIO_AF15_EVENTOUT    ((uint8_t)0x0F)  /*!< EVENTOUT Alternate Function mapping */
195 
196 /**
197   * @}
198   */
199 
200 /**
201   * @}
202   */
203 
204 /* Exported macro ------------------------------------------------------------*/
205 /** @defgroup GPIOEx_Exported_Macros GPIOEx Exported Macros
206   * @{
207   */
208 
209 /** @defgroup GPIOEx_Get_Port_Index GPIOEx Get Port Index
210   * @{
211   */
212 #if defined (GPIOE)
213 #define GPIO_GET_INDEX(__GPIOx__)    (((__GPIOx__) == (GPIOA))? 0uL :\
214                                       ((__GPIOx__) == (GPIOB))? 1uL :\
215                                       ((__GPIOx__) == (GPIOC))? 2uL :\
216                                       ((__GPIOx__) == (GPIOD))? 3uL :\
217                                       ((__GPIOx__) == (GPIOE))? 4uL :\
218                                       ((__GPIOx__) == (GPIOF))? 5uL : 6uL)
219 #else
220 #define GPIO_GET_INDEX(__GPIOx__)    (((__GPIOx__) == (GPIOA))? 0uL :\
221                                       ((__GPIOx__) == (GPIOB))? 1uL :\
222                                       ((__GPIOx__) == (GPIOC))? 2uL :\
223                                       ((__GPIOx__) == (GPIOD))? 3uL :\
224                                       ((__GPIOx__) == (GPIOF))? 5uL : 6uL)
225 #endif /* GPIOE */
226 /**
227   * @}
228   */
229 
230 #define IS_GPIO_AF(AF)         ((AF) <= (uint8_t)0x0F)
231 
232 /**
233   * @}
234   */
235 
236 /* Exported functions --------------------------------------------------------*/
237 /**
238   * @}
239   */
240 
241 /**
242   * @}
243   */
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* STM32U0xx_HAL_GPIO_EX_H */
250 
251