STM32F479xx HAL User Manual
stm32f4xx_ll_exti.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_ll_exti.c
00004   * @author  MCD Application Team
00005   * @brief   EXTI LL module driver.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 #if defined(USE_FULL_LL_DRIVER)
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f4xx_ll_exti.h"
00023 #ifdef  USE_FULL_ASSERT
00024 #include "stm32_assert.h"
00025 #else
00026 #define assert_param(expr) ((void)0U)
00027 #endif
00028 
00029 /** @addtogroup STM32F4xx_LL_Driver
00030   * @{
00031   */
00032 
00033 #if defined (EXTI)
00034 
00035 /** @defgroup EXTI_LL EXTI
00036   * @{
00037   */
00038 
00039 /* Private types -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 /* Private constants ---------------------------------------------------------*/
00042 /* Private macros ------------------------------------------------------------*/
00043 /** @addtogroup EXTI_LL_Private_Macros
00044   * @{
00045   */
00046 
00047 #define IS_LL_EXTI_LINE_0_31(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
00048 
00049 #define IS_LL_EXTI_MODE(__VALUE__)                   (((__VALUE__) == LL_EXTI_MODE_IT)            \
00050                                                    || ((__VALUE__) == LL_EXTI_MODE_EVENT)         \
00051                                                    || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
00052 
00053 
00054 #define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_NONE)       \
00055                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING)     \
00056                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING)    \
00057                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
00058 
00059 /**
00060   * @}
00061   */
00062 
00063 /* Private function prototypes -----------------------------------------------*/
00064 
00065 /* Exported functions --------------------------------------------------------*/
00066 /** @addtogroup EXTI_LL_Exported_Functions
00067   * @{
00068   */
00069 
00070 /** @addtogroup EXTI_LL_EF_Init
00071   * @{
00072   */
00073 
00074 /**
00075   * @brief  De-initialize the EXTI registers to their default reset values.
00076   * @retval An ErrorStatus enumeration value:
00077   *          - SUCCESS: EXTI registers are de-initialized
00078   *          - ERROR: not applicable
00079   */
00080 uint32_t LL_EXTI_DeInit(void)
00081 {
00082   /* Interrupt mask register set to default reset values */
00083   LL_EXTI_WriteReg(IMR,   0x00000000U);
00084   /* Event mask register set to default reset values */
00085   LL_EXTI_WriteReg(EMR,   0x00000000U);
00086   /* Rising Trigger selection register set to default reset values */
00087   LL_EXTI_WriteReg(RTSR,  0x00000000U);
00088   /* Falling Trigger selection register set to default reset values */
00089   LL_EXTI_WriteReg(FTSR,  0x00000000U);
00090   /* Software interrupt event register set to default reset values */
00091   LL_EXTI_WriteReg(SWIER, 0x00000000U);
00092   /* Pending register set to default reset values */
00093   LL_EXTI_WriteReg(PR,    0x00FFFFFFU);
00094 
00095   return SUCCESS;
00096 }
00097 
00098 /**
00099   * @brief  Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
00100   * @param  EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
00101   * @retval An ErrorStatus enumeration value:
00102   *          - SUCCESS: EXTI registers are initialized
00103   *          - ERROR: not applicable
00104   */
00105 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
00106 {
00107   ErrorStatus status = SUCCESS;
00108   /* Check the parameters */
00109   assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
00110   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
00111   assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
00112 
00113   /* ENABLE LineCommand */
00114   if (EXTI_InitStruct->LineCommand != DISABLE)
00115   {
00116     assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
00117 
00118     /* Configure EXTI Lines in range from 0 to 31 */
00119     if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
00120     {
00121       switch (EXTI_InitStruct->Mode)
00122       {
00123         case LL_EXTI_MODE_IT:
00124           /* First Disable Event on provided Lines */
00125           LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
00126           /* Then Enable IT on provided Lines */
00127           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
00128           break;
00129         case LL_EXTI_MODE_EVENT:
00130           /* First Disable IT on provided Lines */
00131           LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
00132           /* Then Enable Event on provided Lines */
00133           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
00134           break;
00135         case LL_EXTI_MODE_IT_EVENT:
00136           /* Directly Enable IT & Event on provided Lines */
00137           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
00138           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
00139           break;
00140         default:
00141           status = ERROR;
00142           break;
00143       }
00144       if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
00145       {
00146         switch (EXTI_InitStruct->Trigger)
00147         {
00148           case LL_EXTI_TRIGGER_RISING:
00149             /* First Disable Falling Trigger on provided Lines */
00150             LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
00151             /* Then Enable Rising Trigger on provided Lines */
00152             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
00153             break;
00154           case LL_EXTI_TRIGGER_FALLING:
00155             /* First Disable Rising Trigger on provided Lines */
00156             LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
00157             /* Then Enable Falling Trigger on provided Lines */
00158             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
00159             break;
00160           case LL_EXTI_TRIGGER_RISING_FALLING:
00161             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
00162             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
00163             break;
00164           default:
00165             status = ERROR;
00166             break;
00167         }
00168       }
00169     }
00170   }
00171   /* DISABLE LineCommand */
00172   else
00173   {
00174     /* De-configure EXTI Lines in range from 0 to 31 */
00175     LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
00176     LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
00177   }
00178   return status;
00179 }
00180 
00181 /**
00182   * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
00183   * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
00184   * @retval None
00185   */
00186 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
00187 {
00188   EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
00189   EXTI_InitStruct->LineCommand    = DISABLE;
00190   EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
00191   EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
00192 }
00193 
00194 /**
00195   * @}
00196   */
00197 
00198 /**
00199   * @}
00200   */
00201 
00202 /**
00203   * @}
00204   */
00205 
00206 #endif /* defined (EXTI) */
00207 
00208 /**
00209   * @}
00210   */
00211 
00212 #endif /* USE_FULL_LL_DRIVER */
00213 
00214 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/