cpu/esp*: changes to use esp_wifi and esp_now
This commit is contained in:
parent
760168e403
commit
97bb33788b
@ -38,10 +38,12 @@ ifneq (,$(filter esp_gdbstub,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter esp_now,$(USEMODULE)))
|
ifneq (,$(filter esp_now,$(USEMODULE)))
|
||||||
|
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
|
||||||
USEMODULE += esp_wifi_any
|
USEMODULE += esp_wifi_any
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter esp_wifi,$(USEMODULE)))
|
ifneq (,$(filter esp_wifi,$(USEMODULE)))
|
||||||
|
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
|
||||||
USEMODULE += esp_wifi_any
|
USEMODULE += esp_wifi_any
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@ -193,6 +193,7 @@ static wifi_config_t wifi_config_sta = {
|
|||||||
.sta = {
|
.sta = {
|
||||||
.ssid = ESP_WIFI_SSID,
|
.ssid = ESP_WIFI_SSID,
|
||||||
.password = ESP_WIFI_PASS,
|
.password = ESP_WIFI_PASS,
|
||||||
|
.bssid_set = 0,
|
||||||
.channel = 0,
|
.channel = 0,
|
||||||
.scan_method = WIFI_ALL_CHANNEL_SCAN,
|
.scan_method = WIFI_ALL_CHANNEL_SCAN,
|
||||||
.sort_method = WIFI_CONNECT_AP_BY_SIGNAL,
|
.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);
|
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
|
* 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
|
* 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.
|
* 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;
|
extern portMUX_TYPE g_intr_lock_mux;
|
||||||
mutex_init(&g_intr_lock_mux);
|
mutex_init(&g_intr_lock_mux);
|
||||||
|
|
||||||
esp_system_event_add_handler (_esp_system_event_handler, NULL);
|
#if CONFIG_ESP32_WIFI_NVS_ENABLED
|
||||||
|
|
||||||
esp_err_t result;
|
|
||||||
#if CONFIG_ESP32_WIFI_NVS_ENABLED
|
|
||||||
result = nvs_flash_init();
|
result = nvs_flash_init();
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
LOG_TAG_ERROR("esp_wifi", "nfs_flash_init failed "
|
LOG_TAG_ERROR("esp_wifi", "nfs_flash_init failed "
|
||||||
"with return value %d\n", result);
|
"with return value %d\n", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_ESP32_WIFI_NVS_ENABLED */
|
||||||
|
|
||||||
/* initialize the WiFi driver with default configuration */
|
/* initialize the WiFi driver with default configuration */
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_WIFI_COUNTRY
|
#ifdef CONFIG_WIFI_COUNTRY
|
||||||
/* TODO */
|
/* TODO */
|
||||||
#endif
|
#endif /* CONFIG_WIFI_COUNTRY */
|
||||||
|
|
||||||
result = esp_wifi_set_mode(WIFI_MODE_STA);
|
result = esp_wifi_set_mode(WIFI_MODE_STA);
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
@ -252,6 +260,7 @@ static void esp_wifi_setup (esp_wifi_netdev_t* dev)
|
|||||||
"with return value %d\n", result);
|
"with return value %d\n", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif /* MODULE_ESP_NOW */
|
||||||
|
|
||||||
/* set the Station configuration */
|
/* set the Station configuration */
|
||||||
result = esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config_sta);
|
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_setup(&_esp_wifi_dev);
|
||||||
_esp_wifi_dev.event = SYSTEM_EVENT_MAX; /* no event */
|
_esp_wifi_dev.event = SYSTEM_EVENT_MAX; /* no event */
|
||||||
_esp_wifi_dev.netif = gnrc_netif_ethernet_create(_esp_wifi_stack,
|
_esp_wifi_dev.netif = gnrc_netif_ethernet_create(_esp_wifi_stack,
|
||||||
ESP_WIFI_STACKSIZE, ESP_WIFI_PRIO,
|
ESP_WIFI_STACKSIZE,
|
||||||
"netdev-esp-wifi",
|
#ifdef MODULE_ESP_NOW
|
||||||
|
ESP_WIFI_PRIO - 1,
|
||||||
|
#else
|
||||||
|
ESP_WIFI_PRIO,
|
||||||
|
#endif
|
||||||
"esp-wifi",
|
"esp-wifi",
|
||||||
(netdev_t *)&_esp_wifi_dev);
|
(netdev_t *)&_esp_wifi_dev);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,13 @@ ifneq (, $(filter esp_sw_timer, $(USEMODULE)))
|
|||||||
USEMODULE += esp_sdk
|
USEMODULE += esp_sdk
|
||||||
endif
|
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))))
|
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
|
||||||
USEMODULE += esp_sdk
|
USEMODULE += esp_sdk
|
||||||
USEMODULE += netopt
|
USEMODULE += netopt
|
||||||
|
|||||||
@ -356,12 +356,14 @@ static int IRAM _send(netdev_t *netdev, const iolist_t *iolist)
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MODULE_ESP_NOW
|
||||||
if (wifi_get_opmode() != ESP_WIFI_MODE) {
|
if (wifi_get_opmode() != ESP_WIFI_MODE) {
|
||||||
ESP_WIFI_DEBUG("WiFi is not in correct mode, cannot send");
|
ESP_WIFI_DEBUG("WiFi is not in correct mode, cannot send");
|
||||||
_in_send = false;
|
_in_send = false;
|
||||||
critical_exit();
|
critical_exit();
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const iolist_t *iol = iolist;
|
const iolist_t *iol = iolist;
|
||||||
size_t iol_len = 0;
|
size_t iol_len = 0;
|
||||||
@ -688,7 +690,12 @@ void auto_init_esp_wifi(void)
|
|||||||
|
|
||||||
/* create netif */
|
/* create netif */
|
||||||
gnrc_netif_ethernet_create(_esp_wifi_stack, ESP_WIFI_STACKSIZE,
|
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);
|
(netdev_t *)&_esp_wifi_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -81,6 +81,9 @@
|
|||||||
|
|
||||||
#endif /* MCU_ESP8266 */
|
#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
|
* 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
|
#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 */
|
/* initialize buffer */
|
||||||
dev->rx_len = 0;
|
dev->rx_len = 0;
|
||||||
@ -418,7 +414,12 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
|||||||
/* set the event handler */
|
/* set the event handler */
|
||||||
esp_system_event_add_handler(_esp_system_event_handler, NULL);
|
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;
|
esp_err_t result;
|
||||||
|
|
||||||
#if CONFIG_ESP32_WIFI_NVS_ENABLED
|
#if CONFIG_ESP32_WIFI_NVS_ENABLED
|
||||||
result = nvs_flash_init();
|
result = nvs_flash_init();
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
@ -504,7 +505,8 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
|||||||
return NULL;
|
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();
|
result = esp_wifi_start();
|
||||||
if (result != ESP_OK) {
|
if (result != ESP_OK) {
|
||||||
LOG_TAG_ERROR("esp_now",
|
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);
|
esp_wifi_set_mac(ESP_IF_WIFI_STA, (uint8_t*)_esp_now_mac);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* MODULE_ESP_WIFI */
|
||||||
|
|
||||||
#else /* MCU_ESP32 */
|
#else /* MCU_ESP32 */
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
|
|||||||
@ -226,11 +226,13 @@ void auto_init(void)
|
|||||||
auto_init_esp_eth();
|
auto_init_esp_eth();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* don't change the order of auto_init_esp_now and auto_init_esp_wifi */
|
||||||
#ifdef MODULE_ESP_NOW
|
#ifdef MODULE_ESP_NOW
|
||||||
extern void auto_init_esp_now(void);
|
extern void auto_init_esp_now(void);
|
||||||
auto_init_esp_now();
|
auto_init_esp_now();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* don't change the order of auto_init_esp_now and auto_init_esp_wifi */
|
||||||
#ifdef MODULE_ESP_WIFI
|
#ifdef MODULE_ESP_WIFI
|
||||||
extern void auto_init_esp_wifi(void);
|
extern void auto_init_esp_wifi(void);
|
||||||
auto_init_esp_wifi();
|
auto_init_esp_wifi();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user