1 /*********************************************************************************************************//** 2 * @file ht32f5xxxx_exti.h 3 * @version $Rev:: 6496 $ 4 * @date $Date:: 2022-11-28 #$ 5 * @brief The header file of the EXTI library. 6 ************************************************************************************************************* 7 * @attention 8 * 9 * Firmware Disclaimer Information 10 * 11 * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the 12 * code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the 13 * proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and 14 * other intellectual property laws. 15 * 16 * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the 17 * code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties 18 * other than HOLTEK and the customer. 19 * 20 * 3. The program technical documentation, including the code, is provided "as is" and for customer reference 21 * only. After delivery by HOLTEK, the customer shall use the program technical documentation, including 22 * the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including 23 * the warranties of merchantability, satisfactory quality and fitness for a particular purpose. 24 * 25 * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2> 26 ************************************************************************************************************/ 27 28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/ 29 #ifndef __HT32F5XXXX_EXTI_H 30 #define __HT32F5XXXX_EXTI_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* Includes ------------------------------------------------------------------------------------------------*/ 37 #include "ht32.h" 38 39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver 40 * @{ 41 */ 42 43 /** @addtogroup EXTI 44 * @{ 45 */ 46 47 /* Exported macro ------------------------------------------------------------------------------------------*/ 48 /** @defgroup EXTI_Exported_Macro EXTI exported macros 49 * @{ 50 */ 51 /*********************************************************************************************************//** 52 * @brief Convert the pin number of GPIO to the channel of EXTI. 53 * @param n: can be 0, 1 to 15 to select the pin number of GPIO. 54 ************************************************************************************************************/ 55 #if (LIBCFG_EXTI_8CH) 56 #define GPIO2EXTI(n) ((n >= 8) ? (n - 8) : n) 57 #else 58 #define GPIO2EXTI(n) (n) 59 #endif 60 61 #define EXTI_GetIRQn(ch) gEXTIn_IRQn[ch] 62 /** 63 * @} 64 */ 65 66 /* Exported types ------------------------------------------------------------------------------------------*/ 67 /** @defgroup EXTI_Exported_Types EXTI exported types 68 * @{ 69 */ 70 71 /* Definitions of EXTI interrupt line */ 72 typedef enum 73 { 74 EXTI_CHANNEL_0 = 0, 75 EXTI_CHANNEL_1, 76 EXTI_CHANNEL_2, 77 EXTI_CHANNEL_3, 78 EXTI_CHANNEL_4, 79 EXTI_CHANNEL_5, 80 EXTI_CHANNEL_6, 81 EXTI_CHANNEL_7, 82 #if (!LIBCFG_EXTI_8CH) 83 EXTI_CHANNEL_8, 84 EXTI_CHANNEL_9, 85 EXTI_CHANNEL_10, 86 EXTI_CHANNEL_11, 87 EXTI_CHANNEL_12, 88 EXTI_CHANNEL_13, 89 EXTI_CHANNEL_14, 90 EXTI_CHANNEL_15, 91 #endif 92 } EXTI_Channel_TypeDef; 93 94 #if (LIBCFG_EXTI_8CH) 95 #define IS_CHANNEL_8(x) (0) 96 #define IS_CHANNEL_9(x) (0) 97 #define IS_CHANNEL_10(x) (0) 98 #define IS_CHANNEL_11(x) (0) 99 #define IS_CHANNEL_12(x) (0) 100 #define IS_CHANNEL_13(x) (0) 101 #define IS_CHANNEL_14(x) (0) 102 #define IS_CHANNEL_15(x) (0) 103 #else 104 #define IS_CHANNEL_8(x) (x == EXTI_CHANNEL_8) 105 #define IS_CHANNEL_9(x) (x == EXTI_CHANNEL_9) 106 #define IS_CHANNEL_10(x) (x == EXTI_CHANNEL_10) 107 #define IS_CHANNEL_11(x) (x == EXTI_CHANNEL_11) 108 #define IS_CHANNEL_12(x) (x == EXTI_CHANNEL_12) 109 #define IS_CHANNEL_13(x) (x == EXTI_CHANNEL_13) 110 #define IS_CHANNEL_14(x) (x == EXTI_CHANNEL_14) 111 #define IS_CHANNEL_15(x) (x == EXTI_CHANNEL_15) 112 #endif 113 114 115 #define IS_EXTI_CHANNEL(CHANNEL) ((CHANNEL == EXTI_CHANNEL_0) || \ 116 (CHANNEL == EXTI_CHANNEL_1) || \ 117 (CHANNEL == EXTI_CHANNEL_2) || \ 118 (CHANNEL == EXTI_CHANNEL_3) || \ 119 (CHANNEL == EXTI_CHANNEL_4) || \ 120 (CHANNEL == EXTI_CHANNEL_5) || \ 121 (CHANNEL == EXTI_CHANNEL_6) || \ 122 (CHANNEL == EXTI_CHANNEL_7) || \ 123 IS_CHANNEL_8(CHANNEL) || \ 124 IS_CHANNEL_9(CHANNEL) || \ 125 IS_CHANNEL_10(CHANNEL) || \ 126 IS_CHANNEL_11(CHANNEL) || \ 127 IS_CHANNEL_12(CHANNEL) || \ 128 IS_CHANNEL_13(CHANNEL) || \ 129 IS_CHANNEL_14(CHANNEL) || \ 130 IS_CHANNEL_15(CHANNEL)) 131 132 133 /* Definitions of EXTI init structure */ 134 typedef enum 135 { 136 EXTI_LOW_LEVEL = 0x0, 137 EXTI_HIGH_LEVEL = 0x1, 138 EXTI_NEGATIVE_EDGE = 0x2, 139 EXTI_POSITIVE_EDGE = 0x3, 140 EXTI_BOTH_EDGE = 0x4 141 } EXTI_Interrupt_TypeDef; 142 143 #define IS_EXTI_INT_TYPE(TYPE) ((TYPE == EXTI_LOW_LEVEL) || \ 144 (TYPE == EXTI_HIGH_LEVEL) || \ 145 (TYPE == EXTI_NEGATIVE_EDGE) || \ 146 (TYPE == EXTI_POSITIVE_EDGE) || \ 147 (TYPE == EXTI_BOTH_EDGE)) 148 149 typedef enum 150 { 151 EXTI_DEBOUNCE_DISABLE = 0x0, 152 EXTI_DEBOUNCE_ENABLE = 0x1 153 } EXTI_Deb_TypeDef; 154 155 #define IS_EXTI_DEBOUNCE_TYPE(TYPE) ((TYPE == EXTI_DEBOUNCE_DISABLE) || \ 156 (TYPE == EXTI_DEBOUNCE_ENABLE)) 157 158 #if (LIBCFG_EXTI_DEBCNTPRE) 159 typedef enum 160 { 161 EXTI_DBCNTPRE_DIV1 = 0, 162 EXTI_DBCNTPRE_DIV2, 163 EXTI_DBCNTPRE_DIV4, 164 EXTI_DBCNTPRE_DIV8, 165 EXTI_DBCNTPRE_DIV16, 166 EXTI_DBCNTPRE_DIV32, 167 EXTI_DBCNTPRE_DIV64, 168 EXTI_DBCNTPRE_DIV128, 169 } EXTI_DebCntPre_TypeDef; 170 171 #define IS_EXTI_DEBOUNCE_COUNTER_PRESCALER(TYPE) ((TYPE == EXTI_DBCNTPRE_DIV1) || \ 172 (TYPE == EXTI_DBCNTPRE_DIV2) || \ 173 (TYPE == EXTI_DBCNTPRE_DIV4) || \ 174 (TYPE == EXTI_DBCNTPRE_DIV8) || \ 175 (TYPE == EXTI_DBCNTPRE_DIV16) || \ 176 (TYPE == EXTI_DBCNTPRE_DIV32) || \ 177 (TYPE == EXTI_DBCNTPRE_DIV64) || \ 178 (TYPE == EXTI_DBCNTPRE_DIV128)) 179 #endif 180 181 typedef struct 182 { 183 u32 EXTI_Channel; 184 EXTI_Deb_TypeDef EXTI_Debounce; 185 #if (LIBCFG_EXTI_8BIT_DEBOUNCE_COUNTER) 186 u8 EXTI_DebounceCnt; 187 #else 188 u16 EXTI_DebounceCnt; 189 #endif 190 EXTI_Interrupt_TypeDef EXTI_IntType; 191 } EXTI_InitTypeDef; 192 /** 193 * @} 194 */ 195 196 /* Exported constants --------------------------------------------------------------------------------------*/ 197 /** @defgroup EXTI_Exported_Constants EXTI exported constants 198 * @{ 199 */ 200 201 /* Definitions of EXTI wake up polarity */ 202 #define EXTI_WAKEUP_HIGH_LEVEL ((u8)0x0) 203 #define EXTI_WAKEUP_LOW_LEVEL ((u8)0x1) 204 205 #define IS_EXTI_WAKEUP_TYPE(TYPE) ((TYPE == EXTI_WAKEUP_HIGH_LEVEL) || \ 206 (TYPE == EXTI_WAKEUP_LOW_LEVEL)) 207 208 209 #define EXTI_EDGE_POSITIVE ((u8)0x0) 210 #define EXTI_EDGE_NEGATIVE ((u8)0x1) 211 212 #define IS_EXTI_EDGE(EDGE) ((EDGE == EXTI_EDGE_POSITIVE) || \ 213 (EDGE == EXTI_EDGE_NEGATIVE)) 214 215 #if (LIBCFG_EXTI_8BIT_DEBOUNCE_COUNTER) 216 #define IS_EXTI_DEBOUNCE_SIZE(SIZE) (SIZE <= 0xFF) 217 #else 218 #define IS_EXTI_DEBOUNCE_SIZE(SIZE) (SIZE <= 0xFFFF) 219 #endif 220 221 extern const IRQn_Type gEXTIn_IRQn[16]; 222 223 /** 224 * @} 225 */ 226 227 /* Exported functions --------------------------------------------------------------------------------------*/ 228 /** @defgroup EXTI_Exported_Functions EXTI exported functions 229 * @{ 230 */ 231 void EXTI_DeInit(u32 EXTI_Channel); 232 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 233 void EXTI_IntConfig(u32 EXTI_Channel, ControlStatus NewState); 234 #if (LIBCFG_EXTI_DEBCNTPRE) 235 void EXTI_SetDebounceCounterPrescaler(EXTI_DebCntPre_TypeDef EXTI_DBCNTPRE_DIVn); 236 #endif 237 void EXTI_WakeupEventConfig(u32 EXTI_Channel, u8 EXTI_WakeUpType, ControlStatus NewState); 238 void EXTI_WakeupEventIntConfig(ControlStatus NewState); 239 void EXTI_ClearEdgeFlag(u32 EXTI_Channel); 240 void EXTI_ClearWakeupFlag(u32 EXTI_Channel); 241 FlagStatus EXTI_GetEdgeFlag(u32 EXTI_Channel); 242 FlagStatus EXTI_GetEdgeStatus(u32 EXTI_Channel, u32 EXTI_Edge); 243 FlagStatus EXTI_GetWakeupFlagStatus(u32 EXTI_Channel); 244 void EXTI_SWIntCmd(u32 EXTI_Channel, ControlStatus NewState); 245 FlagStatus EXTI_GetSWCmdStatus(u32 EXTI_Channel); 246 /** 247 * @} 248 */ 249 250 251 /** 252 * @} 253 */ 254 255 /** 256 * @} 257 */ 258 259 #ifdef __cplusplus 260 } 261 #endif 262 263 #endif 264