stm8l15x_gpio.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_gpio.h
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file contains all the functions prototypes for the GPIO firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM8L15x_GPIO_H
  30. #define __STM8L15x_GPIO_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup I2C
  37. * @{
  38. */
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @addtogroup GPIO_Exported_Types
  41. * @{
  42. */
  43. /**
  44. * @defgroup GPIO_Modes
  45. *
  46. * @brief
  47. *
  48. * Bits definitions:
  49. * - Bit 7: 0 = INPUT mode
  50. * 1 = OUTPUT mode
  51. * 1 = PULL-UP (input) or PUSH-PULL (output)
  52. * - Bit 5: 0 = No external interrupt (input) or No slope control (output)
  53. * 1 = External interrupt (input) or Slow control enabled (output)
  54. * - Bit 4: 0 = Low level (output)
  55. * 1 = High level (output push-pull) or HI-Z (output open-drain)
  56. * @{
  57. */
  58. typedef enum
  59. {
  60. GPIO_Mode_In_FL_No_IT = (uint8_t)0x00, /*!< Input floating, no external interrupt */
  61. GPIO_Mode_In_PU_No_IT = (uint8_t)0x40, /*!< Input pull-up, no external interrupt */
  62. GPIO_Mode_In_FL_IT = (uint8_t)0x20, /*!< Input floating, external interrupt */
  63. GPIO_Mode_In_PU_IT = (uint8_t)0x60, /*!< Input pull-up, external interrupt */
  64. GPIO_Mode_Out_OD_Low_Fast = (uint8_t)0xA0, /*!< Output open-drain, low level, 10MHz */
  65. GPIO_Mode_Out_PP_Low_Fast = (uint8_t)0xE0, /*!< Output push-pull, low level, 10MHz */
  66. GPIO_Mode_Out_OD_Low_Slow = (uint8_t)0x80, /*!< Output open-drain, low level, 2MHz */
  67. GPIO_Mode_Out_PP_Low_Slow = (uint8_t)0xC0, /*!< Output push-pull, low level, 2MHz */
  68. GPIO_Mode_Out_OD_HiZ_Fast = (uint8_t)0xB0, /*!< Output open-drain, high-impedance level, 10MHz */
  69. GPIO_Mode_Out_PP_High_Fast = (uint8_t)0xF0, /*!< Output push-pull, high level, 10MHz */
  70. GPIO_Mode_Out_OD_HiZ_Slow = (uint8_t)0x90, /*!< Output open-drain, high-impedance level, 2MHz */
  71. GPIO_Mode_Out_PP_High_Slow = (uint8_t)0xD0 /*!< Output push-pull, high level, 2MHz */
  72. }GPIO_Mode_TypeDef;
  73. /**
  74. * @}
  75. */
  76. /** @defgroup GPIO_Pin
  77. * @{
  78. */
  79. typedef enum
  80. {
  81. GPIO_Pin_0 = ((uint8_t)0x01), /*!< Pin 0 selected */
  82. GPIO_Pin_1 = ((uint8_t)0x02), /*!< Pin 1 selected */
  83. GPIO_Pin_2 = ((uint8_t)0x04), /*!< Pin 2 selected */
  84. GPIO_Pin_3 = ((uint8_t)0x08), /*!< Pin 3 selected */
  85. GPIO_Pin_4 = ((uint8_t)0x10), /*!< Pin 4 selected */
  86. GPIO_Pin_5 = ((uint8_t)0x20), /*!< Pin 5 selected */
  87. GPIO_Pin_6 = ((uint8_t)0x40), /*!< Pin 6 selected */
  88. GPIO_Pin_7 = ((uint8_t)0x80), /*!< Pin 7 selected */
  89. GPIO_Pin_LNib = ((uint8_t)0x0F), /*!< Low nibble pins selected */
  90. GPIO_Pin_HNib = ((uint8_t)0xF0), /*!< High nibble pins selected */
  91. GPIO_Pin_All = ((uint8_t)0xFF) /*!< All pins selected */
  92. }GPIO_Pin_TypeDef;
  93. /**
  94. * @}
  95. */
  96. /**
  97. * @}
  98. */
  99. /* Exported constants --------------------------------------------------------*/
  100. /* Exported macros -----------------------------------------------------------*/
  101. /** @addtogroup GPIO_Exported_Macros
  102. * @{
  103. */
  104. /**
  105. * @brief Macro used by the assert function to check the different functions parameters.
  106. */
  107. /**
  108. * @brief Macro used by the assert function in order to check the different
  109. * values of GPIOMode_TypeDef.
  110. */
  111. #define IS_GPIO_MODE(MODE) \
  112. (((MODE) == GPIO_Mode_In_FL_No_IT) || \
  113. ((MODE) == GPIO_Mode_In_PU_No_IT) || \
  114. ((MODE) == GPIO_Mode_In_FL_IT) || \
  115. ((MODE) == GPIO_Mode_In_PU_IT) || \
  116. ((MODE) == GPIO_Mode_Out_OD_Low_Fast) || \
  117. ((MODE) == GPIO_Mode_Out_PP_Low_Fast) || \
  118. ((MODE) == GPIO_Mode_Out_OD_Low_Slow) || \
  119. ((MODE) == GPIO_Mode_Out_PP_Low_Slow) || \
  120. ((MODE) == GPIO_Mode_Out_OD_HiZ_Fast) || \
  121. ((MODE) == GPIO_Mode_Out_PP_High_Fast) || \
  122. ((MODE) == GPIO_Mode_Out_OD_HiZ_Slow) || \
  123. ((MODE) == GPIO_Mode_Out_PP_High_Slow))
  124. /**
  125. * @brief Macro used by the assert function in order to check the different
  126. * values of GPIO_Pins.
  127. */
  128. #define IS_GPIO_PIN(PIN) ((PIN) != (uint8_t)0x00)
  129. /**
  130. * @}
  131. */
  132. /* Exported functions ------------------------------------------------------- */
  133. /* Initialization and Configuration *******************************************/
  134. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  135. void GPIO_Init(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode);
  136. void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin, FunctionalState NewState);
  137. /* GPIO Read and Write ********************************************************/
  138. void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t GPIO_PortVal);
  139. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal);
  140. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin);
  141. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin);
  142. void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin);
  143. uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  144. uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  145. BitStatus GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  146. BitStatus GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
  147. #endif /* __STM8L15x_GPIO_H */
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/