cpu/esp*: changes to use esp_wifi and esp_now

This commit is contained in:
Gunar Schorcht 2019-02-02 14:37:21 +01:00 committed by Schorcht
parent 760168e403
commit 97bb33788b
6 changed files with 53 additions and 19 deletions

View File

@ -38,10 +38,12 @@ ifneq (,$(filter esp_gdbstub,$(USEMODULE)))
endif
ifneq (,$(filter esp_now,$(USEMODULE)))
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
USEMODULE += esp_wifi_any
endif
ifneq (,$(filter esp_wifi,$(USEMODULE)))
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
USEMODULE += esp_wifi_any
endif

View File

@ -193,6 +193,7 @@ static wifi_config_t wifi_config_sta = {
.sta = {
.ssid = ESP_WIFI_SSID,
.password = ESP_WIFI_PASS,
.bssid_set = 0,
.channel = 0,
.scan_method = WIFI_ALL_CHANNEL_SCAN,
.sort_method = WIFI_CONNECT_AP_BY_SIGNAL,
@ -205,25 +206,32 @@ static void esp_wifi_setup (esp_wifi_netdev_t* dev)
{
DEBUG("%s: %p\n", __func__, dev);
/* initialize buffer */
dev->rx_len = 0;
/* set the event handler */
esp_system_event_add_handler(_esp_system_event_handler, NULL);
/*
* Init the WiFi driver. TODO It is not only required before ESP_WIFI is
* initialized but also before other WiFi functions are used. Once other
* WiFi functions are realized it has to be moved to a more common place.
*/
esp_err_t result;
#ifndef MODULE_ESP_NOW
/* if esp_now is used, the following part is already done */
extern portMUX_TYPE g_intr_lock_mux;
mutex_init(&g_intr_lock_mux);
esp_system_event_add_handler (_esp_system_event_handler, NULL);
esp_err_t result;
#if CONFIG_ESP32_WIFI_NVS_ENABLED
#if CONFIG_ESP32_WIFI_NVS_ENABLED
result = nvs_flash_init();
if (result != ESP_OK) {
LOG_TAG_ERROR("esp_wifi", "nfs_flash_init failed "
"with return value %d\n", result);
return;
}
#endif
#endif /* CONFIG_ESP32_WIFI_NVS_ENABLED */
/* initialize the WiFi driver with default configuration */
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
@ -242,9 +250,9 @@ static void esp_wifi_setup (esp_wifi_netdev_t* dev)
return NULL;
}
#ifdef CONFIG_WIFI_COUNTRY
#ifdef CONFIG_WIFI_COUNTRY
/* TODO */
#endif
#endif /* CONFIG_WIFI_COUNTRY */
result = esp_wifi_set_mode(WIFI_MODE_STA);
if (result != ESP_OK) {
@ -252,6 +260,7 @@ static void esp_wifi_setup (esp_wifi_netdev_t* dev)
"with return value %d\n", result);
return;
}
#endif /* MODULE_ESP_NOW */
/* set the Station configuration */
result = esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config_sta);
@ -474,8 +483,12 @@ void auto_init_esp_wifi (void)
esp_wifi_setup(&_esp_wifi_dev);
_esp_wifi_dev.event = SYSTEM_EVENT_MAX; /* no event */
_esp_wifi_dev.netif = gnrc_netif_ethernet_create(_esp_wifi_stack,
ESP_WIFI_STACKSIZE, ESP_WIFI_PRIO,
"netdev-esp-wifi",
ESP_WIFI_STACKSIZE,
#ifdef MODULE_ESP_NOW
ESP_WIFI_PRIO - 1,
#else
ESP_WIFI_PRIO,
#endif
"esp-wifi",
(netdev_t *)&_esp_wifi_dev);
}

View File

@ -33,7 +33,13 @@ ifneq (, $(filter esp_sw_timer, $(USEMODULE)))
USEMODULE += esp_sdk
endif
ifneq (, $(filter esp_now esp_wifi, $(USEMODULE)))
ifneq (, $(filter esp_wifi, $(USEMODULE)))
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
USEMODULE += esp_sdk
USEMODULE += netopt
endif
ifneq (, $(filter esp_now, $(USEMODULE)))
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
USEMODULE += esp_sdk
USEMODULE += netopt

View File

@ -356,12 +356,14 @@ static int IRAM _send(netdev_t *netdev, const iolist_t *iolist)
return -EIO;
}
#ifndef MODULE_ESP_NOW
if (wifi_get_opmode() != ESP_WIFI_MODE) {
ESP_WIFI_DEBUG("WiFi is not in correct mode, cannot send");
_in_send = false;
critical_exit();
return -EIO;
}
#endif
const iolist_t *iol = iolist;
size_t iol_len = 0;
@ -688,7 +690,12 @@ void auto_init_esp_wifi(void)
/* create netif */
gnrc_netif_ethernet_create(_esp_wifi_stack, ESP_WIFI_STACKSIZE,
ESP_WIFI_PRIO, "esp_wifi",
#ifdef MODULE_ESP_NOW
ESP_WIFI_PRIO - 1,
#else
ESP_WIFI_PRIO,
#endif
"esp-wifi",
(netdev_t *)&_esp_wifi_dev);
}

View File

@ -81,6 +81,9 @@
#endif /* MCU_ESP8266 */
#if MODULE_ESP_WIFI && !ESP_NOW_UNICAST
#error If module esp_wifi is used, module esp_now has to be used in unicast mode
#endif
/**
* There is only one ESP-NOW device. We define it as static device variable
@ -404,13 +407,6 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
}
#ifdef MCU_ESP32
/*
* Init the WiFi driver. TODO It is not only required before ESP_NOW is
* initialized but also before other WiFi functions are used. Once other
* WiFi functions are realized it has to be moved to a more common place.
*/
extern portMUX_TYPE g_intr_lock_mux;
mutex_init(&g_intr_lock_mux);
/* initialize buffer */
dev->rx_len = 0;
@ -418,7 +414,12 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
/* set the event handler */
esp_system_event_add_handler(_esp_system_event_handler, NULL);
/* init the WiFi driver */
extern portMUX_TYPE g_intr_lock_mux;
mutex_init(&g_intr_lock_mux);
esp_err_t result;
#if CONFIG_ESP32_WIFI_NVS_ENABLED
result = nvs_flash_init();
if (result != ESP_OK) {
@ -504,7 +505,8 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
return NULL;
}
/* start the WiFi driver */
#ifndef MODULE_ESP_WIFI
/* start WiFi if esp_wifi is not used, otherwise it is done by esp_wifi */
result = esp_wifi_start();
if (result != ESP_OK) {
LOG_TAG_ERROR("esp_now",
@ -516,6 +518,8 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
esp_wifi_set_mac(ESP_IF_WIFI_STA, (uint8_t*)_esp_now_mac);
#endif
#endif /* MODULE_ESP_WIFI */
#else /* MCU_ESP32 */
int result;

View File

@ -226,11 +226,13 @@ void auto_init(void)
auto_init_esp_eth();
#endif
/* don't change the order of auto_init_esp_now and auto_init_esp_wifi */
#ifdef MODULE_ESP_NOW
extern void auto_init_esp_now(void);
auto_init_esp_now();
#endif
/* don't change the order of auto_init_esp_now and auto_init_esp_wifi */
#ifdef MODULE_ESP_WIFI
extern void auto_init_esp_wifi(void);
auto_init_esp_wifi();