apm32f0xx_gpio.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*!
  2. * @file apm32f0xx_gpio.h
  3. *
  4. * @brief This file contains all the functions prototypes for the GPIO firmware library
  5. *
  6. * @version V1.0.3
  7. *
  8. * @date 2022-09-20
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F0XX_GPIO_H
  27. #define __APM32F0XX_GPIO_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f0xx.h"
  33. /** @addtogroup APM32F0xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup GPIO_Driver
  37. @{
  38. */
  39. /** @defgroup GPIO_Macros Macros
  40. @{
  41. */
  42. /**@} end of group GPIO_Macros */
  43. /** @defgroup GPIO_Enumerations Enumerations
  44. @{
  45. */
  46. /**
  47. * @brief Configuration Mode enumeration
  48. */
  49. typedef enum
  50. {
  51. GPIO_MODE_IN = 0x00, /*!< GPIO Input Mode */
  52. GPIO_MODE_OUT = 0x01, /*!< GPIO Output Mode */
  53. GPIO_MODE_AF = 0x02, /*!< GPIO Alternate function Mode */
  54. GPIO_MODE_AN = 0x03, /*!< GPIO Analog In/Out Mode */
  55. } GPIO_MODE_T;
  56. /**
  57. * @brief Output type enumeration
  58. */
  59. typedef enum
  60. {
  61. GPIO_OUT_TYPE_PP = 0x00, /*!< General purpose output push-pull */
  62. GPIO_OUT_TYPE_OD = 0x01, /*!< General purpose output Open-drain */
  63. } GPIO_OUT_TYPE_T;
  64. /**
  65. * @brief GPIO Output Maximum frequency selection
  66. */
  67. typedef enum
  68. {
  69. GPIO_SPEED_2MHz = 0x00, /*!< Output speed up to 2 MHz */
  70. GPIO_SPEED_10MHz = 0x01, /*!< Output speed up to 10 MHz */
  71. GPIO_SPEED_50MHz = 0x03, /*!< Output speed up to 50 MHz */
  72. } GPIO_SPEED_T;
  73. /**
  74. * @brief Configuration Pull-Up Pull-Down enumeration
  75. */
  76. typedef enum
  77. {
  78. GPIO_PUPD_NO = 0x00, /*!< GPIO no pull mode */
  79. GPIO_PUPD_PU = 0x01, /*!< GPIO pull-up mode */
  80. GPIO_PUPD_PD = 0x02, /*!< GPIO pull-down mode */
  81. } GPIO_PUPD_T;
  82. /**
  83. * @brief Bit SET and Bit RESET enumeration
  84. */
  85. typedef enum
  86. {
  87. Bit_RESET,
  88. Bit_SET
  89. } GPIO_BSRET_T;
  90. /**
  91. * @brief Definition of the GPIO pins
  92. */
  93. typedef enum
  94. {
  95. GPIO_PIN_0 = ((uint16_t)BIT0), /*!< GPIO pin 0 selected */
  96. GPIO_PIN_1 = ((uint16_t)BIT1), /*!< GPIO pin 1 selected */
  97. GPIO_PIN_2 = ((uint16_t)BIT2), /*!< GPIO pin 2 selected */
  98. GPIO_PIN_3 = ((uint16_t)BIT3), /*!< GPIO pin 3 selected */
  99. GPIO_PIN_4 = ((uint16_t)BIT4), /*!< GPIO pin 4 selected */
  100. GPIO_PIN_5 = ((uint16_t)BIT5), /*!< GPIO pin 5 selected */
  101. GPIO_PIN_6 = ((uint16_t)BIT6), /*!< GPIO pin 6 selected */
  102. GPIO_PIN_7 = ((uint16_t)BIT7), /*!< GPIO pin 7 selected */
  103. GPIO_PIN_8 = ((uint16_t)BIT8), /*!< GPIO pin 8 selected */
  104. GPIO_PIN_9 = ((uint16_t)BIT9), /*!< GPIO pin 9 selected */
  105. GPIO_PIN_10 = ((uint16_t)BIT10), /*!< GPIO pin 10 selected */
  106. GPIO_PIN_11 = ((uint16_t)BIT11), /*!< GPIO pin 11 selected */
  107. GPIO_PIN_12 = ((uint16_t)BIT12), /*!< GPIO pin 12 selected */
  108. GPIO_PIN_13 = ((uint16_t)BIT13), /*!< GPIO pin 13 selected */
  109. GPIO_PIN_14 = ((uint16_t)BIT14), /*!< GPIO pin 14 selected */
  110. GPIO_PIN_15 = ((uint16_t)BIT15), /*!< GPIO pin 15 selected */
  111. GPIO_PIN_ALL = ((uint32_t)0XFFFF), /*!< GPIO all pins selected */
  112. } GPIO_PIN_T;
  113. /**
  114. * @brief GPIO Pin sources
  115. */
  116. typedef enum
  117. {
  118. GPIO_PIN_SOURCE_0 = ((uint8_t)0x00), /*!< GPIO pin source 0 */
  119. GPIO_PIN_SOURCE_1 = ((uint8_t)0x01), /*!< GPIO pin source 1 */
  120. GPIO_PIN_SOURCE_2 = ((uint8_t)0x02), /*!< GPIO pin source 2 */
  121. GPIO_PIN_SOURCE_3 = ((uint8_t)0x03), /*!< GPIO pin source 3 */
  122. GPIO_PIN_SOURCE_4 = ((uint8_t)0x04), /*!< GPIO pin source 4 */
  123. GPIO_PIN_SOURCE_5 = ((uint8_t)0x05), /*!< GPIO pin source 5 */
  124. GPIO_PIN_SOURCE_6 = ((uint8_t)0x06), /*!< GPIO pin source 6 */
  125. GPIO_PIN_SOURCE_7 = ((uint8_t)0x07), /*!< GPIO pin source 7 */
  126. GPIO_PIN_SOURCE_8 = ((uint8_t)0x08), /*!< GPIO pin source 8 */
  127. GPIO_PIN_SOURCE_9 = ((uint8_t)0x09), /*!< GPIO pin source 9 */
  128. GPIO_PIN_SOURCE_10 = ((uint8_t)0x0A), /*!< GPIO pin source 10 */
  129. GPIO_PIN_SOURCE_11 = ((uint8_t)0x0B), /*!< GPIO pin source 11 */
  130. GPIO_PIN_SOURCE_12 = ((uint8_t)0x0C), /*!< GPIO pin source 12 */
  131. GPIO_PIN_SOURCE_13 = ((uint8_t)0x0D), /*!< GPIO pin source 13 */
  132. GPIO_PIN_SOURCE_14 = ((uint8_t)0x0E), /*!< GPIO pin source 14 */
  133. GPIO_PIN_SOURCE_15 = ((uint8_t)0x0F), /*!< GPIO pin source 15 */
  134. } GPIO_PIN_SOURCE_T;
  135. /**
  136. * @brief gpio alternate function define
  137. */
  138. typedef enum
  139. {
  140. GPIO_AF_PIN0 = ((uint8_t)0x00), /*!< GPIO alternate function pin 0 */
  141. GPIO_AF_PIN1 = ((uint8_t)0x01), /*!< GPIO alternate function pin 1 */
  142. GPIO_AF_PIN2 = ((uint8_t)0x02), /*!< GPIO alternate function pin 2 */
  143. GPIO_AF_PIN3 = ((uint8_t)0x03), /*!< GPIO alternate function pin 3 */
  144. GPIO_AF_PIN4 = ((uint8_t)0x04), /*!< GPIO alternate function pin 4 */
  145. GPIO_AF_PIN5 = ((uint8_t)0x05), /*!< GPIO alternate function pin 5 */
  146. GPIO_AF_PIN6 = ((uint8_t)0x06), /*!< GPIO alternate function pin 6 */
  147. GPIO_AF_PIN7 = ((uint8_t)0x07), /*!< GPIO alternate function pin 7 */
  148. } GPIO_AF_T;
  149. /**@} end of group GPIO_Enumerations */
  150. /** @defgroup GPIO_Structures Structures
  151. @{
  152. */
  153. /**
  154. * @brief GPIO Config structure definition
  155. */
  156. typedef struct
  157. {
  158. uint16_t pin; /*!< Specifies the GPIO pins to be configured */
  159. GPIO_MODE_T mode; /*!< Specifies the operating mode for the selected pins */
  160. GPIO_OUT_TYPE_T outtype; /*!< Specifies the speed for the selected pins */
  161. GPIO_SPEED_T speed; /*!< Specifies the operating output type for the selected pins */
  162. GPIO_PUPD_T pupd; /*!< Specifies the operating Pull-up/Pull down for the selected pins */
  163. } GPIO_Config_T;
  164. /**@} end of group GPIO_Structures */
  165. /** @defgroup GPIO_Variables Variables
  166. @{
  167. */
  168. /**@} end of group GPIO_Variables*/
  169. /** @defgroup GPIO_Functions Functions
  170. @{
  171. */
  172. /* Reset and common Configuration */
  173. void GPIO_Reset(GPIO_T* port);
  174. void GPIO_Config(GPIO_T* port, GPIO_Config_T* gpioConfig);
  175. void GPIO_ConfigStructInit(GPIO_Config_T* gpioConfig);
  176. /* GPIO Lock functions */
  177. void GPIO_ConfigPinLock(GPIO_T* port, uint16_t pin);
  178. /* GPIO Read functions */
  179. uint16_t GPIO_ReadOutputPort(GPIO_T* port);
  180. uint16_t GPIO_ReadInputPort(GPIO_T* port);
  181. uint8_t GPIO_ReadInputBit(GPIO_T* port, uint16_t pin);
  182. uint8_t GPIO_ReadOutputBit(GPIO_T* port, uint16_t pin);
  183. /* GPIO Write functions */
  184. void GPIO_SetBit(GPIO_T* port, uint16_t pin);
  185. void GPIO_ClearBit(GPIO_T* port, uint16_t pin);
  186. void GPIO_WriteBitValue(GPIO_T* port, uint16_t pin, GPIO_BSRET_T bitVal);
  187. void GPIO_WriteOutputPort(GPIO_T* port, uint16_t portValue);
  188. /* GPIO Other functions */
  189. void GPIO_ConfigPinAF(GPIO_T* port, GPIO_PIN_SOURCE_T pinSource, GPIO_AF_T afPin);
  190. #ifdef __cplusplus
  191. }
  192. #endif
  193. #endif /* __APM32F0xx_GPIO_H */
  194. /**@} end of group GPIO_Functions */
  195. /**@} end of group GPIO_Driver */
  196. /**@} end of group APM32F0xx_StdPeriphDriver */