board_io.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #include <board.h>
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #include "drv_gpio.h"
  5. static void _delay_us(rt_uint32_t ns)
  6. {
  7. volatile rt_uint16_t delay;
  8. while(ns--)
  9. {
  10. delay = 200;
  11. while(delay--);
  12. }
  13. }
  14. static void _delay_ms(rt_uint32_t ms)
  15. {
  16. volatile rt_uint16_t delay;
  17. while(ms--)
  18. {
  19. _delay_us(1000);
  20. }
  21. }
  22. #if defined(RT_USING_WIFI) && (defined(WIFI_USING_AP6212) || defined(WIFI_USING_AP6181))
  23. /**
  24. * PC16 WL_WAKE_HOST
  25. * PC17 WL_REG_EN
  26. */
  27. int io_AP6212(void)
  28. {
  29. gpio_set_func(GPIO_PORT_C, GPIO_Pin_17, GPIO_FUNC_0);
  30. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_17, 0);
  31. rt_kprintf("Enable WL_REG_EN\n");
  32. gpio_set_value(GPIO_PORT_C, GPIO_Pin_17, 0);
  33. rt_thread_delay(1);
  34. gpio_set_value(GPIO_PORT_C, GPIO_Pin_17, 1);
  35. return 0;
  36. }
  37. INIT_DEVICE_EXPORT(io_AP6212);
  38. #endif
  39. #if defined(RT_USING_BT) && (defined(WIFI_USING_AP6212) || defined(WIFI_USING_AP6181))
  40. #include <drv_rtc.h>
  41. /**
  42. * PC16 32768 clock
  43. */
  44. int io_AP6212_bt(void)
  45. {
  46. rtc32k_enable();
  47. return 0;
  48. }
  49. INIT_DEVICE_EXPORT(io_AP6212_bt);
  50. #endif
  51. #if defined(BOARD_HALLEY2)
  52. int io_halley2(void)
  53. {
  54. #ifdef RT_USING_EMAC
  55. /* PC23 for MAC_RST_N */
  56. gpio_set_func(GPIO_PORT_C, GPIO_Pin_23, GPIO_FUNC_0);
  57. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 0);
  58. rt_thread_delay(1);
  59. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 1);
  60. rt_thread_delay(1);
  61. #endif
  62. return 0;
  63. }
  64. INIT_DEVICE_EXPORT(io_halley2);
  65. #endif
  66. #if defined(BOARD_PHOENIX)
  67. int io_phoenix(void)
  68. {
  69. /* PB0(1) for Audio Shutdown IO */
  70. gpio_set_func(GPIO_PORT_B, GPIO_Pin_0, GPIO_FUNC_2);
  71. gpio_direction_output(GPIO_PORT_B,GPIO_Pin_0, 0);
  72. gpio_set_value(GPIO_PORT_B,GPIO_Pin_0,0);
  73. /* PB3 for reset EMAC PHY */
  74. gpio_set_func(GPIO_PORT_B, GPIO_Pin_3, GPIO_FUNC_2);
  75. gpio_direction_output(GPIO_PORT_B, GPIO_Pin_3, 0);
  76. rt_thread_delay(1);
  77. gpio_direction_output(GPIO_PORT_B, GPIO_Pin_3, 1);
  78. rt_thread_delay(1);
  79. return 0;
  80. }
  81. INIT_DEVICE_EXPORT(io_phoenix);
  82. #endif
  83. #ifdef BOARD_HALLEY2_REALBOARD
  84. int io_realboard(void)
  85. {
  86. /* Audio Shutdown IO */
  87. gpio_direction_output(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  88. gpio_set_value(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  89. #ifdef RT_USING_EMAC
  90. gpio_set_func(GPIO_PORT_B, GPIO_Pin_7, GPIO_OUTPUT0);
  91. gpio_set_func(GPIO_PORT_B, GPIO_Pin_8, GPIO_OUTPUT0);
  92. gpio_set_func(GPIO_PORT_B, GPIO_Pin_9, GPIO_OUTPUT0);
  93. gpio_set_func(GPIO_PORT_B, GPIO_Pin_10, GPIO_OUTPUT0);
  94. gpio_set_func(GPIO_PORT_B, GPIO_Pin_11, GPIO_OUTPUT0);
  95. gpio_set_func(GPIO_PORT_B, GPIO_Pin_12, GPIO_OUTPUT0);
  96. gpio_set_func(GPIO_PORT_B, GPIO_Pin_13, GPIO_INPUT);
  97. gpio_set_func(GPIO_PORT_B, GPIO_Pin_14, GPIO_INPUT);
  98. gpio_set_func(GPIO_PORT_B, GPIO_Pin_15, GPIO_INPUT);
  99. /* PC23 for MAC_RST_N */
  100. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 0);
  101. _delay_ms(100);
  102. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 1);
  103. _delay_ms(100);
  104. #endif
  105. return 0;
  106. }
  107. INIT_BOARD_EXPORT(io_realboard);
  108. #endif /* BOARD_HALLEY2_REALBOARD_X1000 */
  109. #ifdef BOARD_HALLEY2_REALBOARD_V2
  110. int io_realboard_v2(void)
  111. {
  112. /* Audio Shutdown IO */
  113. gpio_direction_output(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  114. gpio_set_value(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  115. /* Reset lcd,TP,... */
  116. gpio_direction_output(LCD_TP_INT_PORT, LCD_TP_INT_PIN,1);
  117. _delay_ms(300);
  118. gpio_direction_output(LCD_RST_PORT, LCD_RST_PIN,0);
  119. _delay_ms(100);
  120. gpio_set_value(LCD_RST_PORT, LCD_RST_PIN, 1);
  121. /* LED */
  122. gpio_direction_output(BLINK_LED0_PORT, BLINK_LED0_PIN,1);
  123. gpio_direction_output(BLINK_LED1_PORT, BLINK_LED1_PIN,1);
  124. gpio_direction_output(BLINK_LED2_PORT, BLINK_LED2_PIN,1);
  125. gpio_direction_output(BLINK_LED3_PORT, BLINK_LED3_PIN,1);
  126. return 0;
  127. }
  128. INIT_BOARD_EXPORT(io_realboard_v2);
  129. #endif /* BOARD_HALLEY2_REALBOARD_V2 */
  130. #ifdef BOARD_HALLEY2_FIR
  131. int io_halley2_fir(void)
  132. {
  133. /* Audio Shutdown IO */
  134. gpio_direction_output(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  135. /* LCD */
  136. rt_kprintf("lcd power enable...\n");
  137. gpio_direction_output(LCD_PWEN_PORT,LCD_PWEN_PIN, 0); //LCD Power Enable
  138. gpio_direction_output(LCD_RST_PORT,LCD_RST_PIN, 0);
  139. gpio_direction_output(LCD_BL_PORT,LCD_BL_PIN, 0);
  140. /* Touch */
  141. gpio_direction_output(TP_PWEN_PORT,TP_PWEN_PIN, 0);
  142. gpio_direction_output(TP_RST_PORT,TP_RST_PIN, 0);
  143. /* LED */
  144. gpio_direction_output(LED_BT_PORT,LED_BT_PIN, 1);
  145. gpio_direction_output(LED_WIFI_PORT,LED_WIFI_PIN, 1);
  146. gpio_direction_output(LED_ZB_PORT,LED_ZB_PIN, 1);
  147. return 0;
  148. }
  149. INIT_BOARD_EXPORT(io_halley2_fir);
  150. #endif /* BOARD_HALLEY2_FIR */