board_dev.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_LCD_ILI9341) && defined(NU_PKG_USING_ILI9341_SPI)
  15. #include <lcd_ili9341.h>
  16. #if defined(PKG_USING_GUIENGINE)
  17. #include <rtgui/driver.h>
  18. #endif
  19. int rt_hw_ili9341_port(void)
  20. {
  21. if (rt_hw_lcd_ili9341_spi_init("spi1") != RT_EOK)
  22. return -1;
  23. rt_hw_lcd_ili9341_init();
  24. #if defined(PKG_USING_GUIENGINE)
  25. rt_device_t lcd_ili9341;
  26. lcd_ili9341 = rt_device_find("lcd");
  27. if (lcd_ili9341)
  28. {
  29. rtgui_graphic_set_device(lcd_ili9341);
  30. }
  31. #endif
  32. return 0;
  33. }
  34. INIT_COMPONENT_EXPORT(rt_hw_ili9341_port);
  35. #endif /* BOARD_USING_LCD_ILI9341 */
  36. #if defined(BOARD_USING_ESP8266)
  37. #include <at_device_esp8266.h>
  38. #define LOG_TAG "at.sample.esp"
  39. #undef DBG_TAG
  40. #include <at_log.h>
  41. static struct at_device_esp8266 esp0 =
  42. {
  43. "esp0", /* esp8266 device name */
  44. "uart4", /* esp8266 serial device name, EX: uart1, uuart1 */
  45. "NT_ZY_BUFFALO", /* Wi-Fi SSID */
  46. "12345678", /* Wi-Fi PASSWORD */
  47. 1024 /* Receive buffer length */
  48. };
  49. static int rt_hw_esp8266_port(void)
  50. {
  51. struct at_device_esp8266 *esp8266 = &esp0;
  52. rt_base_t esp_rst_pin = NU_GET_PININDEX(NU_PC, 13);
  53. rt_base_t esp_fwupdate_pin = NU_GET_PININDEX(NU_PD, 12);
  54. /* ESP8266 reset pin PC.13 */
  55. rt_pin_mode(esp_rst_pin, PIN_MODE_OUTPUT);
  56. rt_pin_write(esp_rst_pin, 1);
  57. /* ESP8266 reset pin PD.12 */
  58. rt_pin_mode(esp_fwupdate_pin, PIN_MODE_OUTPUT);
  59. rt_pin_write(esp_fwupdate_pin, 1);
  60. return at_device_register(&(esp8266->device),
  61. esp8266->device_name,
  62. esp8266->client_name,
  63. AT_DEVICE_CLASS_ESP8266,
  64. (void *) esp8266);
  65. }
  66. INIT_APP_EXPORT(rt_hw_esp8266_port);
  67. static void at_wifi_set(int argc, char **argv)
  68. {
  69. struct at_device_ssid_pwd sATDConf;
  70. struct at_device *at_dev = RT_NULL;
  71. /* If the number of arguments less than 2 */
  72. if (argc != 3)
  73. {
  74. rt_kprintf("\n");
  75. rt_kprintf("at_wifi_set <ssid> <password>\n");
  76. return ;
  77. }
  78. sATDConf.ssid = argv[1]; //ssid
  79. sATDConf.password = argv[2]; //password
  80. if ((at_dev = at_device_get_first_initialized()) != RT_NULL)
  81. at_device_control(at_dev, AT_DEVICE_CTRL_SET_WIFI_INFO, &sATDConf);
  82. else
  83. {
  84. rt_kprintf("Can't find any initialized AT device.\n");
  85. }
  86. }
  87. #ifdef FINSH_USING_MSH
  88. MSH_CMD_EXPORT(at_wifi_set, AT device wifi set ssid / password function);
  89. #endif
  90. #endif /* BOARD_USING_ESP8266 */