You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

239 lines
8.6 KiB

  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</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. #if defined(USE_FULL_LL_DRIVER)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32f0xx_ll_exti.h"
  38. #ifdef USE_FULL_ASSERT
  39. #include "stm32_assert.h"
  40. #else
  41. #define assert_param(expr) ((void)0U)
  42. #endif
  43. /** @addtogroup STM32F0xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (EXTI)
  47. /** @defgroup EXTI_LL EXTI
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /* Private macros ------------------------------------------------------------*/
  54. /** @addtogroup EXTI_LL_Private_Macros
  55. * @{
  56. */
  57. #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
  58. #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
  59. || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
  60. || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  61. #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
  62. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
  63. || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
  64. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  65. /**
  66. * @}
  67. */
  68. /* Private function prototypes -----------------------------------------------*/
  69. /* Exported functions --------------------------------------------------------*/
  70. /** @addtogroup EXTI_LL_Exported_Functions
  71. * @{
  72. */
  73. /** @addtogroup EXTI_LL_EF_Init
  74. * @{
  75. */
  76. /**
  77. * @brief De-initialize the EXTI registers to their default reset values.
  78. * @retval An ErrorStatus enumeration value:
  79. * - SUCCESS: EXTI registers are de-initialized
  80. * - ERROR: not applicable
  81. */
  82. uint32_t LL_EXTI_DeInit(void)
  83. {
  84. /* Interrupt mask register set to default reset values */
  85. #if defined(STM32F030x6) || defined(STM32F031x6) ||defined(STM32F038xx)
  86. LL_EXTI_WriteReg(IMR, 0x0FF40000U);
  87. #elif defined(STM32F070x6) || defined(STM32F042x6) || defined(STM32F048xx)
  88. LL_EXTI_WriteReg(IMR, 0x7FF40000U);
  89. #elif defined(STM32F030x8) || defined(STM32F051x8) || defined(STM32F058xx)
  90. LL_EXTI_WriteReg(IMR, 0x0F940000U);
  91. #else
  92. LL_EXTI_WriteReg(IMR, 0x7F840000U);
  93. #endif
  94. /* Event mask register set to default reset values */
  95. LL_EXTI_WriteReg(EMR, 0x00000000U);
  96. /* Rising Trigger selection register set to default reset values */
  97. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  98. /* Falling Trigger selection register set to default reset values */
  99. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  100. /* Software interrupt event register set to default reset values */
  101. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  102. /* Pending register clear */
  103. LL_EXTI_WriteReg(PR, 0x007BFFFFU);
  104. return SUCCESS;
  105. }
  106. /**
  107. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  108. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  109. * @retval An ErrorStatus enumeration value:
  110. * - SUCCESS: EXTI registers are initialized
  111. * - ERROR: not applicable
  112. */
  113. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  114. {
  115. ErrorStatus status = SUCCESS;
  116. /* Check the parameters */
  117. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  118. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  119. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  120. /* ENABLE LineCommand */
  121. if (EXTI_InitStruct->LineCommand != DISABLE)
  122. {
  123. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  124. /* Configure EXTI Lines in range from 0 to 31 */
  125. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  126. {
  127. switch (EXTI_InitStruct->Mode)
  128. {
  129. case LL_EXTI_MODE_IT:
  130. /* First Disable Event on provided Lines */
  131. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  132. /* Then Enable IT on provided Lines */
  133. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  134. break;
  135. case LL_EXTI_MODE_EVENT:
  136. /* First Disable IT on provided Lines */
  137. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  138. /* Then Enable Event on provided Lines */
  139. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  140. break;
  141. case LL_EXTI_MODE_IT_EVENT:
  142. /* Directly Enable IT & Event on provided Lines */
  143. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  144. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  145. break;
  146. default:
  147. status = ERROR;
  148. break;
  149. }
  150. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  151. {
  152. switch (EXTI_InitStruct->Trigger)
  153. {
  154. case LL_EXTI_TRIGGER_RISING:
  155. /* First Disable Falling Trigger on provided Lines */
  156. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  157. /* Then Enable Rising Trigger on provided Lines */
  158. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  159. break;
  160. case LL_EXTI_TRIGGER_FALLING:
  161. /* First Disable Rising Trigger on provided Lines */
  162. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  163. /* Then Enable Falling Trigger on provided Lines */
  164. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  165. break;
  166. case LL_EXTI_TRIGGER_RISING_FALLING:
  167. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  168. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  169. break;
  170. default:
  171. status = ERROR;
  172. break;
  173. }
  174. }
  175. }
  176. }
  177. /* DISABLE LineCommand */
  178. else
  179. {
  180. /* De-configure EXTI Lines in range from 0 to 31 */
  181. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  182. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  183. }
  184. return status;
  185. }
  186. /**
  187. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  188. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  189. * @retval None
  190. */
  191. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  192. {
  193. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  194. EXTI_InitStruct->LineCommand = DISABLE;
  195. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  196. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  197. }
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */
  204. /**
  205. * @}
  206. */
  207. #endif /* defined (EXTI) */
  208. /**
  209. * @}
  210. */
  211. #endif /* USE_FULL_LL_DRIVER */
  212. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/