stm32f4xx_ll_exti.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_exti.c
  4. * @author MCD Application Team
  5. * @brief EXTI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 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 "stm32f4xx_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 STM32F4xx_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. LL_EXTI_WriteReg(IMR, 0x00000000U);
  86. /* Event mask register set to default reset values */
  87. LL_EXTI_WriteReg(EMR, 0x00000000U);
  88. /* Rising Trigger selection register set to default reset values */
  89. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  90. /* Falling Trigger selection register set to default reset values */
  91. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  92. /* Software interrupt event register set to default reset values */
  93. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  94. /* Pending register set to default reset values */
  95. LL_EXTI_WriteReg(PR, 0x00FFFFFFU);
  96. return SUCCESS;
  97. }
  98. /**
  99. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  100. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  101. * @retval An ErrorStatus enumeration value:
  102. * - SUCCESS: EXTI registers are initialized
  103. * - ERROR: not applicable
  104. */
  105. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  106. {
  107. ErrorStatus status = SUCCESS;
  108. /* Check the parameters */
  109. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  110. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  111. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  112. /* ENABLE LineCommand */
  113. if (EXTI_InitStruct->LineCommand != DISABLE)
  114. {
  115. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  116. /* Configure EXTI Lines in range from 0 to 31 */
  117. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  118. {
  119. switch (EXTI_InitStruct->Mode)
  120. {
  121. case LL_EXTI_MODE_IT:
  122. /* First Disable Event on provided Lines */
  123. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  124. /* Then Enable IT on provided Lines */
  125. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  126. break;
  127. case LL_EXTI_MODE_EVENT:
  128. /* First Disable IT on provided Lines */
  129. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  130. /* Then Enable Event on provided Lines */
  131. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  132. break;
  133. case LL_EXTI_MODE_IT_EVENT:
  134. /* Directly Enable IT & Event on provided Lines */
  135. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  136. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  137. break;
  138. default:
  139. status = ERROR;
  140. break;
  141. }
  142. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  143. {
  144. switch (EXTI_InitStruct->Trigger)
  145. {
  146. case LL_EXTI_TRIGGER_RISING:
  147. /* First Disable Falling Trigger on provided Lines */
  148. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  149. /* Then Enable Rising Trigger on provided Lines */
  150. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  151. break;
  152. case LL_EXTI_TRIGGER_FALLING:
  153. /* First Disable Rising Trigger on provided Lines */
  154. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  155. /* Then Enable Falling Trigger on provided Lines */
  156. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  157. break;
  158. case LL_EXTI_TRIGGER_RISING_FALLING:
  159. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  160. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  161. break;
  162. default:
  163. status = ERROR;
  164. break;
  165. }
  166. }
  167. }
  168. }
  169. /* DISABLE LineCommand */
  170. else
  171. {
  172. /* De-configure EXTI Lines in range from 0 to 31 */
  173. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  174. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  175. }
  176. return status;
  177. }
  178. /**
  179. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  180. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  181. * @retval None
  182. */
  183. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  184. {
  185. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  186. EXTI_InitStruct->LineCommand = DISABLE;
  187. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  188. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  189. }
  190. /**
  191. * @}
  192. */
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. #endif /* defined (EXTI) */
  200. /**
  201. * @}
  202. */
  203. #endif /* USE_FULL_LL_DRIVER */
  204. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/