1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_gpio.h
4   * @author  MCD Application Team
5   * @brief   Header file of GPIO HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 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 __STM32L0xx_HAL_GPIO_H
21 #define __STM32L0xx_HAL_GPIO_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l0xx_hal_def.h"
29 
30 /** @addtogroup STM32L0xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup GPIO GPIO
35   * @{
36   */
37 /******************************************************************************/
38 /* Exported types ------------------------------------------------------------*/
39 /******************************************************************************/
40 
41 /** @defgroup GPIO_Exported_Types GPIO Exported Types
42   * @{
43   */
44 
45 /** @defgroup GPIO_Init_Configuration GPIO init configuration structure
46   * @{
47   */
48 /**
49   * @brief   GPIO Init structure definition
50   */
51 typedef struct
52 {
53   uint32_t Pin;       /*!< Specifies the GPIO pins to be configured.
54                            This parameter can be a combination of @ref GPIO_pins_define */
55 
56   uint32_t Mode;      /*!< Specifies the operating mode for the selected pins.
57                            This parameter can be a value of @ref GPIO_mode_define */
58 
59   uint32_t Pull;      /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
60                            This parameter can be a value of @ref GPIO_pull_define */
61 
62   uint32_t Speed;     /*!< Specifies the speed for the selected pins.
63                            This parameter can be a value of @ref GPIO_speed_define */
64 
65   uint32_t Alternate;  /*!< Peripheral to be connected to the selected pins
66                             This parameter can be a value of @ref GPIOEx_Alternate_function_selection */
67 } GPIO_InitTypeDef;
68 /**
69   * @}
70   */
71 
72 /** @defgroup GPIO_SetReset_Definition  GPIO set reset definition
73   * @{
74   */
75 /**
76   * @brief  GPIO Bit SET and Bit RESET enumeration
77   */
78 typedef enum
79 {
80   GPIO_PIN_RESET = 0U,
81   GPIO_PIN_SET
82 } GPIO_PinState;
83 /**
84   * @}
85   */
86 
87 
88 #define IS_GPIO_PIN_ACTION(__ACTION__) (((__ACTION__) == GPIO_PIN_RESET) || ((__ACTION__) == GPIO_PIN_SET))
89 
90 /**
91   * @}
92   */
93 /******************************************************************************/
94 /* Exported constants --------------------------------------------------------*/
95 /******************************************************************************/
96 
97 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants
98   * @{
99   */
100 
101 /** @defgroup GPIO_pins_define Pin definition
102   * @{
103   */
104 #define GPIO_PIN_0                 (0x0001U)  /* Pin 0 selected    */
105 #define GPIO_PIN_1                 (0x0002U)  /* Pin 1 selected    */
106 #define GPIO_PIN_2                 (0x0004U)  /* Pin 2 selected    */
107 #define GPIO_PIN_3                 (0x0008U)  /* Pin 3 selected    */
108 #define GPIO_PIN_4                 (0x0010U)  /* Pin 4 selected    */
109 #define GPIO_PIN_5                 (0x0020U)  /* Pin 5 selected    */
110 #define GPIO_PIN_6                 (0x0040U)  /* Pin 6 selected    */
111 #define GPIO_PIN_7                 (0x0080U)  /* Pin 7 selected    */
112 #define GPIO_PIN_8                 (0x0100U)  /* Pin 8 selected    */
113 #define GPIO_PIN_9                 (0x0200U)  /* Pin 9 selected    */
114 #define GPIO_PIN_10                (0x0400U)  /* Pin 10 selected   */
115 #define GPIO_PIN_11                (0x0800U)  /* Pin 11 selected   */
116 #define GPIO_PIN_12                (0x1000U)  /* Pin 12 selected   */
117 #define GPIO_PIN_13                (0x2000U)  /* Pin 13 selected   */
118 #define GPIO_PIN_14                (0x4000U)  /* Pin 14 selected   */
119 #define GPIO_PIN_15                (0x8000U)  /* Pin 15 selected   */
120 #define GPIO_PIN_All               (0xFFFFU)  /* All pins selected */
121 /**
122   * @}
123   */
124 
125 #define GPIO_PIN_MASK              (0x0000FFFFU) /* PIN mask for assert test */
126 #define IS_GPIO_PIN(__PIN__)        ((((uint32_t)(__PIN__) & GPIO_PIN_MASK) != 0x00U) &&\
127                                      (((uint32_t)(__PIN__) & ~GPIO_PIN_MASK) == 0x00U))
128 
129 /** @defgroup GPIO_mode_define Mode definition
130   * @brief GPIO Configuration Mode
131   *        Elements values convention: 0x00WX00YZ
132   *           - W  : EXTI trigger detection on 3 bits
133   *           - X  : EXTI mode (IT or Event) on 2 bits
134   *           - Y  : Output type (Push Pull or Open Drain) on 1 bit
135   *           - Z  : GPIO mode (Input, Output, Alternate or Analog) on 2 bits
136   * @{
137   */
138 #define  GPIO_MODE_INPUT                        MODE_INPUT                                                  /*!< Input Floating Mode                   */
139 #define  GPIO_MODE_OUTPUT_PP                    (MODE_OUTPUT | OUTPUT_PP)                                   /*!< Output Push Pull Mode                 */
140 #define  GPIO_MODE_OUTPUT_OD                    (MODE_OUTPUT | OUTPUT_OD)                                   /*!< Output Open Drain Mode                */
141 #define  GPIO_MODE_AF_PP                        (MODE_AF | OUTPUT_PP)                                       /*!< Alternate Function Push Pull Mode     */
142 #define  GPIO_MODE_AF_OD                        (MODE_AF | OUTPUT_OD)                                       /*!< Alternate Function Open Drain Mode    */
143 
144 #define  GPIO_MODE_ANALOG                       MODE_ANALOG                                                 /*!< Analog Mode  */
145 
146 #define  GPIO_MODE_IT_RISING                    (MODE_INPUT | EXTI_IT | TRIGGER_RISING)                     /*!< External Interrupt Mode with Rising edge trigger detection          */
147 #define  GPIO_MODE_IT_FALLING                   (MODE_INPUT | EXTI_IT | TRIGGER_FALLING)                    /*!< External Interrupt Mode with Falling edge trigger detection         */
148 #define  GPIO_MODE_IT_RISING_FALLING            (MODE_INPUT | EXTI_IT | TRIGGER_RISING | TRIGGER_FALLING)   /*!< External Interrupt Mode with Rising/Falling edge trigger detection  */
149 
150 #define  GPIO_MODE_EVT_RISING                   (MODE_INPUT | EXTI_EVT | TRIGGER_RISING)                     /*!< External Event Mode with Rising edge trigger detection             */
151 #define  GPIO_MODE_EVT_FALLING                  (MODE_INPUT | EXTI_EVT | TRIGGER_FALLING)                    /*!< External Event Mode with Falling edge trigger detection            */
152 #define  GPIO_MODE_EVT_RISING_FALLING           (MODE_INPUT | EXTI_EVT | TRIGGER_RISING | TRIGGER_FALLING)   /*!< External Event Mode with Rising/Falling edge trigger detection     */
153 
154 /**
155   * @}
156   */
157 
158 #define IS_GPIO_MODE(__MODE__) (((__MODE__) == GPIO_MODE_INPUT)              ||\
159                                 ((__MODE__) == GPIO_MODE_OUTPUT_PP)          ||\
160                                 ((__MODE__) == GPIO_MODE_OUTPUT_OD)          ||\
161                                 ((__MODE__) == GPIO_MODE_AF_PP)              ||\
162                                 ((__MODE__) == GPIO_MODE_AF_OD)              ||\
163                                 ((__MODE__) == GPIO_MODE_IT_RISING)          ||\
164                                 ((__MODE__) == GPIO_MODE_IT_FALLING)         ||\
165                                 ((__MODE__) == GPIO_MODE_IT_RISING_FALLING)  ||\
166                                 ((__MODE__) == GPIO_MODE_EVT_RISING)         ||\
167                                 ((__MODE__) == GPIO_MODE_EVT_FALLING)        ||\
168                                 ((__MODE__) == GPIO_MODE_EVT_RISING_FALLING) ||\
169                                 ((__MODE__) == GPIO_MODE_ANALOG))
170 
171 
172 /** @defgroup GPIO_speed_define Speed definition
173   * @brief GPIO Output Maximum frequency
174   * @{
175   */
176 #define  GPIO_SPEED_FREQ_LOW              (0x00000000U)  /*!< range up to 0.4 MHz, please refer to the product datasheet */
177 #define  GPIO_SPEED_FREQ_MEDIUM           (0x00000001U)  /*!< range 0.4 MHz to 2 MHz, please refer to the product datasheet */
178 #define  GPIO_SPEED_FREQ_HIGH             (0x00000002U)  /*!< range   2 MHz to 10 MHz, please refer to the product datasheet */
179 #define  GPIO_SPEED_FREQ_VERY_HIGH        (0x00000003U)  /*!< range  10 MHz to 35 MHz, please refer to the product datasheet */
180 
181 /**
182   * @}
183   */
184 
185 #define IS_GPIO_SPEED(__SPEED__) (((__SPEED__) == GPIO_SPEED_FREQ_LOW     )  || ((__SPEED__) == GPIO_SPEED_FREQ_MEDIUM     ) || \
186                                   ((__SPEED__) == GPIO_SPEED_FREQ_HIGH  ) || ((__SPEED__) == GPIO_SPEED_FREQ_VERY_HIGH))
187 
188 
189 /** @defgroup GPIO_pull_define Pull definition
190   * @brief GPIO Pull-Up or Pull-Down Activation
191   * @{
192   */
193 #define  GPIO_NOPULL        (0x00000000U)   /*!< No Pull-up or Pull-down activation  */
194 #define  GPIO_PULLUP        (0x00000001U)   /*!< Pull-up activation                  */
195 #define  GPIO_PULLDOWN      (0x00000002U)   /*!< Pull-down activation                */
196 
197 /**
198   * @}
199   */
200 
201 #define IS_GPIO_PULL(__PULL__) (((__PULL__) == GPIO_NOPULL) || ((__PULL__) == GPIO_PULLUP) || \
202                                 ((__PULL__) == GPIO_PULLDOWN))
203 
204 
205 /**
206   * @}
207   */
208 /******************************************************************************/
209 /* Exported macro ------------------------------------------------------------*/
210 /******************************************************************************/
211 /* Exported macro ------------------------------------------------------------*/
212 /** @defgroup GPIO_Exported_Macro GPIO Exported Macros
213   * @{
214   */
215 /**
216   * @brief  Checks whether the specified EXTI line flag is set or not.
217   * @param  __EXTI_LINE__ specifies the EXTI line flag to check.
218   *         This parameter can be GPIO_PIN_x where x can be(0..15)
219   * @retval The new state of __EXTI_LINE__ (SET or RESET).
220   */
221 #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
222 
223 /**
224   * @brief  Clears the EXTI's line pending flags.
225   * @param  __EXTI_LINE__ specifies the EXTI lines flags to clear.
226   *         This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
227   * @retval None
228   */
229 #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
230 
231 /**
232   * @brief  Checks whether the specified EXTI line is asserted or not.
233   * @param  __EXTI_LINE__ specifies the EXTI line to check.
234   *          This parameter can be GPIO_PIN_x where x can be(0..15)
235   * @retval The new state of __EXTI_LINE__ (SET or RESET).
236   */
237 #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
238 
239 /**
240   * @brief  Clears the EXTI's line pending bits.
241   * @param  __EXTI_LINE__ specifies the EXTI lines to clear.
242   *          This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
243   * @retval None
244   */
245 #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
246 
247 /**
248   * @brief  Generates a Software interrupt on selected EXTI line.
249   * @param  __EXTI_LINE__ specifies the EXTI line to check.
250   *          This parameter can be GPIO_PIN_x where x can be(0..15)
251   * @retval None
252   */
253 #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__))
254 
255 /**
256   * @}
257   */
258 /* Include GPIO HAL Extension module */
259 #include "stm32l0xx_hal_gpio_ex.h"
260 
261 /******************************************************************************/
262 /* Exported functions --------------------------------------------------------*/
263 /******************************************************************************/
264 
265 /* Exported functions --------------------------------------------------------*/
266 /** @defgroup GPIO_Exported_Functions GPIO Exported Functions
267   * @{
268   */
269 
270 /* Initialization and de-initialization functions *******************************/
271 /** @defgroup GPIO_Exported_Functions_Group1 Initialization and de-initialization functions
272  *  @{
273  */
274 void  HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init);
275 void  HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin);
276 /**
277   * @}
278   */
279 
280 /* IO operation functions *******************************************************/
281 /** @defgroup GPIO_Exported_Functions_Group2 IO operation functions
282  *  @{
283  */
284 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
285 void          HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
286 void          HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
287 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
288 void          HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
289 void          HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
290 /**
291   * @}
292   */
293 
294 /**
295   * @}
296   */
297 
298 /* Define the private group ***********************************/
299 /**************************************************************/
300 /** @defgroup GPIO_Private GPIO Private
301   * @{
302   */
303 #define GPIO_MODE_Pos                           0U
304 #define GPIO_MODE                               (0x3UL << GPIO_MODE_Pos)
305 #define MODE_INPUT                              (0x0UL << GPIO_MODE_Pos)
306 #define MODE_OUTPUT                             (0x1UL << GPIO_MODE_Pos)
307 #define MODE_AF                                 (0x2UL << GPIO_MODE_Pos)
308 #define MODE_ANALOG                             (0x3UL << GPIO_MODE_Pos)
309 #define OUTPUT_TYPE_Pos                         4U
310 #define OUTPUT_TYPE                             (0x1UL << OUTPUT_TYPE_Pos)
311 #define OUTPUT_PP                               (0x0UL << OUTPUT_TYPE_Pos)
312 #define OUTPUT_OD                               (0x1UL << OUTPUT_TYPE_Pos)
313 #define EXTI_MODE_Pos                           16U
314 #define EXTI_MODE                               (0x3UL << EXTI_MODE_Pos)
315 #define EXTI_IT                                 (0x1UL << EXTI_MODE_Pos)
316 #define EXTI_EVT                                (0x2UL << EXTI_MODE_Pos)
317 #define TRIGGER_MODE_Pos                         20U
318 #define TRIGGER_MODE                            (0x7UL << TRIGGER_MODE_Pos)
319 #define TRIGGER_RISING                          (0x1UL << TRIGGER_MODE_Pos)
320 #define TRIGGER_FALLING                         (0x2UL << TRIGGER_MODE_Pos)
321 /**
322   * @}
323   */
324 /**************************************************************/
325 
326 
327 /**
328   * @}
329   */
330 
331 /**
332   * @}
333   */
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* __STM32L0xx_HAL_GPIO_H */
340 
341 
342