board_io.c 4.9 KB

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