py32f002b_ll_exti.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_ll_exti.c
  4. * @author MCU Application Team
  5. * @brief EXTI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. #if defined(USE_FULL_LL_DRIVER)
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "py32f002b_ll_exti.h"
  33. #ifdef USE_FULL_ASSERT
  34. #include "py32_assert.h"
  35. #else
  36. #define assert_param(expr) ((void)0U)
  37. #endif /* USE_FULL_ASSERT */
  38. /** @addtogroup PY32F002B_LL_Driver
  39. * @{
  40. */
  41. #if defined (EXTI)
  42. /** @defgroup EXTI_LL EXTI
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private constants ---------------------------------------------------------*/
  48. /* Private macros ------------------------------------------------------------*/
  49. /** @addtogroup EXTI_LL_Private_Macros
  50. * @{
  51. */
  52. #define IS_LL_EXTI_LINE(__VALUE__) ((__VALUE__ == LL_EXTI_LINE_0 ) || \
  53. (__VALUE__ == LL_EXTI_LINE_1 ) || \
  54. (__VALUE__ == LL_EXTI_LINE_2 ) || \
  55. (__VALUE__ == LL_EXTI_LINE_3 ) || \
  56. (__VALUE__ == LL_EXTI_LINE_4 ) || \
  57. (__VALUE__ == LL_EXTI_LINE_5 ) || \
  58. (__VALUE__ == LL_EXTI_LINE_6 ) || \
  59. (__VALUE__ == LL_EXTI_LINE_7 ) || \
  60. (__VALUE__ == LL_EXTI_LINE_17 ) || \
  61. (__VALUE__ == LL_EXTI_LINE_18 ) || \
  62. (__VALUE__ == LL_EXTI_LINE_29 ))
  63. #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
  64. || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
  65. || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  66. #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
  67. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
  68. || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
  69. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  70. /**
  71. * @}
  72. */
  73. /* Private function prototypes -----------------------------------------------*/
  74. /* Exported functions --------------------------------------------------------*/
  75. /** @addtogroup EXTI_LL_Exported_Functions
  76. * @{
  77. */
  78. /** @addtogroup EXTI_LL_EF_Init
  79. * @{
  80. */
  81. /**
  82. * @brief De-initialize the EXTI registers to their default reset values.
  83. * @retval An ErrorStatus enumeration value:
  84. * - 0x00: EXTI registers are de-initialized
  85. */
  86. uint32_t LL_EXTI_DeInit(void)
  87. {
  88. /* Interrupt mask register set to default reset values */
  89. LL_EXTI_WriteReg(IMR, 0x20000000U);
  90. /* Event mask register set to default reset values */
  91. LL_EXTI_WriteReg(EMR, 0x00000000U);
  92. /* Rising Trigger selection register set to default reset values */
  93. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  94. /* Falling Trigger selection register set to default reset values */
  95. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  96. /* Software interrupt event register set to default reset values */
  97. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  98. /* Pending register set to default reset values */
  99. LL_EXTI_WriteReg(PR, 0x0000600FFU);
  100. return 0x00u;
  101. }
  102. /**
  103. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  104. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  105. * @retval An ErrorStatus enumeration value:
  106. * - 0x00: EXTI registers are initialized
  107. * - any other value : wrong configuration
  108. */
  109. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  110. {
  111. uint32_t status = 0x00u;
  112. /* Check the parameters */
  113. assert_param(IS_LL_EXTI_LINE(EXTI_InitStruct->Line));
  114. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  115. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  116. /* ENABLE LineCommand */
  117. if (EXTI_InitStruct->LineCommand != DISABLE)
  118. {
  119. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  120. /* Configure EXTI Lines*/
  121. if (EXTI_InitStruct->Line != LL_EXTI_LINE_NONE)
  122. {
  123. switch (EXTI_InitStruct->Mode)
  124. {
  125. case LL_EXTI_MODE_IT:
  126. /* First Disable Event on provided Lines */
  127. LL_EXTI_DisableEvent(EXTI_InitStruct->Line);
  128. /* Then Enable IT on provided Lines */
  129. LL_EXTI_EnableIT(EXTI_InitStruct->Line);
  130. break;
  131. case LL_EXTI_MODE_EVENT:
  132. /* First Disable IT on provided Lines */
  133. LL_EXTI_DisableIT(EXTI_InitStruct->Line);
  134. /* Then Enable Event on provided Lines */
  135. LL_EXTI_EnableEvent(EXTI_InitStruct->Line);
  136. break;
  137. case LL_EXTI_MODE_IT_EVENT:
  138. /* Directly Enable IT & Event on provided Lines */
  139. LL_EXTI_EnableIT(EXTI_InitStruct->Line);
  140. LL_EXTI_EnableEvent(EXTI_InitStruct->Line);
  141. break;
  142. default:
  143. status = 0x01u;
  144. break;
  145. }
  146. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  147. {
  148. switch (EXTI_InitStruct->Trigger)
  149. {
  150. case LL_EXTI_TRIGGER_RISING:
  151. /* First Disable Falling Trigger on provided Lines */
  152. LL_EXTI_DisableFallingTrig(EXTI_InitStruct->Line);
  153. /* Then Enable Rising Trigger on provided Lines */
  154. LL_EXTI_EnableRisingTrig(EXTI_InitStruct->Line);
  155. break;
  156. case LL_EXTI_TRIGGER_FALLING:
  157. /* First Disable Rising Trigger on provided Lines */
  158. LL_EXTI_DisableRisingTrig(EXTI_InitStruct->Line);
  159. /* Then Enable Falling Trigger on provided Lines */
  160. LL_EXTI_EnableFallingTrig(EXTI_InitStruct->Line);
  161. break;
  162. case LL_EXTI_TRIGGER_RISING_FALLING:
  163. LL_EXTI_EnableRisingTrig(EXTI_InitStruct->Line);
  164. LL_EXTI_EnableFallingTrig(EXTI_InitStruct->Line);
  165. break;
  166. default:
  167. status |= 0x02u;
  168. break;
  169. }
  170. }
  171. }
  172. }
  173. /* DISABLE LineCommand */
  174. else
  175. {
  176. /* De-configure EXTI Lines*/
  177. LL_EXTI_DisableIT(EXTI_InitStruct->Line);
  178. LL_EXTI_DisableEvent(EXTI_InitStruct->Line);
  179. }
  180. return status;
  181. }
  182. /**
  183. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  184. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  185. * @retval None
  186. */
  187. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  188. {
  189. EXTI_InitStruct->Line = LL_EXTI_LINE_NONE;
  190. EXTI_InitStruct->LineCommand = DISABLE;
  191. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  192. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  193. }
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @}
  199. */
  200. /**
  201. * @}
  202. */
  203. #endif /* defined (EXTI) */
  204. /**
  205. * @}
  206. */
  207. #endif /* USE_FULL_LL_DRIVER */
  208. /************************ (C) COPYRIGHT Puya *****END OF FILE****/