mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 00:48:19 +01:00
Remove manual handling of ethernet power pin (#4062)
This commit is contained in:
parent
7258a82875
commit
0f9c956c04
3 changed files with 9 additions and 26 deletions
|
@ -79,7 +79,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
CLK_MODES, upper=True, space="_"
|
CLK_MODES, upper=True, space="_"
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_PHY_ADDR, default=0): cv.int_range(min=0, max=31),
|
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_POWER_PIN): pins.internal_gpio_output_pin_number,
|
||||||
cv.Optional(CONF_MANUAL_IP): MANUAL_IP_SCHEMA,
|
cv.Optional(CONF_MANUAL_IP): MANUAL_IP_SCHEMA,
|
||||||
cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name,
|
cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name,
|
||||||
cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
|
cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
|
||||||
|
@ -118,8 +118,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_POWER_PIN in config:
|
if CONF_POWER_PIN in config:
|
||||||
pin = await cg.gpio_pin_expression(config[CONF_POWER_PIN])
|
cg.add(var.set_power_pin(config[CONF_POWER_PIN]))
|
||||||
cg.add(var.set_power_pin(pin))
|
|
||||||
|
|
||||||
if CONF_MANUAL_IP in config:
|
if CONF_MANUAL_IP in config:
|
||||||
cg.add(var.set_manual_ip(manual_ip(config[CONF_MANUAL_IP])))
|
cg.add(var.set_manual_ip(manual_ip(config[CONF_MANUAL_IP])))
|
||||||
|
|
|
@ -29,10 +29,6 @@ void EthernetComponent::setup() {
|
||||||
// Delay here to allow power to stabilise before Ethernet is initialised.
|
// Delay here to allow power to stabilise before Ethernet is initialised.
|
||||||
delay(300); // NOLINT
|
delay(300); // NOLINT
|
||||||
|
|
||||||
if (this->power_pin_ != nullptr) {
|
|
||||||
this->power_pin_->setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = esp_netif_init();
|
err = esp_netif_init();
|
||||||
ESPHL_ERROR_CHECK(err, "ETH netif init error");
|
ESPHL_ERROR_CHECK(err, "ETH netif init error");
|
||||||
|
@ -47,6 +43,8 @@ void EthernetComponent::setup() {
|
||||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||||
|
|
||||||
phy_config.phy_addr = this->phy_addr_;
|
phy_config.phy_addr = this->phy_addr_;
|
||||||
|
if (this->power_pin_ != -1)
|
||||||
|
phy_config.reset_gpio_num = this->power_pin_;
|
||||||
|
|
||||||
mac_config.smi_mdc_gpio_num = this->mdc_pin_;
|
mac_config.smi_mdc_gpio_num = this->mdc_pin_;
|
||||||
mac_config.smi_mdio_gpio_num = this->mdio_pin_;
|
mac_config.smi_mdio_gpio_num = this->mdio_pin_;
|
||||||
|
@ -96,11 +94,6 @@ void EthernetComponent::setup() {
|
||||||
/* start Ethernet driver state machine */
|
/* start Ethernet driver state machine */
|
||||||
err = esp_eth_start(this->eth_handle_);
|
err = esp_eth_start(this->eth_handle_);
|
||||||
ESPHL_ERROR_CHECK(err, "ETH start error");
|
ESPHL_ERROR_CHECK(err, "ETH start error");
|
||||||
|
|
||||||
if (this->power_pin_ != nullptr) {
|
|
||||||
this->orig_power_control_fun_ = phy->pwrctl;
|
|
||||||
phy->pwrctl = EthernetComponent::eth_phy_power_control;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetComponent::loop() {
|
void EthernetComponent::loop() {
|
||||||
|
@ -169,7 +162,8 @@ void EthernetComponent::dump_config() {
|
||||||
|
|
||||||
ESP_LOGCONFIG(TAG, "Ethernet:");
|
ESP_LOGCONFIG(TAG, "Ethernet:");
|
||||||
this->dump_connect_params_();
|
this->dump_connect_params_();
|
||||||
LOG_PIN(" Power Pin: ", this->power_pin_);
|
if (this->power_pin_ != -1)
|
||||||
|
ESP_LOGCONFIG(TAG, " Power Pin: %u", this->power_pin_);
|
||||||
ESP_LOGCONFIG(TAG, " MDC Pin: %u", this->mdc_pin_);
|
ESP_LOGCONFIG(TAG, " MDC Pin: %u", this->mdc_pin_);
|
||||||
ESP_LOGCONFIG(TAG, " MDIO Pin: %u", this->mdio_pin_);
|
ESP_LOGCONFIG(TAG, " MDIO Pin: %u", this->mdio_pin_);
|
||||||
ESP_LOGCONFIG(TAG, " Type: %s", eth_type.c_str());
|
ESP_LOGCONFIG(TAG, " Type: %s", eth_type.c_str());
|
||||||
|
@ -277,12 +271,6 @@ void EthernetComponent::start_connect_() {
|
||||||
this->connect_begin_ = millis();
|
this->connect_begin_ = millis();
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
}
|
}
|
||||||
esp_err_t EthernetComponent::eth_phy_power_control(esp_eth_phy_t *phy, bool enable) {
|
|
||||||
global_eth_component->power_pin_->digital_write(enable);
|
|
||||||
// power up takes some time, datasheet says max 300µs
|
|
||||||
delay(1);
|
|
||||||
return global_eth_component->orig_power_control_fun_(phy, enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EthernetComponent::is_connected() { return this->state_ == EthernetComponentState::CONNECTED; }
|
bool EthernetComponent::is_connected() { return this->state_ == EthernetComponentState::CONNECTED; }
|
||||||
|
|
||||||
|
@ -319,7 +307,7 @@ void EthernetComponent::dump_connect_params_() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetComponent::set_phy_addr(uint8_t phy_addr) { this->phy_addr_ = phy_addr; }
|
void EthernetComponent::set_phy_addr(uint8_t phy_addr) { this->phy_addr_ = phy_addr; }
|
||||||
void EthernetComponent::set_power_pin(GPIOPin *power_pin) { this->power_pin_ = power_pin; }
|
void EthernetComponent::set_power_pin(int power_pin) { this->power_pin_ = power_pin; }
|
||||||
void EthernetComponent::set_mdc_pin(uint8_t mdc_pin) { this->mdc_pin_ = mdc_pin; }
|
void EthernetComponent::set_mdc_pin(uint8_t mdc_pin) { this->mdc_pin_ = mdc_pin; }
|
||||||
void EthernetComponent::set_mdio_pin(uint8_t mdio_pin) { this->mdio_pin_ = mdio_pin; }
|
void EthernetComponent::set_mdio_pin(uint8_t mdio_pin) { this->mdio_pin_ = mdio_pin; }
|
||||||
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; }
|
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; }
|
||||||
|
|
|
@ -45,7 +45,7 @@ class EthernetComponent : public Component {
|
||||||
bool is_connected();
|
bool is_connected();
|
||||||
|
|
||||||
void set_phy_addr(uint8_t phy_addr);
|
void set_phy_addr(uint8_t phy_addr);
|
||||||
void set_power_pin(GPIOPin *power_pin);
|
void set_power_pin(int power_pin);
|
||||||
void set_mdc_pin(uint8_t mdc_pin);
|
void set_mdc_pin(uint8_t mdc_pin);
|
||||||
void set_mdio_pin(uint8_t mdio_pin);
|
void set_mdio_pin(uint8_t mdio_pin);
|
||||||
void set_type(EthernetType type);
|
void set_type(EthernetType type);
|
||||||
|
@ -63,11 +63,9 @@ class EthernetComponent : public Component {
|
||||||
void start_connect_();
|
void start_connect_();
|
||||||
void dump_connect_params_();
|
void dump_connect_params_();
|
||||||
|
|
||||||
static esp_err_t eth_phy_power_control(esp_eth_phy_t *phy, bool enable);
|
|
||||||
|
|
||||||
std::string use_address_;
|
std::string use_address_;
|
||||||
uint8_t phy_addr_{0};
|
uint8_t phy_addr_{0};
|
||||||
GPIOPin *power_pin_{nullptr};
|
int power_pin_{-1};
|
||||||
uint8_t mdc_pin_{23};
|
uint8_t mdc_pin_{23};
|
||||||
uint8_t mdio_pin_{18};
|
uint8_t mdio_pin_{18};
|
||||||
EthernetType type_{ETHERNET_TYPE_LAN8720};
|
EthernetType type_{ETHERNET_TYPE_LAN8720};
|
||||||
|
@ -80,8 +78,6 @@ class EthernetComponent : public Component {
|
||||||
uint32_t connect_begin_;
|
uint32_t connect_begin_;
|
||||||
esp_netif_t *eth_netif_{nullptr};
|
esp_netif_t *eth_netif_{nullptr};
|
||||||
esp_eth_handle_t eth_handle_;
|
esp_eth_handle_t eth_handle_;
|
||||||
|
|
||||||
std::function<esp_err_t(esp_eth_phy_t *, bool)> orig_power_control_fun_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
Loading…
Reference in a new issue