stm32f0xx_exti.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_exti.c
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the EXTI peripheral:
  9. * + Initialization and Configuration
  10. * + Interrupts and flags management
  11. *
  12. * @verbatim
  13. ==============================================================================
  14. ##### EXTI features #####
  15. ==============================================================================
  16. [..] External interrupt/event lines are mapped as following:
  17. (#) All available GPIO pins are connected to the 16 external
  18. interrupt/event lines from EXTI0 to EXTI15.
  19. (#) EXTI line 16 is connected to the PVD output, not applicable for STM32F030 devices.
  20. (#) EXTI line 17 is connected to the RTC Alarm event.
  21. (#) EXTI line 18 is connected to the RTC Alarm event, applicable only for STM32F072 devices.
  22. (#) EXTI line 19 is connected to the RTC Tamper and TimeStamp events.
  23. (#) EXTI line 20 is connected to the RTC wakeup event, applicable only for STM32F072 devices.
  24. (#) EXTI line 21 is connected to the Comparator 1 wakeup event, applicable only for STM32F051 and STM32F072 devices.
  25. (#) EXTI line 22 is connected to the Comparator 2 wakeup event, applicable only for STM32F051 and STM32F072 devices.
  26. (#) EXTI line 23 is connected to the I2C1 wakeup event, not applicable for STM32F030 devices.
  27. (#) EXTI line 25 is connected to the USART1 wakeup event, not applicable for STM32F030 devices.
  28. (#) EXTI line 26 is connected to the USART2 wakeup event, applicable only for STM32F072 devices.
  29. (#) EXTI line 27 is connected to the CEC wakeup event, applicable only for STM32F051 and STM32F072 devices.
  30. (#) EXTI line 31 is connected to the VDD USB monitor event, applicable only for STM32F072 devices.
  31. ##### How to use this driver #####
  32. ==============================================================================
  33. [..] In order to use an I/O pin as an external interrupt source, follow
  34. steps below:
  35. (#) Configure the I/O in input mode using GPIO_Init()
  36. (#) Select the input source pin for the EXTI line using
  37. SYSCFG_EXTILineConfig().
  38. (#) Select the mode(interrupt, event) and configure the trigger selection
  39. (Rising, falling or both) using EXTI_Init(). For the internal interrupt,
  40. the trigger selection is not needed( the active edge is always the rising one).
  41. (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init().
  42. (#) Optionally, you can generate a software interrupt using the function EXTI_GenerateSWInterrupt().
  43. [..]
  44. (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
  45. registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  46. @endverbatim
  47. *
  48. ******************************************************************************
  49. * @attention
  50. *
  51. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  52. *
  53. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  54. * You may not use this file except in compliance with the License.
  55. * You may obtain a copy of the License at:
  56. *
  57. * http://www.st.com/software_license_agreement_liberty_v2
  58. *
  59. * Unless required by applicable law or agreed to in writing, software
  60. * distributed under the License is distributed on an "AS IS" BASIS,
  61. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  62. * See the License for the specific language governing permissions and
  63. * limitations under the License.
  64. *
  65. ******************************************************************************
  66. */
  67. /* Includes ------------------------------------------------------------------*/
  68. #include "stm32f0xx_exti.h"
  69. /** @addtogroup STM32F0xx_StdPeriph_Driver
  70. * @{
  71. */
  72. /** @defgroup EXTI
  73. * @brief EXTI driver modules
  74. * @{
  75. */
  76. /* Private typedef -----------------------------------------------------------*/
  77. /* Private define ------------------------------------------------------------*/
  78. #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
  79. /* Private macro -------------------------------------------------------------*/
  80. /* Private variables ---------------------------------------------------------*/
  81. /* Private function prototypes -----------------------------------------------*/
  82. /* Private functions ---------------------------------------------------------*/
  83. /** @defgroup EXTI_Private_Functions
  84. * @{
  85. */
  86. /** @defgroup EXTI_Group1 Initialization and Configuration functions
  87. * @brief Initialization and Configuration functions
  88. *
  89. @verbatim
  90. ==============================================================================
  91. ##### Initialization and Configuration functions #####
  92. ==============================================================================
  93. @endverbatim
  94. * @{
  95. */
  96. /**
  97. * @brief Deinitializes the EXTI peripheral registers to their default reset
  98. * values.
  99. * @param None
  100. * @retval None
  101. */
  102. void EXTI_DeInit(void)
  103. {
  104. EXTI->IMR = 0x0F940000;
  105. EXTI->EMR = 0x00000000;
  106. EXTI->RTSR = 0x00000000;
  107. EXTI->FTSR = 0x00000000;
  108. EXTI->PR = 0x006BFFFF;
  109. }
  110. /**
  111. * @brief Initializes the EXTI peripheral according to the specified
  112. * parameters in the EXTI_InitStruct.
  113. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure that
  114. * contains the configuration information for the EXTI peripheral.
  115. * @retval None
  116. */
  117. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  118. {
  119. uint32_t tmp = 0;
  120. /* Check the parameters */
  121. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  122. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  123. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  124. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  125. tmp = (uint32_t)EXTI_BASE;
  126. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  127. {
  128. /* Clear EXTI line configuration */
  129. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  130. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  131. tmp += EXTI_InitStruct->EXTI_Mode;
  132. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  133. /* Clear Rising Falling edge configuration */
  134. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  135. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  136. /* Select the trigger for the selected interrupts */
  137. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  138. {
  139. /* Rising Falling edge */
  140. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  141. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  142. }
  143. else
  144. {
  145. tmp = (uint32_t)EXTI_BASE;
  146. tmp += EXTI_InitStruct->EXTI_Trigger;
  147. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  148. }
  149. }
  150. else
  151. {
  152. tmp += EXTI_InitStruct->EXTI_Mode;
  153. /* Disable the selected external lines */
  154. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  155. }
  156. }
  157. /**
  158. * @brief Fills each EXTI_InitStruct member with its reset value.
  159. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  160. * be initialized.
  161. * @retval None
  162. */
  163. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  164. {
  165. EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  166. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  167. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  168. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  169. }
  170. /**
  171. * @brief Generates a Software interrupt on selected EXTI line.
  172. * @param EXTI_Line: specifies the EXTI line on which the software interrupt
  173. * will be generated.
  174. * This parameter can be any combination of EXTI_Linex where x can be (0..27).
  175. * @retval None
  176. */
  177. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  178. {
  179. /* Check the parameters */
  180. assert_param(IS_EXTI_LINE(EXTI_Line));
  181. EXTI->SWIER |= EXTI_Line;
  182. }
  183. /**
  184. * @}
  185. */
  186. /** @defgroup EXTI_Group2 Interrupts and flags management functions
  187. * @brief Interrupts and flags management functions
  188. *
  189. @verbatim
  190. ==============================================================================
  191. ##### Interrupts and flags management functions #####
  192. ==============================================================================
  193. @endverbatim
  194. * @{
  195. */
  196. /**
  197. * @brief Checks whether the specified EXTI line flag is set or not.
  198. * @param EXTI_Line: specifies the EXTI line flag to check.
  199. * This parameter can be EXTI_Linex where x can be (0..27).
  200. * @retval The new state of EXTI_Line (SET or RESET).
  201. */
  202. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  203. {
  204. FlagStatus bitstatus = RESET;
  205. /* Check the parameters */
  206. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  207. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  208. {
  209. bitstatus = SET;
  210. }
  211. else
  212. {
  213. bitstatus = RESET;
  214. }
  215. return bitstatus;
  216. }
  217. /**
  218. * @brief Clears the EXTI's line pending flags.
  219. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  220. * This parameter can be any combination of EXTI_Linex where x can be (0..27).
  221. * @retval None
  222. */
  223. void EXTI_ClearFlag(uint32_t EXTI_Line)
  224. {
  225. /* Check the parameters */
  226. assert_param(IS_EXTI_LINE(EXTI_Line));
  227. EXTI->PR = EXTI_Line;
  228. }
  229. /**
  230. * @brief Checks whether the specified EXTI line is asserted or not.
  231. * @param EXTI_Line: specifies the EXTI line to check.
  232. * This parameter can be EXTI_Linex where x can be (0..27).
  233. * @retval The new state of EXTI_Line (SET or RESET).
  234. */
  235. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  236. {
  237. ITStatus bitstatus = RESET;
  238. /* Check the parameters */
  239. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  240. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  241. {
  242. bitstatus = SET;
  243. }
  244. else
  245. {
  246. bitstatus = RESET;
  247. }
  248. return bitstatus;
  249. }
  250. /**
  251. * @brief Clears the EXTI's line pending bits.
  252. * @param EXTI_Line: specifies the EXTI lines to clear.
  253. * This parameter can be any combination of EXTI_Linex where x can be (0..27).
  254. * @retval None
  255. */
  256. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  257. {
  258. /* Check the parameters */
  259. assert_param(IS_EXTI_LINE(EXTI_Line));
  260. EXTI->PR = EXTI_Line;
  261. }
  262. /**
  263. * @}
  264. */
  265. /**
  266. * @}
  267. */
  268. /**
  269. * @}
  270. */
  271. /**
  272. * @}
  273. */
  274. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/