interface.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_dm9101,
  19. kEthernet_dm9k,
  20. kInput,
  21. kOutput,
  22. kPMU,
  23. kDMA1,
  24. // kTIMER1,
  25. kInterfaceEnd,
  26. } interface_type;
  27. typedef enum
  28. {
  29. RCC_APB1Periph,
  30. RCC_APB2Periph,
  31. RCC_AHB1Periph,
  32. RCC_AHB2Periph,
  33. RCC_AHB3Periph,
  34. } enum_clock_type;
  35. typedef struct
  36. {
  37. interface_type type;
  38. enum_clock_type RCC_AXBPeriph;
  39. uint32_t AF_Clock;
  40. } Gpio_Clock;
  41. typedef enum
  42. {
  43. kRunLed,
  44. kPRelayCtr,
  45. kNRelayCtr,
  46. kPreRelayCtr,
  47. kFanCtr,
  48. kOut1Ctr, // charger
  49. kOut2Ctr, // charger heat
  50. kExtWatchDog,
  51. kExtRelayLed,
  52. kExtFaultLed,
  53. kISOPRelayCtr,
  54. kISONRelayCtr,
  55. kSoftI2C3_SDA,
  56. kSoftI2C3_SCL,
  57. kSoftI2C4_SDA,
  58. kSoftI2C4_SCL,
  59. kOutputEnd,
  60. } Output_Type;
  61. typedef enum
  62. {
  63. kLDetect,
  64. kInputEnd,
  65. } Input_type;
  66. typedef struct
  67. {
  68. GPIO_TypeDef *GPIOx;
  69. INT16U GPIO_PinSource;
  70. INT8U GPIO_AF;
  71. } GPIO_AF_Info;
  72. typedef struct
  73. {
  74. interface_type type;
  75. Output_Type Out_Type;
  76. Input_type In_Type;
  77. GPIO_TypeDef *GPIOx;
  78. INT32U GPIO_Pin;
  79. GPIOMode_TypeDef GPIO_Mode;
  80. GPIO_AF_Info AF_Info;
  81. GPIOOType_TypeDef GPIO_OType;
  82. GPIOSpeed_TypeDef GPIO_Speed;
  83. GPIOPuPd_TypeDef GPIO_PuPd;
  84. } Interface_struct;
  85. // // soft I2C
  86. // #define SI2C3_SDA_PIN GPIO_PIN_3
  87. // #define SI2C3_SDA_PORT GPIOD
  88. // #define SI2C3_SCL_PIN GPIO_PIN_2
  89. // #define SI2C3_SCL_PORT GPIOD
  90. // #define SI2C4_SDA_PIN GPIO_PIN_15
  91. // #define SI2C4_SDA_PORT GPIOE
  92. // #define SI2C4_SCL_PIN GPIO_PIN_14
  93. // #define SI2C4_SCL_PORT GPIOE
  94. // #define SI2C3_SDA_HIGH GPIO_SetBits(SI2C3_SDA_PORT, SI2C3_SDA_PIN)
  95. // #define SI2C3_SDA_LOW GPIO_ResetBits(SI2C3_SDA_PORT, SI2C3_SDA_PIN)
  96. // #define SI2C3_SCL_HIGH GPIO_SetBits(SI2C3_SCL_PORT, SI2C3_SCL_PIN)
  97. // #define SI2C3_SCL_LOW GPIO_ResetBits(SI2C3_SCL_PORT, SI2C3_SCL_PIN)
  98. // #define SI2C4_SDA_HIGH GPIO_SetBits(SI2C4_SDA_PORT, SI2C4_SDA_PIN)
  99. // #define SI2C4_SDA_LOW GPIO_ResetBits(SI2C4_SDA_PORT, SI2C4_SDA_PIN)
  100. // #define SI2C4_SCL_HIGH GPIO_SetBits(SI2C4_SCL_PORT, SI2C4_SCL_PIN)
  101. // #define SI2C4_SCL_LOW GPIO_ResetBits(SI2C4_SCL_PORT, SI2C4_SCL_PIN)
  102. // #define SI2C3_SDA_OUT gpio_mode_set(SI2C3_SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SI2C3_SDA_PIN)
  103. // #define SI2C3_SDA_IN gpio_mode_set(SI2C3_SDA_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SI2C3_SDA_PIN)
  104. // #define SI2C3_SDA_READ gpio_input_bit_get(SI2C3_SDA_PORT, SI2C3_SDA_PIN)
  105. // #define SI2C4_SDA_OUT gpio_mode_set(SI2C4_SDA_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, SI2C4_SDA_PIN)
  106. // #define SI2C4_SDA_IN gpio_mode_set(SI2C4_SDA_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, SI2C4_SDA_PIN)
  107. // #define SI2C4_SDA_READ gpio_input_bit_get(SI2C4_SDA_PORT, SI2C4_SDA_PIN)
  108. // uart
  109. #define UART3_ENABLE_PORT GPIOB
  110. #define UART3_ENABLE_PIN GPIO_Pin_2
  111. #define UART3_TX_ENABLE GPIO_SetBits(UART3_ENABLE_PORT, UART3_ENABLE_PIN)
  112. #define UART3_RX_ENABLE GPIO_ResetBits(UART3_ENABLE_PORT, UART3_ENABLE_PIN)
  113. // // SPI
  114. // #define SPI2_CS_PORT GPIOA
  115. // #define SPI2_CS_PIN GPIO_PIN_15
  116. // #define SPI2_CS_HIGH GPIO_SetBits(SPI2_CS_PORT, SPI2_CS_PIN)
  117. // #define SPI2_CS_LOW GPIO_ResetBits(SPI2_CS_PORT, SPI2_CS_PIN)
  118. // ethernet
  119. #define ETH_RESET_PORT GPIOH
  120. #define ETH_RESET_PIN GPIO_Pin_6
  121. // #define ETH_RXER_PORT GPIOG
  122. // #define ETH_RXER_PIN GPIO_PIN_12
  123. #define ETH_RESET_ON GPIO_ResetBits(ETH_RESET_PORT, ETH_RESET_PIN)
  124. #define ETH_RESET_OFF GPIO_SetBits(ETH_RESET_PORT, ETH_RESET_PIN)
  125. #define DM9K_RESET_PORT GPIOA
  126. #define DM9K_RESET_PIN GPIO_Pin_15
  127. #define DM9K_RESET_ON GPIO_ResetBits(DM9K_RESET_PORT, DM9K_RESET_PIN)
  128. #define DM9K_RESET_OFF GPIO_SetBits(DM9K_RESET_PORT, DM9K_RESET_PIN)
  129. // output
  130. #define LED0_RUN_PORT GPIOC
  131. #define LED0_RUN_PIN GPIO_Pin_2
  132. #define LED1_RUN_PORT GPIOF
  133. #define LED1_RUN_PIN GPIO_Pin_7
  134. #define LED2_RUN_PORT GPIOF
  135. #define LED2_RUN_PIN GPIO_Pin_8
  136. #define LED3_RUN_PORT GPIOI
  137. #define LED3_RUN_PIN GPIO_Pin_10
  138. // #define PRelayCtr_PORT GPIOD
  139. // #define PRelayCtr_PIN GPIO_PIN_6
  140. // #define NRelayCtr_PORT GPIOD
  141. // #define NRelayCtr_PIN GPIO_PIN_5
  142. // #define PreRelayCtr_PORT GPIOG
  143. // #define PreRelayCtr_PIN GPIO_PIN_9
  144. // #define Fan_PORT GPIOG
  145. // #define Fan_PIN GPIO_PIN_10
  146. // #define OUT1CTR_PORT GPIOD
  147. // #define OUT1CTR_PIN GPIO_PIN_7
  148. // #define OUT2CTR_PORT GPIOE
  149. // #define OUT2CTR_PIN GPIO_PIN_1
  150. // #define EXTWATCHDOG_PORT GPIOC
  151. // #define EXTWATCHDOG_PIN GPIO_PIN_3
  152. // #define ExtRelayLed_PORT GPIOD
  153. // #define ExtRelayLed_PIN GPIO_PIN_11
  154. // #define ExtFaultLed_PORT GPIOD
  155. // #define ExtFaultLed_PIN GPIO_PIN_10
  156. // #define ISOPRelayCtr_PORT GPIOF
  157. // #define ISOPRelayCtr_PIN GPIO_PIN_14
  158. // #define ISONRelayCtr_PORT GPIOF
  159. // #define ISONRelayCtr_PIN GPIO_PIN_15
  160. // // input
  161. // #define LDetect1_PORT GPIOD
  162. // #define LDetect1_PIN GPIO_PIN_13
  163. // output operation
  164. #define LED0_RUN_ON GPIO_SetBits(LED0_RUN_PORT, LED0_RUN_PIN)
  165. #define LED0_RUN_OFF GPIO_ResetBits(LED0_RUN_PORT, LED0_RUN_PIN)
  166. #define LED0_RUN_TOGGLE GPIO_ToggleBits(LED0_RUN_PORT, LED0_RUN_PIN)
  167. #define LED1_RUN_ON GPIO_SetBits(LED1_RUN_PORT, LED1_RUN_PIN)
  168. #define LED1_RUN_OFF GPIO_ResetBits(LED1_RUN_PORT, LED1_RUN_PIN)
  169. #define LED1_RUN_TOGGLE GPIO_ToggleBits(LED1_RUN_PORT, LED1_RUN_PIN)
  170. #define LED2_RUN_ON GPIO_SetBits(LED2_RUN_PORT, LED2_RUN_PIN)
  171. #define LED2_RUN_OFF GPIO_ResetBits(LED2_RUN_PORT, LED2_RUN_PIN)
  172. #define LED2_RUN_TOGGLE GPIO_ToggleBits(LED2_RUN_PORT, LED2_RUN_PIN)
  173. #define LED3_RUN_ON GPIO_SetBits(LED3_RUN_PORT, LED3_RUN_PIN)
  174. #define LED3_RUN_OFF GPIO_ResetBits(LED3_RUN_PORT, LED3_RUN_PIN)
  175. #define LED3_RUN_TOGGLE GPIO_ToggleBits(LED3_RUN_PORT, LED3_RUN_PIN)
  176. // #define PRelayCtr_ON GPIO_SetBits(PRelayCtr_PORT, PRelayCtr_PIN)
  177. // #define PRelayCtr_OFF GPIO_ResetBits(PRelayCtr_PORT, PRelayCtr_PIN)
  178. // #define NRelayCtr_ON GPIO_SetBits(NRelayCtr_PORT, NRelayCtr_PIN)
  179. // #define NRelayCtr_OFF GPIO_ResetBits(NRelayCtr_PORT, NRelayCtr_PIN)
  180. // #define PreRelayCtr_ON GPIO_SetBits(PreRelayCtr_PORT, PreRelayCtr_PIN)
  181. // #define PreRelayCtr_OFF GPIO_ResetBits(PreRelayCtr_PORT, PreRelayCtr_PIN)
  182. // #define FAN_ON GPIO_SetBits(Fan_PORT, Fan_PIN)
  183. // #define FAN_OFF GPIO_ResetBits(Fan_PORT, Fan_PIN)
  184. // #define OUT1CTR_ON GPIO_SetBits(OUT1CTR_PORT, OUT1CTR_PIN)
  185. // #define OUT1CTR_OFF GPIO_ResetBits(OUT1CTR_PORT, OUT1CTR_PIN)
  186. // #define OUT2CTR_ON GPIO_SetBits(OUT2CTR_PORT, OUT2CTR_PIN)
  187. // #define OUT2CTR_OFF GPIO_ResetBits(OUT2CTR_PORT, OUT2CTR_PIN)
  188. // #define FEED_DOG_ON GPIO_SetBits(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN)
  189. // #define FEED_DOG_OFF GPIO_ResetBits(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN)
  190. // #define FEED_DOG_TOGGLE GPIO_WriteBit(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN, (FlagStatus)(1 - (gpio_output_bit_get(EXTWATCHDOG_PORT, EXTWATCHDOG_PIN))))
  191. // #define ExtRelayLed_ON GPIO_SetBits(ExtRelayLed_PORT, ExtRelayLed_PIN)
  192. // #define ExtRelayLed_OFF GPIO_ResetBits(ExtRelayLed_PORT, ExtRelayLed_PIN)
  193. // #define ExtFaultLed_ON GPIO_SetBits(ExtFaultLed_PORT, ExtFaultLed_PIN)
  194. // #define ExtFaultLed_OFF GPIO_ResetBits(ExtFaultLed_PORT, ExtFaultLed_PIN)
  195. // #define ISOPRelay_ON GPIO_SetBits(ISOPRelayCtr_PORT, ISOPRelayCtr_PIN)
  196. // #define ISOPRelay_OFF GPIO_ResetBits(ISOPRelayCtr_PORT, ISOPRelayCtr_PIN)
  197. // #define ISONRelay_ON GPIO_SetBits(ISONRelayCtr_PORT, ISONRelayCtr_PIN)
  198. // #define ISONRelay_OFF GPIO_ResetBits(ISONRelayCtr_PORT, ISONRelayCtr_PIN)
  199. // // input result
  200. // #define L_IN1_IS_LOW (gpio_input_bit_get(LDetect1_PORT, LDetect1_PIN) == RESET)
  201. void interface_init(void);
  202. void gpio_clock_init(void);
  203. #endif