mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 18:52:19 +01:00
[ethernet] Conditionally compile PHY-specific code to reduce flash usage
This commit is contained in:
@@ -77,6 +77,13 @@ ETHERNET_TYPES = {
|
|||||||
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
|
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# PHY types that need compile-time defines for conditional compilation
|
||||||
|
_PHY_TYPE_TO_DEFINE = {
|
||||||
|
"KSZ8081": "USE_ETHERNET_KSZ8081",
|
||||||
|
"KSZ8081RNA": "USE_ETHERNET_KSZ8081",
|
||||||
|
# Add other PHY types here only if they need conditional compilation
|
||||||
|
}
|
||||||
|
|
||||||
SPI_ETHERNET_TYPES = ["W5500", "DM9051"]
|
SPI_ETHERNET_TYPES = ["W5500", "DM9051"]
|
||||||
SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
|
SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
|
||||||
|
|
||||||
@@ -345,6 +352,10 @@ async def to_code(config):
|
|||||||
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])))
|
||||||
|
|
||||||
|
# Add compile-time define for PHY types with specific code
|
||||||
|
if phy_define := _PHY_TYPE_TO_DEFINE.get(config[CONF_TYPE]):
|
||||||
|
cg.add_define(phy_define)
|
||||||
|
|
||||||
cg.add_define("USE_ETHERNET")
|
cg.add_define("USE_ETHERNET")
|
||||||
|
|
||||||
# Disable WiFi when using Ethernet to save memory
|
# Disable WiFi when using Ethernet to save memory
|
||||||
|
@@ -229,10 +229,12 @@ void EthernetComponent::setup() {
|
|||||||
ESPHL_ERROR_CHECK(err, "ETH driver install error");
|
ESPHL_ERROR_CHECK(err, "ETH driver install error");
|
||||||
|
|
||||||
#ifndef USE_ETHERNET_SPI
|
#ifndef USE_ETHERNET_SPI
|
||||||
|
#ifdef USE_ETHERNET_KSZ8081
|
||||||
if (this->type_ == ETHERNET_TYPE_KSZ8081RNA && this->clk_mode_ == EMAC_CLK_OUT) {
|
if (this->type_ == ETHERNET_TYPE_KSZ8081RNA && this->clk_mode_ == EMAC_CLK_OUT) {
|
||||||
// KSZ8081RNA default is incorrect. It expects a 25MHz clock instead of the 50MHz we provide.
|
// KSZ8081RNA default is incorrect. It expects a 25MHz clock instead of the 50MHz we provide.
|
||||||
this->ksz8081_set_clock_reference_(mac);
|
this->ksz8081_set_clock_reference_(mac);
|
||||||
}
|
}
|
||||||
|
#endif // USE_ETHERNET_KSZ8081
|
||||||
|
|
||||||
for (const auto &phy_register : this->phy_registers_) {
|
for (const auto &phy_register : this->phy_registers_) {
|
||||||
this->write_phy_register_(mac, phy_register);
|
this->write_phy_register_(mac, phy_register);
|
||||||
@@ -721,6 +723,7 @@ bool EthernetComponent::powerdown() {
|
|||||||
|
|
||||||
#ifndef USE_ETHERNET_SPI
|
#ifndef USE_ETHERNET_SPI
|
||||||
|
|
||||||
|
#ifdef USE_ETHERNET_KSZ8081
|
||||||
constexpr uint8_t KSZ80XX_PC2R_REG_ADDR = 0x1F;
|
constexpr uint8_t KSZ80XX_PC2R_REG_ADDR = 0x1F;
|
||||||
|
|
||||||
void EthernetComponent::ksz8081_set_clock_reference_(esp_eth_mac_t *mac) {
|
void EthernetComponent::ksz8081_set_clock_reference_(esp_eth_mac_t *mac) {
|
||||||
@@ -749,6 +752,7 @@ void EthernetComponent::ksz8081_set_clock_reference_(esp_eth_mac_t *mac) {
|
|||||||
ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s", format_hex_pretty((u_int8_t *) &phy_control_2, 2).c_str());
|
ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s", format_hex_pretty((u_int8_t *) &phy_control_2, 2).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // USE_ETHERNET_KSZ8081
|
||||||
|
|
||||||
void EthernetComponent::write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data) {
|
void EthernetComponent::write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data) {
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
|
@@ -104,8 +104,10 @@ class EthernetComponent : public Component {
|
|||||||
void start_connect_();
|
void start_connect_();
|
||||||
void finish_connect_();
|
void finish_connect_();
|
||||||
void dump_connect_params_();
|
void dump_connect_params_();
|
||||||
|
#ifdef USE_ETHERNET_KSZ8081
|
||||||
/// @brief Set `RMII Reference Clock Select` bit for KSZ8081.
|
/// @brief Set `RMII Reference Clock Select` bit for KSZ8081.
|
||||||
void ksz8081_set_clock_reference_(esp_eth_mac_t *mac);
|
void ksz8081_set_clock_reference_(esp_eth_mac_t *mac);
|
||||||
|
#endif
|
||||||
/// @brief Set arbitratry PHY registers from config.
|
/// @brief Set arbitratry PHY registers from config.
|
||||||
void write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data);
|
void write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data);
|
||||||
|
|
||||||
|
@@ -175,6 +175,7 @@
|
|||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
#define USE_ARDUINO_VERSION_CODE VERSION_CODE(3, 2, 1)
|
#define USE_ARDUINO_VERSION_CODE VERSION_CODE(3, 2, 1)
|
||||||
#define USE_ETHERNET
|
#define USE_ETHERNET
|
||||||
|
#define USE_ETHERNET_KSZ8081
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
|
Reference in New Issue
Block a user