Add support for WiFi to ESP32-P4 (#10463)

* feat(p4): Add support for WiFi to ESP32-P4

Implements support for external MCU connected through SDIO

* fix(p4): Init SDIO host properly on Network boot

esp-hosted has one function marked as "constructor" that did not run in the boot phase of the chip. This calls the function when network is started
This commit is contained in:
Me No Dev 2024-10-15 17:25:45 +03:00 committed by GitHub
parent 3733c87c83
commit 3edf518825
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 58 additions and 28 deletions

View file

@ -56,11 +56,11 @@ dependencies:
espressif/esp-zboss-lib:
version: "^1.0.1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp-zigbee-lib:
version: "^1.0.1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp-dsp:
version: "^1.3.4"
rules:
@ -68,23 +68,31 @@ dependencies:
espressif/esp_rainmaker:
version: "^1.0.0"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/rmaker_common:
version: "^1.4.6"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp_insights:
version: "^1.0.1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/qrcode:
version: "^0.1.0~1"
rules:
- if: "target != esp32c2"
- if: "target not in [esp32c2, esp32p4]"
espressif/esp-sr:
version: "^1.4.2"
rules:
- if: "target in [esp32s3]"
espressif/esp_hosted:
version: "^0.0.22"
rules:
- if: "target == esp32p4"
espressif/esp_wifi_remote:
version: "^0.4.1"
rules:
- if: "target == esp32p4"
espressif/libsodium:
version: "^1.0.20~1"
require: public

View file

@ -423,7 +423,7 @@ const char *NetworkEvents::eventName(arduino_event_id_t id) {
case ARDUINO_EVENT_PPP_GOT_IP: return "PPP_GOT_IP";
case ARDUINO_EVENT_PPP_LOST_IP: return "PPP_LOST_IP";
case ARDUINO_EVENT_PPP_GOT_IP6: return "PPP_GOT_IP6";
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
case ARDUINO_EVENT_WIFI_OFF: return "WIFI_OFF";
case ARDUINO_EVENT_WIFI_READY: return "WIFI_READY";
case ARDUINO_EVENT_WIFI_SCAN_DONE: return "SCAN_DONE";

View file

@ -16,14 +16,15 @@
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "sdkconfig.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "esp_wifi_types.h"
#include "esp_smartconfig.h"
#include "network_provisioning/network_config.h"
#endif
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
static const int WIFI_SCANNING_BIT = BIT0;
static const int WIFI_SCAN_DONE_BIT = BIT1;
#endif
@ -41,7 +42,7 @@ typedef enum {
ARDUINO_EVENT_ETH_GOT_IP,
ARDUINO_EVENT_ETH_LOST_IP,
ARDUINO_EVENT_ETH_GOT_IP6,
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
ARDUINO_EVENT_WIFI_OFF,
ARDUINO_EVENT_WIFI_READY,
ARDUINO_EVENT_WIFI_SCAN_DONE,
@ -93,7 +94,7 @@ typedef union {
ip_event_got_ip_t got_ip;
ip_event_got_ip6_t got_ip6;
esp_eth_handle_t eth_connected;
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
wifi_event_sta_scan_done_t wifi_scan_done;
wifi_event_sta_authmode_change_t wifi_sta_authmode_change;
wifi_event_sta_connected_t wifi_sta_connected;
@ -104,6 +105,8 @@ typedef union {
wifi_event_ap_staconnected_t wifi_ap_staconnected;
wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected;
wifi_event_ftm_report_t wifi_ftm_report;
#endif
#if SOC_WIFI_SUPPORTED
wifi_sta_config_t prov_cred_recv;
network_prov_wifi_sta_fail_reason_t prov_fail_reason;
smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd;
@ -147,7 +150,7 @@ public:
friend class ESP_NetworkInterface;
friend class ETHClass;
friend class PPPClass;
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
friend class STAClass;
friend class APClass;
friend class WiFiGenericClass;

View file

@ -10,6 +10,10 @@
#include "esp_mac.h"
#include "netdb.h"
#if CONFIG_ESP_WIFI_REMOTE_ENABLED
extern "C" esp_err_t esp_hosted_init(void *);
#endif
NetworkManager::NetworkManager() {}
NetworkInterface *getNetifByID(Network_Interface_ID id);
@ -18,6 +22,9 @@ bool NetworkManager::begin() {
static bool initialized = false;
if (!initialized) {
initialized = true;
#if CONFIG_ESP_WIFI_REMOTE_ENABLED
esp_hosted_init(NULL);
#endif
#if CONFIG_IDF_TARGET_ESP32
uint8_t mac[8];
if (esp_efuse_mac_get_default(mac) == ESP_OK) {

View file

@ -7,7 +7,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiAP.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

View file

@ -6,7 +6,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiSTA.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

View file

@ -22,7 +22,7 @@
*/
#include "WiFi.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
extern "C" {
#include <stdint.h>

View file

@ -22,7 +22,8 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#include "sdkconfig.h"
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>

View file

@ -25,7 +25,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiAP.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>
#include <stdbool.h>

View file

@ -23,7 +23,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "esp_wifi_types.h"
#include "WiFiType.h"

View file

@ -24,7 +24,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
extern "C" {
#include <stdint.h>
@ -39,7 +39,9 @@ extern "C" {
#include <esp_event.h>
#include <esp_mac.h>
#include <esp_netif.h>
#if SOC_WIFI_SUPPORTED
#include <esp_phy.h>
#endif
#include "lwip/ip_addr.h"
#include "lwip/opt.h"
#include "lwip/err.h"
@ -103,6 +105,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
arduino_event.event_id = ARDUINO_EVENT_WIFI_FTM_REPORT;
memcpy(&arduino_event.event_info.wifi_ftm_report, event_data, sizeof(wifi_event_ftm_report_t));
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
/*
* SMART CONFIG
* */
@ -157,6 +160,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
} else if (event_base == NETWORK_PROV_EVENT && event_id == NETWORK_PROV_WIFI_CRED_SUCCESS) {
log_v("Provisioning Success!");
arduino_event.event_id = ARDUINO_EVENT_PROV_CRED_SUCCESS;
#endif
}
if (arduino_event.event_id < ARDUINO_EVENT_MAX) {
@ -170,6 +174,7 @@ static bool initWiFiEvents() {
return false;
}
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
if (esp_event_handler_instance_register(SC_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb, NULL, NULL)) {
log_e("event_handler_instance_register for SC_EVENT Failed!");
return false;
@ -179,6 +184,7 @@ static bool initWiFiEvents() {
log_e("event_handler_instance_register for NETWORK_PROV_EVENT Failed!");
return false;
}
#endif
return true;
}
@ -189,6 +195,7 @@ static bool deinitWiFiEvents() {
return false;
}
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
if (esp_event_handler_unregister(SC_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb)) {
log_e("esp_event_handler_unregister for SC_EVENT Failed!");
return false;
@ -198,6 +205,7 @@ static bool deinitWiFiEvents() {
log_e("esp_event_handler_unregister for NETWORK_PROV_EVENT Failed!");
return false;
}
#endif
return true;
}
@ -370,6 +378,7 @@ void WiFiGenericClass::_eventCallback(arduino_event_t *event) {
// log_d("Arduino Event: %d - %s", event->event_id, WiFi.eventName(event->event_id));
if (event->event_id == ARDUINO_EVENT_WIFI_SCAN_DONE) {
WiFiScanClass::_scanDone();
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
} else if (event->event_id == ARDUINO_EVENT_SC_GOT_SSID_PSWD) {
WiFi.begin(
(const char *)event->event_info.sc_got_ssid_pswd.ssid, (const char *)event->event_info.sc_got_ssid_pswd.password, 0,
@ -378,6 +387,7 @@ void WiFiGenericClass::_eventCallback(arduino_event_t *event) {
} else if (event->event_id == ARDUINO_EVENT_SC_SEND_ACK_DONE) {
esp_smartconfig_stop();
WiFiSTAClass::_smartConfigDone = true;
#endif
}
}
@ -693,6 +703,7 @@ bool WiFiGenericClass::initiateFTM(uint8_t frm_count, uint16_t burst_period, uin
* @return true on success
*/
bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode) {
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
esp_phy_ant_gpio_config_t wifi_ant_io;
@ -759,7 +770,7 @@ set_ant:
log_e("Failed to set antenna configuration");
return false;
}
#endif
return true;
}

View file

@ -23,7 +23,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "esp_err.h"
#include "esp_event.h"

View file

@ -24,7 +24,7 @@
*/
#include "WiFiMulti.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <limits.h>
#include <string.h>
#include <esp32-hal.h>

View file

@ -26,7 +26,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "WiFi.h"
#include <vector>

View file

@ -25,7 +25,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiSTA.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include <stdint.h>
#include <stdbool.h>

View file

@ -23,7 +23,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "WiFiType.h"
#include "WiFiGeneric.h"

View file

@ -25,7 +25,7 @@
#include "WiFi.h"
#include "WiFiGeneric.h"
#include "WiFiScan.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
extern "C" {
#include <stdint.h>

View file

@ -23,7 +23,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "WiFiType.h"
#include "WiFiGeneric.h"

View file

@ -22,7 +22,7 @@
#pragma once
#include "soc/soc_caps.h"
#if SOC_WIFI_SUPPORTED
#if SOC_WIFI_SUPPORTED || CONFIG_ESP_WIFI_REMOTE_ENABLED
#include "esp_wifi_types.h"