mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-04 03:48:29 +02:00
ESP-IDF support and generic target platforms (#2303)
* Socket refactor and SSL * esp-idf temp * Fixes * Echo component and noise * Add noise API transport support * Updates * ESP-IDF * Complete * Fixes * Fixes * Versions update * New i2c APIs * Complete i2c refactor * SPI migration * Revert ESP Preferences migration, too complex for now * OTA support * Remove echo again * Remove ssl again * GPIOFlags updates * Rename esphal and ICACHE_RAM_ATTR * Make ESP32 arduino compilable again * Fix GPIO flags * Complete pin registry refactor and fixes * Fixes to make test1 compile * Remove sdkconfig file * Ignore sdkconfig file * Fixes in reviewing * Make test2 compile * Make test4 compile * Make test5 compile * Run clang-format * Fix lint errors * Use esp-idf APIs instead of btStart * Another round of fixes * Start implementing ESP8266 * Make test3 compile * Guard esp8266 code * Lint * Reformat * Fixes * Fixes v2 * more fixes * ESP-IDF tidy target * Convert ARDUINO_ARCH_ESPxx * Update WiFiSignalSensor * Update time ifdefs * OTA needs millis from hal * RestartSwitch needs delay from hal * ESP-IDF Uart * Fix OTA blank password * Allow setting sdkconfig * Fix idf partitions and allow setting sdkconfig from yaml * Re-add read/write compat APIs and fix esp8266 uart * Fix esp8266 store log strings in flash * Fix ESP32 arduino preferences not initialized * Update ifdefs * Change how sdkconfig change is detected * Add checks to ci-custom and fix them * Run clang-format * Add esp-idf clang-tidy target and fix errors * Fixes from clang-tidy idf round 2 * Fixes from compiling tests with esp-idf * Run clang-format * Switch test5.yaml to esp-idf * Implement ESP8266 Preferences * Lint * Re-do PIO package version selection a bit * Fix arduinoespressif32 package version * Fix unit tests * Lint * Lint fixes * Fix readv/writev not defined * Fix graphing component * Re-add all old options from core/config.py Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from esphome import pins
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.components.network import add_mdns_library
|
||||
from esphome.const import (
|
||||
CONF_DOMAIN,
|
||||
CONF_ID,
|
||||
@@ -9,17 +8,16 @@ from esphome.const import (
|
||||
CONF_STATIC_IP,
|
||||
CONF_TYPE,
|
||||
CONF_USE_ADDRESS,
|
||||
ESP_PLATFORM_ESP32,
|
||||
CONF_ENABLE_MDNS,
|
||||
CONF_GATEWAY,
|
||||
CONF_SUBNET,
|
||||
CONF_DNS1,
|
||||
CONF_DNS2,
|
||||
)
|
||||
from esphome.core import CORE, coroutine_with_priority
|
||||
from esphome.components.network import IPAddress
|
||||
|
||||
CONFLICTS_WITH = ["wifi"]
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
DEPENDENCIES = ["esp32"]
|
||||
AUTO_LOAD = ["network"]
|
||||
|
||||
ethernet_ns = cg.esphome_ns.namespace("ethernet")
|
||||
@@ -55,7 +53,6 @@ MANUAL_IP_SCHEMA = cv.Schema(
|
||||
)
|
||||
|
||||
EthernetComponent = ethernet_ns.class_("EthernetComponent", cg.Component)
|
||||
IPAddress = cg.global_ns.class_("IPAddress")
|
||||
ManualIP = ethernet_ns.struct("ManualIP")
|
||||
|
||||
|
||||
@@ -74,20 +71,24 @@ CONFIG_SCHEMA = cv.All(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(EthernetComponent),
|
||||
cv.Required(CONF_TYPE): cv.enum(ETHERNET_TYPES, upper=True),
|
||||
cv.Required(CONF_MDC_PIN): pins.output_pin,
|
||||
cv.Required(CONF_MDIO_PIN): pins.input_output_pin,
|
||||
cv.Required(CONF_MDC_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Required(CONF_MDIO_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Optional(CONF_CLK_MODE, default="GPIO0_IN"): cv.enum(
|
||||
CLK_MODES, upper=True, space="_"
|
||||
),
|
||||
cv.Optional(CONF_PHY_ADDR, default=0): cv.int_range(min=0, max=31),
|
||||
cv.Optional(CONF_POWER_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_MANUAL_IP): MANUAL_IP_SCHEMA,
|
||||
cv.Optional(CONF_ENABLE_MDNS, default=True): cv.boolean,
|
||||
cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name,
|
||||
cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
|
||||
cv.Optional("enable_mdns"): cv.invalid(
|
||||
"This option has been removed. Please use the [disabled] option under the "
|
||||
"new mdns component instead."
|
||||
),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA),
|
||||
_validate,
|
||||
cv.only_with_arduino,
|
||||
)
|
||||
|
||||
|
||||
@@ -122,6 +123,3 @@ async def to_code(config):
|
||||
cg.add(var.set_manual_ip(manual_ip(config[CONF_MANUAL_IP])))
|
||||
|
||||
cg.add_define("USE_ETHERNET")
|
||||
|
||||
if config[CONF_ENABLE_MDNS]:
|
||||
add_mdns_library()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "esphome/core/util.h"
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||
|
||||
#include <eth_phy/phy_lan8720.h>
|
||||
#include <eth_phy/phy_tlk110.h>
|
||||
@@ -75,10 +75,6 @@ void EthernetComponent::setup() {
|
||||
ESPHL_ERROR_CHECK(err, "ETH init error");
|
||||
err = esp_eth_enable();
|
||||
ESPHL_ERROR_CHECK(err, "ETH enable error");
|
||||
|
||||
#ifdef USE_MDNS
|
||||
network_setup_mdns();
|
||||
#endif
|
||||
}
|
||||
void EthernetComponent::loop() {
|
||||
const uint32_t now = millis();
|
||||
@@ -118,8 +114,6 @@ void EthernetComponent::loop() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
network_tick_mdns();
|
||||
}
|
||||
void EthernetComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Ethernet:");
|
||||
@@ -131,10 +125,10 @@ void EthernetComponent::dump_config() {
|
||||
}
|
||||
float EthernetComponent::get_setup_priority() const { return setup_priority::WIFI; }
|
||||
bool EthernetComponent::can_proceed() { return this->is_connected(); }
|
||||
IPAddress EthernetComponent::get_ip_address() {
|
||||
network::IPAddress EthernetComponent::get_ip_address() {
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
|
||||
return IPAddress(ip.ip.addr);
|
||||
return {ip.ip.addr};
|
||||
}
|
||||
|
||||
void EthernetComponent::on_wifi_event_(system_event_id_t event, system_event_info_t info) {
|
||||
@@ -229,10 +223,10 @@ bool EthernetComponent::is_connected() { return this->state_ == EthernetComponen
|
||||
void EthernetComponent::dump_connect_params_() {
|
||||
tcpip_adapter_ip_info_t ip;
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
|
||||
ESP_LOGCONFIG(TAG, " IP Address: %s", IPAddress(ip.ip.addr).toString().c_str());
|
||||
ESP_LOGCONFIG(TAG, " IP Address: %s", network::IPAddress(ip.ip.addr).str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Hostname: '%s'", App.get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Subnet: %s", IPAddress(ip.netmask.addr).toString().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Gateway: %s", IPAddress(ip.gw.addr).toString().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Subnet: %s", network::IPAddress(ip.netmask.addr).str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Gateway: %s", network::IPAddress(ip.gw.addr).str().c_str());
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(3, 3, 4)
|
||||
const ip_addr_t *dns_ip1 = dns_getserver(0);
|
||||
@@ -243,8 +237,8 @@ void EthernetComponent::dump_connect_params_() {
|
||||
ip_addr_t tmp_ip2 = dns_getserver(1);
|
||||
const ip_addr_t *dns_ip2 = &tmp_ip2;
|
||||
#endif
|
||||
ESP_LOGCONFIG(TAG, " DNS1: %s", IPAddress(dns_ip1->u_addr.ip4.addr).toString().c_str());
|
||||
ESP_LOGCONFIG(TAG, " DNS2: %s", IPAddress(dns_ip2->u_addr.ip4.addr).toString().c_str());
|
||||
ESP_LOGCONFIG(TAG, " DNS1: %s", network::IPAddress(dns_ip1->u_addr.ip4.addr).str().c_str());
|
||||
ESP_LOGCONFIG(TAG, " DNS2: %s", network::IPAddress(dns_ip2->u_addr.ip4.addr).str().c_str());
|
||||
uint8_t mac[6];
|
||||
esp_eth_get_mac(mac);
|
||||
ESP_LOGCONFIG(TAG, " MAC Address: %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
@@ -270,4 +264,4 @@ void EthernetComponent::set_use_address(const std::string &use_address) { this->
|
||||
} // namespace ethernet
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
#endif // USE_ESP32_FRAMEWORK_ARDUINO
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/esphal.h"
|
||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/components/network/ip_address.h"
|
||||
|
||||
#include "esp_eth.h"
|
||||
#include <esp_wifi.h>
|
||||
@@ -19,11 +20,11 @@ enum EthernetType {
|
||||
};
|
||||
|
||||
struct ManualIP {
|
||||
IPAddress static_ip;
|
||||
IPAddress gateway;
|
||||
IPAddress subnet;
|
||||
IPAddress dns1; ///< The first DNS server. 0.0.0.0 for default.
|
||||
IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
|
||||
network::IPAddress static_ip;
|
||||
network::IPAddress gateway;
|
||||
network::IPAddress subnet;
|
||||
network::IPAddress dns1; ///< The first DNS server. 0.0.0.0 for default.
|
||||
network::IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
|
||||
};
|
||||
|
||||
enum class EthernetComponentState {
|
||||
@@ -50,7 +51,7 @@ class EthernetComponent : public Component {
|
||||
void set_clk_mode(eth_clock_mode_t clk_mode);
|
||||
void set_manual_ip(const ManualIP &manual_ip);
|
||||
|
||||
IPAddress get_ip_address();
|
||||
network::IPAddress get_ip_address();
|
||||
std::string get_use_address() const;
|
||||
void set_use_address(const std::string &use_address);
|
||||
|
||||
@@ -84,4 +85,4 @@ extern EthernetComponent *global_eth_component;
|
||||
} // namespace ethernet
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
#endif // USE_ESP32_FRAMEWORK_ARDUINO
|
||||
|
||||
Reference in New Issue
Block a user