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