STM32F439xx 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) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 #if defined(USE_FULL_LL_DRIVER)
00036 
00037 /* Includes ------------------------------------------------------------------*/
00038 #include "stm32f4xx_ll_exti.h"
00039 #ifdef  USE_FULL_ASSERT
00040 #include "stm32_assert.h"
00041 #else
00042 #define assert_param(expr) ((void)0U)
00043 #endif
00044 
00045 /** @addtogroup STM32F4xx_LL_Driver
00046   * @{
00047   */
00048 
00049 #if defined (EXTI)
00050 
00051 /** @defgroup EXTI_LL EXTI
00052   * @{
00053   */
00054 
00055 /* Private types -------------------------------------------------------------*/
00056 /* Private variables ---------------------------------------------------------*/
00057 /* Private constants ---------------------------------------------------------*/
00058 /* Private macros ------------------------------------------------------------*/
00059 /** @addtogroup EXTI_LL_Private_Macros
00060   * @{
00061   */
00062 
00063 #define IS_LL_EXTI_LINE_0_31(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
00064 
00065 #define IS_LL_EXTI_MODE(__VALUE__)                   (((__VALUE__) == LL_EXTI_MODE_IT)            \
00066                                                    || ((__VALUE__) == LL_EXTI_MODE_EVENT)         \
00067                                                    || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
00068 
00069 
00070 #define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_NONE)       \
00071                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING)     \
00072                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING)    \
00073                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
00074 
00075 /**
00076   * @}
00077   */
00078 
00079 /* Private function prototypes -----------------------------------------------*/
00080 
00081 /* Exported functions --------------------------------------------------------*/
00082 /** @addtogroup EXTI_LL_Exported_Functions
00083   * @{
00084   */
00085 
00086 /** @addtogroup EXTI_LL_EF_Init
00087   * @{
00088   */
00089 
00090 /**
00091   * @brief  De-initialize the EXTI registers to their default reset values.
00092   * @retval An ErrorStatus enumeration value:
00093   *          - SUCCESS: EXTI registers are de-initialized
00094   *          - ERROR: not applicable
00095   */
00096 uint32_t LL_EXTI_DeInit(void)
00097 {
00098   /* Interrupt mask register set to default reset values */
00099   LL_EXTI_WriteReg(IMR,   0x00000000U);
00100   /* Event mask register set to default reset values */
00101   LL_EXTI_WriteReg(EMR,   0x00000000U);
00102   /* Rising Trigger selection register set to default reset values */
00103   LL_EXTI_WriteReg(RTSR,  0x00000000U);
00104   /* Falling Trigger selection register set to default reset values */
00105   LL_EXTI_WriteReg(FTSR,  0x00000000U);
00106   /* Software interrupt event register set to default reset values */
00107   LL_EXTI_WriteReg(SWIER, 0x00000000U);
00108   /* Pending register set to default reset values */
00109   LL_EXTI_WriteReg(PR,    0x00FFFFFFU);
00110 
00111   return SUCCESS;
00112 }
00113 
00114 /**
00115   * @brief  Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
00116   * @param  EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
00117   * @retval An ErrorStatus enumeration value:
00118   *          - SUCCESS: EXTI registers are initialized
00119   *          - ERROR: not applicable
00120   */
00121 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
00122 {
00123   ErrorStatus status = SUCCESS;
00124   /* Check the parameters */
00125   assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
00126   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
00127   assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
00128 
00129   /* ENABLE LineCommand */
00130   if (EXTI_InitStruct->LineCommand != DISABLE)
00131   {
00132     assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
00133 
00134     /* Configure EXTI Lines in range from 0 to 31 */
00135     if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
00136     {
00137       switch (EXTI_InitStruct->Mode)
00138       {
00139         case LL_EXTI_MODE_IT:
00140           /* First Disable Event on provided Lines */
00141           LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
00142           /* Then Enable IT on provided Lines */
00143           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
00144           break;
00145         case LL_EXTI_MODE_EVENT:
00146           /* First Disable IT on provided Lines */
00147           LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
00148           /* Then Enable Event on provided Lines */
00149           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
00150           break;
00151         case LL_EXTI_MODE_IT_EVENT:
00152           /* Directly Enable IT & Event on provided Lines */
00153           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
00154           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
00155           break;
00156         default:
00157           status = ERROR;
00158           break;
00159       }
00160       if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
00161       {
00162         switch (EXTI_InitStruct->Trigger)
00163         {
00164           case LL_EXTI_TRIGGER_RISING:
00165             /* First Disable Falling Trigger on provided Lines */
00166             LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
00167             /* Then Enable Rising Trigger on provided Lines */
00168             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
00169             break;
00170           case LL_EXTI_TRIGGER_FALLING:
00171             /* First Disable Rising Trigger on provided Lines */
00172             LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
00173             /* Then Enable Falling Trigger on provided Lines */
00174             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
00175             break;
00176           case LL_EXTI_TRIGGER_RISING_FALLING:
00177             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
00178             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
00179             break;
00180           default:
00181             status = ERROR;
00182             break;
00183         }
00184       }
00185     }
00186   }
00187   /* DISABLE LineCommand */
00188   else
00189   {
00190     /* De-configure EXTI Lines in range from 0 to 31 */
00191     LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
00192     LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
00193   }
00194   return status;
00195 }
00196 
00197 /**
00198   * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
00199   * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
00200   * @retval None
00201   */
00202 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
00203 {
00204   EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
00205   EXTI_InitStruct->LineCommand    = DISABLE;
00206   EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
00207   EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
00208 }
00209 
00210 /**
00211   * @}
00212   */
00213 
00214 /**
00215   * @}
00216   */
00217 
00218 /**
00219   * @}
00220   */
00221 
00222 #endif /* defined (EXTI) */
00223 
00224 /**
00225   * @}
00226   */
00227 
00228 #endif /* USE_FULL_LL_DRIVER */
00229 
00230 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/