add support for WT32-ETH01

This commit is contained in:
technyon
2023-03-02 19:50:38 +01:00
parent 9e343ee7b8
commit 709135d8ca
5 changed files with 67 additions and 38 deletions

View File

@@ -56,53 +56,55 @@ void Network::setupDevice()
} }
else else
{ {
if(hardwareDetect == 1) Log->print(F("Network device: "));
switch (hardwareDetect)
{ {
Log->println(F("W5500 hardware is disabled, using Wifi.")); case 1:
Log->println(F("Wifi only"));
_networkDeviceType = NetworkDeviceType::WiFi; _networkDeviceType = NetworkDeviceType::WiFi;
} break;
else if(hardwareDetect == 2) case 2:
{
Log->print(F("Using PIN ")); Log->print(F("Using PIN "));
Log->print(hardwareDetectGpio); Log->print(hardwareDetectGpio);
Log->println(F(" for network device selection")); Log->println(F(" for network device selection"));
pinMode(hardwareDetectGpio, INPUT_PULLUP); pinMode(hardwareDetectGpio, INPUT_PULLUP);
_networkDeviceType = digitalRead(hardwareDetectGpio) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500; _networkDeviceType = digitalRead(hardwareDetectGpio) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
} break;
else if(hardwareDetect == 3) case 3:
{
Log->println(F("W5500 on M5Stack Atom POE")); Log->println(F("W5500 on M5Stack Atom POE"));
_networkDeviceType = NetworkDeviceType::W5500; _networkDeviceType = NetworkDeviceType::W5500;
} break;
else if(hardwareDetect == 4) case 4:
{
Log->println(F("Olimex ESP32-POE / ESP-POE-ISO")); Log->println(F("Olimex ESP32-POE / ESP-POE-ISO"));
_networkDeviceType = NetworkDeviceType::LAN8720; _networkDeviceType = NetworkDeviceType::Olimex_LAN8720;
} break;
else case 5:
{ Log->println(F("WT32-ETH01"));
_networkDeviceType = NetworkDeviceType::WT32_LAN8720;
break;
default:
Log->println(F("Unknown hardware selected, falling back to Wifi.")); Log->println(F("Unknown hardware selected, falling back to Wifi."));
_networkDeviceType = NetworkDeviceType::WiFi; _networkDeviceType = NetworkDeviceType::WiFi;
break;
} }
} }
switch (_networkDeviceType) switch (_networkDeviceType)
{ {
case NetworkDeviceType::W5500: case NetworkDeviceType::W5500:
Log->println(F("Network device: W5500"));
_device = new W5500Device(_hostname, _preferences, hardwareDetect); _device = new W5500Device(_hostname, _preferences, hardwareDetect);
break; break;
case NetworkDeviceType::LAN8720: case NetworkDeviceType::Olimex_LAN8720:
Log->println(F("Network device: LAN8720")); _device = new EthLan8720Device(_hostname, _preferences, ETH_PHY_ADDR, 12, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLOCK_GPIO17_OUT);
_device = new EthLan8720Device(_hostname, _preferences); break;
case NetworkDeviceType::WT32_LAN8720:
_device = new EthLan8720Device(_hostname, _preferences, 1, 16);
break; break;
case NetworkDeviceType::WiFi: case NetworkDeviceType::WiFi:
Log->println(F("Network device: Builtin WiFi"));
_device = new WifiDevice(_hostname, _preferences); _device = new WifiDevice(_hostname, _preferences);
break; break;
default: default:
Log->println(F("Unknown network device type, defaulting to WiFi"));
_device = new WifiDevice(_hostname, _preferences); _device = new WifiDevice(_hostname, _preferences);
break; break;
} }

View File

@@ -10,7 +10,8 @@ enum class NetworkDeviceType
{ {
WiFi, WiFi,
W5500, W5500,
LAN8720 Olimex_LAN8720,
WT32_LAN8720
}; };
#define JSON_BUFFER_SIZE 1024 #define JSON_BUFFER_SIZE 1024

View File

@@ -1117,6 +1117,7 @@ const std::vector<std::pair<String, String>> WebCfgServer::getNetworkDetectionOp
options.push_back(std::make_pair("2", "Detect W5500 (GPIO CS=5; SCK=18; MISO=19; MOSI=23; RST=33)")); options.push_back(std::make_pair("2", "Detect W5500 (GPIO CS=5; SCK=18; MISO=19; MOSI=23; RST=33)"));
options.push_back(std::make_pair("3", "M5Stack Atom POE (W5500)")); options.push_back(std::make_pair("3", "M5Stack Atom POE (W5500)"));
options.push_back(std::make_pair("4", "Olimex ESP32-POE / ESP-POE-ISO")); options.push_back(std::make_pair("4", "Olimex ESP32-POE / ESP-POE-ISO"));
options.push_back(std::make_pair("5", "WT32-ETH01"));
return options; return options;
} }

View File

@@ -10,8 +10,15 @@
#include "espMqttClient.h" #include "espMqttClient.h"
#include "../RestartReason.h" #include "../RestartReason.h"
EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _preferences) EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _preferences, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode, bool use_mac_from_efuse)
: NetworkDevice(hostname) : NetworkDevice(hostname),
_phy_addr(phy_addr),
_power(power),
_mdc(mdc),
_mdio(mdio),
_type(ethtype),
_clock_mode(clock_mode),
_use_mac_from_efuse(use_mac_from_efuse)
{ {
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect); _restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
@@ -62,7 +69,7 @@ void EthLan8720Device::initialize()
{ {
delay(250); delay(250);
_hardwareInitialized = ETH.begin(ETH_PHY_ADDR, 12, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLOCK_GPIO17_OUT); _hardwareInitialized = ETH.begin(_phy_addr, _power, _mdc, _mdio, _type, _clock_mode, _use_mac_from_efuse);
if(_restartOnDisconnect) if(_restartOnDisconnect)
{ {

View File

@@ -5,11 +5,21 @@
#include <Preferences.h> #include <Preferences.h>
#include "NetworkDevice.h" #include "NetworkDevice.h"
#include "espMqttClient.h" #include "espMqttClient.h"
#include <ETH.h>
class EthLan8720Device : public NetworkDevice class EthLan8720Device : public NetworkDevice
{ {
public: public:
EthLan8720Device(const String& hostname, Preferences* _preferences); EthLan8720Device(const String& hostname,
Preferences* _preferences,
uint8_t phy_addr = ETH_PHY_ADDR,
int power = ETH_PHY_POWER,
int mdc = ETH_PHY_MDC,
int mdio = ETH_PHY_MDIO,
eth_phy_type_t ethtype = ETH_PHY_TYPE,
eth_clock_mode_t clock_mode = ETH_CLK_MODE,
bool use_mac_from_efuse = false);
const String deviceName() const override; const String deviceName() const override;
@@ -63,6 +73,14 @@ private:
bool _useEncryption = false; bool _useEncryption = false;
bool _hardwareInitialized = false; bool _hardwareInitialized = false;
uint8_t _phy_addr;
int _power;
int _mdc;
int _mdio;
eth_phy_type_t _type;
eth_clock_mode_t _clock_mode;
bool _use_mac_from_efuse;
char _ca[TLS_CA_MAX_SIZE] = {0}; char _ca[TLS_CA_MAX_SIZE] = {0};
char _cert[TLS_CERT_MAX_SIZE] = {0}; char _cert[TLS_CERT_MAX_SIZE] = {0};
char _key[TLS_KEY_MAX_SIZE] = {0}; char _key[TLS_KEY_MAX_SIZE] = {0};