mirror of
https://github.com/esphome/esphome.git
synced 2025-11-14 05:45:48 +00:00
Compare commits
1 Commits
dev
...
ethernet_m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d87063865c |
@@ -383,6 +383,7 @@ async def to_code(config):
|
|||||||
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
|
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
|
||||||
|
|
||||||
if CONF_MANUAL_IP in config:
|
if CONF_MANUAL_IP in config:
|
||||||
|
cg.add_define("USE_ETHERNET_MANUAL_IP")
|
||||||
cg.add(var.set_manual_ip(manual_ip(config[CONF_MANUAL_IP])))
|
cg.add(var.set_manual_ip(manual_ip(config[CONF_MANUAL_IP])))
|
||||||
|
|
||||||
# Add compile-time define for PHY types with specific code
|
# Add compile-time define for PHY types with specific code
|
||||||
|
|||||||
@@ -550,11 +550,14 @@ void EthernetComponent::start_connect_() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_netif_ip_info_t info;
|
esp_netif_ip_info_t info;
|
||||||
|
#ifdef USE_ETHERNET_MANUAL_IP
|
||||||
if (this->manual_ip_.has_value()) {
|
if (this->manual_ip_.has_value()) {
|
||||||
info.ip = this->manual_ip_->static_ip;
|
info.ip = this->manual_ip_->static_ip;
|
||||||
info.gw = this->manual_ip_->gateway;
|
info.gw = this->manual_ip_->gateway;
|
||||||
info.netmask = this->manual_ip_->subnet;
|
info.netmask = this->manual_ip_->subnet;
|
||||||
} else {
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
info.ip.addr = 0;
|
info.ip.addr = 0;
|
||||||
info.gw.addr = 0;
|
info.gw.addr = 0;
|
||||||
info.netmask.addr = 0;
|
info.netmask.addr = 0;
|
||||||
@@ -575,6 +578,7 @@ void EthernetComponent::start_connect_() {
|
|||||||
err = esp_netif_set_ip_info(this->eth_netif_, &info);
|
err = esp_netif_set_ip_info(this->eth_netif_, &info);
|
||||||
ESPHL_ERROR_CHECK(err, "DHCPC set IP info error");
|
ESPHL_ERROR_CHECK(err, "DHCPC set IP info error");
|
||||||
|
|
||||||
|
#ifdef USE_ETHERNET_MANUAL_IP
|
||||||
if (this->manual_ip_.has_value()) {
|
if (this->manual_ip_.has_value()) {
|
||||||
LwIPLock lock;
|
LwIPLock lock;
|
||||||
if (this->manual_ip_->dns1.is_set()) {
|
if (this->manual_ip_->dns1.is_set()) {
|
||||||
@@ -587,7 +591,9 @@ void EthernetComponent::start_connect_() {
|
|||||||
d = this->manual_ip_->dns2;
|
d = this->manual_ip_->dns2;
|
||||||
dns_setserver(1, &d);
|
dns_setserver(1, &d);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
err = esp_netif_dhcpc_start(this->eth_netif_);
|
err = esp_netif_dhcpc_start(this->eth_netif_);
|
||||||
if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
|
if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
|
||||||
ESPHL_ERROR_CHECK(err, "DHCPC start error");
|
ESPHL_ERROR_CHECK(err, "DHCPC start error");
|
||||||
@@ -685,7 +691,9 @@ void EthernetComponent::set_clk_mode(emac_rmii_clock_mode_t clk_mode) { this->cl
|
|||||||
void EthernetComponent::add_phy_register(PHYRegister register_value) { this->phy_registers_.push_back(register_value); }
|
void EthernetComponent::add_phy_register(PHYRegister register_value) { this->phy_registers_.push_back(register_value); }
|
||||||
#endif
|
#endif
|
||||||
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; }
|
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; }
|
||||||
|
#ifdef USE_ETHERNET_MANUAL_IP
|
||||||
void EthernetComponent::set_manual_ip(const ManualIP &manual_ip) { this->manual_ip_ = manual_ip; }
|
void EthernetComponent::set_manual_ip(const ManualIP &manual_ip) { this->manual_ip_ = manual_ip; }
|
||||||
|
#endif
|
||||||
|
|
||||||
// set_use_address() is guaranteed to be called during component setup by Python code generation,
|
// set_use_address() is guaranteed to be called during component setup by Python code generation,
|
||||||
// so use_address_ will always be valid when get_use_address() is called - no fallback needed.
|
// so use_address_ will always be valid when get_use_address() is called - no fallback needed.
|
||||||
|
|||||||
@@ -82,7 +82,9 @@ class EthernetComponent : public Component {
|
|||||||
void add_phy_register(PHYRegister register_value);
|
void add_phy_register(PHYRegister register_value);
|
||||||
#endif
|
#endif
|
||||||
void set_type(EthernetType type);
|
void set_type(EthernetType type);
|
||||||
|
#ifdef USE_ETHERNET_MANUAL_IP
|
||||||
void set_manual_ip(const ManualIP &manual_ip);
|
void set_manual_ip(const ManualIP &manual_ip);
|
||||||
|
#endif
|
||||||
void set_fixed_mac(const std::array<uint8_t, 6> &mac) { this->fixed_mac_ = mac; }
|
void set_fixed_mac(const std::array<uint8_t, 6> &mac) { this->fixed_mac_ = mac; }
|
||||||
|
|
||||||
network::IPAddresses get_ip_addresses();
|
network::IPAddresses get_ip_addresses();
|
||||||
@@ -137,7 +139,9 @@ class EthernetComponent : public Component {
|
|||||||
uint8_t mdc_pin_{23};
|
uint8_t mdc_pin_{23};
|
||||||
uint8_t mdio_pin_{18};
|
uint8_t mdio_pin_{18};
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_ETHERNET_MANUAL_IP
|
||||||
optional<ManualIP> manual_ip_{};
|
optional<ManualIP> manual_ip_{};
|
||||||
|
#endif
|
||||||
uint32_t connect_begin_;
|
uint32_t connect_begin_;
|
||||||
|
|
||||||
// Group all uint8_t types together (enums and bools)
|
// Group all uint8_t types together (enums and bools)
|
||||||
|
|||||||
@@ -215,6 +215,7 @@
|
|||||||
#define USE_ARDUINO_VERSION_CODE VERSION_CODE(3, 3, 2)
|
#define USE_ARDUINO_VERSION_CODE VERSION_CODE(3, 3, 2)
|
||||||
#define USE_ETHERNET
|
#define USE_ETHERNET
|
||||||
#define USE_ETHERNET_KSZ8081
|
#define USE_ETHERNET_KSZ8081
|
||||||
|
#define USE_ETHERNET_MANUAL_IP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
|
|||||||
Reference in New Issue
Block a user