1 /** 2 **************************************************************************************** 3 * 4 * @file gr55xx_hal_aon_gpio.h 5 * @author BLE Driver Team 6 * @brief Header file containing functions prototypes of AON 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_AON_GPIO AON_GPIO 47 * @brief AON_GPIO HAL module driver. 48 * @{ 49 */ 50 51 /* Define to prevent recursive inclusion -------------------------------------*/ 52 #ifndef __GR55xx_HAL_AON_GPIO_H__ 53 #define __GR55xx_HAL_AON_GPIO_H__ 54 55 /* Includes ------------------------------------------------------------------*/ 56 #include "gr55xx_ll_aon_gpio.h" 57 #include "gr55xx_hal_def.h" 58 /* Include AON GPIO HAL Extended module */ 59 #include "gr55xx_hal_aon_gpio_ex.h" 60 61 #ifdef __cplusplus 62 extern "C" { 63 #endif 64 65 /* Exported types ------------------------------------------------------------*/ 66 /** @addtogroup HAL_AON_GPIO_ENUMERATIONS Enumerations 67 * @{ 68 */ 69 70 /** 71 * @brief AON_GPIO Bit SET and Bit RESET enumerations 72 */ 73 typedef enum { 74 AON_GPIO_PIN_RESET = 0U, /**< AON GPIO pin low level.*/ 75 AON_GPIO_PIN_SET /**< AON GPIO pin high level.*/ 76 } aon_gpio_pin_state_t; 77 78 /** @} */ 79 80 /** @addtogroup HAL_AON_GPIO_STRUCTURES Structures 81 * @{ 82 */ 83 84 /** 85 * @brief AON_GPIO init structure definition 86 */ 87 typedef struct _aon_gpio_init { 88 uint32_t pin; /**< Specifies the AON_GPIO pins to be configured. 89 This parameter can be any value of @ref AON_GPIO_Pins */ 90 91 uint32_t mode; /**< Specifies the operating mode for the selected pins. 92 This parameter can be a value of @ref AON_GPIO_Mode */ 93 94 uint32_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. 95 This parameter can be a value of @ref AON_GPIO_Pull */ 96 97 uint32_t mux; /**< Specifies the Peripheral to be connected to the selected pins. 98 This parameter can be a value of @ref GPIOEx_Mux_Function_Selection. */ 99 } aon_gpio_init_t; 100 101 /** @} */ 102 103 /** @addtogroup HAL_AON_GPIO_CALLBACK_STRUCTURES Callback Structures 104 * @{ 105 */ 106 107 /** @defgroup AON_GPIO_Callback AON_GPIO Callback 108 * @{ 109 */ 110 111 /** 112 * @brief HAL AON_GPIO Callback function definition 113 */ 114 typedef struct _aon_gpio_callback { 115 void (*aon_gpio_callback)(uint16_t aon_gpio_pin); /**< AON GPIO pin detection callback */ 116 } aon_gpio_callback_t; 117 118 /** @} */ 119 120 /** @} */ 121 122 /** 123 * @defgroup HAL_AON_GPIO_MACRO Defines 124 * @{ 125 */ 126 127 /* Exported constants --------------------------------------------------------*/ 128 /** @defgroup AON_GPIO_Exported_Constants AON_GPIO Exported Constants 129 * @{ 130 */ 131 132 /** @defgroup AON_GPIO_Pins AON_GPIO pins 133 * @{ 134 */ 135 #define AON_GPIO_PIN_0 ((uint16_t)0x0001U) /**< Pin 0 selected */ 136 #define AON_GPIO_PIN_1 ((uint16_t)0x0002U) /**< Pin 1 selected */ 137 #define AON_GPIO_PIN_2 ((uint16_t)0x0004U) /**< Pin 2 selected */ 138 #define AON_GPIO_PIN_3 ((uint16_t)0x0008U) /**< Pin 3 selected */ 139 #define AON_GPIO_PIN_4 ((uint16_t)0x0010U) /**< Pin 4 selected */ 140 #define AON_GPIO_PIN_5 ((uint16_t)0x0020U) /**< Pin 5 selected */ 141 #define AON_GPIO_PIN_6 ((uint16_t)0x0040U) /**< Pin 6 selected */ 142 #define AON_GPIO_PIN_7 ((uint16_t)0x0080U) /**< Pin 7 selected */ 143 144 #define AON_GPIO_PIN_ALL ((uint16_t)0x00FFU) /**< All pins selected */ 145 146 #define AON_GPIO_PIN_MASK (0x000000FFU) /**< PIN mask for assert test */ 147 /** @} */ 148 149 /** @defgroup AON_GPIO_Mode AON_GPIO mode 150 * @brief AON_GPIO Configuration Mode 151 * Elements values convention: 0x000000YX 152 * - X : IO Direction mode (Input, Output, Mux) 153 * - Y : IT trigger detection 154 * @{ 155 */ 156 #define AON_GPIO_MODE_INPUT (LL_AON_GPIO_MODE_INPUT << 0) /**< Input Mode */ 157 #define AON_GPIO_MODE_OUTPUT (LL_AON_GPIO_MODE_OUTPUT << 0) /**< Output Mode */ 158 #define AON_GPIO_MODE_MUX (LL_GPIO_MODE_MUX << 0) /**< Mux Mode */ 159 #define AON_GPIO_MODE_IT_RISING (LL_AON_GPIO_TRIGGER_RISING << 4) /**< Interrupt Mode with Rising edge 160 trigger detection */ 161 #define AON_GPIO_MODE_IT_FALLING (LL_AON_GPIO_TRIGGER_FALLING << 4) /**< Interrupt Mode with Falling edge 162 trigger detection */ 163 #define AON_GPIO_MODE_IT_HIGH (LL_AON_GPIO_TRIGGER_HIGH << 4) /**< Interrupt Mode with High-level 164 trigger detection */ 165 #define AON_GPIO_MODE_IT_LOW (LL_AON_GPIO_TRIGGER_LOW << 4) /**< Interrupt Mode with Low-level 166 trigger detection */ 167 /** @} */ 168 169 /** @defgroup AON_GPIO_Pull AON_GPIO pull 170 * @brief AON_GPIO Pull-Up or Pull-Down activation 171 * @{ 172 */ 173 #define AON_GPIO_NOPULL LL_AON_GPIO_PULL_NO /**< No Pull-up or Pull-down activation */ 174 #define AON_GPIO_PULLUP LL_AON_GPIO_PULL_UP /**< Pull-up activation */ 175 #define AON_GPIO_PULLDOWN LL_AON_GPIO_PULL_DOWN /**< Pull-down activation */ 176 /** @} */ 177 178 /** 179 * @brief AON_GPIO_default_config initStruct default configuartion 180 */ 181 #define AON_GPIO_DEFAULT_CONFIG \ 182 { \ 183 .pin = AON_GPIO_PIN_ALL, \ 184 .mode = AON_GPIO_MODE_INPUT, \ 185 .pull = AON_GPIO_PULLDOWN, \ 186 .mux = AON_GPIO_MUX_7, \ 187 } 188 /** @} */ 189 190 /* Exported macro ------------------------------------------------------------*/ 191 /** @defgroup AON_GPIO_Exported_Macros AON_GPIO Exported Macros 192 * @{ 193 */ 194 195 /** 196 * @brief Check whether the specified AON_GPIO pin is asserted or not. 197 * @param __AON_GPIO_PIN__ specifies the AON_GPIO pin to be checked. 198 * This parameter can be AON_GPIO_PIN_x where x can be (0..15). 199 * @retval The new state of __AON_GPIO_PIN__ (SET or RESET). 200 */ 201 #define __HAL_AON_GPIO_IT_GET_IT(__AON_GPIO_PIN__) ll_aon_gpio_read_flag_it(__AON_GPIO_PIN__) 202 203 /** 204 * @brief Clear the AON_GPIO pin pending bits. 205 * @param __AON_GPIO_PIN__ specifies the AON_GPIO pins to be cleared. 206 * This parameter can be any combination of AON_GPIO_PIN_x where x can be (0..15). 207 * @retval None 208 */ 209 #define __HAL_AON_GPIO_IT_CLEAR_IT(__AON_GPIO_PIN__) ll_aon_gpio_clear_flag_it(__AON_GPIO_PIN__) 210 211 /** @} */ 212 213 /* Private macros ------------------------------------------------------------*/ 214 /** @addtogroup AON_GPIO_Private_Macros AON_GPIO Private Macros 215 * @{ 216 */ 217 218 /** 219 * @brief Check if AON GPIO pin action is valid. 220 * @param __ACTION__ AON GPIO pin action. 221 * @retval SET (__ACTION__ is valid) or RESET (__ACTION__ is invalid) 222 */ 223 #define IS_AON_GPIO_PIN_ACTION(__ACTION__) (((__ACTION__) == AON_GPIO_PIN_RESET) || \ 224 ((__ACTION__) == AON_GPIO_PIN_SET)) 225 226 /** 227 * @brief Check if AON GPIO pins are valid. 228 * @param __PIN__ AON GPIO pins. 229 * @retval SET (__PIN__ is valid) or RESET (__PIN__ is invalid) 230 */ 231 #define IS_AON_GPIO_PIN(__PIN__) ((((__PIN__) & AON_GPIO_PIN_MASK) != 0x00U) && \ 232 (((__PIN__) & ~AON_GPIO_PIN_MASK) == 0x00U)) 233 234 /** 235 * @brief Check if AON GPIO mode is valid. 236 * @param __MODE__ AON GPIO mode. 237 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 238 */ 239 #define IS_AON_GPIO_MODE(__MODE__) (((__MODE__) == AON_GPIO_MODE_INPUT) || \ 240 ((__MODE__) == AON_GPIO_MODE_OUTPUT) || \ 241 ((__MODE__) == AON_GPIO_MODE_MUX) || \ 242 ((__MODE__) == AON_GPIO_MODE_IT_RISING) || \ 243 ((__MODE__) == AON_GPIO_MODE_IT_FALLING) || \ 244 ((__MODE__) == AON_GPIO_MODE_IT_HIGH) || \ 245 ((__MODE__) == AON_GPIO_MODE_IT_LOW)) 246 247 /** 248 * @brief Check if AON GPIO pull type is valid. 249 * @param __PULL__ AON GPIO pull type. 250 * @retval SET (__PULL__ is valid) or RESET (__PULL__ is invalid) 251 */ 252 #define IS_AON_GPIO_PULL(__PULL__) (((__PULL__) == AON_GPIO_NOPULL) || \ 253 ((__PULL__) == AON_GPIO_PULLUP) || \ 254 ((__PULL__) == AON_GPIO_PULLDOWN)) 255 256 /** @} */ 257 258 /** @} */ 259 260 /* Exported functions --------------------------------------------------------*/ 261 /** @addtogroup HAL_AON_GPIO_DRIVER_FUNCTIONS Functions 262 * @{ 263 */ 264 265 /** @addtogroup AON_GPIO_Exported_Functions_Group1 Initialization and de-initialization functions 266 * @brief Initialization and Configuration functions 267 * @{ 268 */ 269 270 /** 271 **************************************************************************************** 272 * @brief Initialize the AON_GPIOx peripheral according to the specified parameters in the @ref aon_gpio_init_t. 273 * 274 * @param[in] p_aon_gpio_init: Pointer to an @ref aon_gpio_init_t structure that contains 275 * the configuration information for the specified AON_GPIO peripheral port. 276 **************************************************************************************** 277 */ 278 void hal_aon_gpio_init(aon_gpio_init_t *p_aon_gpio_init); 279 280 /** 281 **************************************************************************************** 282 * @brief De-initialize the AON_GPIOx peripheral registers to their default reset values. 283 * 284 * @param[in] aon_gpio_pin: Specifies the port bit to be written. 285 * This parameter can be a combination of the following values: 286 * @arg @ref AON_GPIO_PIN_0 287 * @arg @ref AON_GPIO_PIN_1 288 * @arg @ref AON_GPIO_PIN_2 289 * @arg @ref AON_GPIO_PIN_3 290 * @arg @ref AON_GPIO_PIN_4 291 * @arg @ref AON_GPIO_PIN_5 292 * @arg @ref AON_GPIO_PIN_ALL 293 **************************************************************************************** 294 */ 295 void hal_aon_gpio_deinit(uint32_t aon_gpio_pin); 296 297 /** @} */ 298 299 /** @addtogroup AON_GPIO_Exported_Functions_Group2 IO operation functions 300 * @brief AON_GPIO Read, Write, Toggle, Lock and EXTI management functions. 301 * @{ 302 */ 303 304 /** 305 **************************************************************************************** 306 * @brief Read the specified input port pin. 307 * 308 * @param[in] aon_gpio_pin: Specifies the port bit to be read. 309 * This parameter can be one of the following values: 310 * @arg @ref AON_GPIO_PIN_0 311 * @arg @ref AON_GPIO_PIN_1 312 * @arg @ref AON_GPIO_PIN_2 313 * @arg @ref AON_GPIO_PIN_3 314 * @arg @ref AON_GPIO_PIN_4 315 * @arg @ref AON_GPIO_PIN_5 316 * 317 * @return The input port pin value. 318 **************************************************************************************** 319 */ 320 aon_gpio_pin_state_t hal_aon_gpio_read_pin(uint16_t aon_gpio_pin); 321 322 /** 323 **************************************************************************************** 324 * @brief Set or clear the selected data port bit. 325 * 326 * @param[in] aon_gpio_pin: Specifies the port bit to be written. 327 * This parameter can be a combination of the following values: 328 * @arg @ref AON_GPIO_PIN_0 329 * @arg @ref AON_GPIO_PIN_1 330 * @arg @ref AON_GPIO_PIN_2 331 * @arg @ref AON_GPIO_PIN_3 332 * @arg @ref AON_GPIO_PIN_4 333 * @arg @ref AON_GPIO_PIN_5 334 * @arg @ref AON_GPIO_PIN_ALL 335 * @param[in] pin_state: Specifies the value to be written to the selected bit. 336 * This parameter can be one of the AON_GPIO_PinState enum values: 337 * @arg AON_GPIO_PIN_RESET: to clear the port pin 338 * @arg AON_GPIO_PIN_SET: to set the port pin 339 **************************************************************************************** 340 */ 341 void hal_aon_gpio_write_pin(uint16_t aon_gpio_pin, aon_gpio_pin_state_t pin_state); 342 343 /** 344 **************************************************************************************** 345 * @brief Toggle the specified AON_GPIO pin. 346 * 347 * @param[in] aon_gpio_pin: Specifies the pin to be toggled. 348 * This parameter can be a combination of the following values: 349 * @arg @ref AON_GPIO_PIN_0 350 * @arg @ref AON_GPIO_PIN_1 351 * @arg @ref AON_GPIO_PIN_2 352 * @arg @ref AON_GPIO_PIN_3 353 * @arg @ref AON_GPIO_PIN_4 354 * @arg @ref AON_GPIO_PIN_5 355 * @arg @ref AON_GPIO_PIN_ALL 356 **************************************************************************************** 357 */ 358 void hal_aon_gpio_toggle_pin(uint16_t aon_gpio_pin); 359 360 /** @} */ 361 362 /** @addtogroup AON_GPIO_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks 363 * @brief IRQ Handler and Callbacks functions 364 * @{ 365 */ 366 367 /** 368 **************************************************************************************** 369 * @brief Handle AON_GPIO interrupt request. 370 **************************************************************************************** 371 */ 372 void hal_aon_gpio_irq_handler(void); 373 374 /** 375 **************************************************************************************** 376 * @brief AON GPIO pin detection callback. 377 * 378 * @note This function should not be modified. When the callback is needed, 379 * the hal_aon_gpio_callback can be implemented in the user file. 380 * 381 * @param[in] aon_gpio_pin: Indicate the port pin whose interrupt was triggered. 382 * This parameter can be a combination of the following values: 383 * @arg @ref AON_GPIO_PIN_0 384 * @arg @ref AON_GPIO_PIN_1 385 * @arg @ref AON_GPIO_PIN_2 386 * @arg @ref AON_GPIO_PIN_3 387 * @arg @ref AON_GPIO_PIN_4 388 * @arg @ref AON_GPIO_PIN_5 389 * @arg @ref AON_GPIO_PIN_ALL 390 **************************************************************************************** 391 */ 392 void hal_aon_gpio_callback(uint16_t aon_gpio_pin); 393 394 /** @} */ 395 396 /** @} */ 397 398 #ifdef __cplusplus 399 } 400 #endif 401 402 #endif /* __GR55xx_HAL_AON_GPIO_H__ */ 403 404 /** @} */ 405 406 /** @} */ 407 408 /** @} */ 409