| 1 | /**
|
|---|
| 2 | ******************************************************************************
|
|---|
| 3 | * @file stm32g0xx_ll_exti.c
|
|---|
| 4 | * @author MCD Application Team
|
|---|
| 5 | * @brief EXTI LL module driver.
|
|---|
| 6 | ******************************************************************************
|
|---|
| 7 | * @attention
|
|---|
| 8 | *
|
|---|
| 9 | * <h2><center>© Copyright (c) 2018 STMicroelectronics.
|
|---|
| 10 | * All rights reserved.</center></h2>
|
|---|
| 11 | *
|
|---|
| 12 | * This software component is licensed by ST under BSD 3-Clause license,
|
|---|
| 13 | * the "License"; You may not use this file except in compliance with the
|
|---|
| 14 | * License. You may obtain a copy of the License at:
|
|---|
| 15 | * opensource.org/licenses/BSD-3-Clause
|
|---|
| 16 | *
|
|---|
| 17 | ******************************************************************************
|
|---|
| 18 | */
|
|---|
| 19 | #if defined(USE_FULL_LL_DRIVER)
|
|---|
| 20 |
|
|---|
| 21 | /* Includes ------------------------------------------------------------------*/
|
|---|
| 22 | #include "stm32g0xx_ll_exti.h"
|
|---|
| 23 | #ifdef USE_FULL_ASSERT
|
|---|
| 24 | #include "stm32_assert.h"
|
|---|
| 25 | #else
|
|---|
| 26 | #define assert_param(expr) ((void)0U)
|
|---|
| 27 | #endif
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup STM32G0xx_LL_Driver
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | #if defined (EXTI)
|
|---|
| 34 |
|
|---|
| 35 | /** @defgroup EXTI_LL EXTI
|
|---|
| 36 | * @{
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | /* Private types -------------------------------------------------------------*/
|
|---|
| 40 | /* Private variables ---------------------------------------------------------*/
|
|---|
| 41 | /* Private constants ---------------------------------------------------------*/
|
|---|
| 42 | /* Private macros ------------------------------------------------------------*/
|
|---|
| 43 | /** @addtogroup EXTI_LL_Private_Macros
|
|---|
| 44 | * @{
|
|---|
| 45 | */
|
|---|
| 46 |
|
|---|
| 47 | #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
|
|---|
| 48 | #if defined(STM32G081xx) || defined(STM32G071xx)
|
|---|
| 49 | #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
|
|---|
| 50 | #endif
|
|---|
| 51 | #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
|
|---|
| 52 | || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
|
|---|
| 53 | || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
|
|---|
| 57 | || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
|
|---|
| 58 | || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
|
|---|
| 59 | || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * @}
|
|---|
| 63 | */
|
|---|
| 64 |
|
|---|
| 65 | /* Private function prototypes -----------------------------------------------*/
|
|---|
| 66 |
|
|---|
| 67 | /* Exported functions --------------------------------------------------------*/
|
|---|
| 68 | /** @addtogroup EXTI_LL_Exported_Functions
|
|---|
| 69 | * @{
|
|---|
| 70 | */
|
|---|
| 71 |
|
|---|
| 72 | /** @addtogroup EXTI_LL_EF_Init
|
|---|
| 73 | * @{
|
|---|
| 74 | */
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * @brief De-initialize the EXTI registers to their default reset values.
|
|---|
| 78 | * @retval An ErrorStatus enumeration value:
|
|---|
| 79 | * - 0x00: EXTI registers are de-initialized
|
|---|
| 80 | */
|
|---|
| 81 | uint32_t LL_EXTI_DeInit(void)
|
|---|
| 82 | {
|
|---|
| 83 | /* Interrupt mask register set to default reset values */
|
|---|
| 84 | LL_EXTI_WriteReg(IMR1, 0xFFF80000U);
|
|---|
| 85 | /* Event mask register set to default reset values */
|
|---|
| 86 | LL_EXTI_WriteReg(EMR1, 0x00000000U);
|
|---|
| 87 | /* Rising Trigger selection register set to default reset values */
|
|---|
| 88 | LL_EXTI_WriteReg(RTSR1, 0x00000000U);
|
|---|
| 89 | /* Falling Trigger selection register set to default reset values */
|
|---|
| 90 | LL_EXTI_WriteReg(FTSR1, 0x00000000U);
|
|---|
| 91 | /* Software interrupt event register set to default reset values */
|
|---|
| 92 | LL_EXTI_WriteReg(SWIER1, 0x00000000U);
|
|---|
| 93 | /* Pending register set to default reset values */
|
|---|
| 94 | LL_EXTI_WriteReg(RPR1, 0x0007FFFFU);
|
|---|
| 95 | LL_EXTI_WriteReg(FPR1, 0x0007FFFFU);
|
|---|
| 96 |
|
|---|
| 97 | #if defined(STM32G081xx) || defined(STM32G071xx)
|
|---|
| 98 | /* Interrupt mask register 2 set to default reset values */
|
|---|
| 99 | LL_EXTI_WriteReg(IMR2, 0x00000003U);
|
|---|
| 100 | /* Event mask register 2 set to default reset values */
|
|---|
| 101 | LL_EXTI_WriteReg(EMR2, 0x00000000U);
|
|---|
| 102 | #endif
|
|---|
| 103 |
|
|---|
| 104 | return 0x00u;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
|
|---|
| 109 | * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
|
|---|
| 110 | * @retval An ErrorStatus enumeration value:
|
|---|
| 111 | * - 0x00: EXTI registers are initialized
|
|---|
| 112 | * - any other calue : wrong configuration
|
|---|
| 113 | */
|
|---|
| 114 | uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
|
|---|
| 115 | {
|
|---|
| 116 | uint32_t status = 0x00u;
|
|---|
| 117 |
|
|---|
| 118 | /* Check the parameters */
|
|---|
| 119 | assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
|
|---|
| 120 | #if defined(STM32G081xx) || defined(STM32G071xx)
|
|---|
| 121 | assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
|
|---|
| 122 | #endif
|
|---|
| 123 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
|
|---|
| 124 | assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
|
|---|
| 125 |
|
|---|
| 126 | /* ENABLE LineCommand */
|
|---|
| 127 | if (EXTI_InitStruct->LineCommand != DISABLE)
|
|---|
| 128 | {
|
|---|
| 129 | assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
|
|---|
| 130 |
|
|---|
| 131 | /* Configure EXTI Lines in range from 0 to 31 */
|
|---|
| 132 | if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
|
|---|
| 133 | {
|
|---|
| 134 | switch (EXTI_InitStruct->Mode)
|
|---|
| 135 | {
|
|---|
| 136 | case LL_EXTI_MODE_IT:
|
|---|
| 137 | /* First Disable Event on provided Lines */
|
|---|
| 138 | LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 139 | /* Then Enable IT on provided Lines */
|
|---|
| 140 | LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 141 | break;
|
|---|
| 142 | case LL_EXTI_MODE_EVENT:
|
|---|
| 143 | /* First Disable IT on provided Lines */
|
|---|
| 144 | LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 145 | /* Then Enable Event on provided Lines */
|
|---|
| 146 | LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 147 | break;
|
|---|
| 148 | case LL_EXTI_MODE_IT_EVENT:
|
|---|
| 149 | /* Directly Enable IT & Event on provided Lines */
|
|---|
| 150 | LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 151 | LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 152 | break;
|
|---|
| 153 | default:
|
|---|
| 154 | status = 0x01u;
|
|---|
| 155 | break;
|
|---|
| 156 | }
|
|---|
| 157 | if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
|
|---|
| 158 | {
|
|---|
| 159 | switch (EXTI_InitStruct->Trigger)
|
|---|
| 160 | {
|
|---|
| 161 | case LL_EXTI_TRIGGER_RISING:
|
|---|
| 162 | /* First Disable Falling Trigger on provided Lines */
|
|---|
| 163 | LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 164 | /* Then Enable Rising Trigger on provided Lines */
|
|---|
| 165 | LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 166 | break;
|
|---|
| 167 | case LL_EXTI_TRIGGER_FALLING:
|
|---|
| 168 | /* First Disable Rising Trigger on provided Lines */
|
|---|
| 169 | LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 170 | /* Then Enable Falling Trigger on provided Lines */
|
|---|
| 171 | LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 172 | break;
|
|---|
| 173 | case LL_EXTI_TRIGGER_RISING_FALLING:
|
|---|
| 174 | LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 175 | LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 176 | break;
|
|---|
| 177 | default:
|
|---|
| 178 | status |= 0x02u;
|
|---|
| 179 | break;
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 | #if defined(STM32G081xx) || defined(STM32G071xx)
|
|---|
| 184 | /* Configure EXTI Lines in range from 32 to 63 */
|
|---|
| 185 | if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
|
|---|
| 186 | {
|
|---|
| 187 | switch (EXTI_InitStruct->Mode)
|
|---|
| 188 | {
|
|---|
| 189 | case LL_EXTI_MODE_IT:
|
|---|
| 190 | /* First Disable Event on provided Lines */
|
|---|
| 191 | LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 192 | /* Then Enable IT on provided Lines */
|
|---|
| 193 | LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 194 | break;
|
|---|
| 195 | case LL_EXTI_MODE_EVENT:
|
|---|
| 196 | /* First Disable IT on provided Lines */
|
|---|
| 197 | LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 198 | /* Then Enable Event on provided Lines */
|
|---|
| 199 | LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 200 | break;
|
|---|
| 201 | case LL_EXTI_MODE_IT_EVENT:
|
|---|
| 202 | /* Directly Enable IT & Event on provided Lines */
|
|---|
| 203 | LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 204 | LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 205 | break;
|
|---|
| 206 | default:
|
|---|
| 207 | status |= 0x04u;
|
|---|
| 208 | break;
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|
| 211 | #endif
|
|---|
| 212 | }
|
|---|
| 213 | /* DISABLE LineCommand */
|
|---|
| 214 | else
|
|---|
| 215 | {
|
|---|
| 216 | /* De-configure EXTI Lines in range from 0 to 31 */
|
|---|
| 217 | LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 218 | LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
|
|---|
| 219 | #if defined(STM32G081xx) || defined(STM32G071xx)
|
|---|
| 220 | /* De-configure EXTI Lines in range from 32 to 63 */
|
|---|
| 221 | LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 222 | LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
|
|---|
| 223 | #endif
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | return status;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
|
|---|
| 231 | * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
|
|---|
| 232 | * @retval None
|
|---|
| 233 | */
|
|---|
| 234 | void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
|
|---|
| 235 | {
|
|---|
| 236 | EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
|
|---|
| 237 | #if defined(STM32G081xx) || defined(STM32G071xx)
|
|---|
| 238 | EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
|
|---|
| 239 | #endif
|
|---|
| 240 | EXTI_InitStruct->LineCommand = DISABLE;
|
|---|
| 241 | EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
|
|---|
| 242 | EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | /**
|
|---|
| 246 | * @}
|
|---|
| 247 | */
|
|---|
| 248 |
|
|---|
| 249 | /**
|
|---|
| 250 | * @}
|
|---|
| 251 | */
|
|---|
| 252 |
|
|---|
| 253 | /**
|
|---|
| 254 | * @}
|
|---|
| 255 | */
|
|---|
| 256 |
|
|---|
| 257 | #endif /* defined (EXTI) */
|
|---|
| 258 |
|
|---|
| 259 | /**
|
|---|
| 260 | * @}
|
|---|
| 261 | */
|
|---|
| 262 |
|
|---|
| 263 | #endif /* USE_FULL_LL_DRIVER */
|
|---|
| 264 |
|
|---|
| 265 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|---|