1 /*! 2 * @file apm32e10x_gpio.h 3 * 4 * @brief This file contains all the functions prototypes for the GPIO firmware library 5 * 6 * @version V1.0.2 7 * 8 * @date 2022-12-31 9 * 10 * @attention 11 * 12 * Copyright (C) 2021-2023 Geehy Semiconductor 13 * 14 * You may not use this file except in compliance with the 15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE). 16 * 17 * The program is only for reference, which is distributed in the hope 18 * that it will be useful and instructional for customers to develop 19 * their software. Unless required by applicable law or agreed to in 20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT 21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions 23 * and limitations under the License. 24 */ 25 26 /* Define to prevent recursive inclusion */ 27 #ifndef __APM32E10X_GPIO_H 28 #define __APM32E10X_GPIO_H 29 30 /* Includes */ 31 #include "apm32e10x.h" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /** @addtogroup APM32E10x_StdPeriphDriver 38 @{ 39 */ 40 41 /** @addtogroup GPIO_Driver 42 @{ 43 */ 44 45 /** @defgroup GPIO_Enumerations Enumerations 46 @{ 47 */ 48 49 /** 50 * @brief GPIO Output Maximum frequency selection 51 */ 52 typedef enum 53 { 54 GPIO_SPEED_10MHz = 1, 55 GPIO_SPEED_2MHz, 56 GPIO_SPEED_50MHz 57 }GPIO_SPEED_T; 58 59 /** 60 * @brief Configuration Mode enumeration 61 */ 62 typedef enum 63 { 64 GPIO_MODE_ANALOG = 0x0, /*!< Analog mode */ 65 GPIO_MODE_IN_FLOATING = 0x04, /*!< Floating input */ 66 GPIO_MODE_IN_PD = 0x28, /*!< Input with pull-down */ 67 GPIO_MODE_IN_PU = 0x48, /*!< Input with pull-up */ 68 GPIO_MODE_OUT_PP = 0x80, /*!< General purpose output push-pull */ 69 GPIO_MODE_OUT_OD = 0x84, /*!< General purpose output Open-drain */ 70 GPIO_MODE_AF_PP = 0x88, /*!< Alternate function output Push-pull */ 71 GPIO_MODE_AF_OD = 0x8C, /*!< Alternate function output Open-drain */ 72 }GPIO_MODE_T; 73 74 /** 75 * @brief Definition of the GPIO pins 76 */ 77 typedef enum 78 { 79 GPIO_PIN_0 = ((uint16_t)BIT0), 80 GPIO_PIN_1 = ((uint16_t)BIT1), 81 GPIO_PIN_2 = ((uint16_t)BIT2), 82 GPIO_PIN_3 = ((uint16_t)BIT3), 83 GPIO_PIN_4 = ((uint16_t)BIT4), 84 GPIO_PIN_5 = ((uint16_t)BIT5), 85 GPIO_PIN_6 = ((uint16_t)BIT6), 86 GPIO_PIN_7 = ((uint16_t)BIT7), 87 GPIO_PIN_8 = ((uint16_t)BIT8), 88 GPIO_PIN_9 = ((uint16_t)BIT9), 89 GPIO_PIN_10 = ((uint16_t)BIT10), 90 GPIO_PIN_11 = ((uint16_t)BIT11), 91 GPIO_PIN_12 = ((uint16_t)BIT12), 92 GPIO_PIN_13 = ((uint16_t)BIT13), 93 GPIO_PIN_14 = ((uint16_t)BIT14), 94 GPIO_PIN_15 = ((uint16_t)BIT15), 95 GPIO_PIN_ALL = ((uint32_t)0XFFFF) 96 } GPIO_PIN_T; 97 98 /** 99 * @brief GPIO remap type define 100 */ 101 typedef enum 102 { 103 GPIO_NO_REMAP_SPI1 = 0x00000010, 104 GPIO_REMAP_SPI1 = 0x00000011, 105 106 GPIO_NO_REMAP_I2C1 = 0x00000110, 107 GPIO_REMAP_I2C1 = 0x00000111, 108 109 GPIO_NO_REMAP_USART1 = 0x00000210, 110 GPIO_REMAP_USART1 = 0x00000211, 111 112 GPIO_NO_REMAP_USART2 = 0x00000310, 113 GPIO_REMAP_USART2 = 0x00000311, 114 115 GPIO_NO_REMAP_USART3 = 0x00000430, 116 GPIO_PARTIAL_REMAP_USART3 = 0x00000431, 117 GPIO_FULL_REMAP_USART3 = 0x00000433, 118 119 GPIO_NO_REMAP_TMR1 = 0x00000630, 120 GPIO_PARTIAL_REMAP_TMR1 = 0x00000631, 121 GPIO_FULL_REMAP_TMR1 = 0x00000633, 122 123 GPIO_NO_REMAP_TMR2 = 0x00000830, 124 GPIO_PARTIAL_REMAP1_TMR2 = 0x00000831, 125 GPIO_PARTIAL_REMAP2_TMR2 = 0x00000832, 126 GPIO_FULL_REMAP_TMR2 = 0x00000833, 127 128 GPIO_NO_REMAP_TMR3 = 0x00000A30, 129 GPIO_PARTIAL_REMAP_TMR3 = 0x00000A32, 130 GPIO_FULL_REMAP_TMR3 = 0x00000A33, 131 132 GPIO_NO_REMAP_TMR4 = 0x00000C10, 133 GPIO_REMAP_TMR4 = 0x00000C11, 134 135 GPIO_NO_REMAP_CAN1 = 0x00000D30, 136 GPIO_REMAP1_CAN1 = 0x00000D32, 137 GPIO_REMAP2_CAN1 = 0x00000D33, 138 139 GPIO_NO_REMAP_PD01 = 0x00000F10, 140 GPIO_REMAP_PD01 = 0x00000F11, 141 142 GPIO_NO_REMAP_TMR5CH4_LSI = 0x00001010, 143 GPIO_REMAP_TMR5CH4_LSI = 0x00001011, 144 145 GPIO_NO_REMAP_ADC1_ETRGINJ = 0x00001110, 146 GPIO_REMAP_ADC1_ETRGINJ = 0x00001111, 147 148 GPIO_NO_REMAP_ADC1_ETRGREG = 0x00001210, 149 GPIO_REMAP_ADC1_ETRGREG = 0x00001211, 150 151 GPIO_NO_REMAP_ADC2_ETRGINJ = 0x00001310, 152 GPIO_REMAP_ADC2_ETRGINJ = 0x00001311, 153 154 GPIO_NO_REMAP_ADC2_ETRGREG = 0x00001410, 155 GPIO_REMAP_ADC2_ETRGREG = 0x00001411, 156 157 GPIO_NO_REMAP_CAN2 = 0x00001610, 158 GPIO_REMAP_CAN2 = 0x00001611, 159 160 GPIO_NO_REMAP_SWJ = 0x00001870, 161 GPIO_REMAP_SWJ_NOJTRST = 0x00001871, 162 GPIO_REMAP_SWJ_JTAGDISABLE = 0x00001872, 163 GPIO_REMAP_SWJ_DISABLE = 0x00001874, 164 165 GPIO_NO_REMAP_EMMC_NADV = 0x00010A10, 166 GPIO_REMAP_EMMC_NADV = 0x00010A11 167 }GPIO_REMAP_T; 168 169 /** 170 * @brief gpio port source define 171 */ 172 typedef enum 173 { 174 GPIO_PORT_SOURCE_A, 175 GPIO_PORT_SOURCE_B, 176 GPIO_PORT_SOURCE_C, 177 GPIO_PORT_SOURCE_D, 178 GPIO_PORT_SOURCE_E, 179 GPIO_PORT_SOURCE_F, 180 GPIO_PORT_SOURCE_G 181 }GPIO_PORT_SOURCE_T; 182 183 /** 184 * @brief gpio pin source define 185 */ 186 typedef enum 187 { 188 GPIO_PIN_SOURCE_0, 189 GPIO_PIN_SOURCE_1, 190 GPIO_PIN_SOURCE_2, 191 GPIO_PIN_SOURCE_3, 192 GPIO_PIN_SOURCE_4, 193 GPIO_PIN_SOURCE_5, 194 GPIO_PIN_SOURCE_6, 195 GPIO_PIN_SOURCE_7, 196 GPIO_PIN_SOURCE_8, 197 GPIO_PIN_SOURCE_9, 198 GPIO_PIN_SOURCE_10, 199 GPIO_PIN_SOURCE_11, 200 GPIO_PIN_SOURCE_12, 201 GPIO_PIN_SOURCE_13, 202 GPIO_PIN_SOURCE_14, 203 GPIO_PIN_SOURCE_15 204 }GPIO_PIN_SOURCE_T; 205 206 /**@} end of group GPIO_Enumerations */ 207 208 209 /** @defgroup GPIO_Structures Structures 210 @{ 211 */ 212 213 /** 214 * @brief GPIO Config structure definition 215 */ 216 typedef struct 217 { 218 uint16_t pin; 219 GPIO_SPEED_T speed; 220 GPIO_MODE_T mode; 221 }GPIO_Config_T; 222 223 /**@} end of group GPIO_Structures */ 224 225 /** @defgroup GPIO_Functions Functions 226 @{ 227 */ 228 229 /* Reset and common Configuration */ 230 void GPIO_Reset(GPIO_T* port); 231 void GPIO_AFIOReset(void); 232 void GPIO_Config(GPIO_T* port, GPIO_Config_T* gpioConfig); 233 void GPIO_ConfigStructInit(GPIO_Config_T* gpioConfig); 234 235 /* Read */ 236 uint8_t GPIO_ReadInputBit(GPIO_T* port, uint16_t pin); 237 uint16_t GPIO_ReadInputPort(GPIO_T* port); 238 uint8_t GPIO_ReadOutputBit(GPIO_T* port, uint16_t pin); 239 uint16_t GPIO_ReadOutputPort(GPIO_T* port); 240 241 /* Write */ 242 void GPIO_SetBit(GPIO_T* port, uint16_t pin); 243 void GPIO_ResetBit(GPIO_T* port, uint16_t pin); 244 void GPIO_WriteOutputPort(GPIO_T* port, uint16_t portValue); 245 void GPIO_WriteBitValue(GPIO_T* port, uint16_t pin, uint8_t bitVal); 246 247 /* GPIO Configuration */ 248 void GPIO_ConfigPinLock(GPIO_T* port, uint16_t pin); 249 void GPIO_ConfigEventOutput(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource); 250 void GPIO_EnableEventOutput(void); 251 void GPIO_DisableEventOutput(void); 252 void GPIO_ConfigPinRemap(GPIO_REMAP_T remap); 253 void GPIO_ConfigEINTLine(GPIO_PORT_SOURCE_T portSource, GPIO_PIN_SOURCE_T pinSource); 254 255 /**@} end of group GPIO_Functions */ 256 /**@} end of group GPIO_Driver */ 257 /**@} end of group APM32E10x_StdPeriphDriver*/ 258 259 #ifdef __cplusplus 260 } 261 #endif 262 263 #endif /* __APM32E10X_GPIO_H */ 264