board_dev.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 */