forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esphome: some patches to get new esp-idf running
- Loading branch information
Showing
6 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
From 98644ad1bcea4c30d514036ab2ab38cf19a3227c Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <[email protected]> | ||
Date: Sun, 9 Apr 2023 08:24:38 +0200 | ||
Subject: [PATCH 1/5] fix include | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
Signed-off-by: Jörg Thalheim <[email protected]> | ||
--- | ||
esphome/components/esp32/core.cpp | 4 ++++ | ||
esphome/core/helpers.cpp | 5 +++++ | ||
2 files changed, 9 insertions(+) | ||
|
||
diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp | ||
index 6123d83a..b22968c9 100644 | ||
--- a/esphome/components/esp32/core.cpp | ||
+++ b/esphome/components/esp32/core.cpp | ||
@@ -13,6 +13,10 @@ | ||
#include <hal/cpu_hal.h> | ||
#endif | ||
|
||
+#ifdef USE_ESP_IDF | ||
+#include <esp_timer.h> | ||
+#endif | ||
+ | ||
#ifdef USE_ARDUINO | ||
#include <esp32-hal.h> | ||
#endif | ||
diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp | ||
index 7f5c3ad3..7b55cb29 100644 | ||
--- a/esphome/core/helpers.cpp | ||
+++ b/esphome/core/helpers.cpp | ||
@@ -34,6 +34,11 @@ | ||
#include "esp_efuse_table.h" | ||
#endif | ||
|
||
+#ifdef USE_ESP32 | ||
+#include "esp_random.h" | ||
+#include "esp_mac.h" | ||
+#endif | ||
+ | ||
namespace esphome { | ||
|
||
// STL backports | ||
-- | ||
2.39.2 | ||
|
37 changes: 37 additions & 0 deletions
37
pkgs/tools/misc/esphome/0002-fix-freertos-compatibility.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
From d2b3163808b12f8367081f16d99370a7df64d712 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <[email protected]> | ||
Date: Sun, 9 Apr 2023 09:17:41 +0200 | ||
Subject: [PATCH 2/5] fix freertos compatibility | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
Signed-off-by: Jörg Thalheim <[email protected]> | ||
--- | ||
esphome/components/wifi/wifi_component_esp_idf.cpp | 3 ++- | ||
1 file changed, 2 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/esphome/components/wifi/wifi_component_esp_idf.cpp b/esphome/components/wifi/wifi_component_esp_idf.cpp | ||
index 28831644..fba399f6 100644 | ||
--- a/esphome/components/wifi/wifi_component_esp_idf.cpp | ||
+++ b/esphome/components/wifi/wifi_component_esp_idf.cpp | ||
@@ -2,6 +2,7 @@ | ||
|
||
#ifdef USE_ESP_IDF | ||
|
||
+#define ENABLE_BACKWARD_COMPATIBILITY | ||
#include <freertos/FreeRTOS.h> | ||
#include <freertos/task.h> | ||
#include <freertos/event_groups.h> | ||
@@ -31,7 +32,7 @@ namespace wifi { | ||
static const char *const TAG = "wifi_esp32"; | ||
|
||
static EventGroupHandle_t s_wifi_event_group; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||
-static xQueueHandle s_event_queue; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||
+static QueueHandle_t s_event_queue; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||
static esp_netif_t *s_sta_netif = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||
static esp_netif_t *s_ap_netif = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||
static bool s_sta_started = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) | ||
-- | ||
2.39.2 | ||
|
185 changes: 185 additions & 0 deletions
185
pkgs/tools/misc/esphome/0003-wifi-port-to-new-esp-netif-api.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
From 49686ccc2c8afe662abaf3823c58ad3d681361ef Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <[email protected]> | ||
Date: Sun, 9 Apr 2023 09:42:30 +0200 | ||
Subject: [PATCH 3/5] wifi: port to new esp netif api | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
Signed-off-by: Jörg Thalheim <[email protected]> | ||
--- | ||
.../wifi/wifi_component_esp_idf.cpp | 66 ++++++++++--------- | ||
1 file changed, 36 insertions(+), 30 deletions(-) | ||
|
||
diff --git a/esphome/components/wifi/wifi_component_esp_idf.cpp b/esphome/components/wifi/wifi_component_esp_idf.cpp | ||
index fba399f6..3deb8f72 100644 | ||
--- a/esphome/components/wifi/wifi_component_esp_idf.cpp | ||
+++ b/esphome/components/wifi/wifi_component_esp_idf.cpp | ||
@@ -414,17 +414,17 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) { | ||
if (!this->wifi_mode_(true, {})) | ||
return false; | ||
|
||
- tcpip_adapter_dhcp_status_t dhcp_status; | ||
- esp_err_t err = tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &dhcp_status); | ||
+ esp_netif_dhcp_status_t dhcp_status; | ||
+ esp_err_t err = esp_netif_dhcpc_get_status(s_sta_netif, &dhcp_status); | ||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_dhcpc_get_status failed: %s", esp_err_to_name(err)); | ||
+ ESP_LOGV(TAG, "esp_netif_dhcpc_get_status failed: %s", esp_err_to_name(err)); | ||
return false; | ||
} | ||
|
||
if (!manual_ip.has_value()) { | ||
// Use DHCP client | ||
- if (dhcp_status != TCPIP_ADAPTER_DHCP_STARTED) { | ||
- err = tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA); | ||
+ if (dhcp_status != ESP_NETIF_DHCP_STARTED) { | ||
+ err = esp_netif_dhcpc_start(s_sta_netif); | ||
if (err != ESP_OK) { | ||
ESP_LOGV(TAG, "Starting DHCP client failed! %d", err); | ||
} | ||
@@ -433,21 +433,20 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) { | ||
return true; | ||
} | ||
|
||
- tcpip_adapter_ip_info_t info; | ||
+ esp_netif_ip_info_t info; | ||
memset(&info, 0, sizeof(info)); | ||
info.ip.addr = static_cast<uint32_t>(manual_ip->static_ip); | ||
info.gw.addr = static_cast<uint32_t>(manual_ip->gateway); | ||
info.netmask.addr = static_cast<uint32_t>(manual_ip->subnet); | ||
|
||
- err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); | ||
+ err = esp_netif_dhcpc_stop(s_sta_netif); | ||
if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_dhcpc_stop failed: %s", esp_err_to_name(err)); | ||
+ ESP_LOGV(TAG, "esp_netif_dhcpc_stop failed: %s", esp_err_to_name(err)); | ||
return false; | ||
} | ||
- | ||
- err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &info); | ||
+ err = esp_netif_set_ip_info(s_sta_netif, &info); | ||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_set_ip_info failed: %s", esp_err_to_name(err)); | ||
+ ESP_LOGV(TAG, "esp_netif_set_ip_info failed: %s", esp_err_to_name(err)); | ||
return false; | ||
} | ||
|
||
@@ -468,10 +467,10 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) { | ||
network::IPAddress WiFiComponent::wifi_sta_ip() { | ||
if (!this->has_sta()) | ||
return {}; | ||
- tcpip_adapter_ip_info_t ip; | ||
- esp_err_t err = tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip); | ||
+ esp_netif_ip_info_t ip; | ||
+ esp_err_t err = esp_netif_get_ip_info(s_sta_netif, &ip); | ||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_get_ip_info failed: %s", esp_err_to_name(err)); | ||
+ ESP_LOGV(TAG, "esp_netif_get_ip_info failed: %s", esp_err_to_name(err)); | ||
return false; | ||
} | ||
return {ip.ip.addr}; | ||
@@ -591,9 +590,9 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) { | ||
if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_STA_START) { | ||
ESP_LOGV(TAG, "Event: WiFi STA start"); | ||
// apply hostname | ||
- err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, App.get_name().c_str()); | ||
+ err = esp_netif_set_hostname(s_sta_netif, App.get_name().c_str()); | ||
if (err != ERR_OK) { | ||
- ESP_LOGW(TAG, "tcpip_adapter_set_hostname failed: %s", esp_err_to_name(err)); | ||
+ ESP_LOGW(TAG, "esp_netif_set_hostname failed: %s", esp_err_to_name(err)); | ||
} | ||
|
||
s_sta_started = true; | ||
@@ -641,7 +640,7 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) { | ||
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_STA_GOT_IP) { | ||
const auto &it = data->data.ip_got_ip; | ||
#ifdef LWIP_IPV6_AUTOCONFIG | ||
- tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA); | ||
+ esp_netif_create_ip6_linklocal(s_sta_netif); | ||
#endif | ||
ESP_LOGV(TAG, "Event: Got IP static_ip=%s gateway=%s", format_ip4_addr(it.ip_info.ip).c_str(), | ||
format_ip4_addr(it.ip_info.gw).c_str()); | ||
@@ -749,6 +748,13 @@ bool WiFiComponent::wifi_scan_start_() { | ||
scan_done_ = false; | ||
return true; | ||
} | ||
+ | ||
+typedef struct { | ||
+ bool enable; | ||
+ ip4_addr_t start_ip; | ||
+ ip4_addr_t end_ip; | ||
+} dhcps_lease_t; | ||
+ | ||
bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) { | ||
esp_err_t err; | ||
|
||
@@ -756,7 +762,7 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) { | ||
if (!this->wifi_mode_({}, true)) | ||
return false; | ||
|
||
- tcpip_adapter_ip_info_t info; | ||
+ esp_netif_ip_info_t info; | ||
memset(&info, 0, sizeof(info)); | ||
if (manual_ip.has_value()) { | ||
info.ip.addr = static_cast<uint32_t>(manual_ip->static_ip); | ||
@@ -767,17 +773,17 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) { | ||
info.gw.addr = static_cast<uint32_t>(network::IPAddress(192, 168, 4, 1)); | ||
info.netmask.addr = static_cast<uint32_t>(network::IPAddress(255, 255, 255, 0)); | ||
} | ||
- tcpip_adapter_dhcp_status_t dhcp_status; | ||
- tcpip_adapter_dhcps_get_status(TCPIP_ADAPTER_IF_AP, &dhcp_status); | ||
- err = tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP); | ||
+ esp_netif_dhcp_status_t dhcp_status; | ||
+ esp_netif_dhcps_get_status(s_ap_netif, &dhcp_status); | ||
+ err = esp_netif_dhcps_stop(s_ap_netif); | ||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_dhcps_stop failed! %d", err); | ||
+ ESP_LOGV(TAG, "esp_netif_dhcps_stop failed! %d", err); | ||
return false; | ||
} | ||
|
||
- err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info); | ||
+ err = esp_netif_set_ip_info(s_ap_netif, &info); | ||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_set_ip_info failed! %d", err); | ||
+ ESP_LOGV(TAG, "esp_netif_set_ip_info failed! %d", err); | ||
return false; | ||
} | ||
|
||
@@ -790,17 +796,17 @@ bool WiFiComponent::wifi_ap_ip_config_(optional<ManualIP> manual_ip) { | ||
start_address[3] += 100; | ||
lease.end_ip.addr = static_cast<uint32_t>(start_address); | ||
ESP_LOGV(TAG, "DHCP server IP lease end: %s", start_address.str().c_str()); | ||
- err = tcpip_adapter_dhcps_option(TCPIP_ADAPTER_OP_SET, TCPIP_ADAPTER_REQUESTED_IP_ADDRESS, &lease, sizeof(lease)); | ||
+ err = esp_netif_dhcps_option(s_ap_netif, ESP_NETIF_OP_SET, ESP_NETIF_REQUESTED_IP_ADDRESS, &lease, sizeof(lease)); | ||
|
||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_dhcps_option failed! %d", err); | ||
+ ESP_LOGV(TAG, "esp_netif_dhcps_option failed! %d", err); | ||
return false; | ||
} | ||
|
||
- err = tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP); | ||
+ err = esp_netif_dhcps_start(s_ap_netif); | ||
|
||
if (err != ESP_OK) { | ||
- ESP_LOGV(TAG, "tcpip_adapter_dhcps_start failed! %d", err); | ||
+ ESP_LOGV(TAG, "esp_netif_dhcps_start failed! %d", err); | ||
return false; | ||
} | ||
|
||
@@ -846,8 +852,8 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) { | ||
return true; | ||
} | ||
network::IPAddress WiFiComponent::wifi_soft_ap_ip() { | ||
- tcpip_adapter_ip_info_t ip; | ||
- tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip); | ||
+ esp_netif_ip_info_t ip; | ||
+ esp_netif_get_ip_info(s_ap_netif, &ip); | ||
return {ip.ip.addr}; | ||
} | ||
bool WiFiComponent::wifi_disconnect_() { return esp_wifi_disconnect(); } | ||
-- | ||
2.39.2 | ||
|
38 changes: 38 additions & 0 deletions
38
pkgs/tools/misc/esphome/0004-mdns-add-mdns-component-when-using-esp-idf.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
From ecbda607a14e69b947a172b9b84c02e418dda891 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <[email protected]> | ||
Date: Sun, 9 Apr 2023 10:33:18 +0200 | ||
Subject: [PATCH 4/5] mdns: add mdns component when using esp-idf | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain; charset=UTF-8 | ||
Content-Transfer-Encoding: 8bit | ||
|
||
Signed-off-by: Jörg Thalheim <[email protected]> | ||
--- | ||
esphome/components/mdns/__init__.py | 11 +++++++++++ | ||
1 file changed, 11 insertions(+) | ||
|
||
diff --git a/esphome/components/mdns/__init__.py b/esphome/components/mdns/__init__.py | ||
index e27786a9..97ee02e7 100644 | ||
--- a/esphome/components/mdns/__init__.py | ||
+++ b/esphome/components/mdns/__init__.py | ||
@@ -78,6 +78,17 @@ async def to_code(config): | ||
cg.add_library("ESP8266mDNS", None) | ||
elif CORE.is_rp2040: | ||
cg.add_library("LEAmDNS", None) | ||
+ elif CORE.using_esp_idf: | ||
+ from esphome.components.esp32 import add_idf_component | ||
+ # add mdns component from esp-idf | ||
+ add_idf_component( | ||
+ name="mdns", | ||
+ repo="https://github.com/espressif/esp-protocols", | ||
+ ref="mdns-v1.0.9", | ||
+ path="components/mdns", | ||
+ refresh=None, | ||
+ ) | ||
+ | ||
|
||
if config[CONF_DISABLED]: | ||
return | ||
-- | ||
2.39.2 | ||
|
Oops, something went wrong.