board_io.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_CANNA)
  52. int io_canna(void)
  53. {
  54. /* PC25(1) for Audio Shutdown IO */
  55. gpio_set_func(GPIO_PORT_C, GPIO_Pin_25, GPIO_FUNC_1);
  56. gpio_direction_output(GPIO_PORT_C,GPIO_Pin_25, 0);
  57. gpio_set_value(GPIO_PORT_C,GPIO_Pin_25, 0);
  58. return 0;
  59. }
  60. INIT_DEVICE_EXPORT(io_canna);
  61. #endif
  62. #if defined(BOARD_HALLEY2)
  63. int io_halley2(void)
  64. {
  65. #ifdef RT_USING_EMAC
  66. /* PC23 for MAC_RST_N */
  67. gpio_set_func(GPIO_PORT_C, GPIO_Pin_23, GPIO_FUNC_0);
  68. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 0);
  69. rt_thread_delay(1);
  70. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 1);
  71. rt_thread_delay(1);
  72. #endif
  73. return 0;
  74. }
  75. INIT_DEVICE_EXPORT(io_halley2);
  76. #endif
  77. #if defined(BOARD_PHOENIX)
  78. int io_phoenix(void)
  79. {
  80. /* PB0(1) for Audio Shutdown IO */
  81. gpio_set_func(GPIO_PORT_B, GPIO_Pin_0, GPIO_FUNC_2);
  82. gpio_direction_output(GPIO_PORT_B,GPIO_Pin_0, 0);
  83. gpio_set_value(GPIO_PORT_B,GPIO_Pin_0,0);
  84. /* PB3 for reset EMAC PHY */
  85. gpio_set_func(GPIO_PORT_B, GPIO_Pin_3, GPIO_FUNC_2);
  86. gpio_direction_output(GPIO_PORT_B, GPIO_Pin_3, 0);
  87. rt_thread_delay(1);
  88. gpio_direction_output(GPIO_PORT_B, GPIO_Pin_3, 1);
  89. rt_thread_delay(1);
  90. return 0;
  91. }
  92. INIT_DEVICE_EXPORT(io_phoenix);
  93. #endif
  94. #if defined(BOARD_OX)
  95. int io_ox(void)
  96. {
  97. /* PB6 for Audio Shutdown IO */
  98. gpio_set_func(GPIO_PORT_B, GPIO_Pin_6, GPIO_FUNC_1);
  99. gpio_direction_output(GPIO_PORT_B,GPIO_Pin_6, 0);
  100. gpio_set_value(GPIO_PORT_B,GPIO_Pin_6, 0);
  101. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_25, GPIO_OUTPUT0);
  102. rt_thread_delay(rt_tick_from_millisecond(100));
  103. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_25, GPIO_OUTPUT1);
  104. /* PB19 for LCD black light */
  105. gpio_direction_output(GPIO_PORT_B,GPIO_Pin_19, GPIO_OUTPUT1);
  106. #ifdef RT_USING_EMAC
  107. /* PC23 for MAC_RST_N */
  108. // gpio_set_func(GPIO_PORT_C, GPIO_Pin_23, GPIO_FUNC_0);
  109. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 0);
  110. rt_thread_delay(1);
  111. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 1);
  112. rt_thread_delay(1);
  113. #endif
  114. return 0;
  115. }
  116. INIT_DEVICE_EXPORT(io_ox);
  117. #endif
  118. #ifdef BOARD_HALLEY2_REALBOARD
  119. int io_realboard(void)
  120. {
  121. /* Audio Shutdown IO */
  122. gpio_direction_output(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  123. gpio_set_value(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  124. #ifdef RT_USING_EMAC
  125. gpio_set_func(GPIO_PORT_B, GPIO_Pin_7, GPIO_OUTPUT0);
  126. gpio_set_func(GPIO_PORT_B, GPIO_Pin_8, GPIO_OUTPUT0);
  127. gpio_set_func(GPIO_PORT_B, GPIO_Pin_9, GPIO_OUTPUT0);
  128. gpio_set_func(GPIO_PORT_B, GPIO_Pin_10, GPIO_OUTPUT0);
  129. gpio_set_func(GPIO_PORT_B, GPIO_Pin_11, GPIO_OUTPUT0);
  130. gpio_set_func(GPIO_PORT_B, GPIO_Pin_12, GPIO_OUTPUT0);
  131. gpio_set_func(GPIO_PORT_B, GPIO_Pin_13, GPIO_INPUT);
  132. gpio_set_func(GPIO_PORT_B, GPIO_Pin_14, GPIO_INPUT);
  133. gpio_set_func(GPIO_PORT_B, GPIO_Pin_15, GPIO_INPUT);
  134. /* PC23 for MAC_RST_N */
  135. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 0);
  136. _delay_ms(100);
  137. gpio_direction_output(GPIO_PORT_C, GPIO_Pin_23, 1);
  138. _delay_ms(100);
  139. #endif
  140. return 0;
  141. }
  142. INIT_BOARD_EXPORT(io_realboard);
  143. #endif /* BOARD_HALLEY2_REALBOARD_X1000 */
  144. #ifdef BOARD_HALLEY2_REALBOARD_V2
  145. int io_realboard_v2(void)
  146. {
  147. /* Audio Shutdown IO */
  148. gpio_direction_output(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  149. gpio_set_value(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  150. /* Reset lcd,TP,... */
  151. gpio_direction_output(LCD_TP_INT_PORT, LCD_TP_INT_PIN,1);
  152. _delay_ms(300);
  153. gpio_direction_output(LCD_RST_PORT, LCD_RST_PIN,0);
  154. _delay_ms(100);
  155. gpio_set_value(LCD_RST_PORT, LCD_RST_PIN, 1);
  156. /* LED */
  157. gpio_direction_output(BLINK_LED0_PORT, BLINK_LED0_PIN,1);
  158. gpio_direction_output(BLINK_LED1_PORT, BLINK_LED1_PIN,1);
  159. gpio_direction_output(BLINK_LED2_PORT, BLINK_LED2_PIN,1);
  160. gpio_direction_output(BLINK_LED3_PORT, BLINK_LED3_PIN,1);
  161. return 0;
  162. }
  163. INIT_BOARD_EXPORT(io_realboard_v2);
  164. #endif /* BOARD_HALLEY2_REALBOARD_V2 */
  165. #ifdef BOARD_HALLEY2_FIR
  166. int io_halley2_fir(void)
  167. {
  168. /* Audio Shutdown IO */
  169. gpio_direction_output(AUDIO_SHUTDOWN_PORT,AUDIO_SHUTDOWN_PIN, AUDIO_SHUTDOWN_MUTE);
  170. /* LCD */
  171. rt_kprintf("lcd power enable...\n");
  172. gpio_direction_output(LCD_PWEN_PORT,LCD_PWEN_PIN, 0); //LCD Power Enable
  173. gpio_direction_output(LCD_RST_PORT,LCD_RST_PIN, 0);
  174. gpio_direction_output(LCD_BL_PORT,LCD_BL_PIN, 0);
  175. /* Touch */
  176. gpio_direction_output(TP_PWEN_PORT,TP_PWEN_PIN, 0);
  177. gpio_direction_output(TP_RST_PORT,TP_RST_PIN, 0);
  178. /* LED */
  179. gpio_direction_output(LED_BT_PORT,LED_BT_PIN, 1);
  180. gpio_direction_output(LED_WIFI_PORT,LED_WIFI_PIN, 1);
  181. gpio_direction_output(LED_ZB_PORT,LED_ZB_PIN, 1);
  182. return 0;
  183. }
  184. INIT_BOARD_EXPORT(io_halley2_fir);
  185. #endif /* BOARD_HALLEY2_FIR */