1 /** 2 ****************************************************************************** 3 * @file rtl8721d_gpio.h 4 * @author 5 * @version V1.0.0 6 * @date 2016-05-17 7 * @brief This file contains all the functions prototypes for the GPIO firmware 8 * library. 9 ****************************************************************************** 10 * @attention 11 * 12 * This module is a confidential and proprietary property of RealTek and 13 * possession or use of this module requires written permission of RealTek. 14 * 15 * Copyright(c) 2016, Realtek Semiconductor Corporation. All rights reserved. 16 ****************************************************************************** 17 */ 18 19 #ifndef _RTL8721D_GPIO_H_ 20 #define _RTL8721D_GPIO_H_ 21 22 /** @addtogroup AmebaD_Periph_Driver 23 * @{ 24 */ 25 26 /** @defgroup GPIO 27 * @brief GPIO driver modules 28 * @{ 29 */ 30 31 /** @addtogroup GPIO 32 * @verbatim 33 ***************************************************************************************** 34 * Introduction 35 ***************************************************************************************** 36 * GPIO: 37 * - Base Address: GPIO 38 * - Port number: support A/B two ports 39 * - Pin number: 0 ~ 31(portA), 0 ~ 31(portB) 40 * - IRQ: GPIO_IRQ 41 * - portA/B can be configured to interrupt mode 42 * 43 ***************************************************************************************** 44 * How to use GPIO in normal mode 45 ***************************************************************************************** 46 * To use GPIO peripheral in normal mode, the following steps are mandatory: 47 * 48 * 1. Enable the GPIO interface clock using 49 * RCC_PeriphClockCmd(APBPeriph_GPIO, APBPeriph_GPIO_CLOCK, ENABLE); 50 * 51 * 2. Fill the GPIO_InitStruct with the desired parameters. 52 * 53 * 3. configure GPIO with the configuration(GPIO mode, pull up/down) of step2: 54 * GPIO_Init(&GPIO_InitStruct) 55 * 56 * 4. Read or write GPIO pin according to GPIO out/in mode using 57 * GPIO_ReadDataBit() or GPIO_WriteBit() 58 * 59 ***************************************************************************************** 60 * How to use GPIO in interrupt mode 61 ***************************************************************************************** 62 * To use GPIO in interrupt mode, the following steps are mandatory: 63 * 64 * 1. Enable the GPIO interface clock using 65 * RCC_PeriphClockCmd(APBPeriph_GPIO, APBPeriph_GPIO_CLOCK, ENABLE); 66 * 67 * 2. Fill the GPIO_InitStruct with the desired parameters. 68 * 69 * 3. configure GPIO with the configuration(GPIO mode, pull up/down) of step2: 70 * GPIO_Init(&GPIO_InitStruct) 71 * 72 * 4. Register a user interrupt handler: 73 * GPIO_UserRegIrq 74 * 75 * 5. Configure interrupt mode(trigger, polarity, debounce): 76 * GPIO_INTMode() 77 * 78 * 6. Enable the interrupt of a specified pin: 79 * GPIO_INTConfig() 80 * 81 * @note PortA/B can configure interrupt mode. 82 * 83 ***************************************************************************************** 84 * How to use GPIO port (multiple GPIO pins) 85 ***************************************************************************************** 86 * To use GPIO port, the following steps are mandatory: 87 * 88 * 1. Enable the GPIO interface clock using 89 * RCC_PeriphClockCmd(APBPeriph_GPIO, APBPeriph_GPIO_CLOCK, ENABLE); 90 * 91 * 2. Configure GPIO data direction(IN/OUT) 92 * GPIO_PortDirection() 93 * 94 * 3. Read or write GPIO pin according to GPIO out/in mode using 95 * GPIO_PortRead() 96 * GPIO_PortWrite() 97 * 98 ***************************************************************************************** 99 * @endverbatim 100 */ 101 102 /* Exported types ------------------------------------------------------------*/ 103 104 /** @defgroup GPIO_Exported_Types GPIO Exported Types 105 * @{ 106 */ 107 108 /** 109 * @brief GPIO Init structure definition 110 */ 111 typedef struct { 112 u32 GPIO_Mode; /*!< Specifies the operating mode for the selected pins. 113 This parameter can be a value of @ref GPIO_Mode_parameter_definitions */ 114 115 u32 GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins. 116 This parameter can be a value of @ref GPIO_Pull_parameter_definitions */ 117 118 u32 GPIO_ITTrigger; /*!< Specifies interrupt mode is level or edge trigger 119 This parameter can be a value of @ref GPIO_INT_Trigger_parameter_definitions */ 120 121 u32 GPIO_ITPolarity; /*!< Specifies interrupt mode is high or low active trigger 122 This parameter can be a value of @ref GPIO_INT_Polarity_parameter_definitions */ 123 124 u32 GPIO_ITDebounce; /*!< Specifies enable or disable de-bounce for interrupt 125 This parameter can be a value of @ref GPIO_INT_Debounce_parameter_definitions*/ 126 127 u32 GPIO_Pin; /*!< Specifies the selected pins. 128 This parameter contains two parts: Pin: [7:5]: port number; [4:0]: pin number */ 129 } GPIO_InitTypeDef; 130 /** 131 * @} 132 */ 133 134 /* Exported constants --------------------------------------------------------*/ 135 136 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants 137 * @{ 138 */ 139 140 /** @defgroup GPIO_Mode_parameter_definitions 141 * @{ 142 */ 143 #define GPIO_Mode_IN 0x00 /*!< GPIO Input Mode */ 144 #define GPIO_Mode_OUT 0x01 /*!< GPIO Output Mode */ 145 #define GPIO_Mode_INT 0x02 /*!< GPIO Interrupt Mode */ 146 /** 147 * @} 148 */ 149 150 /** @defgroup GPIO_Pull_parameter_definitions 151 * @{ 152 */ 153 #define GPIO_PuPd_NOPULL 0x00 /*!< GPIO Interrnal HIGHZ */ 154 #define GPIO_PuPd_DOWN 0x01 /*!< GPIO Interrnal Pull DOWN */ 155 #define GPIO_PuPd_UP 0x02 /*!< GPIO Interrnal Pull UP */ 156 #define GPIO_PuPd_SHUTDOWN 0x03 /*!< GPIO Interrnal PAD shutdown */ 157 158 /** 159 * @} 160 */ 161 162 /** @defgroup GPIO_INT_Trigger_parameter_definitions 163 * @{ 164 */ 165 #define GPIO_INT_Trigger_LEVEL 0x0 /*!< This interrupt is level trigger */ 166 #define GPIO_INT_Trigger_EDGE 0x1 /*!< This interrupt is edge trigger */ 167 #define GPIO_INT_Trigger_BOTHEDGE 0x2 /*!< This interrupt is both-edge trigger */ 168 169 #define IS_GPIOIT_LEVEL_TYPE(TYPE) (((TYPE) == GPIO_INT_Trigger_LEVEL)\ 170 || ((TYPE) == GPIO_INT_Trigger_EDGE)\ 171 || ((TYPE) == GPIO_INT_Trigger_BOTHEDGE)) 172 /** 173 * @} 174 */ 175 176 /** @defgroup GPIO_INT_Polarity_parameter_definitions 177 * @{ 178 */ 179 #define GPIO_INT_POLARITY_ACTIVE_LOW 0x0 /*!< Setting interrupt to low active: falling edge or low level */ 180 #define GPIO_INT_POLARITY_ACTIVE_HIGH 0x1 /*!< Setting interrupt to high active: rising edge or high level */ 181 182 #define IS_GPIOIT_POLARITY_TYPE(TYPE) (((TYPE) == GPIO_INT_POLARITY_ACTIVE_LOW)\ 183 || ((TYPE) == GPIO_INT_POLARITY_ACTIVE_HIGH)) 184 /** 185 * @} 186 */ 187 188 /** @defgroup GPIO_INT_Debounce_parameter_definitions 189 * @{ 190 */ 191 #define GPIO_INT_DEBOUNCE_DISABLE 0x0 /*!< Disable interrupt debounce */ 192 #define GPIO_INT_DEBOUNCE_ENABLE 0x1 /*!< Enable interrupt debounce */ 193 194 #define IS_GPIOIT_DEBOUNCE_TYPE(TYPE) (((TYPE) == GPIO_INT_DEBOUNCE_DISABLE)\ 195 || ((TYPE) == GPIO_INT_DEBOUNCE_ENABLE)) 196 /** 197 * @} 198 */ 199 200 /** @defgroup GPIO_Pin_State_definitions 201 * @{ 202 */ 203 //#define GPIO_PIN_LOW 0 /*!< Pin state is low */ 204 //#define GPIO_PIN_HIGH 1 /*!< Pin state is high */ 205 /** 206 * @} 207 */ 208 209 /** @defgroup GPIO_Port_definitions 210 * @{ 211 */ 212 #define GPIO_PORT_A 0 /*!< Port number A */ 213 #define GPIO_PORT_B 1 /*!< Port number B */ 214 /** 215 * @} 216 */ 217 218 /** @defgroup GPIO_IRQ_Event_definitions 219 * @{ 220 */ 221 #define HAL_IRQ_NONE 0 /*!< No interrupt event */ 222 #define HAL_IRQ_RISE 1 /*!< Rising edge or high level interrupt event */ 223 #define HAL_IRQ_FALL 2 /*!< Falling edge or low level interrupt event */ 224 /** 225 * @} 226 */ 227 228 /** 229 * @} 230 */ 231 232 /** @defgroup GPIO_Exported_Functions GPIO Exported Functions 233 * @{ 234 */ 235 _LONG_CALL_ void GPIO_WriteBit(u32 GPIO_Pin, u32 BitVal); 236 _LONG_CALL_ u32 GPIO_ReadDataBit(u32 GPIO_Pin); 237 _LONG_CALL_ void GPIO_DeInit(u32 GPIO_Pin); 238 _LONG_CALL_ void GPIO_UserRegIrq(u32 GPIO_Pin, VOID *IrqHandler, VOID *IrqData); 239 _LONG_CALL_ void GPIO_INTMode(u32 GPIO_Pin, u32 NewState, u32 GPIO_ITTrigger, u32 GPIO_ITPolarity, u32 GPIO_ITDebounce); 240 _LONG_CALL_ void GPIO_INTConfig(u32 GPIO_Pin, u32 NewState); 241 _LONG_CALL_ void GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct); 242 _LONG_CALL_ u32 GPIO_INTHandler(IN VOID *pData); 243 _LONG_CALL_ void GPIO_Direction(u32 GPIO_Pin, u32 data_direction); 244 _LONG_CALL_ u32 GPIO_PortRead(u32 GPIO_Port, u32 GPIO_Mask); 245 _LONG_CALL_ void GPIO_PortWrite(u32 GPIO_Port, u32 GPIO_Mask, u32 Port_State); 246 _LONG_CALL_ void GPIO_PortDirection(u32 GPIO_Port, u32 GPIO_Mask, u32 data_direction); 247 /** 248 * @} 249 */ 250 251 /** 252 * @} 253 */ 254 255 /** 256 * @} 257 */ 258 259 260 typedef void (*GPIO_IRQ_FUN)(VOID *Data, u32 Id); 261 typedef void (*GPIO_USER_IRQ_FUN)(u32 Id); 262 263 #endif // end of "#define _RTL8721D_GPIO_H_" 264 /******************* (C) COPYRIGHT 2016 Realtek Semiconductor *****END OF FILE****/ 265