stm32f1xx_ll_exti.c 8.3 KB

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