HW_GPIO_ATY.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**
  2. * @file HW_GPIO_ATY.h
  3. *
  4. * @param Project DEVICE_GENERAL_ATY_LIB
  5. *
  6. * @author ATY
  7. *
  8. * @copyright
  9. * - Copyright 2017 - 2023 MZ-ATY
  10. * - This code follows:
  11. * - MZ-ATY Various Contents Joint Statement -
  12. * <a href="https://mengze.top/MZ-ATY_VCJS">
  13. * https://mengze.top/MZ-ATY_VCJS</a>
  14. * - CC 4.0 BY-NC-SA -
  15. * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
  16. * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
  17. * - Your use will be deemed to have accepted the terms of this statement.
  18. *
  19. * @brief Familiar definition of GPIO for users
  20. *
  21. * @version
  22. * - 1_01_220602 > ATY
  23. * -# Preliminary version, first Release
  24. * - Undone
  25. ********************************************************************************
  26. */
  27. #ifndef __HW_GPIO_ATY_H
  28. #define __HW_GPIO_ATY_H
  29. #include "INCLUDE_ATY.h"
  30. #if defined(__STC51_ATY)
  31. #define GPIO_SET_H(Port, Pin) Pin = 1
  32. #define GPIO_SET_L(Port, Pin) Pin = 0
  33. #define GPIO_GET_H(Port, Pin) Pin == 1
  34. #define GPIO_GET_L(Port, Pin) Pin == 0
  35. #define GPIO_SET_IN(Port, Pin) Pin = 1;__NOP_ATY;__NOP_ATY
  36. #define GPIO_SET_OUT(Port, Pin) Pin = 0
  37. #elif defined(__HC32_ATY)
  38. #define GPIO_SET_H(Port, Pin) Gpio_SetIO(Port, Pin)
  39. #define GPIO_SET_L(Port, Pin) Gpio_ClrIO(Port, Pin)
  40. #define GPIO_GET_H(Port, Pin) Gpio_GetInputIO(Port, Pin) == 1
  41. #define GPIO_GET_L(Port, Pin) Gpio_GetInputIO(Port, Pin) == 0
  42. #elif defined(__STM32_HAL_ATY)
  43. #define GPIO_SET_H(Port, Pin) HAL_GPIO_WritePin(Port, Pin, GPIO_PIN_SET)
  44. #define GPIO_SET_L(Port, Pin) HAL_GPIO_WritePin(Port, Pin, GPIO_PIN_RESET)
  45. #define GPIO_GET_H(Port, Pin) HAL_GPIO_ReadPin(Port, Pin) == GPIO_PIN_SET
  46. #define GPIO_GET_L(Port, Pin) HAL_GPIO_ReadPin(Port, Pin) == GPIO_PIN_RESET
  47. #define GPIO_SET_IN(Port, Pin) GPIO_SetIn(Port, Pin)
  48. #define GPIO_SET_OUT(Port, Pin) GPIO_SetOut(Port, Pin)
  49. #define GPIO_SetOut(GPIOx, GPIO_Pin) \
  50. { \
  51. GPIO_InitTypeDef GPIO_InitStruct; \
  52. __HAL_RCC_GPIOB_CLK_ENABLE(); \
  53. GPIO_InitStruct.Pin = GPIO_Pin; \
  54. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \
  55. GPIO_InitStruct.Pull = GPIO_NOPULL; \
  56. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; \
  57. HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); \
  58. }
  59. #define GPIO_SetIn(GPIOx, GPIO_Pin) \
  60. { \
  61. GPIO_InitTypeDef GPIO_InitStruct; \
  62. __HAL_RCC_GPIOB_CLK_ENABLE(); \
  63. GPIO_InitStruct.Pin = GPIO_Pin; \
  64. GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \
  65. GPIO_InitStruct.Pull = GPIO_NOPULL; \
  66. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; \
  67. HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); \
  68. }
  69. // void GPIO_SetIn(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  70. // void GPIO_SetOut(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  71. #endif /* PLATFORM */
  72. /******************************* For user *************************************/
  73. #if defined(__STC51_ATY)
  74. #ifdef __LED_ATY_H
  75. #ifndef SYSLED_PORT
  76. #define SYSLED_PORT 0
  77. #endif
  78. #ifndef SYSLED_PIN
  79. #define SYSLED_PIN P34
  80. #endif
  81. #endif /* __LED_ATY_H */
  82. #ifdef PW_PIN
  83. #define MCU_Off \
  84. do{ \
  85. /* power off directely */ \
  86. PW_PIN = 0; \
  87. }while(0)
  88. #endif /* PW_PIN */
  89. #ifndef __I2C_HARDWARE_ATY
  90. #define I2C_SCL_PORT 0
  91. #define I2C_SCL_PIN P32
  92. #define I2C_SDA_PORT 0
  93. #define I2C_SDA_PIN P33
  94. #endif /* __I2C_HARDWARE_ATY */
  95. // #ifdef __GP22_ATY_H
  96. #define GP22_RST_PORT 0
  97. #ifndef GP22_RST_PIN
  98. #define GP22_RST_PIN P11
  99. #endif
  100. #define GP22_CSN_PORT 0
  101. #ifndef GP22_CSN_PIN
  102. #define GP22_CSN_PIN P12
  103. #endif
  104. #define GP22_INT_PORT 0
  105. #ifndef GP22_INT_PIN
  106. #define GP22_INT_PIN P16
  107. #endif
  108. #define GP22_EN_PORT 0
  109. #ifndef GP22_EN_PIN
  110. #define GP22_EN_PIN P10
  111. #endif
  112. #define GP22_SIGNAL_PORT 0
  113. #ifndef GP22_SIGNAL_PIN
  114. #define GP22_SIGNAL_PIN 0
  115. #endif
  116. #define GP22_SCLK_PIN P15
  117. #define GP22_MISO_PIN P14
  118. #define GP22_MOSI_PIN P13
  119. // #endif /* __GP22_ATY_H */
  120. #ifdef __MOTOR_STEP_ATY_H
  121. #define MOTOR_EN_PORT 0
  122. #ifndef MOTOR_EN_PIN
  123. #define MOTOR_EN_PIN P24
  124. #endif
  125. #define MOTOR_DIR_PORT 0
  126. #define MOTOR_DIR_PIN P22
  127. #define MOTOR_STEP_PORT 0
  128. #define MOTOR_STEP_PIN P23
  129. #define MOTOR_DIAG_PORT 0
  130. #define MOTOR_DIAG_PIN P55
  131. #endif /* __MOTOR_STEP_ATY_H */
  132. #ifdef __MOTOR_DC_ATY_H
  133. #define MOTOR_A_PORT 0
  134. #ifndef MOTOR_A_PIN
  135. #define MOTOR_A_PIN P54
  136. #endif /* MOTOR_A_PIN */
  137. #define MOTOR_B_PORT 0
  138. #ifndef MOTOR_B_PIN
  139. #define MOTOR_B_PIN P17
  140. #endif /* MOTOR_B_PIN */
  141. #define MOTOR_EN_PORT 0
  142. #ifndef MOTOR_EN_PIN
  143. #define MOTOR_EN_PIN P17
  144. #endif /* MOTOR_EN_PIN */
  145. #endif /* __MOTOR_DC_ATY_H */
  146. #ifdef __WS2812_ATY_H
  147. #define WS2812_PORT 0
  148. #define WS2812_PIN P12
  149. #endif /* __WS2812_ATY_H */
  150. #elif defined(__STM32_HAL_ATY)
  151. #ifdef __LED_ATY_H
  152. #if !defined(SYSLED_PORT) && !defined(SYSLED_PIN)
  153. #define SYSLED_PORT SYSLED_O_GPIO_Port
  154. #define SYSLED_PIN SYSLED_O_Pin
  155. #endif /* SYSLED_PORT SYSLED_PIN */
  156. #endif /* __LED_ATY_H */
  157. #ifndef __I2C_HARDWARE_ATY
  158. #define I2C_SCL_PORT I2C_SCL_GPIO_Port
  159. #define I2C_SCL_PIN I2C_SCL_Pin
  160. #define I2C_SDA_PORT I2C_SDA_GPIO_Port
  161. #define I2C_SDA_PIN I2C_SDA_Pin
  162. #endif /* __I2C_HARDWARE_ATY */
  163. #ifdef __GP22_ATY_H
  164. #define GP22_SIGNAL_PORT SPI1_SIGNAL_GPIO_Port
  165. #define GP22_SIGNAL_PIN SPI1_SIGNAL_Pin
  166. #define GP22_CSN_PORT SPI1_CSN_GPIO_Port
  167. #define GP22_CSN_PIN SPI1_CSN_Pin
  168. #define GP22_RST_PORT SPI1_RST_GPIO_Port
  169. #define GP22_RST_PIN SPI1_RST_Pin
  170. #define GP22_INT_PORT SPI1_INT_GPIO_Port
  171. #define GP22_INT_PIN SPI1_INT_Pin
  172. #endif /* __GP22_ATY_H */
  173. #ifdef __MOTOR_STEP_ATY_H
  174. #define MOTOR_EN_PORT MOTOR_EN_GPIO_Port
  175. #define MOTOR_EN_PIN MOTOR_EN_Pin
  176. #define MOTOR_DIR_PORT MOTOR_DIR_GPIO_Port
  177. #define MOTOR_DIR_PIN MOTOR_DIR_Pin
  178. #define MOTOR_STEP_PORT MOTOR_STEP_GPIO_Port
  179. #define MOTOR_STEP_PIN MOTOR_STEP_Pin
  180. #define MOTOR_DIAG_PORT MOTOR_DIAG_GPIO_Port
  181. #define MOTOR_DIAG_PIN MOTOR_DIAG_Pin
  182. #endif /* __MOTOR_STEP_ATY_H */
  183. #endif /* PLATFORM */
  184. /******************************************************************************/
  185. #endif /* __HW_GPIO_ATY_H */
  186. /******************************** End Of File *********************************/