interface.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #ifndef __INTERFACE_H
  2. #define __INTERFACE_H
  3. #include "includes.h"
  4. #include "stm32f4xx_rcc.h"
  5. #include <stm32f4xx.h>
  6. typedef enum
  7. {
  8. kI2C0 = 0,
  9. kI2C1,
  10. kI2C2,
  11. kADC0,
  12. kADC2,
  13. kSPI2,
  14. kUart1,
  15. kUart3,
  16. kCAN1,
  17. kCAN2,
  18. kEthernet,
  19. kInput,
  20. kOutput,
  21. kPMU,
  22. kDMA1,
  23. // kTIMER1,
  24. kInterfaceEnd,
  25. } interface_type;
  26. typedef struct
  27. {
  28. interface_type type;
  29. uint32_t AXBPeriph_Clock;
  30. } Gpio_Clock;
  31. typedef enum
  32. {
  33. kRunLed,
  34. kPRelayCtr,
  35. kNRelayCtr,
  36. kPreRelayCtr,
  37. kFanCtr,
  38. kOut1Ctr, // charger
  39. kOut2Ctr, // charger heat
  40. kExtWatchDog,
  41. kExtRelayLed,
  42. kExtFaultLed,
  43. kISOPRelayCtr,
  44. kISONRelayCtr,
  45. kSoftI2C3_SDA,
  46. kSoftI2C3_SCL,
  47. kSoftI2C4_SDA,
  48. kSoftI2C4_SCL,
  49. kOutputEnd,
  50. } Output_Type;
  51. typedef enum
  52. {
  53. kLDetect,
  54. kInputEnd,
  55. } Input_type;
  56. typedef struct
  57. {
  58. GPIO_TypeDef *GPIOx;
  59. INT32U GPIO_Pin;
  60. INT8U GPIO_AF;
  61. } GPIO_AF_Info;
  62. typedef struct
  63. {
  64. interface_type type;
  65. Output_Type Out_Type;
  66. Input_type In_Type;
  67. GPIO_TypeDef *GPIOx;
  68. INT32U GPIO_Pin;
  69. INT32U GPIO_Mode;
  70. GPIO_AF_Info AF_Info;
  71. INT8U GPIO_OType;
  72. INT32U GPIO_Speed;
  73. INT32U GPIO_PuPd;
  74. } Interface_struct;
  75. // typedef struct
  76. // {
  77. // interface_type type;
  78. // rcu_periph_enum AXBPeriph_Clock;
  79. // } Gpio_Clock;
  80. // // soft I2C
  81. // #define SI2C3_SDA_PIN GPIO_PIN_3
  82. // #define SI2C3_SDA_PORT GPIOD
  83. // #define SI2C3_SCL_PIN GPIO_PIN_2
  84. // #define SI2C3_SCL_PORT GPIOD
  85. // #define SI2C4_SDA_PIN GPIO_PIN_15
  86. // #define SI2C4_SDA_PORT GPIOE
  87. // #define SI2C4_SCL_PIN GPIO_PIN_14
  88. // #define SI2C4_SCL_PORT GPIOE
  89. // #define SI2C3_SDA_HIGH GPIO_SetBits(SI2C3_SDA_PORT, SI2C3_SDA_PIN)
  90. // #define SI2C3_SDA_LOW GPIO_ResetBits(SI2C3_SDA_PORT, SI2C3_SDA_PIN)
  91. // #define SI2C3_SCL_HIGH GPIO_SetBits(SI2C3_SCL_PORT, SI2C3_SCL_PIN)
  92. // #define SI2C3_SCL_LOW GPIO_ResetBits(SI2C3_SCL_PORT, SI2C3_SCL_PIN)
  93. // #define SI2C4_SDA_HIGH GPIO_SetBits(SI2C4_SDA_PORT, SI2C4_SDA_PIN)
  94. // #define SI2C4_SDA_LOW GPIO_ResetBits(SI2C4_SDA_PORT, SI2C4_SDA_PIN)
  95. // #define SI2C4_SCL_HIGH GPIO_SetBits(SI2C4_SCL_PORT, SI2C4_SCL_PIN)
  96. // #define SI2C4_SCL_LOW GPIO_ResetBits(SI2C4_SCL_PORT, SI2C4_SCL_PIN)
  97. // #define SI2C3_SDA_OUT gpio_mode_set(SI2C3_SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SI2C3_SDA_PIN)
  98. // #define SI2C3_SDA_IN gpio_mode_set(SI2C3_SDA_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SI2C3_SDA_PIN)
  99. // #define SI2C3_SDA_READ gpio_input_bit_get(SI2C3_SDA_PORT, SI2C3_SDA_PIN)
  100. // #define SI2C4_SDA_OUT gpio_mode_set(SI2C4_SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SI2C4_SDA_PIN)
  101. // #define SI2C4_SDA_IN gpio_mode_set(SI2C4_SDA_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SI2C4_SDA_PIN)
  102. // #define SI2C4_SDA_READ gpio_input_bit_get(SI2C4_SDA_PORT, SI2C4_SDA_PIN)
  103. // uart
  104. #define UART1_ENABLE_PORT GPIOA
  105. #define UART1_ENABLE_PIN GPIO_Pin_15
  106. // #define UART5_ENABLE_PORT GPIOE
  107. // #define UART5_ENABLE_PIN GPIO_PIN_6
  108. #define UART1_TX_ENABLE GPIO_SetBits(UART1_ENABLE_PORT, UART1_ENABLE_PIN)
  109. #define UART1_RX_ENABLE GPIO_ResetBits(UART1_ENABLE_PORT, UART1_ENABLE_PIN)
  110. // #define UART5_TX_ENABLE GPIO_SetBits(UART5_ENABLE_PORT, UART5_ENABLE_PIN)
  111. // #define UART5_RX_ENABLE GPIO_ResetBits(UART5_ENABLE_PORT, UART5_ENABLE_PIN)
  112. // // SPI
  113. // #define SPI2_CS_PORT GPIOA
  114. // #define SPI2_CS_PIN GPIO_PIN_15
  115. // #define SPI2_CS_HIGH GPIO_SetBits(SPI2_CS_PORT, SPI2_CS_PIN)
  116. // #define SPI2_CS_LOW GPIO_ResetBits(SPI2_CS_PORT, SPI2_CS_PIN)
  117. // // ethernet
  118. // //#define ENET_REF_CLK GPIO_PIN_1
  119. // //#define ENET_REF_CLK_Port GPIOA
  120. // //#define ENET_MDC GPIO_PIN_1
  121. // //#define ENET_MDC_Port GPIOC
  122. // //#define ENET_MDIO GPIO_PIN_2
  123. // //#define ENET_MDIO_Port GPIOA
  124. // //#define ENET_CRSDV GPIO_PIN_7
  125. // //#define ENET_CRSDV_Port GPIOA
  126. // //#define ENET_RXD0 GPIO_PIN_4
  127. // //#define ENET_RXD0_Port GPIOC
  128. // //#define ENET_RXD1 GPIO_PIN_5
  129. // //#define ENET_RXD1_Port GPIOC
  130. // //#define ENET_TXEN GPIO_PIN_11
  131. // //#define ENET_TXEN_Port GPIOG
  132. // //#define ENET_RXER GPIO_PIN_12
  133. // //#define ENET_RXER_Port GPIOG
  134. // //#define ENET_TXD0 GPIO_PIN_13
  135. // //#define ENET_TXD0_Port GPIOG
  136. // //#define ENET_TXD1 GPIO_PIN_14
  137. // //#define ENET_TXD1_Port GPIOG
  138. #define ETH_RESET_PORT GPIOH
  139. #define ETH_RESET_PIN GPIO_Pin_6
  140. // #define ETH_RXER_PORT GPIOG
  141. // #define ETH_RXER_PIN GPIO_PIN_12
  142. #define ETH_RESET_ON GPIO_ResetBits(ETH_RESET_PORT, ETH_RESET_PIN)
  143. #define ETH_RESET_OFF GPIO_SetBits(ETH_RESET_PORT, ETH_RESET_PIN)
  144. // output
  145. #define LED0_RUN_PORT GPIOC
  146. #define LED0_RUN_PIN GPIO_Pin_2
  147. #define LED1_RUN_PORT GPIOF
  148. #define LED1_RUN_PIN GPIO_Pin_7
  149. #define LED2_RUN_PORT GPIOF
  150. #define LED2_RUN_PIN GPIO_Pin_8
  151. #define LED3_RUN_PORT GPIOI
  152. #define LED3_RUN_PIN GPIO_Pin_10
  153. // #define PRelayCtr_PORT GPIOD
  154. // #define PRelayCtr_PIN GPIO_PIN_6
  155. // #define NRelayCtr_PORT GPIOD
  156. // #define NRelayCtr_PIN GPIO_PIN_5
  157. // #define PreRelayCtr_PORT GPIOG
  158. // #define PreRelayCtr_PIN GPIO_PIN_9
  159. // #define Fan_PORT GPIOG
  160. // #define Fan_PIN GPIO_PIN_10
  161. // #define OUT1CTR_PORT GPIOD
  162. // #define OUT1CTR_PIN GPIO_PIN_7
  163. // #define OUT2CTR_PORT GPIOE
  164. // #define OUT2CTR_PIN GPIO_PIN_1
  165. // #define EXTWATCHDOG_PORT GPIOC
  166. // #define EXTWATCHDOG_PIN GPIO_PIN_3
  167. // #define ExtRelayLed_PORT GPIOD
  168. // #define ExtRelayLed_PIN GPIO_PIN_11
  169. // #define ExtFaultLed_PORT GPIOD
  170. // #define ExtFaultLed_PIN GPIO_PIN_10
  171. // #define ISOPRelayCtr_PORT GPIOF
  172. // #define ISOPRelayCtr_PIN GPIO_PIN_14
  173. // #define ISONRelayCtr_PORT GPIOF
  174. // #define ISONRelayCtr_PIN GPIO_PIN_15
  175. // // input
  176. // #define LDetect1_PORT GPIOD
  177. // #define LDetect1_PIN GPIO_PIN_13
  178. // output operation
  179. #define LED0_RUN_ON GPIO_SetBits(LED0_RUN_PORT, LED0_RUN_PIN)
  180. #define LED0_RUN_OFF GPIO_ResetBits(LED0_RUN_PORT, LED0_RUN_PIN)
  181. #define LED0_RUN_TOGGLE GPIO_ToggleBits(LED0_RUN_PORT, LED0_RUN_PIN)
  182. #define LED1_RUN_ON GPIO_SetBits(LED1_RUN_PORT, LED1_RUN_PIN)
  183. #define LED1_RUN_OFF GPIO_ResetBits(LED1_RUN_PORT, LED1_RUN_PIN)
  184. #define LED1_RUN_TOGGLE GPIO_ToggleBits(LED1_RUN_PORT, LED1_RUN_PIN)
  185. #define LED2_RUN_ON GPIO_SetBits(LED2_RUN_PORT, LED2_RUN_PIN)
  186. #define LED2_RUN_OFF GPIO_ResetBits(LED2_RUN_PORT, LED2_RUN_PIN)
  187. #define LED2_RUN_TOGGLE GPIO_ToggleBits(LED2_RUN_PORT, LED2_RUN_PIN)
  188. #define LED3_RUN_ON GPIO_SetBits(LED3_RUN_PORT, LED3_RUN_PIN)
  189. #define LED3_RUN_OFF GPIO_ResetBits(LED3_RUN_PORT, LED3_RUN_PIN)
  190. #define LED3_RUN_TOGGLE GPIO_ToggleBits(LED3_RUN_PORT, LED3_RUN_PIN)
  191. // #define PRelayCtr_ON GPIO_SetBits(PRelayCtr_PORT, PRelayCtr_PIN)
  192. // #define PRelayCtr_OFF GPIO_ResetBits(PRelayCtr_PORT, PRelayCtr_PIN)
  193. // #define NRelayCtr_ON GPIO_SetBits(NRelayCtr_PORT, NRelayCtr_PIN)
  194. // #define NRelayCtr_OFF GPIO_ResetBits(NRelayCtr_PORT, NRelayCtr_PIN)
  195. // #define PreRelayCtr_ON GPIO_SetBits(PreRelayCtr_PORT, PreRelayCtr_PIN)
  196. // #define PreRelayCtr_OFF GPIO_ResetBits(PreRelayCtr_PORT, PreRelayCtr_PIN)
  197. // #define FAN_ON GPIO_SetBits(Fan_PORT, Fan_PIN)
  198. // #define FAN_OFF GPIO_ResetBits(Fan_PORT, Fan_PIN)
  199. // #define OUT1CTR_ON GPIO_SetBits(OUT1CTR_PORT, OUT1CTR_PIN)
  200. // #define OUT1CTR_OFF GPIO_ResetBits(OUT1CTR_PORT, OUT1CTR_PIN)
  201. // #define OUT2CTR_ON GPIO_SetBits(OUT2CTR_PORT, OUT2CTR_PIN)
  202. // #define OUT2CTR_OFF GPIO_ResetBits(OUT2CTR_PORT, OUT2CTR_PIN)
  203. // #define FEED_DOG_ON GPIO_SetBits(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN)
  204. // #define FEED_DOG_OFF GPIO_ResetBits(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN)
  205. // #define FEED_DOG_TOGGLE GPIO_WriteBit(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN, (FlagStatus)(1 - (gpio_output_bit_get(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN))))
  206. // #define ExtRelayLed_ON GPIO_SetBits(ExtRelayLed_PORT, ExtRelayLed_PIN)
  207. // #define ExtRelayLed_OFF GPIO_ResetBits(ExtRelayLed_PORT, ExtRelayLed_PIN)
  208. // #define ExtFaultLed_ON GPIO_SetBits(ExtFaultLed_PORT, ExtFaultLed_PIN)
  209. // #define ExtFaultLed_OFF GPIO_ResetBits(ExtFaultLed_PORT, ExtFaultLed_PIN)
  210. // #define ISOPRelay_ON GPIO_SetBits(ISOPRelayCtr_PORT, ISOPRelayCtr_PIN)
  211. // #define ISOPRelay_OFF GPIO_ResetBits(ISOPRelayCtr_PORT, ISOPRelayCtr_PIN)
  212. // #define ISONRelay_ON GPIO_SetBits(ISONRelayCtr_PORT, ISONRelayCtr_PIN)
  213. // #define ISONRelay_OFF GPIO_ResetBits(ISONRelayCtr_PORT, ISONRelayCtr_PIN)
  214. // // input result
  215. // #define L_IN1_IS_LOW (gpio_input_bit_get(LDetect1_PORT, LDetect1_PIN) == RESET)
  216. void interface_init(void);
  217. void gpio_clock_init(void);
  218. #endif