ch32v00X_gpio.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v00X_gpio.h
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2024/01/01
  6. * Description : This file contains all the functions prototypes for the
  7. * GPIO firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V00X_GPIO_H
  14. #define __CH32V00X_GPIO_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <ch32v00X.h>
  19. /* Output Maximum frequency selection */
  20. typedef enum
  21. {
  22. GPIO_Speed_30MHz = 1,
  23. } GPIOSpeed_TypeDef;
  24. /* Configuration Mode enumeration */
  25. typedef enum
  26. {
  27. GPIO_Mode_AIN = 0x0,
  28. GPIO_Mode_IN_FLOATING = 0x04,
  29. GPIO_Mode_IPD = 0x28,
  30. GPIO_Mode_IPU = 0x48,
  31. GPIO_Mode_Out_OD = 0x14,
  32. GPIO_Mode_Out_PP = 0x10,
  33. GPIO_Mode_AF_OD = 0x1C,
  34. GPIO_Mode_AF_PP = 0x18
  35. } GPIOMode_TypeDef;
  36. /* GPIO Init structure definition */
  37. typedef struct
  38. {
  39. uint16_t GPIO_Pin; /* Specifies the GPIO pins to be configured.
  40. This parameter can be any value of @ref GPIO_pins_define */
  41. GPIOSpeed_TypeDef GPIO_Speed; /* Specifies the speed for the selected pins.
  42. This parameter can be a value of @ref GPIOSpeed_TypeDef */
  43. GPIOMode_TypeDef GPIO_Mode; /* Specifies the operating mode for the selected pins.
  44. This parameter can be a value of @ref GPIOMode_TypeDef */
  45. } GPIO_InitTypeDef;
  46. /* Bit_SET and Bit_RESET enumeration */
  47. typedef enum
  48. {
  49. Bit_RESET = 0,
  50. Bit_SET
  51. } BitAction;
  52. /* GPIO_pins_define */
  53. #define GPIO_Pin_0 ((uint16_t)0x0001) /* Pin 0 selected */
  54. #define GPIO_Pin_1 ((uint16_t)0x0002) /* Pin 1 selected */
  55. #define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */
  56. #define GPIO_Pin_3 ((uint16_t)0x0008) /* Pin 3 selected */
  57. #define GPIO_Pin_4 ((uint16_t)0x0010) /* Pin 4 selected */
  58. #define GPIO_Pin_5 ((uint16_t)0x0020) /* Pin 5 selected */
  59. #define GPIO_Pin_6 ((uint16_t)0x0040) /* Pin 6 selected */
  60. #define GPIO_Pin_7 ((uint16_t)0x0080) /* Pin 7 selected */
  61. #define GPIO_Pin_All ((uint16_t)0x00FF) /* All pins selected */
  62. /* GPIO_Remap_define */
  63. #define GPIO_PartialRemap1_SPI1 ((uint32_t)0x08100001) /* SPI1 Partial Alternate Function mapping */
  64. #define GPIO_PartialRemap2_SPI1 ((uint32_t)0x08100002) /* SPI1 Partia2 Alternate Function mapping */
  65. #define GPIO_PartialRemap3_SPI1 ((uint32_t)0x08100003) /* SPI1 Partia3 Alternate Function mapping */
  66. #define GPIO_PartialRemap4_SPI1 ((uint32_t)0x08100004) /* SPI1 Partia4 Alternate Function mapping */
  67. #define GPIO_PartialRemap5_SPI1 ((uint32_t)0x08100005) /* SPI1 Partia5 Alternate Function mapping */
  68. #define GPIO_FullRemap_SPI1 ((uint32_t)0x08100006) /* SPI1 Full Alternate Function mapping */
  69. #define GPIO_PartialRemap1_I2C1 ((uint32_t)0x08130008) /* I2C1 Partia1 Alternate Function mapping */
  70. #define GPIO_PartialRemap2_I2C1 ((uint32_t)0x08130010) /* I2C1 Partia2 Alternate Function mapping */
  71. #define GPIO_PartialRemap3_I2C1 ((uint32_t)0x08130018) /* I2C1 Partia3 Alternate Function mapping */
  72. #define GPIO_FullRemap4_I2C1 ((uint32_t)0x08130020) /* I2C1 Full Alternate Function mapping */
  73. #define GPIO_PartialRemap1_USART1 ((uint32_t)0x00160040) /* USART1 Partial1 Alternate Function mapping */
  74. #define GPIO_PartialRemap2_USART1 ((uint32_t)0x00160080) /* USART1 Partial2 Alternate Function mapping */
  75. #define GPIO_PartialRemap3_USART1 ((uint32_t)0x001600C0) /* USART1 Partial3 Alternate Function mapping */
  76. #define GPIO_PartialRemap4_USART1 ((uint32_t)0x00160100) /* USART1 Partial4 Alternate Function mapping */
  77. #define GPIO_PartialRemap5_USART1 ((uint32_t)0x00160140) /* USART1 Partial5 Alternate Function mapping */
  78. #define GPIO_PartialRemap6_USART1 ((uint32_t)0x00160180) /* USART1 Partial6 Alternate Function mapping */
  79. #define GPIO_PartialRemap7_USART1 ((uint32_t)0x001601C0) /* USART1 Partial7 Alternate Function mapping */
  80. #define GPIO_PartialRemap8_USART1 ((uint32_t)0x00160200) /* USART1 Partial8 Alternate Function mapping */
  81. #define GPIO_FullRemap_USART1 ((uint32_t)0x00160240) /* USART1 Full Alternate Function mapping */
  82. #define GPIO_PartialRemap1_TIM1 ((uint32_t)0x001A0400) /* TIM1 Partial1 Alternate Function mapping */
  83. #define GPIO_PartialRemap2_TIM1 ((uint32_t)0x001A0800) /* TIM1 Partial2 Alternate Function mapping */
  84. #define GPIO_PartialRemap3_TIM1 ((uint32_t)0x001A0C00) /* TIM1 Partial3 Alternate Function mapping */
  85. #define GPIO_PartialRemap4_TIM1 ((uint32_t)0x001A1000) /* TIM1 Partial4 Alternate Function mapping */
  86. #define GPIO_PartialRemap5_TIM1 ((uint32_t)0x001A1400) /* TIM1 Partial5 Alternate Function mapping */
  87. #define GPIO_PartialRemap6_TIM1 ((uint32_t)0x001A1800) /* TIM1 Partial6 Alternate Function mapping */
  88. #define GPIO_PartialRemap7_TIM1 ((uint32_t)0x001A1C00) /* TIM1 Partial7 Alternate Function mapping */
  89. #define GPIO_PartialRemap8_TIM1 ((uint32_t)0x001A2000) /* TIM1 Partial8 Alternate Function mapping */
  90. #define GPIO_FullRemap_TIM1 ((uint32_t)0x001A2400) /* TIM1 Full Alternate Function mapping */
  91. #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x084E0001) /* TIM2 Partial1 Alternate Function mapping */
  92. #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x084E0002) /* TIM2 Partial2 Alternate Function mapping */
  93. #define GPIO_PartialRemap3_TIM2 ((uint32_t)0x084E0003) /* TIM2 Partial3 Alternate Function mapping */
  94. #define GPIO_PartialRemap4_TIM2 ((uint32_t)0x084E0004) /* TIM2 Partial4 Alternate Function mapping */
  95. #define GPIO_PartialRemap5_TIM2 ((uint32_t)0x084E0005) /* TIM2 Partial5 Alternate Function mapping */
  96. #define GPIO_PartialRemap6_TIM2 ((uint32_t)0x084E0006) /* TIM2 Partial6 Alternate Function mapping */
  97. #define GPIO_FullRemap_TIM2 ((uint32_t)0x084E0007) /* TIM2 Full Alternate Function mapping */
  98. #define GPIO_Remap_PA1_2 ((uint32_t)0x00200002) /* PA1 and PA2 Alternate Function mapping */
  99. #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200004) /* ADC1 External Trigger Injected Conversion remapping */
  100. #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200008) /* ADC1 External Trigger Regular Conversion remapping */
  101. #define GPIO_PartialRemap1_USART2 ((uint32_t)0x08240010) /* USART2 Partial1 Alternate Function mapping */
  102. #define GPIO_PartialRemap2_USART2 ((uint32_t)0x08240020) /* USART2 Partial2 Alternate Function mapping */
  103. #define GPIO_PartialRemap3_USART2 ((uint32_t)0x08240030) /* USART2 Partial3 Alternate Function mapping */
  104. #define GPIO_PartialRemap4_USART2 ((uint32_t)0x08240040) /* USART2 Partial4 Alternate Function mapping */
  105. #define GPIO_PartialRemap5_USART2 ((uint32_t)0x08240050) /* USART2 Partial5 Alternate Function mapping */
  106. #define GPIO_FullRemap_USART2 ((uint32_t)0x08240060) /* USART2 Full Alternate Function mapping */
  107. #define GPIO_Remap_LSI_CAL ((uint32_t)0x00200080) /* LSI calibration Alternate Function mapping */
  108. #define GPIO_Remap_SDI_Disable ((uint32_t)0x08300400) /* SDI Disabled */
  109. /* GPIO_Port_Sources */
  110. #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
  111. #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
  112. #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
  113. #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
  114. /* GPIO_Pin_sources */
  115. #define GPIO_PinSource0 ((uint8_t)0x00)
  116. #define GPIO_PinSource1 ((uint8_t)0x01)
  117. #define GPIO_PinSource2 ((uint8_t)0x02)
  118. #define GPIO_PinSource3 ((uint8_t)0x03)
  119. #define GPIO_PinSource4 ((uint8_t)0x04)
  120. #define GPIO_PinSource5 ((uint8_t)0x05)
  121. #define GPIO_PinSource6 ((uint8_t)0x06)
  122. #define GPIO_PinSource7 ((uint8_t)0x07)
  123. void GPIO_DeInit(GPIO_TypeDef *GPIOx);
  124. void GPIO_AFIODeInit(void);
  125. void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_InitStruct);
  126. void GPIO_StructInit(GPIO_InitTypeDef *GPIO_InitStruct);
  127. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  128. uint16_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx);
  129. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  130. uint16_t GPIO_ReadOutputData(GPIO_TypeDef *GPIOx);
  131. void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  132. void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  133. void GPIO_WriteBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  134. void GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t PortVal);
  135. void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
  136. void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  137. void GPIO_EventOutputCmd(FunctionalState NewState);
  138. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
  139. void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  140. void GPIO_IPD_Unused(void);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* __CH32V00X_GPIO_H */