diff --git a/src/NukiNetwork.cpp b/src/NukiNetwork.cpp index b60ec77..94de48a 100644 --- a/src/NukiNetwork.cpp +++ b/src/NukiNetwork.cpp @@ -218,59 +218,12 @@ void NukiNetwork::setupDevice() #if defined(CONFIG_IDF_TARGET_ESP32) else if(custPHY >= 4 && custPHY <= 9) { - std::string custName; - eth_phy_type_t custEthtype; - eth_clock_mode_t custCLK; - - switch(custPHY) - { - case 4: - custName = "Custom (LAN8720)"; - custEthtype = ETH_PHY_TYPE_LAN8720; - break; - case 5: - custName = "Custom (RTL8201)"; - custEthtype = ETH_PHY_RTL8201; - break; - case 6: - custName = "Custom (TLK110)"; - custEthtype = ETH_PHY_TLK110; - break; - case 7: - custName = "Custom (DP83848)"; - custEthtype = ETH_PHY_DP83848; - break; - case 8: - custName = "Custom (KSZ8041)"; - custEthtype = ETH_PHY_KSZ8041; - break; - case 9: - custName = "Custom (KSZ8081)"; - custEthtype = ETH_PHY_KSZ8081; - break; - default: - custName = "Custom (LAN8720)"; - custEthtype = ETH_PHY_TYPE_LAN8720; - break; - } - int custCLKpref = _preferences->getInt(preference_network_custom_clk, 0); - switch(custCLKpref) - { - case 0: - custCLK = ETH_CLOCK_GPIO0_IN; - break; - case 2: - custCLK = ETH_CLOCK_GPIO16_OUT; - break; - case 3: - custCLK = ETH_CLOCK_GPIO17_OUT; - break; - default: - custCLK = ETH_CLOCK_GPIO17_OUT; - break; - } + std::string custName = NetworkUtil::GetCustomEthernetDeviceName(custPHY); + eth_phy_type_t custEthtype = NetworkUtil::GetCustomEthernetType(custPHY); + eth_clock_mode_t custCLK = NetworkUtil::GetCustomClock(custCLKpref); + _device = new EthernetDevice(_hostname, _preferences, _ipConfiguration, custName, _preferences->getInt(preference_network_custom_addr, -1), _preferences->getInt(preference_network_custom_pwr, -1), _preferences->getInt(preference_network_custom_mdc, -1), _preferences->getInt(preference_network_custom_mdio, -1), custEthtype, custCLK); } #endif diff --git a/src/util/NetworkUtil.cpp b/src/util/NetworkUtil.cpp index 31ef1a9..79ed0d6 100644 --- a/src/util/NetworkUtil.cpp +++ b/src/util/NetworkUtil.cpp @@ -1,5 +1,6 @@ #include "NetworkUtil.h" #include "../Logger.h" +#include "../networkDevices/LAN8720Definitions.h" NetworkDeviceType NetworkUtil::GetDeviceTypeFromPreference(int hardwareDetect, int customPhy) { @@ -51,3 +52,71 @@ NetworkDeviceType NetworkUtil::GetDeviceTypeFromPreference(int hardwareDetect, i break; } } + +std::string NetworkUtil::GetCustomEthernetDeviceName(int custPHY) +{ + switch(custPHY) + { + case 4: + return "Custom (LAN8720)"; + case 5: + return"Custom (RTL8201)"; + case 6: + return "Custom (TLK110)"; + case 7: + return "Custom (DP83848)"; + case 8: + return "Custom (KSZ8041)"; + case 9: + return "Custom (KSZ8081)"; + default: + return"Custom (LAN8720)"; + } +} + +eth_phy_type_t NetworkUtil::GetCustomEthernetType(int custPHY) +{ + switch(custPHY) + { + case 4: + return ETH_PHY_TYPE_LAN8720; + break; + case 5: + return ETH_PHY_RTL8201; + break; + case 6: + return ETH_PHY_TLK110; + break; + case 7: + return ETH_PHY_DP83848; + break; + case 8: + return ETH_PHY_KSZ8041; + break; + case 9: + return ETH_PHY_KSZ8081; + break; + default: + return ETH_PHY_TYPE_LAN8720; + break; + } +} + +eth_clock_mode_t NetworkUtil::GetCustomClock(int custCLKpref) +{ + switch(custCLKpref) + { + case 0: + return ETH_CLOCK_GPIO0_IN; + break; + case 2: + return ETH_CLOCK_GPIO16_OUT; + break; + case 3: + return ETH_CLOCK_GPIO17_OUT; + break; + default: + return ETH_CLOCK_GPIO17_OUT; + break; + } +} diff --git a/src/util/NetworkUtil.h b/src/util/NetworkUtil.h index 676e6ee..6c6a5c0 100644 --- a/src/util/NetworkUtil.h +++ b/src/util/NetworkUtil.h @@ -1,9 +1,14 @@ #pragma once +#include +#include #include "../enums/NetworkDeviceType.h" class NetworkUtil { public: static NetworkDeviceType GetDeviceTypeFromPreference(int hardwareDetect, int customPhy); + static std::string GetCustomEthernetDeviceName(int custPHY); + static eth_phy_type_t GetCustomEthernetType(int custPHY); + static eth_clock_mode_t GetCustomClock(int custCLKpref); }; \ No newline at end of file