board_dev.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**************************************************************************//**
  2. *
  3. * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-1-16 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include <rtdevice.h>
  13. #include <drv_gpio.h>
  14. #if defined(BOARD_USING_ESP8266)
  15. #include <at_device_esp8266.h>
  16. #define LOG_TAG "at.sample.esp"
  17. #undef DBG_TAG
  18. #include <at_log.h>
  19. static struct at_device_esp8266 esp0 =
  20. {
  21. "esp0", /* esp8266 device name */
  22. "uart4", /* esp8266 serial device name, EX: uart1, uuart1 */
  23. "NT_ZY_BUFFALO", /* Wi-Fi SSID */
  24. "12345678", /* Wi-Fi PASSWORD */
  25. 1024 /* Receive buffer length */
  26. };
  27. static int rt_hw_esp8266_port(void)
  28. {
  29. struct at_device_esp8266 *esp8266 = &esp0;
  30. rt_base_t esp_rst_pin = NU_GET_PININDEX(NU_PC, 13);
  31. rt_base_t esp_fwupdate_pin = NU_GET_PININDEX(NU_PD, 12);
  32. /* ESP8266 reset pin PC.13 */
  33. rt_pin_mode(esp_rst_pin, PIN_MODE_OUTPUT);
  34. rt_pin_write(esp_rst_pin, 1);
  35. /* ESP8266 reset pin PD.12 */
  36. rt_pin_mode(esp_fwupdate_pin, PIN_MODE_OUTPUT);
  37. rt_pin_write(esp_fwupdate_pin, 1);
  38. return at_device_register(&(esp8266->device),
  39. esp8266->device_name,
  40. esp8266->client_name,
  41. AT_DEVICE_CLASS_ESP8266,
  42. (void *) esp8266);
  43. }
  44. INIT_APP_EXPORT(rt_hw_esp8266_port);
  45. static void at_wifi_set(int argc, char **argv)
  46. {
  47. struct at_device_ssid_pwd sATDConf;
  48. struct at_device *at_dev = RT_NULL;
  49. /* If the number of arguments less than 2 */
  50. if (argc != 3)
  51. {
  52. rt_kprintf("\n");
  53. rt_kprintf("at_wifi_set <ssid> <password>\n");
  54. return ;
  55. }
  56. sATDConf.ssid = argv[1]; //ssid
  57. sATDConf.password = argv[2]; //password
  58. if ((at_dev = at_device_get_first_initialized()) != RT_NULL)
  59. at_device_control(at_dev, AT_DEVICE_CTRL_SET_WIFI_INFO, &sATDConf);
  60. else
  61. {
  62. rt_kprintf("Can't find any initialized AT device.\n");
  63. }
  64. }
  65. #ifdef FINSH_USING_MSH
  66. MSH_CMD_EXPORT(at_wifi_set, AT device wifi set ssid / password function);
  67. #endif
  68. #endif /* BOARD_USING_ESP8266 */
  69. #if defined(BOARD_USING_LCD_ILI9341) && defined(NU_PKG_USING_ILI9341_SPI)
  70. #if defined(NU_PKG_USING_ADC_TOUCH_SW)
  71. #include "adc_touch.h"
  72. #include "touch_sw.h"
  73. #include "NuMicro.h"
  74. #define NU_MFP_POS(PIN) ((PIN % 8) * 4)
  75. #define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN))
  76. S_CALIBRATION_MATRIX g_sCalMat = { 52, 6247, -2804852, 4917, 47, -2309716, 65536 };
  77. static void nu_pin_func(rt_base_t pin, int data)
  78. {
  79. uint32_t pin_index = NU_GET_PINS(pin);
  80. uint32_t port_index = NU_GET_PORT(pin);
  81. __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
  82. uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
  83. *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
  84. }
  85. static void tp_switch_to_analog(rt_base_t pin)
  86. {
  87. GPIO_T *port = (GPIO_T *)(GPIOA_BASE + (0x40) * NU_GET_PORT(pin));
  88. if (pin == NU_GET_PININDEX(NU_PB, 11))
  89. nu_pin_func(pin, SYS_GPB_MFPH_PB11MFP_EADC0_CH11);
  90. else if (pin == NU_GET_PININDEX(NU_PB, 8))
  91. nu_pin_func(pin, SYS_GPB_MFPH_PB8MFP_EADC0_CH8);
  92. GPIO_DISABLE_DIGITAL_PATH(port, NU_GET_PIN_MASK(NU_GET_PINS(pin)));
  93. }
  94. static void tp_switch_to_digital(rt_base_t pin)
  95. {
  96. GPIO_T *port = (GPIO_T *)(GPIOA_BASE + (0x40) * NU_GET_PORT(pin));
  97. nu_pin_func(pin, 0);
  98. /* Enable digital path on these EADC pins */
  99. GPIO_ENABLE_DIGITAL_PATH(port, NU_GET_PIN_MASK(NU_GET_PINS(pin)));
  100. }
  101. static S_TOUCH_SW sADCTP =
  102. {
  103. .adc_name = "eadc0",
  104. .i32ADCChnYU = 11,
  105. .i32ADCChnXR = 8,
  106. .pin =
  107. {
  108. NU_GET_PININDEX(NU_PB, 10), // XL
  109. NU_GET_PININDEX(NU_PB, 11), // YU
  110. NU_GET_PININDEX(NU_PB, 8), // XR
  111. NU_GET_PININDEX(NU_PB, 9), // YD
  112. },
  113. .switch_to_analog = tp_switch_to_analog,
  114. .switch_to_digital = tp_switch_to_digital,
  115. };
  116. #endif
  117. #include <lcd_ili9341.h>
  118. #if defined(PKG_USING_GUIENGINE)
  119. #include <rtgui/driver.h>
  120. #endif
  121. int rt_hw_ili9341_port(void)
  122. {
  123. if (rt_hw_lcd_ili9341_spi_init("spi1", RT_NULL) != RT_EOK)
  124. return -1;
  125. rt_hw_lcd_ili9341_init();
  126. #if defined(PKG_USING_GUIENGINE)
  127. rt_device_t lcd_ili9341;
  128. lcd_ili9341 = rt_device_find("lcd");
  129. if (lcd_ili9341)
  130. {
  131. rtgui_graphic_set_device(lcd_ili9341);
  132. }
  133. #endif
  134. #if defined(NU_PKG_USING_ADC_TOUCH_SW)
  135. nu_adc_touch_sw_register(&sADCTP);
  136. #endif
  137. return 0;
  138. }
  139. INIT_COMPONENT_EXPORT(rt_hw_ili9341_port);
  140. #endif /* BOARD_USING_LCD_ILI9341 */