Subversion Repositories ScreenTimer

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f0xx_ll_exti.c
  4.   * @author  MCD Application Team
  5.   * @brief   EXTI LL module driver.
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2016 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.  
  20. #if defined(USE_FULL_LL_DRIVER)
  21.  
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "stm32f0xx_ll_exti.h"
  24. #ifdef  USE_FULL_ASSERT
  25. #include "stm32_assert.h"
  26. #else
  27. #define assert_param(expr) ((void)0U)
  28. #endif
  29.  
  30. /** @addtogroup STM32F0xx_LL_Driver
  31.   * @{
  32.   */
  33.  
  34. #if defined (EXTI)
  35.  
  36. /** @defgroup EXTI_LL EXTI
  37.   * @{
  38.   */
  39.  
  40. /* Private types -------------------------------------------------------------*/
  41. /* Private variables ---------------------------------------------------------*/
  42. /* Private constants ---------------------------------------------------------*/
  43. /* Private macros ------------------------------------------------------------*/
  44. /** @addtogroup EXTI_LL_Private_Macros
  45.   * @{
  46.   */
  47.  
  48. #define IS_LL_EXTI_LINE_0_31(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
  49.  
  50. #define IS_LL_EXTI_MODE(__VALUE__)                   (((__VALUE__) == LL_EXTI_MODE_IT)            \
  51.                                                    || ((__VALUE__) == LL_EXTI_MODE_EVENT)         \
  52.                                                    || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  53.  
  54.  
  55. #define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_NONE)       \
  56.                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING)     \
  57.                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING)    \
  58.                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  59.  
  60. /**
  61.   * @}
  62.   */
  63.  
  64. /* Private function prototypes -----------------------------------------------*/
  65.  
  66. /* Exported functions --------------------------------------------------------*/
  67. /** @addtogroup EXTI_LL_Exported_Functions
  68.   * @{
  69.   */
  70.  
  71. /** @addtogroup EXTI_LL_EF_Init
  72.   * @{
  73.   */
  74.  
  75. /**
  76.   * @brief  De-initialize the EXTI registers to their default reset values.
  77.   * @retval An ErrorStatus enumeration value:
  78.   *          - SUCCESS: EXTI registers are de-initialized
  79.   *          - ERROR: not applicable
  80.   */
  81. uint32_t LL_EXTI_DeInit(void)
  82. {
  83.   /* Interrupt mask register set to default reset values */
  84. #if defined(STM32F030x6) || defined(STM32F031x6) ||defined(STM32F038xx)
  85.   LL_EXTI_WriteReg(IMR,   0x0FF40000U);
  86. #elif defined(STM32F070x6) || defined(STM32F042x6) || defined(STM32F048xx)
  87.   LL_EXTI_WriteReg(IMR,   0x7FF40000U);
  88. #elif defined(STM32F030x8) || defined(STM32F051x8) || defined(STM32F058xx)
  89.   LL_EXTI_WriteReg(IMR,   0x0F940000U);
  90. #else
  91.   LL_EXTI_WriteReg(IMR,   0x7F840000U);
  92. #endif
  93.   /* Event mask register set to default reset values */
  94.   LL_EXTI_WriteReg(EMR,   0x00000000U);
  95.   /* Rising Trigger selection register set to default reset values */
  96.   LL_EXTI_WriteReg(RTSR,  0x00000000U);
  97.   /* Falling Trigger selection register set to default reset values */
  98.   LL_EXTI_WriteReg(FTSR,  0x00000000U);
  99.   /* Software interrupt event register set to default reset values */
  100.   LL_EXTI_WriteReg(SWIER, 0x00000000U);
  101.   /* Pending register clear */
  102.   LL_EXTI_WriteReg(PR,    0x007BFFFFU);
  103.  
  104.   return SUCCESS;
  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.   *          - SUCCESS: EXTI registers are initialized
  112.   *          - ERROR: not applicable
  113.   */
  114. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  115. {
  116.   ErrorStatus status = SUCCESS;
  117.   /* Check the parameters */
  118.   assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  119.   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  120.   assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  121.  
  122.   /* ENABLE LineCommand */
  123.   if (EXTI_InitStruct->LineCommand != DISABLE)
  124.   {
  125.     assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  126.  
  127.     /* Configure EXTI Lines in range from 0 to 31 */
  128.     if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  129.     {
  130.       switch (EXTI_InitStruct->Mode)
  131.       {
  132.         case LL_EXTI_MODE_IT:
  133.           /* First Disable Event on provided Lines */
  134.           LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  135.           /* Then Enable IT on provided Lines */
  136.           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  137.           break;
  138.         case LL_EXTI_MODE_EVENT:
  139.           /* First Disable IT on provided Lines */
  140.           LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  141.           /* Then Enable Event on provided Lines */
  142.           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  143.           break;
  144.         case LL_EXTI_MODE_IT_EVENT:
  145.           /* Directly Enable IT & Event on provided Lines */
  146.           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  147.           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  148.           break;
  149.         default:
  150.           status = ERROR;
  151.           break;
  152.       }
  153.       if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  154.       {
  155.         switch (EXTI_InitStruct->Trigger)
  156.         {
  157.           case LL_EXTI_TRIGGER_RISING:
  158.             /* First Disable Falling Trigger on provided Lines */
  159.             LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  160.             /* Then Enable Rising Trigger on provided Lines */
  161.             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  162.             break;
  163.           case LL_EXTI_TRIGGER_FALLING:
  164.             /* First Disable Rising Trigger on provided Lines */
  165.             LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  166.             /* Then Enable Falling Trigger on provided Lines */
  167.             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  168.             break;
  169.           case LL_EXTI_TRIGGER_RISING_FALLING:
  170.             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  171.             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  172.             break;
  173.           default:
  174.             status = ERROR;
  175.             break;
  176.         }
  177.       }
  178.     }
  179.   }
  180.   /* DISABLE LineCommand */
  181.   else
  182.   {
  183.     /* De-configure EXTI Lines in range from 0 to 31 */
  184.     LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  185.     LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  186.   }
  187.   return status;
  188. }
  189.  
  190. /**
  191.   * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
  192.   * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  193.   * @retval None
  194.   */
  195. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  196. {
  197.   EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
  198.   EXTI_InitStruct->LineCommand    = DISABLE;
  199.   EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
  200.   EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
  201. }
  202.  
  203. /**
  204.   * @}
  205.   */
  206.  
  207. /**
  208.   * @}
  209.   */
  210.  
  211. /**
  212.   * @}
  213.   */
  214.  
  215. #endif /* defined (EXTI) */
  216.  
  217. /**
  218.   * @}
  219.   */
  220.  
  221. #endif /* USE_FULL_LL_DRIVER */
  222.  
  223. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  224.