1 /*! 2 * @file apm32f0xx_eint.c 3 * 4 * @brief This file contains all the functions for the EINT peripheral 5 * 6 * @version V1.0.3 7 * 8 * @date 2022-09-20 9 * 10 * @attention 11 * 12 * Copyright (C) 2020-2022 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 /* Includes */ 27 #include "apm32f0xx_eint.h" 28 29 /** @addtogroup APM32F0xx_StdPeriphDriver 30 @{ 31 */ 32 33 /** @addtogroup EINT_Driver 34 @{ 35 */ 36 37 /** @defgroup EINT_Macros Macros 38 @{ 39 */ 40 41 /**@} end of group EINT_Macros */ 42 43 /** @defgroup EINT_Enumerates Enumerates 44 @{ 45 */ 46 47 /**@} end of group EINT_Enumerates */ 48 49 /** @defgroup EINT_Structures Structures 50 @{ 51 */ 52 53 /**@} end of group EINT_Structures */ 54 55 /** @defgroup EINT_Variables Variables 56 @{ 57 */ 58 59 /**@} end of group EINT_Variables */ 60 61 /** @defgroup EINT_Functions Functions 62 @{ 63 */ 64 65 /*! 66 * @brief Set the EINT peripheral registers to their default reset values 67 * 68 * @param None 69 * 70 * @retval None 71 */ EINT_Reset(void)72void EINT_Reset(void) 73 { 74 EINT->IMASK = EINT_INTMASK_RESET_VALUE; 75 EINT->EMASK = EINT_EVTMASK_RESET_VALUE; 76 EINT->RTEN = EINT_RTSEL_RESET_VALUE; 77 EINT->FTEN = EINT_FTSEL_RESET_VALUE; 78 EINT->IPEND = EINT_PEND_RESET_VALUE; 79 } 80 81 /*! 82 * @brief Configure the EINT 83 * 84 * @param eintConfig: Pointer to EINT_Config_T structure 85 * 86 * @retval None 87 */ EINT_Config(EINT_Config_T * eintConfig)88void EINT_Config(EINT_Config_T* eintConfig) 89 { 90 if (eintConfig->lineCmd == DISABLE) 91 { 92 if (eintConfig->mode == EINT_MODE_INTERRUPT) 93 { 94 EINT->IMASK &= ~eintConfig->line; 95 } 96 else if (eintConfig->mode == EINT_MODE_EVENT) 97 { 98 EINT->EMASK &= ~eintConfig->line; 99 } 100 } 101 else 102 { 103 if (eintConfig->mode == EINT_MODE_INTERRUPT) 104 { 105 EINT->IMASK |= eintConfig->line; 106 } 107 else if (eintConfig->mode == EINT_MODE_EVENT) 108 { 109 EINT->EMASK |= eintConfig->line; 110 } 111 112 if (eintConfig->trigger == EINT_TRIGGER_RISING) 113 { 114 EINT->RTEN |= eintConfig->line; 115 } 116 else if (eintConfig->trigger == EINT_TRIGGER_FALLING) 117 { 118 EINT->FTEN |= eintConfig->line; 119 } 120 else 121 { 122 EINT->RTEN |= eintConfig->line; 123 EINT->FTEN |= eintConfig->line; 124 } 125 126 } 127 } 128 129 /*! 130 * @brief Fills each EINT_Config_T member with its default value 131 * 132 * @param eintConfig: Pointer to a EINT_Config_T structure which will be initialized 133 * 134 * @retval None 135 */ EINT_ConfigStructInit(EINT_Config_T * eintConfig)136void EINT_ConfigStructInit(EINT_Config_T* eintConfig) 137 { 138 eintConfig->line = EINT_LINENONE; 139 eintConfig->mode = EINT_MODE_INTERRUPT; 140 eintConfig->trigger = EINT_TRIGGER_FALLING; 141 eintConfig->lineCmd = DISABLE; 142 } 143 144 /*! 145 * @brief Select software interrupt on EINT line 146 * 147 * @param line: specifies the EINT line on which the software interrupt 148 * 149 * @retval None 150 */ EINT_SelectSWInterrupt(uint32_t line)151void EINT_SelectSWInterrupt(uint32_t line) 152 { 153 EINT->SWINTE |= (uint32_t)line; 154 } 155 156 /*! 157 * @brief Read the specified EINT line flag 158 * 159 * @param line: Select the EINT line 160 * 161 * @retval status: The new state of flag (SET or RESET) 162 */ EINT_ReadStatusFlag(uint32_t line)163uint8_t EINT_ReadStatusFlag(uint32_t line) 164 { 165 uint8_t status = RESET; 166 167 if ((EINT->IPEND & line) != (uint32_t)RESET) 168 { 169 status = SET; 170 } 171 else 172 { 173 status = RESET; 174 } 175 176 return status; 177 } 178 179 /*! 180 * @brief Clears the EINT line pending bits 181 * 182 * @param line: Select the EINT line 183 * 184 * @retval None 185 */ EINT_ClearStatusFlag(uint32_t line)186void EINT_ClearStatusFlag(uint32_t line) 187 { 188 EINT->IPEND = line; 189 } 190 191 /*! 192 * @brief Read the specified EINT line interrupt flag 193 * 194 * @param line: Select the EINT line 195 * 196 * @retval None 197 */ EINT_ReadIntFlag(uint32_t line)198uint8_t EINT_ReadIntFlag(uint32_t line) 199 { 200 uint8_t status = RESET; 201 uint32_t enablestatus = 0; 202 203 enablestatus = EINT->IMASK & line; 204 205 if ((EINT->IPEND & line) != ((uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 206 { 207 status = SET; 208 } 209 else 210 { 211 status = RESET; 212 } 213 214 return status; 215 } 216 217 /*! 218 * @brief Clears the EINT line pending bits 219 * 220 * @param line: Select the EINT line 221 * 222 * @retval None 223 */ EINT_ClearIntFlag(uint32_t line)224void EINT_ClearIntFlag(uint32_t line) 225 { 226 EINT->IPEND = line; 227 } 228 229 /**@} end of group EINT_Functions */ 230 /**@} end of group EINT_Driver */ 231 /**@} end of group APM32F0xx_StdPeriphDriver */ 232