1 /** 2 **************************************************************************************** 3 * 4 * @file app_io.h 5 * @author BLE Driver Team 6 * @brief Header file containing functions prototypes of GPIO app 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 APP_DRIVER APP DRIVER 43 * @{ 44 */ 45 46 /** @defgroup APP_GPIO GPIO 47 * @brief GPIO APP module driver. 48 * @{ 49 */ 50 51 52 #ifndef _APP_IO_H_ 53 #define _APP_IO_H_ 54 55 #include <stdint.h> 56 #include "app_drv_error.h" 57 58 /** @addtogroup APP_GPIO_PIN_DEFINES Defines 59 * @{ 60 */ 61 /** @addtogroup GR551x_pins IO pins 62 * @{ 63 */ 64 65 /** 66 * @brief APP_GPIO_DEFINE Defines 67 */ 68 #define APP_IO_PIN_0 ((uint32_t)0x00000001U) /**< Pin 0 selected */ 69 #define APP_IO_PIN_1 ((uint32_t)0x00000002U) /**< Pin 1 selected */ 70 #define APP_IO_PIN_2 ((uint32_t)0x00000004U) /**< Pin 2 selected */ 71 #define APP_IO_PIN_3 ((uint32_t)0x00000008U) /**< Pin 3 selected */ 72 #define APP_IO_PIN_4 ((uint32_t)0x00000010U) /**< Pin 4 selected */ 73 #define APP_IO_PIN_5 ((uint32_t)0x00000020U) /**< Pin 5 selected */ 74 #define APP_IO_PIN_6 ((uint32_t)0x00000040U) /**< Pin 6 selected */ 75 #define APP_IO_PIN_7 ((uint32_t)0x00000080U) /**< Pin 7 selected */ 76 #define APP_IO_PIN_8 ((uint32_t)0x00000100U) /**< Pin 8 selected */ 77 #define APP_IO_PIN_9 ((uint32_t)0x00000200U) /**< Pin 9 selected */ 78 #define APP_IO_PIN_10 ((uint32_t)0x00000400U) /**< Pin 10 selected */ 79 #define APP_IO_PIN_11 ((uint32_t)0x00000800U) /**< Pin 11 selected */ 80 #define APP_IO_PIN_12 ((uint32_t)0x00001000U) /**< Pin 12 selected */ 81 #define APP_IO_PIN_13 ((uint32_t)0x00002000U) /**< Pin 13 selected */ 82 #define APP_IO_PIN_14 ((uint32_t)0x00004000U) /**< Pin 14 selected */ 83 #define APP_IO_PIN_15 ((uint32_t)0x00008000U) /**< Pin 15 selected */ 84 #define APP_IO_PIN_16 ((uint32_t)0x00010000U) /**< Pin 16 selected */ 85 #define APP_IO_PIN_17 ((uint32_t)0x00020000U) /**< Pin 17 selected */ 86 #define APP_IO_PIN_18 ((uint32_t)0x00040000U) /**< Pin 18 selected */ 87 #define APP_IO_PIN_19 ((uint32_t)0x00080000U) /**< Pin 19 selected */ 88 #define APP_IO_PIN_20 ((uint32_t)0x00100000U) /**< Pin 20 selected */ 89 #define APP_IO_PIN_21 ((uint32_t)0x00200000U) /**< Pin 21 selected */ 90 #define APP_IO_PIN_22 ((uint32_t)0x00400000U) /**< Pin 22 selected */ 91 #define APP_IO_PIN_23 ((uint32_t)0x00800000U) /**< Pin 23 selected */ 92 #define APP_IO_PIN_24 ((uint32_t)0x01000000U) /**< Pin 24 selected */ 93 #define APP_IO_PIN_25 ((uint32_t)0x02000000U) /**< Pin 25 selected */ 94 #define APP_IO_PIN_26 ((uint32_t)0x04000000U) /**< Pin 26 selected */ 95 #define APP_IO_PIN_27 ((uint32_t)0x08000000U) /**< Pin 27 selected */ 96 #define APP_IO_PIN_28 ((uint32_t)0x10000000U) /**< Pin 28 selected */ 97 #define APP_IO_PIN_29 ((uint32_t)0x20000000U) /**< Pin 29 selected */ 98 #define APP_IO_PIN_30 ((uint32_t)0x40000000U) /**< Pin 30 selected */ 99 #define APP_IO_PIN_31 ((uint32_t)0x80000000U) /**< Pin 31 selected */ 100 101 #define APP_IO_PINS_0_15 ((uint32_t)0x0000FFFFU) /**< 0~15 pins selected */ 102 #define APP_IO_PINS_16_31 ((uint32_t)0xFFFF0000U) /**< 16~31 pins selected */ 103 #define APP_IO_PIN_ALL ((uint32_t)0xFFFFFFFFU) /**< All pins selected */ 104 #define APP_MSIO_PIN_MASK ((uint32_t)0x0000001FU) /**< PIN mask for assert test */ 105 #define APP_MSIO_PIN_ALL ((uint32_t)0x001FU) /**< All pins selected */ 106 #define APP_AON_IO_PIN_MASK ((uint32_t)0x000000FFU) /**< PIN mask for assert test */ 107 #define APP_AON_IO_PIN_ALL ((uint32_t)0x00FFU) /**< All pins selected */ 108 109 #define APP_IO_PIN_MASK ((uint32_t)0xFFFFFFFFU) /**< PIN mask for assert test */ 110 111 /** 112 * @brief GR551x_APP_GPIO_default_config initStruct default configuart APP_GPIOn 113 */ 114 #define APP_IO_DEFAULT_CONFIG \ 115 { \ 116 .pin = APP_IO_PIN_ALL, \ 117 .mode = APP_IO_MODE_INPUT, \ 118 .pull = APP_IO_PULLDOWN, \ 119 .mux = APP_IO_MUX_7, \ 120 } 121 122 /** @} */ 123 /** @} */ 124 125 /** @addtogroup APP_GPIO_ENUMERATIONS Enumerations 126 * @{ 127 */ 128 /** 129 * @brief GPIO state Enumerations definition 130 */ 131 typedef enum { 132 APP_IO_PIN_RESET, /**< IO pin low level. */ 133 APP_IO_PIN_SET, /**< IO pin high level. */ 134 } app_io_pin_state_t; 135 136 /** 137 * @brief GPIO type Enumerations definition 138 */ 139 typedef enum { 140 APP_IO_TYPE_NORMAL, /**< General Purpose Input/Output. */ 141 APP_IO_TYPE_AON, /**< Always-on Input/Output. */ 142 APP_IO_TYPE_MSIO, /**< Mixed Signal I/O. */ 143 APP_IO_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */ 144 } app_io_type_t; 145 146 /** 147 * @brief GPIO mode Enumerations definition 148 */ 149 typedef enum { 150 APP_IO_MODE_INPUT, /**< Input Mode. */ 151 APP_IO_MODE_OUT_PUT, /**< Output Mode. */ 152 APP_IO_MODE_MUX, /**< Mux Mode. */ 153 APP_IO_MODE_IT_RISING, /**< Interrupt Mode with Rising edge trigger detection. */ 154 APP_IO_MODE_IT_FALLING, /**< Interrupt Mode with Falling edge trigger detection. */ 155 APP_IO_MODE_IT_HIGH, /**< Interrupt Mode with High-level trigger detection. */ 156 APP_IO_MODE_IT_LOW, /**< Interrupt Mode with Low-level trigger detection. */ 157 APP_IO_MODE_ANALOG, /**< Analog IO Mode. */ 158 APP_IO_MODE_MAX, /**< Only for check parameter, not used as input parameters. */ 159 } app_io_mode_t; 160 161 /** 162 * @brief GPIO wake-up mode Enumerations definition 163 */ 164 typedef enum { 165 APP_IO_NONE_WAKEUP, /**< None Wakeup. */ 166 APP_IO_DISABLE_WAKEUP, /**< Disable AON GPIO Wakeup. */ 167 APP_IO_ENABLE_WAKEUP, /**< Enable AON GPIO Wakeup. */ 168 } app_handle_mode_t; 169 170 /** 171 * @brief GPIO handler context type Enumerations definition 172 */ 173 typedef enum { 174 APP_IO_CTX_WAKEUP, /**< the event of wakeup. */ 175 APP_IO_CTX_INT, /**< the event of interrupt. */ 176 } app_ctx_type_t; 177 178 /** 179 * @brief GPIO pull Enumerations definition 180 */ 181 typedef enum { 182 APP_IO_NOPULL, /**< No Pull-up or Pull-down activation. */ 183 APP_IO_PULLUP, /**< Pull-up activation. */ 184 APP_IO_PULLDOWN, /**< Pull-down activation. */ 185 APP_IO_PULL_MAX /**< Only for check parameter, not used as input parameters. */ 186 } app_io_pull_t; 187 188 /** 189 * @brief GPIO mux Enumerations definition 190 */ 191 typedef enum { 192 APP_IO_MUX_0, /**< IO mux mode 0. */ 193 APP_IO_MUX_1, /**< IO mux mode 1. */ 194 APP_IO_MUX_2, /**< IO mux mode 2. */ 195 APP_IO_MUX_3, /**< IO mux mode 3. */ 196 APP_IO_MUX_4, /**< IO mux mode 4. */ 197 APP_IO_MUX_5, /**< IO mux mode 5. */ 198 APP_IO_MUX_6, /**< IO mux mode 6. */ 199 APP_IO_MUX_7, /**< IO mux mode 7. */ 200 APP_IO_MUX_8, /**< IO mux mode 8. */ 201 APP_IO_MUX_MAX, /**< Only for check parameter, not used as input parameters. */ 202 } app_io_mux_t; 203 /** @} */ 204 205 /** @addtogroup APP_GPIO_STRUCT Structures 206 * @{ 207 */ 208 /** 209 * @brief GPIO parameter structure definition 210 */ 211 typedef struct { 212 uint32_t pin; /**< Specifies the IO pins to be configured. 213 This parameter can be any value of @ref GR551x_pins */ 214 app_io_mode_t mode; /**< Specifies the operating mode for the selected pins. */ 215 app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */ 216 app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */ 217 } app_io_init_t; 218 /** @} */ 219 220 /* Exported functions --------------------------------------------------------*/ 221 /** @addtogroup HAL_APP_GPIO_DRIVER_FUNCTIONS Functions 222 * @{ 223 */ 224 /** 225 **************************************************************************************** 226 * @brief Initialize the APP GPIO DRIVER according to the specified parameters 227 * in the app_io_type_t and app_io_init_t. 228 * 229 * @param[in] type: GPIO type. 230 * @param[in] p_init: Pointer to app_io_init_t parameter which contains the 231 * configuration information for the specified GPIO. 232 * 233 * @return Result of initialization. 234 **************************************************************************************** 235 */ 236 uint16_t app_io_init(app_io_type_t type, app_io_init_t *p_init); 237 238 /** 239 **************************************************************************************** 240 * @brief De-initialize the GPIOx peripheral. 241 * 242 * @param[in] type: GPIO type, See app_io_type_t. 243 * @param[in] pin: The pin want to De-initialization. 244 * 245 * @return Result of De-initialization. 246 **************************************************************************************** 247 */ 248 uint16_t app_io_deinit(app_io_type_t type, uint32_t pin); 249 250 /** 251 **************************************************************************************** 252 * @brief Read the specified input port pin.. 253 * 254 * @param[in] type: GPIO type, See app_io_type_t. 255 * @param[in] pin: The pin want to read. 256 * 257 * @return The GPIO state. 258 **************************************************************************************** 259 */ 260 app_io_pin_state_t app_io_read_pin(app_io_type_t type, uint32_t pin); 261 262 /** 263 **************************************************************************************** 264 * @brief Set or clear the selected data port bit. 265 * 266 * @param[in] type: GPIO type, See app_io_type_t. 267 * @param[in] pin: The pin want to set or clear. 268 * @param[in] pin_state: Specifies the value to be written to the selected bit. 269 * 270 * @return Result of write. 271 **************************************************************************************** 272 */ 273 uint16_t app_io_write_pin(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state); 274 275 /** 276 **************************************************************************************** 277 * @brief Toggle the specified GPIO pin. 278 * 279 * @param[in] type: GPIO type, See app_io_type_t. 280 * @param[in] pin: The pin want to toggle. 281 * 282 * @return Result of toggle. 283 **************************************************************************************** 284 */ 285 uint16_t app_io_toggle_pin(app_io_type_t type, uint32_t pin); 286 /** @} */ 287 288 uint16_t app_io_toggle_pin_sym(app_io_type_t type, uint32_t pin); 289 290 uint16_t app_io_write_pin_sym(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state); 291 292 app_io_pin_state_t app_io_read_pin_sym(app_io_type_t type, uint32_t pin); 293 294 uint16_t app_io_deinit_sym(app_io_type_t type, uint32_t pin); 295 296 uint16_t app_io_init_sym(app_io_type_t type, app_io_init_t *p_init); 297 298 #endif 299 300 /** @} */ 301 /** @} */ 302 /** @} */ 303