1 /**
2   ******************************************************************************
3   * @file    stm32c0xx_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) 2022 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 STM32C0xx_HAL_GPIO_EX_H
21 #define STM32C0xx_HAL_GPIO_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32c0xx_hal_def.h"
29 
30 /** @addtogroup STM32C0xx_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 and MCO2) Alternate Function mapping */
53 #define GPIO_AF0_OSC32         ((uint8_t)0x00)  /*!< OSC32 (By pass and Enable) Alternate Function mapping */
54 #define GPIO_AF0_SWJ           ((uint8_t)0x00)  /*!< SWJ (SWD) Alternate Function mapping */
55 #define GPIO_AF0_SPI1          ((uint8_t)0x00)  /*!< SPI1 Alternate Function mapping */
56 #define GPIO_AF0_I2S1          ((uint8_t)0x00)  /*!< I2S1 Alternate Function mapping */
57 #define GPIO_AF0_USART1        ((uint8_t)0x00)  /*!< USART1 Alternate Function mapping */
58 #if !defined(STM32C011xx)
59 #define GPIO_AF0_EVENTOUT      ((uint8_t)0x00)  /*!< EVENTOUT Alternate Function mapping */
60 #define GPIO_AF0_IR            ((uint8_t)0x00)  /*!< IR Alternate Function mapping */
61 #define GPIO_AF0_OSC           ((uint8_t)0x00)  /*!< OSC (By pass and Enable) Alternate Function mapping */
62 #define GPIO_AF0_TIM14         ((uint8_t)0x00)  /*!< TIM14 Alternate Function mapping */
63 #endif /* !STM32C011xx */
64 #if defined(STM32C031xx) || defined(STM32C071xx)
65 #define GPIO_AF0_USART2        ((uint8_t)0x00)  /*!< USART2 Alternate Function mapping */
66 #endif /* STM32C031xx | STM32C071xx */
67 #if defined(SPI2)
68 #define GPIO_AF0_SPI2          ((uint8_t)0x00)  /*!< SPI2 Alternate Function mapping */
69 #endif  /* SPI2 */
70 #if defined(CRS)
71 #define GPIO_AF0_CRS           ((uint8_t)0x00)  /*!< CRS Alternate Function mapping */
72 #endif /* CRS */
73 
74 /**
75   * @brief   AF 1 selection
76   */
77 #define GPIO_AF1_IR            ((uint8_t)0x01)  /*!< IR Alternate Function mapping */
78 #define GPIO_AF1_OSC           ((uint8_t)0x01)  /*!< OSC (By pass and Enable) Alternate Function mapping */
79 #define GPIO_AF1_TIM1          ((uint8_t)0x01)  /*!< TIM1 Alternate Function mapping */
80 #define GPIO_AF1_TIM3          ((uint8_t)0x01)  /*!< TIM3 Alternate Function mapping */
81 #define GPIO_AF1_USART1        ((uint8_t)0x01)  /*!< USART1 Alternate Function mapping */
82 #define GPIO_AF1_USART2        ((uint8_t)0x01)  /*!< USART2 Alternate Function mapping */
83 
84 /**
85   * @brief   AF 2 selection
86   */
87 #define GPIO_AF2_TIM1          ((uint8_t)0x02)  /*!< TIM1 Alternate Function mapping */
88 #if !defined(STM32C011xx)
89 #define GPIO_AF2_TIM14         ((uint8_t)0x02)  /*!< TIM14 Alternate Function mapping */
90 #endif /* STM32C011xx */
91 #define GPIO_AF2_TIM16         ((uint8_t)0x02)  /*!< TIM16 Alternate Function mapping */
92 #define GPIO_AF2_TIM17         ((uint8_t)0x02)  /*!< TIM17 Alternate Function mapping */
93 #if defined(USB_DRD_FS)
94 #define GPIO_AF2_USB           ((uint8_t)0x02)  /*!< USB Alternate Function mapping */
95 #endif /* USB_DRD_FS */
96 
97 /**
98   * @brief   AF 3 selection
99   */
100 #define GPIO_AF3_MCO2          ((uint8_t)0x03)  /*!< MCO2 Alternate Function mapping */
101 #define GPIO_AF3_TIM3          ((uint8_t)0x03)  /*!< TIM3 Alternate Function mapping */
102 #if defined(SPI2)
103 #define GPIO_AF3_SPI2          ((uint8_t)0x03)  /*!< SPI2 Alternate Function mapping */
104 #endif /* SPI2 */
105 #if defined(TIM2)
106 #define GPIO_AF3_TIM2          ((uint8_t)0x03)  /*!< TIM2 Alternate Function mapping */
107 #endif /* TIM2 */
108 
109 /**
110   * @brief   AF 4 selection
111   */
112 #define GPIO_AF4_TIM14         ((uint8_t)0x04)  /*!< TIM14 Alternate Function mapping */
113 #define GPIO_AF4_USART2        ((uint8_t)0x04)  /*!< USART2 Alternate Function mapping */
114 #define GPIO_AF4_USART1        ((uint8_t)0x04)  /*!< USART1 Alternate Function mapping */
115 #if defined(CRS)
116 #define GPIO_AF4_CRS           ((uint8_t)0x04)  /*!< CRS Alternate Function mapping */
117 #endif /* CRS */
118 #if defined(SPI2)
119 #define GPIO_AF4_SPI2          ((uint8_t)0x04)  /*!< SPI2 Alternate Function mapping */
120 #endif /* SPI2 */
121 
122 /**
123   * @brief   AF 5 selection
124   */
125 #define GPIO_AF5_I2S           ((uint8_t)0x05)  /*!< I2S Alternate Function mapping */
126 #define GPIO_AF5_USART1        ((uint8_t)0x05)  /*!< USART1 Alternate Function mapping */
127 #define GPIO_AF5_TIM1          ((uint8_t)0x05)  /*!< TIM1 Alternate Function mapping */
128 #define GPIO_AF5_TIM16         ((uint8_t)0x05)  /*!< TIM16 Alternate Function mapping */
129 #define GPIO_AF5_TIM17         ((uint8_t)0x05)  /*!< TIM17 Alternate Function mapping */
130 #if defined(TIM2)
131 #define GPIO_AF5_TIM2          ((uint8_t)0x05)  /*!< TIM2 Alternate Function mapping */
132 #endif /* TIM2 */
133 #if defined(SPI2)
134 #define GPIO_AF5_SPI2          ((uint8_t)0x05)  /*!< SPI2 Alternate Function mapping */
135 #endif /* SPI2 */
136 #if defined(I2C2)
137 #define GPIO_AF5_I2C2          ((uint8_t)0x05)  /*!< I2C2 Alternate Function mapping */
138 #endif /* I2C2 */
139 
140 /**
141   * @brief   AF 6 selection
142   */
143 #define GPIO_AF6_I2C1          ((uint8_t)0x06)  /*!< I2C1 Alternate Function mapping */
144 #if defined(TIM2)
145 #define GPIO_AF6_TIM2          ((uint8_t)0x06)  /*!< TIM2 Alternate Function mapping */
146 #endif /* TIM2 */
147 #if defined(SPI2)
148 #define GPIO_AF6_SPI2          ((uint8_t)0x06)  /*!< SPI2 Alternate Function mapping */
149 #endif /* SPI2 */
150 #if defined(I2C2)
151 #define GPIO_AF6_I2C2          ((uint8_t)0x06)  /*!< I2C2 Alternate Function mapping */
152 #endif /* I2C2 */
153 #if defined(USB_DRD_FS)
154 #define GPIO_AF6_USB           ((uint8_t)0x06)  /*!< USB Alternate Function mapping */
155 #endif /* USB_DRD_FS */
156 
157 /**
158   * @brief   AF 7 selection
159   */
160 #define GPIO_AF7_EVENTOUT      ((uint8_t)0x07)  /*!< EVENTOUT Alternate Function mapping */
161 #define GPIO_AF7_I2C1          ((uint8_t)0x07)  /*!< I2C1 Alternate Function mapping */
162 /**
163   * @brief   AF 8 selection
164   */
165 #define GPIO_AF8_I2S1          ((uint8_t)0x08)  /*!< I2S1 Alternate Function mapping */
166 #define GPIO_AF8_SPI1          ((uint8_t)0x08)  /*!< SPI1 Alternate Function mapping */
167 #define GPIO_AF8_IR            ((uint8_t)0x08)  /*!< IR Alternate Function mapping */
168 #if defined(I2C2)
169 #define GPIO_AF8_I2C2          ((uint8_t)0x08)  /*!< I2C2 Alternate Function mapping */
170 #endif /* I2C2 */
171 
172 /**
173   * @brief   AF 9 selection
174   */
175 #define GPIO_AF9_TIM1          ((uint8_t)0x09)  /*!< TIM1 Alternate Function mapping */
176 #define GPIO_AF9_USART2        ((uint8_t)0x09)  /*!< USART2 Alternate Function mapping */
177 #define GPIO_AF9_SPI1          ((uint8_t)0x09)  /*!< SPI1 Alternate Function mapping */
178 #define GPIO_AF9_I2S1          ((uint8_t)0x09)  /*!< I2S1 Alternate Function mapping */
179 
180 /**
181   * @brief   AF 10 selection
182   */
183 #define GPIO_AF10_TIM1         ((uint8_t)0x0A)  /*!< TIM1 Alternate Function mapping */
184 #define GPIO_AF10_I2C1         ((uint8_t)0x0A)  /*!< I2C1 Alternate Function mapping */
185 #define GPIO_AF10_SPI1         ((uint8_t)0x0A)  /*!< SPI1 Alternate Function mapping */
186 #define GPIO_AF10_TIM16        ((uint8_t)0x0A)  /*!< TIM16 Alternate Function mapping */
187 #define GPIO_AF10_TIM17        ((uint8_t)0x0A)  /*!< TIM17 Alternate Function mapping */
188 
189 /**
190   * @brief   AF 11 selection
191   */
192 #define GPIO_AF11_TIM1         ((uint8_t)0x0B)  /*!< TIM1 Alternate Function mapping */
193 #define GPIO_AF11_TIM3         ((uint8_t)0x0B)  /*!< TIM3 Alternate Function mapping */
194 #define GPIO_AF11_MCO2         ((uint8_t)0x0B)  /*!< MCO2 Alternate Function mapping */
195 
196 /**
197   * @brief   AF 12 selection
198   */
199 #define GPIO_AF12_TIM3         ((uint8_t)0x0C)  /*!< TIM3 Alternate Function mapping */
200 #define GPIO_AF12_USART1       ((uint8_t)0x0C)  /*!< USART1 Alternate Function mapping */
201 #if defined(STM32C071xx)
202 #define GPIO_AF12_SPI2         ((uint8_t)0x0C)  /*!< SPI2 Alternate Function mapping */
203 #endif /* STM32C071xx */
204 
205 /**
206   * @brief   AF 13 selection
207   */
208 #define GPIO_AF13_TIM14        ((uint8_t)0x0D)  /*!< TIM14 Alternate Function mapping */
209 #define GPIO_AF13_TIM3         ((uint8_t)0x0D)  /*!< TIM3 Alternate Function mapping */
210 
211 /**
212   * @brief   AF 14 selection
213   */
214 #define GPIO_AF14_USART1      ((uint8_t)0x0E)  /*!< USART1 Alternate Function mapping */
215 #define GPIO_AF14_I2C1        ((uint8_t)0x0E)  /*!< I2C1 Alternate Function mapping */
216 #define GPIO_AF14_TIM16       ((uint8_t)0x0E)  /*!< TIM16 Alternate Function mapping */
217 
218 /**
219   * @brief   AF 15 selection
220   */
221 #define GPIO_AF15_EVENTOUT      ((uint8_t)0x0F)  /*!< EVENTOUT Alternate Function mapping */
222 #define GPIO_AF15_MCO2          ((uint8_t)0x0F)  /*!< MCO2 Alternate Function mapping */
223 #if defined(STM32C011xx) || defined(STM32C031xx) || defined(STM32C071xx)
224 #define GPIO_AF15_TIM17         ((uint8_t)0x0F)  /*!< TIM17 Alternate Function mapping */
225 #endif /* STM32C011xx | STM32C031xx | STM32C071xx */
226 #define IS_GPIO_AF(AF)         ((AF) <= (uint8_t)0x0F)
227 
228 /**
229   * @}
230   */
231 
232 /**
233   * @}
234   */
235 
236 /* Exported macro ------------------------------------------------------------*/
237 /** @defgroup GPIOEx_Exported_Macros GPIOEx Exported Macros
238   * @{
239   */
240 
241 /** @defgroup GPIOEx_Get_Port_Index GPIOEx Get Port Index
242   * @{
243   */
244 #if defined(GPIOD)
245 #define GPIO_GET_INDEX(__GPIOx__)    (((__GPIOx__) == (GPIOA))? 0UL :\
246                                       ((__GPIOx__) == (GPIOB))? 1UL :\
247                                       ((__GPIOx__) == (GPIOC))? 2UL :\
248                                       ((__GPIOx__) == (GPIOD))? 3UL :\
249                                       ((__GPIOx__) == (GPIOF))? 5UL : 6UL)
250 #else
251 #define GPIO_GET_INDEX(__GPIOx__)    (((__GPIOx__) == (GPIOA))? 0UL :\
252                                       ((__GPIOx__) == (GPIOB))? 1UL :\
253                                       ((__GPIOx__) == (GPIOC))? 2UL :\
254                                       ((__GPIOx__) == (GPIOF))? 5UL : 6UL)
255 #endif /* GPIOD */
256 /**
257   * @}
258   */
259 
260 /**
261   * @}
262   */
263 
264 /* Exported functions --------------------------------------------------------*/
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif /* STM32C0xx_HAL_GPIO_EX_H */
278