HW_GPIO_ATY.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 - 2025 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(Port, Pin) Pin
  34. #define GPIO_SET_IN(Port, Pin) Pin = 1;__NOP_ATY;__NOP_ATY
  35. #define GPIO_SET_OUT(Port, Pin) Pin = 0
  36. #elif defined(__HC32_ATY)
  37. #define GPIO_SET_H(Port, Pin) Gpio_SetIO(Port, Pin)
  38. #define GPIO_SET_L(Port, Pin) Gpio_ClrIO(Port, Pin)
  39. #define GPIO_GET(Port, Pin) ((Gpio_GetInputIO(Port, Pin) == 0) ? 0: 1)
  40. #elif defined(__STM32_HAL_ATY)
  41. #define GPIO_SET_H(Port, Pin) HAL_GPIO_WritePin(Port, Pin, GPIO_PIN_SET)
  42. #define GPIO_SET_L(Port, Pin) HAL_GPIO_WritePin(Port, Pin, GPIO_PIN_RESET)
  43. #define GPIO_GET(Port, Pin) ((HAL_GPIO_ReadPin(Port, Pin) == GPIO_PIN_RESET) ? 0: 1)
  44. #define GPIO_SET_IN(Port, Pin) GPIO_SetIn(Port, Pin)
  45. #define GPIO_SET_OUT(Port, Pin) GPIO_SetOut(Port, Pin)
  46. #define GPIO_SetOut(GPIOx, GPIO_Pin) \
  47. { \
  48. GPIO_InitTypeDef GPIO_InitStruct; \
  49. __HAL_RCC_GPIOB_CLK_ENABLE(); \
  50. GPIO_InitStruct.Pin = GPIO_Pin; \
  51. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \
  52. GPIO_InitStruct.Pull = GPIO_NOPULL; \
  53. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; \
  54. HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); \
  55. }
  56. #define GPIO_SetIn(GPIOx, GPIO_Pin) \
  57. { \
  58. GPIO_InitTypeDef GPIO_InitStruct; \
  59. __HAL_RCC_GPIOB_CLK_ENABLE(); \
  60. GPIO_InitStruct.Pin = GPIO_Pin; \
  61. GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \
  62. GPIO_InitStruct.Pull = GPIO_NOPULL; \
  63. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; \
  64. HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); \
  65. }
  66. // void GPIO_SetIn(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  67. // void GPIO_SetOut(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  68. #endif /* PLATFORM */
  69. /******************************* For user *************************************/
  70. #if defined (__STC51_ATY)
  71. #ifdef __LED_ATY_H
  72. #ifndef SYSLED_PORT
  73. #define SYSLED_PORT 0
  74. #endif
  75. #ifndef SYSLED_PIN
  76. #define SYSLED_PIN P34
  77. #endif
  78. #endif /* __LED_ATY_H */
  79. #ifdef PW_PIN
  80. #define MCU_Off \
  81. do{ \
  82. /* power off directely */ \
  83. PW_PIN = 0; \
  84. }while(0)
  85. #endif /* PW_PIN */
  86. #ifndef __I2C_HARDWARE_ATY
  87. #define I2C_SCL_PORT 0
  88. #define I2C_SCL_PIN P32
  89. #define I2C_SDA_PORT 0
  90. #define I2C_SDA_PIN P33
  91. #endif /* __I2C_HARDWARE_ATY */
  92. // #ifdef __GP22_ATY_H
  93. #define GP22_RST_PORT 0
  94. #ifndef GP22_RST_PIN
  95. #define GP22_RST_PIN P11
  96. #endif
  97. #define GP22_CSN_PORT 0
  98. #ifndef GP22_CSN_PIN
  99. #define GP22_CSN_PIN P12
  100. #endif
  101. #define GP22_INT_PORT 0
  102. #ifndef GP22_INT_PIN
  103. #define GP22_INT_PIN P16
  104. #endif
  105. #define GP22_EN_PORT 0
  106. #ifndef GP22_EN_PIN
  107. #define GP22_EN_PIN P10
  108. #endif
  109. #define GP22_SIGNAL_PORT 0
  110. #ifndef GP22_SIGNAL_PIN
  111. #define GP22_SIGNAL_PIN 0
  112. #endif
  113. #define GP22_SCLK_PIN P15
  114. #define GP22_MISO_PIN P14
  115. #define GP22_MOSI_PIN P13
  116. // #endif /* __GP22_ATY_H */
  117. #ifdef __MOTOR_DC_ATY_H
  118. #define MOTOR_A_PORT 0
  119. #ifndef MOTOR_A_PIN
  120. #define MOTOR_A_PIN P54
  121. #endif /* MOTOR_A_PIN */
  122. #define MOTOR_B_PORT 0
  123. #ifndef MOTOR_B_PIN
  124. #define MOTOR_B_PIN P17
  125. #endif /* MOTOR_B_PIN */
  126. #define MOTOR_EN_PORT 0
  127. #ifndef MOTOR_EN_PIN
  128. #define MOTOR_EN_PIN P17
  129. #endif /* MOTOR_EN_PIN */
  130. #endif /* __MOTOR_DC_ATY_H */
  131. #ifdef __WS2812_ATY_H
  132. #define WS2812_PORT 0
  133. #define WS2812_PIN P12
  134. #endif /* __WS2812_ATY_H */
  135. #elif defined(__STM32_HAL_ATY)
  136. #ifdef __LED_ATY_H
  137. #if !defined(SYSLED_PORT) && !defined(SYSLED_PIN)
  138. #define SYSLED_PORT SYSLED_GPIO_Port
  139. #define SYSLED_PIN SYSLED_Pin
  140. #endif /* SYSLED_PORT SYSLED_PIN */
  141. #endif /* __LED_ATY_H */
  142. #ifdef __TMC2209_ATY_H
  143. #define MOTOR_EN_PORT MO2_EN_GPIO_Port
  144. #define MOTOR_EN_PIN MO2_EN_Pin
  145. #define MOTOR_DIR_PORT MO2_DIR_GPIO_Port
  146. #define MOTOR_DIR_PIN MO2_DIR_Pin
  147. #define TMC2209_PORT MO2_STEP_GPIO_Port
  148. #define TMC2209_PIN MO2_STEP_Pin
  149. #define MOTOR_DIAG_PORT 0
  150. #define MOTOR_DIAG_PIN 0
  151. #endif /* __TMC2209_ATY_H */
  152. #ifndef __I2C_HARDWARE_ATY
  153. #define I2C_SCL_PORT I2C_SCL_GPIO_Port
  154. #define I2C_SCL_PIN I2C_SCL_Pin
  155. #define I2C_SDA_PORT I2C_SDA_GPIO_Port
  156. #define I2C_SDA_PIN I2C_SDA_Pin
  157. #endif /* __I2C_HARDWARE_ATY */
  158. #ifdef __GP22_ATY_H
  159. #define GP22_SIGNAL_PORT 0
  160. #define GP22_SIGNAL_PIN 0
  161. #define GP22_CSN_PORT TDC_CSN_GPIO_Port
  162. #define GP22_CSN_PIN TDC_CSN_Pin
  163. #define GP22_RST_PORT TDC_RST_GPIO_Port
  164. #define GP22_RST_PIN TDC_RST_Pin
  165. #define GP22_INT_PORT TDC_INT_GPIO_Port
  166. #define GP22_INT_PIN TDC_INT_Pin
  167. #endif /* __GP22_ATY_H */
  168. #endif /* PLATFORM */
  169. /******************************************************************************/
  170. #endif /* __HW_GPIO_ATY_H */
  171. /******************************** End Of File *********************************/