stm32l4xx_ll_exti.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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 "stm32l4xx_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 STM32L4xx_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_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
  59. #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
  60. || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
  61. || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  62. #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
  63. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
  64. || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
  65. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  66. /**
  67. * @}
  68. */
  69. /* Private function prototypes -----------------------------------------------*/
  70. /* Exported functions --------------------------------------------------------*/
  71. /** @addtogroup EXTI_LL_Exported_Functions
  72. * @{
  73. */
  74. /** @addtogroup EXTI_LL_EF_Init
  75. * @{
  76. */
  77. /**
  78. * @brief De-initialize the EXTI registers to their default reset values.
  79. * @retval An ErrorStatus enumeration value:
  80. * - SUCCESS: EXTI registers are de-initialized
  81. * - ERROR: not applicable
  82. */
  83. uint32_t LL_EXTI_DeInit(void)
  84. {
  85. /* Interrupt mask register set to default reset values */
  86. LL_EXTI_WriteReg(IMR1, 0xFF820000U);
  87. /* Event mask register set to default reset values */
  88. LL_EXTI_WriteReg(EMR1, 0x00000000U);
  89. /* Rising Trigger selection register set to default reset values */
  90. LL_EXTI_WriteReg(RTSR1, 0x00000000U);
  91. /* Falling Trigger selection register set to default reset values */
  92. LL_EXTI_WriteReg(FTSR1, 0x00000000U);
  93. /* Software interrupt event register set to default reset values */
  94. LL_EXTI_WriteReg(SWIER1, 0x00000000U);
  95. /* Pending register clear */
  96. LL_EXTI_WriteReg(PR1, 0x007DFFFFU);
  97. /* Interrupt mask register 2 set to default reset values */
  98. #if defined(LL_EXTI_LINE_40)
  99. LL_EXTI_WriteReg(IMR2, 0x00000187U);
  100. #else
  101. LL_EXTI_WriteReg(IMR2, 0x00000087U);
  102. #endif
  103. /* Event mask register 2 set to default reset values */
  104. LL_EXTI_WriteReg(EMR2, 0x00000000U);
  105. /* Rising Trigger selection register 2 set to default reset values */
  106. LL_EXTI_WriteReg(RTSR2, 0x00000000U);
  107. /* Falling Trigger selection register 2 set to default reset values */
  108. LL_EXTI_WriteReg(FTSR2, 0x00000000U);
  109. /* Software interrupt event register 2 set to default reset values */
  110. LL_EXTI_WriteReg(SWIER2, 0x00000000U);
  111. /* Pending register 2 clear */
  112. LL_EXTI_WriteReg(PR2, 0x00000078U);
  113. return SUCCESS;
  114. }
  115. /**
  116. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  117. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  118. * @retval An ErrorStatus enumeration value:
  119. * - SUCCESS: EXTI registers are initialized
  120. * - ERROR: not applicable
  121. */
  122. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  123. {
  124. ErrorStatus status = SUCCESS;
  125. /* Check the parameters */
  126. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  127. assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
  128. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  129. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  130. /* ENABLE LineCommand */
  131. if (EXTI_InitStruct->LineCommand != DISABLE)
  132. {
  133. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  134. /* Configure EXTI Lines in range from 0 to 31 */
  135. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  136. {
  137. switch (EXTI_InitStruct->Mode)
  138. {
  139. case LL_EXTI_MODE_IT:
  140. /* First Disable Event on provided Lines */
  141. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  142. /* Then Enable IT on provided Lines */
  143. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  144. break;
  145. case LL_EXTI_MODE_EVENT:
  146. /* First Disable IT on provided Lines */
  147. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  148. /* Then Enable Event on provided Lines */
  149. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  150. break;
  151. case LL_EXTI_MODE_IT_EVENT:
  152. /* Directly Enable IT & Event on provided Lines */
  153. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  154. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  155. break;
  156. default:
  157. status = ERROR;
  158. break;
  159. }
  160. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  161. {
  162. switch (EXTI_InitStruct->Trigger)
  163. {
  164. case LL_EXTI_TRIGGER_RISING:
  165. /* First Disable Falling Trigger on provided Lines */
  166. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  167. /* Then Enable Rising Trigger on provided Lines */
  168. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  169. break;
  170. case LL_EXTI_TRIGGER_FALLING:
  171. /* First Disable Rising Trigger on provided Lines */
  172. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  173. /* Then Enable Falling Trigger on provided Lines */
  174. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  175. break;
  176. case LL_EXTI_TRIGGER_RISING_FALLING:
  177. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  178. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  179. break;
  180. default:
  181. status = ERROR;
  182. break;
  183. }
  184. }
  185. }
  186. /* Configure EXTI Lines in range from 32 to 63 */
  187. if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
  188. {
  189. switch (EXTI_InitStruct->Mode)
  190. {
  191. case LL_EXTI_MODE_IT:
  192. /* First Disable Event on provided Lines */
  193. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  194. /* Then Enable IT on provided Lines */
  195. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  196. break;
  197. case LL_EXTI_MODE_EVENT:
  198. /* First Disable IT on provided Lines */
  199. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  200. /* Then Enable Event on provided Lines */
  201. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  202. break;
  203. case LL_EXTI_MODE_IT_EVENT:
  204. /* Directly Enable IT & Event on provided Lines */
  205. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  206. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  207. break;
  208. default:
  209. status = ERROR;
  210. break;
  211. }
  212. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  213. {
  214. switch (EXTI_InitStruct->Trigger)
  215. {
  216. case LL_EXTI_TRIGGER_RISING:
  217. /* First Disable Falling Trigger on provided Lines */
  218. LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  219. /* Then Enable IT on provided Lines */
  220. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  221. break;
  222. case LL_EXTI_TRIGGER_FALLING:
  223. /* First Disable Rising Trigger on provided Lines */
  224. LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  225. /* Then Enable Falling Trigger on provided Lines */
  226. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  227. break;
  228. case LL_EXTI_TRIGGER_RISING_FALLING:
  229. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  230. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  231. break;
  232. default:
  233. status = ERROR;
  234. break;
  235. }
  236. }
  237. }
  238. }
  239. /* DISABLE LineCommand */
  240. else
  241. {
  242. /* De-configure EXTI Lines in range from 0 to 31 */
  243. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  244. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  245. /* De-configure EXTI Lines in range from 32 to 63 */
  246. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  247. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  248. }
  249. return status;
  250. }
  251. /**
  252. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  253. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  254. * @retval None
  255. */
  256. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  257. {
  258. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  259. EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
  260. EXTI_InitStruct->LineCommand = DISABLE;
  261. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  262. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  263. }
  264. /**
  265. * @}
  266. */
  267. /**
  268. * @}
  269. */
  270. /**
  271. * @}
  272. */
  273. #endif /* defined (EXTI) */
  274. /**
  275. * @}
  276. */
  277. #endif /* USE_FULL_LL_DRIVER */
  278. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/