interface.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "interface.h"
  2. #include "stm32f4xx_gpio.h"
  3. Gpio_Clock clock_info[] = {
  4. // {.type = kI2C0, .AXBPeriph_Clock = RCC_I2C0},
  5. // {.type = kI2C1, .AXBPeriph_Clock = RCU_I2C1},
  6. // {.type = kI2C2, .AXBPeriph_Clock = RCU_I2C2},
  7. // {.type = kADC0, .AXBPeriph_Clock = RCU_ADC0},
  8. // {.type = kADC2, .AXBPeriph_Clock = RCU_ADC2},
  9. // {.type = kSPI2, .AXBPeriph_Clock = RCU_SPI2},
  10. {.type = kUart1, .RCC_AXBPeriph = RCC_APB2Periph, .AF_Clock = RCC_APB2Periph_USART1},
  11. {.type = kUart3, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_USART3},
  12. {.type = kCAN1, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN1},
  13. {.type = kCAN2, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN2},
  14. {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC},
  15. {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Tx},
  16. {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Rx},
  17. {.type = kEthernet, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_PTP},
  18. // {.type = kPMU, .AXBPeriph_Clock = RCU_PMU},
  19. {.type = kDMA1, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_DMA1},
  20. // // {.type = kTIMER1, .AXBPeriph_Clock = RCU_TIMER1},
  21. };
  22. Interface_struct interface_info[] = {
  23. // // I2C
  24. // {.type = kI2C0, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_6, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_6, .GPIO_AF = GPIO_AF_4}, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  25. // {.type = kI2C0, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_7, .GPIO_AF = GPIO_AF_4}, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  26. // {.type = kI2C1, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_0, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_0, .GPIO_AF = GPIO_AF_4}, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  27. // {.type = kI2C1, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_1, .GPIO_AF = GPIO_AF_4}, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  28. // {.type = kI2C2, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_8, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_8, .GPIO_AF = GPIO_AF_4}, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  29. // {.type = kI2C2, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_9, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_9, .GPIO_AF = GPIO_AF_4}, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  30. // can1
  31. {.type = kCAN1, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_CAN1}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  32. {.type = kCAN1, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_12, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource12, .GPIO_AF = GPIO_AF_CAN1}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  33. // can2
  34. {.type = kCAN2, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_12, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource12, .GPIO_AF = GPIO_AF_CAN2}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  35. {.type = kCAN2, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_CAN2}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  36. // // spi
  37. // {.type = kSPI2, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_10, .GPIO_AF = GPIO_AF_6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  38. // {.type = kSPI2, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_11, .GPIO_AF = GPIO_AF_6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  39. // {.type = kSPI2, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_12, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_12, .GPIO_AF = GPIO_AF_6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  40. // {.type = kSPI2, .GPIOx = SPI2_CS_PORT, .GPIO_Pin = SPI2_CS_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  41. // // ADC
  42. // {.type = kADC2, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_3, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  43. // {.type = kADC2, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  44. // {.type = kADC2, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  45. // {.type = kADC2, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_6, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  46. // {.type = kADC2, .GPIOx = GPIOF, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  47. // {.type = kADC2, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_0, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  48. // {.type = kADC2, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_2, .GPIO_Mode = GPIO_MODE_ANALOG, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  49. // uart1
  50. {.type = kUart1, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_9, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource9, .GPIO_AF = GPIO_AF_USART1}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  51. {.type = kUart1, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_USART1}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  52. {.type = kUart1, .GPIOx = UART1_ENABLE_PORT, .GPIO_Pin = UART1_ENABLE_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  53. // uart3
  54. {.type = kUart3, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_USART3}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  55. {.type = kUart3, .GPIOx = GPIOB, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOB, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_USART3}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  56. {.type = kUart3, .GPIOx = UART3_ENABLE_PORT, .GPIO_Pin = UART3_ENABLE_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  57. // //uart6
  58. // {.type = kUart6, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_6, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource6, .GPIO_AF = GPIO_AF_USART6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  59. // {.type = kUart6, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_USART6}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  60. // {.type = kUart6, .GPIOx = UART6_ENABLE_PORT, .GPIO_Pin = UART6_ENABLE_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  61. // ethernet
  62. {.type = kEthernet, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  63. {.type = kEthernet, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_2, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource2, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  64. {.type = kEthernet, .GPIOx = GPIOA, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOA, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  65. {.type = kEthernet, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  66. {.type = kEthernet, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  67. {.type = kEthernet, .GPIOx = GPIOC, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOC, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  68. {.type = kEthernet, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  69. {.type = kEthernet, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  70. {.type = kEthernet, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_ETH}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  71. {.type = kEthernet, .GPIOx = ETH_RESET_PORT, .GPIO_Pin = ETH_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  72. // // {.type = kEthernet, .GPIOx = ETH_RXER_PORT, .GPIO_Pin = ETH_RXER_PIN, .GPIO_Mode = GPIO_MODE_INPUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  73. // // input
  74. // {.type = kInput, .In_Type = kLDetect, .GPIOx = LDetect1_PORT, .GPIO_Pin = LDetect1_PIN, .GPIO_Mode = GPIO_MODE_INPUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  75. // output
  76. {.type = kOutput, .Out_Type = kRunLed, .GPIOx = LED0_RUN_PORT, .GPIO_Pin = LED0_RUN_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  77. {.type = kOutput, .Out_Type = kRunLed, .GPIOx = LED1_RUN_PORT, .GPIO_Pin = LED1_RUN_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  78. {.type = kOutput, .Out_Type = kRunLed, .GPIOx = LED2_RUN_PORT, .GPIO_Pin = LED2_RUN_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  79. {.type = kOutput, .Out_Type = kRunLed, .GPIOx = LED3_RUN_PORT, .GPIO_Pin = LED3_RUN_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  80. // {.type = kOutput, .Out_Type = kPRelayCtr, .GPIOx = PRelayCtr_PORT, .GPIO_Pin = PRelayCtr_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  81. // {.type = kOutput, .Out_Type = kNRelayCtr, .GPIOx = NRelayCtr_PORT, .GPIO_Pin = NRelayCtr_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  82. // {.type = kOutput, .Out_Type = kPreRelayCtr, .GPIOx = PreRelayCtr_PORT, .GPIO_Pin = PreRelayCtr_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  83. // {.type = kOutput, .Out_Type = kFanCtr, .GPIOx = Fan_PORT, .GPIO_Pin = Fan_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  84. // {.type = kOutput, .Out_Type = kOut1Ctr, .GPIOx = OUT1CTR_PORT, .GPIO_Pin = OUT1CTR_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  85. // {.type = kOutput, .Out_Type = kOut2Ctr, .GPIOx = OUT2CTR_PORT, .GPIO_Pin = OUT2CTR_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  86. // {.type = kOutput, .Out_Type = kExtWatchDog, .GPIOx = OUT2CTR_PORT, .GPIO_Pin = OUT2CTR_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  87. // {.type = kOutput, .Out_Type = kExtRelayLed, .GPIOx = ExtRelayLed_PORT, .GPIO_Pin = ExtRelayLed_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  88. // {.type = kOutput, .Out_Type = kExtFaultLed, .GPIOx = ExtFaultLed_PORT, .GPIO_Pin = ExtFaultLed_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  89. // {.type = kOutput, .Out_Type = kISOPRelayCtr, .GPIOx = ISOPRelayCtr_PORT, .GPIO_Pin = ISOPRelayCtr_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  90. // {.type = kOutput, .Out_Type = kISONRelayCtr, .GPIOx = ISONRelayCtr_PORT, .GPIO_Pin = ISONRelayCtr_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_High_Speed, .GPIO_PuPd = GPIO_PuPd_DOWN},
  91. // {.type = kOutput, .Out_Type = kSoftI2C3_SDA, .GPIOx = SI2C3_SDA_PORT, .GPIO_Pin = SI2C3_SDA_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  92. // {.type = kOutput, .Out_Type = kSoftI2C3_SCL, .GPIOx = SI2C3_SCL_PORT, .GPIO_Pin = SI2C3_SCL_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  93. // {.type = kOutput, .Out_Type = kSoftI2C4_SDA, .GPIOx = SI2C4_SDA_PORT, .GPIO_Pin = SI2C4_SDA_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OTYPE_OD, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  94. // {.type = kOutput, .Out_Type = kSoftI2C4_SCL, .GPIOx = SI2C4_SCL_PORT, .GPIO_Pin = SI2C4_SCL_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  95. };
  96. void interface_init(void)
  97. {
  98. INT8U index = 0;
  99. /* 定义GPIO外设初始化结构体 */
  100. GPIO_InitTypeDef GPIO_StructInit;
  101. for (index = 0; index < sizeof(interface_info) / sizeof(Interface_struct); index++)
  102. {
  103. /* 配置GPIO初始化结构成员*/
  104. GPIO_StructInit.GPIO_Mode = interface_info[index].GPIO_Mode;
  105. GPIO_StructInit.GPIO_OType = interface_info[index].GPIO_OType;
  106. GPIO_StructInit.GPIO_Speed = interface_info[index].GPIO_Speed;
  107. GPIO_StructInit.GPIO_PuPd = interface_info[index].GPIO_PuPd;
  108. GPIO_StructInit.GPIO_Pin = interface_info[index].GPIO_Pin;
  109. GPIO_Init(interface_info[index].GPIOx, &GPIO_StructInit);
  110. if (interface_info[index].GPIO_Mode == GPIO_Mode_AF)
  111. {
  112. GPIO_PinAFConfig(interface_info[index].AF_Info.GPIOx, interface_info[index].AF_Info.GPIO_PinSource, interface_info[index].AF_Info.GPIO_AF);
  113. }
  114. }
  115. }
  116. void gpio_clock_init(void)
  117. {
  118. INT8U index = 0;
  119. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  120. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  121. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  122. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  123. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  124. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  125. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
  126. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
  127. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);
  128. for (index = 0; index < sizeof(clock_info) / sizeof(Gpio_Clock); index++)
  129. {
  130. switch (clock_info[index].RCC_AXBPeriph)
  131. {
  132. case RCC_APB1Periph:
  133. RCC_APB1PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  134. break;
  135. case RCC_APB2Periph:
  136. RCC_APB2PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  137. break;
  138. case RCC_AHB1Periph:
  139. RCC_AHB1PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  140. break;
  141. case RCC_AHB2Periph:
  142. RCC_AHB2PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  143. break;
  144. case RCC_AHB3Periph:
  145. RCC_AHB3PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  146. break;
  147. }
  148. }
  149. }