stm8s_gpio.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_gpio.h
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief This file contains all functions prototype and macros for the GPIO 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. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM8S_GPIO_H
  29. #define __STM8S_GPIO_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /* Exported variables ------------------------------------------------------- */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @addtogroup GPIO_Exported_Types
  35. * @{
  36. */
  37. /**
  38. * @brief GPIO modes
  39. *
  40. * Bits definitions:
  41. * - Bit 7: 0 = INPUT mode
  42. * 1 = OUTPUT mode
  43. * 1 = PULL-UP (input) or PUSH-PULL (output)
  44. * - Bit 5: 0 = No external interrupt (input) or No slope control (output)
  45. * 1 = External interrupt (input) or Slow control enabled (output)
  46. * - Bit 4: 0 = Low level (output)
  47. * 1 = High level (output push-pull) or HI-Z (output open-drain)
  48. */
  49. typedef enum
  50. {
  51. GPIO_MODE_IN_FL_NO_IT = (uint8_t)0x00, /*!< Input floating, no external interrupt */
  52. GPIO_MODE_IN_PU_NO_IT = (uint8_t)0x40, /*!< Input pull-up, no external interrupt */
  53. GPIO_MODE_IN_FL_IT = (uint8_t)0x20, /*!< Input floating, external interrupt */
  54. GPIO_MODE_IN_PU_IT = (uint8_t)0x60, /*!< Input pull-up, external interrupt */
  55. GPIO_MODE_OUT_OD_LOW_FAST = (uint8_t)0xA0, /*!< Output open-drain, low level, 10MHz */
  56. GPIO_MODE_OUT_PP_LOW_FAST = (uint8_t)0xE0, /*!< Output push-pull, low level, 10MHz */
  57. GPIO_MODE_OUT_OD_LOW_SLOW = (uint8_t)0x80, /*!< Output open-drain, low level, 2MHz */
  58. GPIO_MODE_OUT_PP_LOW_SLOW = (uint8_t)0xC0, /*!< Output push-pull, low level, 2MHz */
  59. GPIO_MODE_OUT_OD_HIZ_FAST = (uint8_t)0xB0, /*!< Output open-drain, high-impedance level,10MHz */
  60. GPIO_MODE_OUT_PP_HIGH_FAST = (uint8_t)0xF0, /*!< Output push-pull, high level, 10MHz */
  61. GPIO_MODE_OUT_OD_HIZ_SLOW = (uint8_t)0x90, /*!< Output open-drain, high-impedance level, 2MHz */
  62. GPIO_MODE_OUT_PP_HIGH_SLOW = (uint8_t)0xD0 /*!< Output push-pull, high level, 2MHz */
  63. }GPIO_Mode_TypeDef;
  64. /**
  65. * @brief Definition of the GPIO pins. Used by the @ref GPIO_Init function in
  66. * order to select the pins to be initialized.
  67. */
  68. typedef enum
  69. {
  70. GPIO_PIN_0 = ((uint8_t)0x01), /*!< Pin 0 selected */
  71. GPIO_PIN_1 = ((uint8_t)0x02), /*!< Pin 1 selected */
  72. GPIO_PIN_2 = ((uint8_t)0x04), /*!< Pin 2 selected */
  73. GPIO_PIN_3 = ((uint8_t)0x08), /*!< Pin 3 selected */
  74. GPIO_PIN_4 = ((uint8_t)0x10), /*!< Pin 4 selected */
  75. GPIO_PIN_5 = ((uint8_t)0x20), /*!< Pin 5 selected */
  76. GPIO_PIN_6 = ((uint8_t)0x40), /*!< Pin 6 selected */
  77. GPIO_PIN_7 = ((uint8_t)0x80), /*!< Pin 7 selected */
  78. GPIO_PIN_LNIB = ((uint8_t)0x0F), /*!< Low nibble pins selected */
  79. GPIO_PIN_HNIB = ((uint8_t)0xF0), /*!< High nibble pins selected */
  80. GPIO_PIN_ALL = ((uint8_t)0xFF) /*!< All pins selected */
  81. }GPIO_Pin_TypeDef;
  82. /**
  83. * @}
  84. */
  85. /* Exported constants --------------------------------------------------------*/
  86. /* Exported macros -----------------------------------------------------------*/
  87. /* Private macros ------------------------------------------------------------*/
  88. /** @addtogroup GPIO_Private_Macros
  89. * @{
  90. */
  91. /**
  92. * @brief Macro used by the assert function to check the different functions parameters.
  93. */
  94. /**
  95. * @brief Macro used by the assert function in order to check the different
  96. * values of GPIOMode_TypeDef.
  97. */
  98. #define IS_GPIO_MODE_OK(MODE) \
  99. (((MODE) == GPIO_MODE_IN_FL_NO_IT) || \
  100. ((MODE) == GPIO_MODE_IN_PU_NO_IT) || \
  101. ((MODE) == GPIO_MODE_IN_FL_IT) || \
  102. ((MODE) == GPIO_MODE_IN_PU_IT) || \
  103. ((MODE) == GPIO_MODE_OUT_OD_LOW_FAST) || \
  104. ((MODE) == GPIO_MODE_OUT_PP_LOW_FAST) || \
  105. ((MODE) == GPIO_MODE_OUT_OD_LOW_SLOW) || \
  106. ((MODE) == GPIO_MODE_OUT_PP_LOW_SLOW) || \
  107. ((MODE) == GPIO_MODE_OUT_OD_HIZ_FAST) || \
  108. ((MODE) == GPIO_MODE_OUT_PP_HIGH_FAST) || \
  109. ((MODE) == GPIO_MODE_OUT_OD_HIZ_SLOW) || \
  110. ((MODE) == GPIO_MODE_OUT_PP_HIGH_SLOW))
  111. /**
  112. * @brief Macro used by the assert function in order to check the different
  113. * values of GPIO_Pins.
  114. */
  115. #define IS_GPIO_PIN_OK(PIN) ((PIN) != (uint8_t)0x00)
  116. /**
  117. * @}
  118. */
  119. /* Exported functions ------------------------------------------------------- */
  120. /** @addtogroup GPIO_Exported_Functions
  121. * @{
  122. */
  123. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  124. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode);
  125. void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t PortVal);
  126. void GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);
  127. void GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);
  128. void GPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);
  129. uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  130. uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  131. BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  132. void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState);
  133. /**
  134. * @}
  135. */
  136. #endif /* __STM8L_GPIO_H */
  137. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/