HW_GPIO_ATY.h 6.2 KB

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