user_interface.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright (C) 2013 -2014 Espressif System
  3. *
  4. */
  5. #ifndef __USER_INTERFACE_H__
  6. #define __USER_INTERFACE_H__
  7. #include "os_type.h"
  8. #ifdef LWIP_OPEN_SRC
  9. #include "lwip/ip_addr.h"
  10. #else
  11. #include "ip_addr.h"
  12. #endif
  13. #include "queue.h"
  14. #include "user_config.h"
  15. #include "spi_flash.h"
  16. #ifndef MAC2STR
  17. #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
  18. #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
  19. #endif
  20. enum rst_reason {
  21. DEFAULT_RST_FLAG = 0,
  22. WDT_RST_FLAG = 1,
  23. EXP_RST_FLAG = 2
  24. };
  25. struct rst_info{
  26. uint32 flag;
  27. uint32 exccause;
  28. uint32 epc1;
  29. uint32 epc2;
  30. uint32 epc3;
  31. uint32 excvaddr;
  32. uint32 depc;
  33. };
  34. #define UPGRADE_FW_BIN1 0x00
  35. #define UPGRADE_FW_BIN2 0x01
  36. void system_restore(void);
  37. void system_restart(void);
  38. bool system_deep_sleep_set_option(uint8 option);
  39. void system_deep_sleep(uint32 time_in_us);
  40. uint8 system_upgrade_userbin_check(void);
  41. void system_upgrade_reboot(void);
  42. uint8 system_upgrade_flag_check();
  43. void system_upgrade_flag_set(uint8 flag);
  44. void system_timer_reinit(void);
  45. uint32 system_get_time(void);
  46. /* user task's prio must be 0/1/2 !!!*/
  47. enum {
  48. USER_TASK_PRIO_0 = 0,
  49. USER_TASK_PRIO_1,
  50. USER_TASK_PRIO_2,
  51. USER_TASK_PRIO_MAX
  52. };
  53. bool system_os_task(os_task_t task, uint8 prio, os_event_t *queue, uint8 qlen);
  54. bool system_os_post(uint8 prio, os_signal_t sig, os_param_t par);
  55. void system_print_meminfo(void);
  56. uint32 system_get_free_heap_size(void);
  57. void system_set_os_print(uint8 onoff);
  58. uint8 system_get_os_print();
  59. uint64 system_mktime(uint32 year, uint32 mon, uint32 day, uint32 hour, uint32 min, uint32 sec);
  60. uint32 system_get_chip_id(void);
  61. typedef void (* init_done_cb_t)(void);
  62. void system_init_done_cb(init_done_cb_t cb);
  63. uint32 system_rtc_clock_cali_proc(void);
  64. uint32 system_get_rtc_time(void);
  65. bool system_rtc_mem_read(uint8 src_addr, void *des_addr, uint16 load_size);
  66. bool system_rtc_mem_write(uint8 des_addr, const void *src_addr, uint16 save_size);
  67. void system_uart_swap(void);
  68. uint16 system_adc_read(void);
  69. const char *system_get_sdk_version(void);
  70. #define NULL_MODE 0x00
  71. #define STATION_MODE 0x01
  72. #define SOFTAP_MODE 0x02
  73. #define STATIONAP_MODE 0x03
  74. typedef enum _auth_mode {
  75. AUTH_OPEN = 0,
  76. AUTH_WEP,
  77. AUTH_WPA_PSK,
  78. AUTH_WPA2_PSK,
  79. AUTH_WPA_WPA2_PSK,
  80. AUTH_MAX
  81. } AUTH_MODE;
  82. uint8 wifi_get_opmode(void);
  83. bool wifi_set_opmode(uint8 opmode);
  84. struct bss_info {
  85. STAILQ_ENTRY(bss_info) next;
  86. uint8 bssid[6];
  87. uint8 ssid[32];
  88. uint8 channel;
  89. sint8 rssi;
  90. AUTH_MODE authmode;
  91. uint8 is_hidden;
  92. };
  93. typedef struct _scaninfo {
  94. STAILQ_HEAD(, bss_info) *pbss;
  95. struct espconn *pespconn;
  96. uint8 totalpage;
  97. uint8 pagenum;
  98. uint8 page_sn;
  99. uint8 data_cnt;
  100. } scaninfo;
  101. typedef void (* scan_done_cb_t)(void *arg, STATUS status);
  102. struct station_config {
  103. uint8 ssid[32];
  104. uint8 password[64];
  105. uint8 bssid_set; // Note: If bssid_set is 1, station will just connect to the router
  106. // with both ssid[] and bssid[] matched. Please check about this.
  107. uint8 bssid[6];
  108. };
  109. bool wifi_station_get_config(struct station_config *config);
  110. bool wifi_station_set_config(struct station_config *config);
  111. bool wifi_station_connect(void);
  112. bool wifi_station_disconnect(void);
  113. struct scan_config {
  114. uint8 *ssid; // Note: ssid == NULL, don't filter ssid.
  115. uint8 *bssid; // Note: bssid == NULL, don't filter bssid.
  116. uint8 channel; // Note: channel == 0, scan all channels, otherwise scan set channel.
  117. uint8 show_hidden; // Note: show_hidden == 1, can get hidden ssid routers' info.
  118. };
  119. bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb);
  120. uint8 wifi_station_get_auto_connect(void);
  121. bool wifi_station_set_auto_connect(uint8 set);
  122. enum {
  123. STATION_IDLE = 0,
  124. STATION_CONNECTING,
  125. STATION_WRONG_PASSWORD,
  126. STATION_NO_AP_FOUND,
  127. STATION_CONNECT_FAIL,
  128. STATION_GOT_IP
  129. };
  130. enum dhcp_status {
  131. DHCP_STOPPED,
  132. DHCP_STARTED
  133. };
  134. uint8 wifi_station_get_connect_status(void);
  135. uint8 wifi_station_get_current_ap_id(void);
  136. bool wifi_station_ap_change(uint8 current_ap_id);
  137. bool wifi_station_ap_number_set(uint8 ap_number);
  138. bool wifi_station_dhcpc_start(void);
  139. bool wifi_station_dhcpc_stop(void);
  140. enum dhcp_status wifi_station_dhcpc_status(void);
  141. struct softap_config {
  142. uint8 ssid[32];
  143. uint8 password[64];
  144. uint8 ssid_len; // Note: Recommend to set it according to your ssid
  145. uint8 channel; // Note: support 1 ~ 13
  146. AUTH_MODE authmode; // Note: Don't support AUTH_WEP in softAP mode.
  147. uint8 ssid_hidden; // Note: default 0
  148. uint8 max_connection; // Note: default 4, max 4
  149. uint16 beacon_interval; // Note: support 100 ~ 60000 ms, default 100
  150. };
  151. bool wifi_softap_get_config(struct softap_config *config);
  152. bool wifi_softap_set_config(struct softap_config *config);
  153. struct station_info {
  154. STAILQ_ENTRY(station_info) next;
  155. uint8 bssid[6];
  156. struct ip_addr ip;
  157. };
  158. struct dhcps_lease {
  159. uint32 start_ip;
  160. uint32 end_ip;
  161. };
  162. struct station_info * wifi_softap_get_station_info(void);
  163. void wifi_softap_free_station_info(void);
  164. uint8 wifi_station_get_ap_info(struct station_config config[]);
  165. bool wifi_softap_dhcps_start(void);
  166. bool wifi_softap_dhcps_stop(void);
  167. bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please);
  168. enum dhcp_status wifi_softap_dhcps_status(void);
  169. #define STATION_IF 0x00
  170. #define SOFTAP_IF 0x01
  171. bool wifi_get_ip_info(uint8 if_index, struct ip_info *info);
  172. bool wifi_set_ip_info(uint8 if_index, struct ip_info *info);
  173. bool wifi_get_macaddr(uint8 if_index, uint8 *macaddr);
  174. bool wifi_set_macaddr(uint8 if_index, uint8 *macaddr);
  175. uint8 wifi_get_channel(void);
  176. bool wifi_set_channel(uint8 channel);
  177. void wifi_status_led_install(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func);
  178. void wifi_status_led_uninstall();
  179. /** Get the absolute difference between 2 u32_t values (correcting overflows)
  180. * 'a' is expected to be 'higher' (without overflow) than 'b'. */
  181. #define ESP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1)))
  182. void wifi_promiscuous_enable(uint8 promiscuous);
  183. typedef void (* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len);
  184. void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
  185. enum phy_mode {
  186. PHY_MODE_11B = 1,
  187. PHY_MODE_11G = 2,
  188. PHY_MODE_11N = 3
  189. };
  190. enum phy_mode wifi_get_phy_mode(void);
  191. bool wifi_set_phy_mode(enum phy_mode mode);
  192. enum sleep_type {
  193. NONE_SLEEP_T = 0,
  194. LIGHT_SLEEP_T,
  195. MODEM_SLEEP_T
  196. };
  197. bool wifi_set_sleep_type(enum sleep_type type);
  198. enum sleep_type wifi_get_sleep_type(void);
  199. #endif