py32f0xx_ll_exti.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_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 "py32f0xx_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 PY32F0xx_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_8 ) || \
  61. (__VALUE__ == LL_EXTI_LINE_9 ) || \
  62. (__VALUE__ == LL_EXTI_LINE_10 ) || \
  63. (__VALUE__ == LL_EXTI_LINE_11 ) || \
  64. (__VALUE__ == LL_EXTI_LINE_12 ) || \
  65. (__VALUE__ == LL_EXTI_LINE_13 ) || \
  66. (__VALUE__ == LL_EXTI_LINE_14 ) || \
  67. (__VALUE__ == LL_EXTI_LINE_15 ) || \
  68. (__VALUE__ == LL_EXTI_LINE_16 ) || \
  69. (__VALUE__ == LL_EXTI_LINE_17 ) || \
  70. (__VALUE__ == LL_EXTI_LINE_18 ) || \
  71. (__VALUE__ == LL_EXTI_LINE_19 ) || \
  72. (__VALUE__ == LL_EXTI_LINE_29 ))
  73. #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
  74. || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
  75. || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  76. #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
  77. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
  78. || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
  79. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  80. /**
  81. * @}
  82. */
  83. /* Private function prototypes -----------------------------------------------*/
  84. /* Exported functions --------------------------------------------------------*/
  85. /** @addtogroup EXTI_LL_Exported_Functions
  86. * @{
  87. */
  88. /** @addtogroup EXTI_LL_EF_Init
  89. * @{
  90. */
  91. /**
  92. * @brief De-initialize the EXTI registers to their default reset values.
  93. * @retval An ErrorStatus enumeration value:
  94. * - 0x00: EXTI registers are de-initialized
  95. */
  96. uint32_t LL_EXTI_DeInit(void)
  97. {
  98. /* Interrupt mask register set to default reset values */
  99. LL_EXTI_WriteReg(IMR, 0x20080000U);
  100. /* Event mask register set to default reset values */
  101. LL_EXTI_WriteReg(EMR, 0x00000000U);
  102. /* Rising Trigger selection register set to default reset values */
  103. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  104. /* Falling Trigger selection register set to default reset values */
  105. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  106. /* Software interrupt event register set to default reset values */
  107. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  108. /* Pending register set to default reset values */
  109. LL_EXTI_WriteReg(PR, 0x0007FFFFU);
  110. return 0x00u;
  111. }
  112. /**
  113. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  114. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  115. * @retval An ErrorStatus enumeration value:
  116. * - 0x00: EXTI registers are initialized
  117. * - any other value : wrong configuration
  118. */
  119. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  120. {
  121. uint32_t status = 0x00u;
  122. /* Check the parameters */
  123. assert_param(IS_LL_EXTI_LINE(EXTI_InitStruct->Line));
  124. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  125. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  126. /* ENABLE LineCommand */
  127. if (EXTI_InitStruct->LineCommand != DISABLE)
  128. {
  129. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  130. /* Configure EXTI Lines*/
  131. if (EXTI_InitStruct->Line != LL_EXTI_LINE_NONE)
  132. {
  133. switch (EXTI_InitStruct->Mode)
  134. {
  135. case LL_EXTI_MODE_IT:
  136. /* First Disable Event on provided Lines */
  137. LL_EXTI_DisableEvent(EXTI_InitStruct->Line);
  138. /* Then Enable IT on provided Lines */
  139. LL_EXTI_EnableIT(EXTI_InitStruct->Line);
  140. break;
  141. case LL_EXTI_MODE_EVENT:
  142. /* First Disable IT on provided Lines */
  143. LL_EXTI_DisableIT(EXTI_InitStruct->Line);
  144. /* Then Enable Event on provided Lines */
  145. LL_EXTI_EnableEvent(EXTI_InitStruct->Line);
  146. break;
  147. case LL_EXTI_MODE_IT_EVENT:
  148. /* Directly Enable IT & Event on provided Lines */
  149. LL_EXTI_EnableIT(EXTI_InitStruct->Line);
  150. LL_EXTI_EnableEvent(EXTI_InitStruct->Line);
  151. break;
  152. default:
  153. status = 0x01u;
  154. break;
  155. }
  156. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  157. {
  158. switch (EXTI_InitStruct->Trigger)
  159. {
  160. case LL_EXTI_TRIGGER_RISING:
  161. /* First Disable Falling Trigger on provided Lines */
  162. LL_EXTI_DisableFallingTrig(EXTI_InitStruct->Line);
  163. /* Then Enable Rising Trigger on provided Lines */
  164. LL_EXTI_EnableRisingTrig(EXTI_InitStruct->Line);
  165. break;
  166. case LL_EXTI_TRIGGER_FALLING:
  167. /* First Disable Rising Trigger on provided Lines */
  168. LL_EXTI_DisableRisingTrig(EXTI_InitStruct->Line);
  169. /* Then Enable Falling Trigger on provided Lines */
  170. LL_EXTI_EnableFallingTrig(EXTI_InitStruct->Line);
  171. break;
  172. case LL_EXTI_TRIGGER_RISING_FALLING:
  173. LL_EXTI_EnableRisingTrig(EXTI_InitStruct->Line);
  174. LL_EXTI_EnableFallingTrig(EXTI_InitStruct->Line);
  175. break;
  176. default:
  177. status |= 0x02u;
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. /* DISABLE LineCommand */
  184. else
  185. {
  186. /* De-configure EXTI Lines*/
  187. LL_EXTI_DisableIT(EXTI_InitStruct->Line);
  188. LL_EXTI_DisableEvent(EXTI_InitStruct->Line);
  189. }
  190. return status;
  191. }
  192. /**
  193. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  194. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  195. * @retval None
  196. */
  197. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  198. {
  199. EXTI_InitStruct->Line = LL_EXTI_LINE_NONE;
  200. EXTI_InitStruct->LineCommand = DISABLE;
  201. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  202. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  203. }
  204. /**
  205. * @}
  206. */
  207. /**
  208. * @}
  209. */
  210. /**
  211. * @}
  212. */
  213. #endif /* defined (EXTI) */
  214. /**
  215. * @}
  216. */
  217. #endif /* USE_FULL_LL_DRIVER */
  218. /************************ (C) COPYRIGHT Puya *****END OF FILE****/