stm8s_exti.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_exti.c
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief This file contains all the functions for the EXTI peripheral.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm8s_exti.h"
  29. /** @addtogroup STM8S_StdPeriph_Driver
  30. * @{
  31. */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* Private define ------------------------------------------------------------*/
  34. /* Private macro -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private function prototypes -----------------------------------------------*/
  37. /* Private functions ---------------------------------------------------------*/
  38. /* Public functions ----------------------------------------------------------*/
  39. /**
  40. * @addtogroup EXTI_Public_Functions
  41. * @{
  42. */
  43. /**
  44. * @brief Deinitializes the external interrupt control registers to their default reset value.
  45. * @param None
  46. * @retval None
  47. */
  48. void EXTI_DeInit(void)
  49. {
  50. EXTI->CR1 = EXTI_CR1_RESET_VALUE;
  51. EXTI->CR2 = EXTI_CR2_RESET_VALUE;
  52. }
  53. /**
  54. * @brief Set the external interrupt sensitivity of the selected port.
  55. * @warning
  56. * - The modification of external interrupt sensitivity is only possible when the interrupts are disabled.
  57. * - The normal behavior is to disable the interrupts before calling this function, and re-enable them after.
  58. * @param Port The port number to access.
  59. * @param SensitivityValue The external interrupt sensitivity value to set.
  60. * @retval None
  61. * @par Required preconditions:
  62. * Global interrupts must be disabled before calling this function.
  63. */
  64. void EXTI_SetExtIntSensitivity(EXTI_Port_TypeDef Port, EXTI_Sensitivity_TypeDef SensitivityValue)
  65. {
  66. /* Set external interrupt sensitivity */
  67. switch (Port)
  68. {
  69. case EXTI_PORT_GPIOA:
  70. EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PAIS);
  71. EXTI->CR1 |= (uint8_t)(SensitivityValue);
  72. break;
  73. case EXTI_PORT_GPIOB:
  74. EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PBIS);
  75. EXTI->CR1 |= (uint8_t)((uint8_t)(SensitivityValue) << 2);
  76. break;
  77. case EXTI_PORT_GPIOC:
  78. EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PCIS);
  79. EXTI->CR1 |= (uint8_t)((uint8_t)(SensitivityValue) << 4);
  80. break;
  81. case EXTI_PORT_GPIOD:
  82. EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PDIS);
  83. EXTI->CR1 |= (uint8_t)((uint8_t)(SensitivityValue) << 6);
  84. break;
  85. case EXTI_PORT_GPIOE:
  86. EXTI->CR2 &= (uint8_t)(~EXTI_CR2_PEIS);
  87. EXTI->CR2 |= (uint8_t)(SensitivityValue);
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. /**
  94. * @brief Set the TLI interrupt sensitivity.
  95. * @param SensitivityValue The TLI interrupt sensitivity value.
  96. * @retval None
  97. * @par Required preconditions:
  98. * Global interrupts must be disabled before calling this function.
  99. */
  100. void EXTI_SetTLISensitivity(EXTI_TLISensitivity_TypeDef SensitivityValue)
  101. {
  102. /* Set TLI interrupt sensitivity */
  103. EXTI->CR2 &= (uint8_t)(~EXTI_CR2_TLIS);
  104. EXTI->CR2 |= (uint8_t)(SensitivityValue);
  105. }
  106. /**
  107. * @brief Get the external interrupt sensitivity of the selected port.
  108. * @param Port The port number to access.
  109. * @retval EXTI_Sensitivity_TypeDef The external interrupt sensitivity of the selected port.
  110. */
  111. EXTI_Sensitivity_TypeDef EXTI_GetExtIntSensitivity(EXTI_Port_TypeDef Port)
  112. {
  113. uint8_t value = 0;
  114. switch (Port)
  115. {
  116. case EXTI_PORT_GPIOA:
  117. value = (uint8_t)(EXTI->CR1 & EXTI_CR1_PAIS);
  118. break;
  119. case EXTI_PORT_GPIOB:
  120. value = (uint8_t)((uint8_t)(EXTI->CR1 & EXTI_CR1_PBIS) >> 2);
  121. break;
  122. case EXTI_PORT_GPIOC:
  123. value = (uint8_t)((uint8_t)(EXTI->CR1 & EXTI_CR1_PCIS) >> 4);
  124. break;
  125. case EXTI_PORT_GPIOD:
  126. value = (uint8_t)((uint8_t)(EXTI->CR1 & EXTI_CR1_PDIS) >> 6);
  127. break;
  128. case EXTI_PORT_GPIOE:
  129. value = (uint8_t)(EXTI->CR2 & EXTI_CR2_PEIS);
  130. break;
  131. default:
  132. break;
  133. }
  134. return((EXTI_Sensitivity_TypeDef)value);
  135. }
  136. /**
  137. * @brief Get the TLI interrupt sensitivity.
  138. * @param None
  139. * @retval EXTI_TLISensitivity_TypeDef The TLI interrupt sensitivity read.
  140. */
  141. EXTI_TLISensitivity_TypeDef EXTI_GetTLISensitivity(void)
  142. {
  143. uint8_t value = 0;
  144. /* Get TLI interrupt sensitivity */
  145. value = (uint8_t)(EXTI->CR2 & EXTI_CR2_TLIS);
  146. return((EXTI_TLISensitivity_TypeDef)value);
  147. }
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/