HW_GPIO_ATY.h 6.0 KB

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