stm32f3xx_ll_exti.c 12 KB

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