interface.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. ************************************************************************************************
  3. * @文件 : interface.c
  4. * @作者 : 樊春春
  5. * @版本 : V1.0
  6. * @时间 : 2022/05/31 20:47:46
  7. * @邮箱 : [email protected]
  8. * @说明 :
  9. ************************************************************************************************
  10. **/
  11. #include "interface.h"
  12. #include "stm32f4xx_gpio.h"
  13. Gpio_Clock clock_info[] = {
  14. // {.type = kI2C0, .AXBPeriph_Clock = RCC_I2C0},
  15. // {.type = kI2C1, .AXBPeriph_Clock = RCU_I2C1},
  16. // {.type = kI2C2, .AXBPeriph_Clock = RCU_I2C2},
  17. // {.type = kADC0, .AXBPeriph_Clock = RCU_ADC0},
  18. // {.type = kADC2, .AXBPeriph_Clock = RCU_ADC2},
  19. // {.type = kSPI2, .AXBPeriph_Clock = RCU_SPI2},
  20. {.type = kUart1, .RCC_AXBPeriph = RCC_APB2Periph, .AF_Clock = RCC_APB2Periph_USART1},
  21. {.type = kUart3, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_USART3},
  22. {.type = kCAN1, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN1},
  23. {.type = kCAN2, .RCC_AXBPeriph = RCC_APB1Periph, .AF_Clock = RCC_APB1Periph_CAN2},
  24. {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC},
  25. {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Tx},
  26. {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_Rx},
  27. {.type = kEthernet_dm9101, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_ETH_MAC_PTP},
  28. {.type = kEthernet_dm9k, .RCC_AXBPeriph = RCC_AHB3Periph, .AF_Clock = RCC_AHB3Periph_FSMC},
  29. // {.type = kPMU, .AXBPeriph_Clock = RCU_PMU},
  30. {.type = kDMA1, .RCC_AXBPeriph = RCC_AHB1Periph, .AF_Clock = RCC_AHB1Periph_DMA1},
  31. // // {.type = kTIMER1, .AXBPeriph_Clock = RCU_TIMER1},
  32. };
  33. Interface_struct interface_info[] = {
  34. // // I2C
  35. // {.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},
  36. // {.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},
  37. // {.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},
  38. // {.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},
  39. // {.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},
  40. // {.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},
  41. // can1
  42. {.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},
  43. {.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},
  44. // can2
  45. {.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},
  46. {.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},
  47. // // spi
  48. // {.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},
  49. // {.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},
  50. // {.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},
  51. // {.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},
  52. // // ADC
  53. // {.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},
  54. // {.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},
  55. // {.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},
  56. // {.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},
  57. // {.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},
  58. // {.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},
  59. // {.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},
  60. // uart1
  61. {.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},
  62. {.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},
  63. // uart3
  64. {.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},
  65. {.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},
  66. {.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},
  67. // //uart6
  68. // {.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},
  69. // {.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},
  70. // {.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},
  71. // ethernet-dm9161
  72. {.type = kEthernet_dm9101, .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},
  73. {.type = kEthernet_dm9101, .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},
  74. {.type = kEthernet_dm9101, .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},
  75. {.type = kEthernet_dm9101, .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},
  76. {.type = kEthernet_dm9101, .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},
  77. {.type = kEthernet_dm9101, .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},
  78. {.type = kEthernet_dm9101, .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},
  79. {.type = kEthernet_dm9101, .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},
  80. {.type = kEthernet_dm9101, .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},
  81. {.type = kEthernet_dm9101, .GPIOx = ETH_RESET_PORT, .GPIO_Pin = ETH_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_UP},
  82. // // {.type = kEthernet_dm9101, .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},
  83. // ethernet-dm9k
  84. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_0, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource0, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  85. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_1, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource1, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  86. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  87. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  88. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_8, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource8, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  89. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_9, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource9, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  90. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  91. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  92. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  93. {.type = kEthernet_dm9k, .GPIOx = GPIOD, .GPIO_Pin = GPIO_Pin_15, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOD, .GPIO_PinSource = GPIO_PinSource15, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  94. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_4, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource4, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  95. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_5, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource5, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  96. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_7, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource7, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  97. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_8, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource8, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  98. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_9, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource9, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  99. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  100. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_11, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource11, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  101. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_12, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource12, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  102. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_13, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource13, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  103. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_14, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource14, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  104. {.type = kEthernet_dm9k, .GPIOx = GPIOE, .GPIO_Pin = GPIO_Pin_15, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOE, .GPIO_PinSource = GPIO_PinSource15, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  105. {.type = kEthernet_dm9k, .GPIOx = GPIOG, .GPIO_Pin = GPIO_Pin_10, .GPIO_Mode = GPIO_Mode_AF, .AF_Info = {.GPIOx = GPIOG, .GPIO_PinSource = GPIO_PinSource10, .GPIO_AF = GPIO_AF_FSMC}, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Speed_100MHz, .GPIO_PuPd = GPIO_PuPd_NOPULL},
  106. {.type = kEthernet_dm9k, .GPIOx = DM9K_RESET_PORT, .GPIO_Pin = DM9K_RESET_PIN, .GPIO_Mode = GPIO_Mode_OUT, .GPIO_OType = GPIO_OType_PP, .GPIO_Speed = GPIO_Fast_Speed, .GPIO_PuPd = GPIO_PuPd_UP},
  107. // // input
  108. // {.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},
  109. // output
  110. {.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},
  111. {.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},
  112. {.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},
  113. {.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},
  114. // {.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},
  115. // {.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},
  116. // {.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},
  117. // {.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},
  118. // {.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},
  119. // {.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},
  120. // {.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},
  121. // {.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},
  122. // {.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},
  123. // {.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},
  124. // {.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},
  125. // {.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},
  126. // {.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},
  127. // {.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},
  128. // {.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},
  129. };
  130. void interface_init(void)
  131. {
  132. INT8U index = 0;
  133. /* 定义GPIO外设初始化结构体 */
  134. GPIO_InitTypeDef GPIO_StructInit;
  135. for (index = 0; index < sizeof(interface_info) / sizeof(Interface_struct); index++)
  136. {
  137. /* 配置GPIO初始化结构成员*/
  138. GPIO_StructInit.GPIO_Mode = interface_info[index].GPIO_Mode;
  139. GPIO_StructInit.GPIO_OType = interface_info[index].GPIO_OType;
  140. GPIO_StructInit.GPIO_Speed = interface_info[index].GPIO_Speed;
  141. GPIO_StructInit.GPIO_PuPd = interface_info[index].GPIO_PuPd;
  142. GPIO_StructInit.GPIO_Pin = interface_info[index].GPIO_Pin;
  143. GPIO_Init(interface_info[index].GPIOx, &GPIO_StructInit);
  144. if (interface_info[index].GPIO_Mode == GPIO_Mode_AF)
  145. {
  146. GPIO_PinAFConfig(interface_info[index].AF_Info.GPIOx, interface_info[index].AF_Info.GPIO_PinSource, interface_info[index].AF_Info.GPIO_AF);
  147. }
  148. }
  149. }
  150. void gpio_clock_init(void)
  151. {
  152. INT8U index = 0;
  153. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  154. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  155. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  156. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  157. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  158. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  159. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
  160. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
  161. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);
  162. for (index = 0; index < sizeof(clock_info) / sizeof(Gpio_Clock); index++)
  163. {
  164. switch (clock_info[index].RCC_AXBPeriph)
  165. {
  166. case RCC_APB1Periph:
  167. RCC_APB1PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  168. break;
  169. case RCC_APB2Periph:
  170. RCC_APB2PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  171. break;
  172. case RCC_AHB1Periph:
  173. RCC_AHB1PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  174. break;
  175. case RCC_AHB2Periph:
  176. RCC_AHB2PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  177. break;
  178. case RCC_AHB3Periph:
  179. RCC_AHB3PeriphClockCmd(clock_info[index].AF_Clock, ENABLE);
  180. break;
  181. }
  182. }
  183. }