stm32l4xx_ll_exti.c 11 KB

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