1 /** 2 **************************************************************************************** 3 * 4 * @file gr55xx_hal_gpio.h 5 * @author BLE Driver Team 6 * @brief Header file containing functions prototypes of GPIO HAL library. 7 * 8 **************************************************************************************** 9 * @attention 10 #####Copyright (c) 2019 GOODIX 11 All rights reserved. 12 13 Redistribution and use in source and binary forms, with or without 14 modification, are permitted provided that the following conditions are met: 15 * Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 * Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 * Neither the name of GOODIX nor the names of its contributors may be used 21 to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35 **************************************************************************************** 36 */ 37 38 /** @addtogroup PERIPHERAL Peripheral Driver 39 * @{ 40 */ 41 42 /** @addtogroup HAL_DRIVER HAL Driver 43 * @{ 44 */ 45 46 /** @defgroup HAL_GPIO GPIO 47 * @brief GPIO HAL module driver. 48 * @{ 49 */ 50 51 /* Define to prevent recursive inclusion -------------------------------------*/ 52 #ifndef __GR55xx_HAL_GPIO_H__ 53 #define __GR55xx_HAL_GPIO_H__ 54 55 /* Includes ------------------------------------------------------------------*/ 56 #include "gr55xx_ll_gpio.h" 57 #include "gr55xx_hal_def.h" 58 /* Include GPIO HAL Extended module */ 59 #include "gr55xx_hal_gpio_ex.h" 60 61 #ifdef __cplusplus 62 extern "C" { 63 #endif 64 65 /* Exported types ------------------------------------------------------------*/ 66 /** @addtogroup HAL_GPIO_CALLBACK_STRUCTURES Callback Structures 67 * @{ 68 */ 69 70 /** @defgroup HAL_GPIO_Callback Callback 71 * @{ 72 */ 73 74 /** 75 * @brief HAL_GPIO Callback function definition 76 */ 77 78 typedef struct _hal_gpio_callback { 79 void (*gpio_callback)(gpio_regs_t *GPIOx, uint16_t gpio_pin); /**< GPIO pin detection callback */ 80 } hal_gpio_callback_t; 81 82 /** @} */ 83 84 /** @} */ 85 86 /** @addtogroup HAL_GPIO_ENUMERATIONS Enumerations 87 * @{ 88 */ 89 90 /** 91 * @brief GPIO Bit SET and Bit RESET Enumerations 92 */ 93 typedef enum { 94 GPIO_PIN_RESET = 0U, /**< GPIO pin low level.*/ 95 GPIO_PIN_SET /**< GPIO pin high level.*/ 96 } gpio_pin_state_t; 97 98 /** @} */ 99 100 101 /** @addtogroup HAL_GPIO_STRUCTURES Structures 102 * @{ 103 */ 104 105 /** 106 * @brief GPIO init structure definition 107 */ 108 typedef struct _gpio_init { 109 uint32_t pin; /**< Specifies the GPIO pins to be configured. 110 This parameter can be any value of @ref GPIO_pins */ 111 112 uint32_t mode; /**< Specifies the operating mode for the selected pins. 113 This parameter can be a value of @ref GPIO_mode */ 114 115 uint32_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. 116 This parameter can be a value of @ref GPIO_pull */ 117 118 uint32_t mux; /**< Specifies the Peripheral to be connected to the selected pins. 119 This parameter can be a value of @ref GPIOEx_Mux_Function_Selection. */ 120 } gpio_init_t; 121 122 /** @} */ 123 124 /** 125 * @defgroup HAL_GPIO_MACRO Defines 126 * @{ 127 */ 128 129 /* Exported constants --------------------------------------------------------*/ 130 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants 131 * @{ 132 */ 133 134 /** @defgroup GPIO_pins GPIO pins 135 * @{ 136 */ 137 #define GPIO_PIN_0 ((uint16_t)0x0001U) /**< Pin 0 selected */ 138 #define GPIO_PIN_1 ((uint16_t)0x0002U) /**< Pin 1 selected */ 139 #define GPIO_PIN_2 ((uint16_t)0x0004U) /**< Pin 2 selected */ 140 #define GPIO_PIN_3 ((uint16_t)0x0008U) /**< Pin 3 selected */ 141 #define GPIO_PIN_4 ((uint16_t)0x0010U) /**< Pin 4 selected */ 142 #define GPIO_PIN_5 ((uint16_t)0x0020U) /**< Pin 5 selected */ 143 #define GPIO_PIN_6 ((uint16_t)0x0040U) /**< Pin 6 selected */ 144 #define GPIO_PIN_7 ((uint16_t)0x0080U) /**< Pin 7 selected */ 145 #define GPIO_PIN_8 ((uint16_t)0x0100U) /**< Pin 8 selected */ 146 #define GPIO_PIN_9 ((uint16_t)0x0200U) /**< Pin 9 selected */ 147 #define GPIO_PIN_10 ((uint16_t)0x0400U) /**< Pin 10 selected */ 148 #define GPIO_PIN_11 ((uint16_t)0x0800U) /**< Pin 11 selected */ 149 #define GPIO_PIN_12 ((uint16_t)0x1000U) /**< Pin 12 selected */ 150 #define GPIO_PIN_13 ((uint16_t)0x2000U) /**< Pin 13 selected */ 151 #define GPIO_PIN_14 ((uint16_t)0x4000U) /**< Pin 14 selected */ 152 #define GPIO_PIN_15 ((uint16_t)0x8000U) /**< Pin 15 selected */ 153 #define GPIO_PIN_ALL ((uint16_t)0xFFFFU) /**< All pins selected */ 154 155 #define GPIO_PIN_MASK (0x0000FFFFU) /**< PIN mask for assert test */ 156 /** @} */ 157 158 /** @defgroup GPIO_mode GPIO mode 159 * @brief GPIO Configuration Mode 160 * Elements values convention: 0x000000YX 161 * - X : IO Direction mode (Input, Output, Mux) 162 * - Y : IT trigger detection 163 * @{ 164 */ 165 #define GPIO_MODE_INPUT (LL_GPIO_MODE_INPUT << 0) /**< Input Mode */ 166 #define GPIO_MODE_OUTPUT (LL_GPIO_MODE_OUTPUT << 0) /**< Output Mode */ 167 #define GPIO_MODE_MUX (LL_GPIO_MODE_MUX << 0) /**< Mux Mode */ 168 #define GPIO_MODE_IT_RISING (LL_GPIO_TRIGGER_RISING << 4) /**< Interrupt Mode with Rising edge 169 trigger detection */ 170 #define GPIO_MODE_IT_FALLING (LL_GPIO_TRIGGER_FALLING << 4) /**< Interrupt Mode with Falling edge 171 trigger detection */ 172 #define GPIO_MODE_IT_HIGH (LL_GPIO_TRIGGER_HIGH << 4) /**< Interrupt Mode with High-level 173 trigger detection */ 174 #define GPIO_MODE_IT_LOW (LL_GPIO_TRIGGER_LOW << 4) /**< Interrupt Mode with Low-level 175 trigger detection */ 176 /** @} */ 177 178 /** @defgroup GPIO_pull GPIO pull 179 * @brief GPIO Pull-Up or Pull-Down Activation 180 * @{ 181 */ 182 #define GPIO_NOPULL LL_GPIO_PULL_NO /**< No Pull-up or Pull-down activation */ 183 #define GPIO_PULLUP LL_GPIO_PULL_UP /**< Pull-up activation */ 184 #define GPIO_PULLDOWN LL_GPIO_PULL_DOWN /**< Pull-down activation */ 185 /** @} */ 186 187 /** 188 * @brief GPIO_default_config InitStruct default configuartion 189 */ 190 #define GPIO_DEFAULT_CONFIG \ 191 { \ 192 .pin = GPIO_PIN_ALL, \ 193 .mode = GPIO_MODE_INPUT, \ 194 .pull = GPIO_PULLDOWN, \ 195 .mux = GPIO_PIN_MUX_GPIO, \ 196 } 197 198 /** @} */ 199 200 /* Exported macro ------------------------------------------------------------*/ 201 /** @defgroup GPIO_Exported_Macros GPIO Exported Macros 202 * @{ 203 */ 204 205 /** 206 * @brief Check whether the specified GPIO pin is asserted or not. 207 * @param __GPIOX__ Where X can be (0, 1) to select the GPIO peripheral port 208 * @param __GPIO_PIN__ Specifies the GPIO pin to check. 209 * This parameter can be GPIO_PIN_x where x can be (0..15) 210 * @retval The new state of __GPIO_PIN__ (SET or RESET). 211 */ 212 #define __HAL_GPIO_IT_GET_IT(__GPIOX__, __GPIO_PIN__) ll_gpio_read_flag_it(__GPIOX__, __GPIO_PIN__) 213 214 /** 215 * @brief Clear the GPIO pin pending bits. 216 * @param __GPIOX__ Where X can be (0, 1) to select the GPIO peripheral port 217 * @param __GPIO_PIN__ Specifies the GPIO pins to clear. 218 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 219 * @retval None 220 */ 221 #define __HAL_GPIO_IT_CLEAR_IT(__GPIOX__, __GPIO_PIN__) ll_gpio_clear_flag_it(__GPIOX__, __GPIO_PIN__) 222 223 /** @} */ 224 225 /* Private macros ------------------------------------------------------------*/ 226 /** @addtogroup GPIO_Private_Macros GPIO Private Macros 227 * @{ 228 */ 229 230 /** 231 * @brief Check if GPIO pin action is valid. 232 * @param __ACTION__ GPIO pin action. 233 * @retval SET (__ACTION__ is valid) or RESET (__ACTION__ is invalid) 234 */ 235 #define IS_GPIO_PIN_ACTION(__ACTION__) (((__ACTION__) == GPIO_PIN_RESET) || ((__ACTION__) == GPIO_PIN_SET)) 236 237 /** 238 * @brief Check if GPIO pins are valid. 239 * @param __PIN__ GPIO pins. 240 * @retval SET (__PIN__ is valid) or RESET (__PIN__ is invalid) 241 */ 242 #define IS_GPIO_PIN(__PIN__) ((((__PIN__) & GPIO_PIN_MASK) != 0x00U) && \ 243 (((__PIN__) & ~GPIO_PIN_MASK) == 0x00U)) 244 245 /** 246 * @brief Check if GPIO mode is valid. 247 * @param __MODE__ GPIO mode. 248 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 249 */ 250 #define IS_GPIO_MODE(__MODE__) (((__MODE__) == GPIO_MODE_INPUT) || \ 251 ((__MODE__) == GPIO_MODE_OUTPUT) || \ 252 ((__MODE__) == GPIO_MODE_MUX) || \ 253 ((__MODE__) == GPIO_MODE_IT_RISING) || \ 254 ((__MODE__) == GPIO_MODE_IT_FALLING) || \ 255 ((__MODE__) == GPIO_MODE_IT_HIGH) || \ 256 ((__MODE__) == GPIO_MODE_IT_LOW)) 257 258 /** 259 * @brief Check if GPIO pull type is valid. 260 * @param __PULL__ GPIO pull type. 261 * @retval SET (__PULL__ is valid) or RESET (__PULL__ is invalid) 262 */ 263 #define IS_GPIO_PULL(__PULL__) (((__PULL__) == GPIO_NOPULL) || \ 264 ((__PULL__) == GPIO_PULLUP) || \ 265 ((__PULL__) == GPIO_PULLDOWN)) 266 267 /** @} */ 268 269 /** @} */ 270 271 /* Exported functions --------------------------------------------------------*/ 272 /** @addtogroup HAL_GPIO_DRIVER_FUNCTIONS Functions 273 * @{ 274 */ 275 276 /** @addtogroup GPIO_Exported_Functions_Group1 Initialization/de-initialization functions 277 * @brief Initialization and de-initialization functions 278 * @{ 279 */ 280 281 /** 282 **************************************************************************************** 283 * @brief Initialize the GPIOx peripheral according to the specified parameters in the p_gpio_init. 284 * 285 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port 286 * @param[in] p_gpio_init: Pointer to a gpio_init_t structure that contains the configuration information 287 * for the specified GPIO peripheral port. 288 **************************************************************************************** 289 */ 290 void hal_gpio_init(gpio_regs_t *GPIOx, gpio_init_t *p_gpio_init); 291 292 /** 293 **************************************************************************************** 294 * @brief De-initialize the GPIOx peripheral registers to their default reset values. 295 * 296 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port for GR55xx device 297 * @param[in] gpio_pin: Specifies the port bit to be written. 298 * This parameter can be a combiantion of the following values: 299 * @arg @ref GPIO_PIN_0 300 * @arg @ref GPIO_PIN_1 301 * @arg @ref GPIO_PIN_2 302 * @arg @ref GPIO_PIN_3 303 * @arg @ref GPIO_PIN_4 304 * @arg @ref GPIO_PIN_5 305 * @arg @ref GPIO_PIN_6 306 * @arg @ref GPIO_PIN_7 307 * @arg @ref GPIO_PIN_8 308 * @arg @ref GPIO_PIN_9 309 * @arg @ref GPIO_PIN_10 310 * @arg @ref GPIO_PIN_11 311 * @arg @ref GPIO_PIN_12 312 * @arg @ref GPIO_PIN_13 313 * @arg @ref GPIO_PIN_14 314 * @arg @ref GPIO_PIN_15 315 * @arg @ref GPIO_PIN_ALL 316 **************************************************************************************** 317 */ 318 void hal_gpio_deinit(gpio_regs_t *GPIOx, uint32_t gpio_pin); 319 320 /** @} */ 321 322 /** @addtogroup GPIO_Exported_Functions_Group2 IO operation functions 323 * @{ 324 */ 325 326 /** 327 **************************************************************************************** 328 * @brief Read the specified input port pin. 329 * 330 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port 331 * @param[in] gpio_pin: Specifies the port bit to be read. 332 * This parameter can be a one of the following values: 333 * @arg @ref GPIO_PIN_0 334 * @arg @ref GPIO_PIN_1 335 * @arg @ref GPIO_PIN_2 336 * @arg @ref GPIO_PIN_3 337 * @arg @ref GPIO_PIN_4 338 * @arg @ref GPIO_PIN_5 339 * @arg @ref GPIO_PIN_6 340 * @arg @ref GPIO_PIN_7 341 * @arg @ref GPIO_PIN_8 342 * @arg @ref GPIO_PIN_9 343 * @arg @ref GPIO_PIN_10 344 * @arg @ref GPIO_PIN_11 345 * @arg @ref GPIO_PIN_12 346 * @arg @ref GPIO_PIN_13 347 * @arg @ref GPIO_PIN_14 348 * @arg @ref GPIO_PIN_15 349 * 350 * @retval ::GPIO_PIN_RESET: GPIO pin low level. 351 * @retval ::GPIO_PIN_SET: GPIO pin high level. 352 **************************************************************************************** 353 */ 354 gpio_pin_state_t hal_gpio_read_pin(gpio_regs_t *GPIOx, uint16_t gpio_pin); 355 356 /** 357 **************************************************************************************** 358 * @brief Set or clear the selected data port bit. 359 * 360 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port 361 * @param[in] gpio_pin: Specifies the port bit to be written. 362 * This parameter can be a combiantion of the following values: 363 * @arg @ref GPIO_PIN_0 364 * @arg @ref GPIO_PIN_1 365 * @arg @ref GPIO_PIN_2 366 * @arg @ref GPIO_PIN_3 367 * @arg @ref GPIO_PIN_4 368 * @arg @ref GPIO_PIN_5 369 * @arg @ref GPIO_PIN_6 370 * @arg @ref GPIO_PIN_7 371 * @arg @ref GPIO_PIN_8 372 * @arg @ref GPIO_PIN_9 373 * @arg @ref GPIO_PIN_10 374 * @arg @ref GPIO_PIN_11 375 * @arg @ref GPIO_PIN_12 376 * @arg @ref GPIO_PIN_13 377 * @arg @ref GPIO_PIN_14 378 * @arg @ref GPIO_PIN_15 379 * @arg @ref GPIO_PIN_ALL 380 * @param[in] pin_state: Specifies the value to be written to the selected bit. 381 * This parameter can be one of the GPIO_PinState enum values: 382 * @arg @ref GPIO_PIN_RESET clear the port pin 383 * @arg @ref GPIO_PIN_SET set the port pin 384 **************************************************************************************** 385 */ 386 void hal_gpio_write_pin(gpio_regs_t *GPIOx, uint16_t gpio_pin, gpio_pin_state_t pin_state); 387 388 /** 389 **************************************************************************************** 390 * @brief Toggle the specified GPIO pin. 391 * 392 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port 393 * @param[in] gpio_pin: Specifies the pin to be toggled. 394 * This parameter can be a combiantion of the following values: 395 * @arg @ref GPIO_PIN_0 396 * @arg @ref GPIO_PIN_1 397 * @arg @ref GPIO_PIN_2 398 * @arg @ref GPIO_PIN_3 399 * @arg @ref GPIO_PIN_4 400 * @arg @ref GPIO_PIN_5 401 * @arg @ref GPIO_PIN_6 402 * @arg @ref GPIO_PIN_7 403 * @arg @ref GPIO_PIN_8 404 * @arg @ref GPIO_PIN_9 405 * @arg @ref GPIO_PIN_10 406 * @arg @ref GPIO_PIN_11 407 * @arg @ref GPIO_PIN_12 408 * @arg @ref GPIO_PIN_13 409 * @arg @ref GPIO_PIN_14 410 * @arg @ref GPIO_PIN_15 411 * @arg @ref GPIO_PIN_ALL 412 **************************************************************************************** 413 */ 414 void hal_gpio_toggle_pin(gpio_regs_t *GPIOx, uint16_t gpio_pin); 415 416 /** @} */ 417 418 /** @addtogroup GPIO_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks 419 * @brief IRQ Handler and Callbacks functions 420 * @{ 421 */ 422 423 /** 424 **************************************************************************************** 425 * @brief Handle GPIO interrupt request. 426 * 427 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port 428 **************************************************************************************** 429 */ 430 void hal_gpio_exti_irq_handler(gpio_regs_t *GPIOx); 431 432 /** 433 **************************************************************************************** 434 * @brief GPIO pin detection callback. 435 * 436 * @note This function should not be modified. When the callback is needed, 437 * the hal_gpio_exti_callback can be implemented in the user file. 438 * 439 * @param[in] GPIOx: Where x can be (0, 1) to select the GPIO peripheral port 440 * @param[in] gpio_pin: Indicate the port pin whose interrupt was triggered. 441 * This parameter can be a combiantion of the following values: 442 * @arg @ref GPIO_PIN_0 443 * @arg @ref GPIO_PIN_1 444 * @arg @ref GPIO_PIN_2 445 * @arg @ref GPIO_PIN_3 446 * @arg @ref GPIO_PIN_4 447 * @arg @ref GPIO_PIN_5 448 * @arg @ref GPIO_PIN_6 449 * @arg @ref GPIO_PIN_7 450 * @arg @ref GPIO_PIN_8 451 * @arg @ref GPIO_PIN_9 452 * @arg @ref GPIO_PIN_10 453 * @arg @ref GPIO_PIN_11 454 * @arg @ref GPIO_PIN_12 455 * @arg @ref GPIO_PIN_13 456 * @arg @ref GPIO_PIN_14 457 * @arg @ref GPIO_PIN_15 458 * @arg @ref GPIO_PIN_ALL 459 **************************************************************************************** 460 */ 461 void hal_gpio_exti_callback(gpio_regs_t *GPIOx, uint16_t gpio_pin); 462 463 /** @} */ 464 465 /** @} */ 466 467 #ifdef __cplusplus 468 } 469 #endif 470 471 #endif /* __GR55xx_HAL_GPIO_H__ */ 472 473 /** @} */ 474 475 /** @} */ 476 477 /** @} */ 478