From 06268cdd4433e41c1ba77a8208a72107d58fc090 Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Wed, 7 Aug 2024 21:43:32 +0200 Subject: [PATCH 1/8] Added support for w5500 --- .github/workflows/cpplint.yml | 2 +- include/NetworkSettings.h | 1 + include/PinMapping.h | 8 +++ lib/ETHSPI/src/ETHSPI.cpp | 121 ++++++++++++++++++++++++++++++++++ lib/ETHSPI/src/ETHSPI.h | 20 ++++++ src/NetworkSettings.cpp | 29 ++++++-- src/PinMapping.cpp | 48 ++++++++++++++ src/WebApi_device.cpp | 8 +++ 8 files changed, 231 insertions(+), 6 deletions(-) create mode 100644 lib/ETHSPI/src/ETHSPI.cpp create mode 100644 lib/ETHSPI/src/ETHSPI.h diff --git a/.github/workflows/cpplint.yml b/.github/workflows/cpplint.yml index 4ee4b4a82..6ada43cf7 100644 --- a/.github/workflows/cpplint.yml +++ b/.github/workflows/cpplint.yml @@ -18,4 +18,4 @@ jobs: pip install cpplint - name: Linting run: | - cpplint --repository=. --recursive --filter=-build/c++11,-runtime/references,-readability/braces,-whitespace,-legal,-build/include ./src ./include ./lib/Hoymiles ./lib/MqttSubscribeParser ./lib/TimeoutHelper ./lib/ResetReason + cpplint --repository=. --recursive --filter=-build/c++11,-runtime/references,-readability/braces,-whitespace,-legal,-build/include ./src ./include ./lib/Hoymiles ./lib/MqttSubscribeParser ./lib/TimeoutHelper ./lib/ResetReason ./lib/ETHSPI diff --git a/include/NetworkSettings.h b/include/NetworkSettings.h index 40ddc914d..0b34315a8 100644 --- a/include/NetworkSettings.h +++ b/include/NetworkSettings.h @@ -83,6 +83,7 @@ class NetworkSettingsClass { bool _ethConnected = false; std::vector _cbEventList; bool _lastMdnsEnabled = false; + bool _spiEth = false; }; extern NetworkSettingsClass NetworkSettings; \ No newline at end of file diff --git a/include/PinMapping.h b/include/PinMapping.h index 75b27294e..2cf44d3df 100644 --- a/include/PinMapping.h +++ b/include/PinMapping.h @@ -26,6 +26,13 @@ struct PinMapping_t { int8_t cmt_gpio3; int8_t cmt_sdio; + int8_t w5500_sclk; + int8_t w5500_mosi; + int8_t w5500_miso; + int8_t w5500_cs; + int8_t w5500_int; + int8_t w5500_rst; + int8_t eth_phy_addr; bool eth_enabled; int eth_power; @@ -70,6 +77,7 @@ class PinMappingClass { bool isValidNrf24Config() const; bool isValidCmt2300Config() const; + bool isValidW5500Config() const; bool isValidEthConfig() const; bool isValidHuaweiConfig() const; diff --git a/lib/ETHSPI/src/ETHSPI.cpp b/lib/ETHSPI/src/ETHSPI.cpp new file mode 100644 index 000000000..6673e65fe --- /dev/null +++ b/lib/ETHSPI/src/ETHSPI.cpp @@ -0,0 +1,121 @@ +#include "ETHSPI.h" + +#include + +// Functions from WiFiGeneric +void tcpipInit(); +void add_esp_interface_netif(esp_interface_t interface, esp_netif_t* esp_netif); + +ETHSPIClass::ETHSPIClass() : + eth_handle(nullptr), + eth_netif(nullptr) +{ + +} + +void ETHSPIClass::begin(int8_t pin_sclk, int8_t pin_mosi, int8_t pin_miso, int8_t pin_cs, int8_t pin_int, int8_t pin_rst, spi_host_device_t host_id) +{ + gpio_reset_pin(static_cast(pin_rst)); + gpio_set_direction(static_cast(pin_rst), GPIO_MODE_OUTPUT); + gpio_set_level(static_cast(pin_rst), 0); + + gpio_reset_pin(static_cast(pin_sclk)); + gpio_reset_pin(static_cast(pin_mosi)); + gpio_reset_pin(static_cast(pin_miso)); + gpio_reset_pin(static_cast(pin_cs)); + gpio_set_pull_mode(static_cast(pin_miso), GPIO_PULLUP_ONLY); + + // Workaround, because calling gpio_install_isr_service directly causes issues with attachInterrupt later + attachInterrupt(digitalPinToInterrupt(pin_int), nullptr, CHANGE); + detachInterrupt(digitalPinToInterrupt(pin_int)); + gpio_reset_pin(static_cast(pin_int)); + gpio_set_pull_mode(static_cast(pin_int), GPIO_PULLUP_ONLY); + + spi_bus_config_t buscfg = { + .mosi_io_num = pin_mosi, + .miso_io_num = pin_miso, + .sclk_io_num = pin_sclk, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .data4_io_num = -1, + .data5_io_num = -1, + .data6_io_num = -1, + .data7_io_num = -1, + .max_transfer_sz = 0, // uses default value internally + .flags = 0, + .intr_flags = 0 + }; + + ESP_ERROR_CHECK(spi_bus_initialize(host_id, &buscfg, SPI_DMA_CH_AUTO)); + + spi_device_interface_config_t devcfg = { + .command_bits = 16, // actually address phase + .address_bits = 8, // actually command phase + .dummy_bits = 0, + .mode = 0, + .duty_cycle_pos = 0, + .cs_ena_pretrans = 0, // only 0 supported + .cs_ena_posttrans = 0, // only 0 supported + .clock_speed_hz = 20000000, // stable with on OpenDTU Fusion Shield + .input_delay_ns = 0, + .spics_io_num = pin_cs, + .flags = 0, + .queue_size = 20, + .pre_cb = nullptr, + .post_cb = nullptr + }; + + spi_device_handle_t spi; + ESP_ERROR_CHECK(spi_bus_add_device(host_id, &devcfg, &spi)); + + // Reset sequence + delayMicroseconds(500); + gpio_set_level(static_cast(pin_rst), 1); + delayMicroseconds(1000); + + // Arduino function to start networking stack if not already started + tcpipInit(); + + ESP_ERROR_CHECK(tcpip_adapter_set_default_eth_handlers()); // ? + + eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi); + w5500_config.int_gpio_num = pin_int; + + eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); + mac_config.rx_task_stack_size = 4096; + esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config); + + eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); + phy_config.reset_gpio_num = -1; + esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config); + + esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); + ESP_ERROR_CHECK(esp_eth_driver_install(ð_config, ð_handle)); + + // Configure MAC address + uint8_t mac_addr[6]; + ESP_ERROR_CHECK(esp_efuse_mac_get_default(mac_addr)); + mac_addr[5] |= 0x03; // derive ethernet MAC address from base MAC address + ESP_ERROR_CHECK(esp_eth_ioctl(eth_handle, ETH_CMD_S_MAC_ADDR, mac_addr)); + + esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_ETH(); + eth_netif = esp_netif_new(&netif_config); + + ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle))); + + // Add to Arduino + add_esp_interface_netif(ESP_IF_ETH, eth_netif); + + ESP_ERROR_CHECK(esp_eth_start(eth_handle)); +} + +String ETHSPIClass::macAddress() +{ + uint8_t mac_addr[6] = {0, 0, 0, 0, 0, 0}; + esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr); + char mac_addr_str[24]; + snprintf(mac_addr_str, sizeof(mac_addr_str), "%02X:%02X:%02X:%02X:%02X:%02X", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); + return String(mac_addr_str); +} + +ETHSPIClass ETHSPI; \ No newline at end of file diff --git a/lib/ETHSPI/src/ETHSPI.h b/lib/ETHSPI/src/ETHSPI.h new file mode 100644 index 000000000..7ac0f6b23 --- /dev/null +++ b/lib/ETHSPI/src/ETHSPI.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +class ETHSPIClass +{ +private: + esp_eth_handle_t eth_handle; + esp_netif_t *eth_netif; + +public: + ETHSPIClass(); + + void begin(int8_t pin_sclk, int8_t pin_mosi, int8_t pin_miso, int8_t pin_cs, int8_t pin_int, int8_t pin_rst, spi_host_device_t host_id); + String macAddress(); +}; + +extern ETHSPIClass ETHSPI; \ No newline at end of file diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index 55ea428e5..c3a258280 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -7,8 +7,10 @@ #include "MessageOutput.h" #include "PinMapping.h" #include "Utils.h" +#include "SPIPortManager.h" #include "defaults.h" #include +#include #include #include "__compiled_constants.h" @@ -30,6 +32,26 @@ void NetworkSettingsClass::init(Scheduler& scheduler) WiFi.disconnect(true, true); WiFi.onEvent(std::bind(&NetworkSettingsClass::NetworkEvent, this, _1)); + + if (PinMapping.isValidW5500Config()) { + _spiEth = true; + + PinMapping_t& pin = PinMapping.get(); + if (PinMapping.isValidCmt2300Config() && PinMapping.isValidNrf24Config()) { + MessageOutput.println("No ETH connection possible with CMT and NRF enabled."); + } else { + auto oSPInum = SPIPortManager.allocatePort("ETHSPI"); + if (oSPInum) { + spi_host_device_t host_id = SPIPortManager.SPIhostNum(*oSPInum); + ETHSPI.begin(pin.w5500_sclk, pin.w5500_mosi, pin.w5500_miso, pin.w5500_cs, pin.w5500_int, pin.w5500_rst, + host_id); + } + } + } else if (PinMapping.isValidEthConfig()) { + PinMapping_t& pin = PinMapping.get(); + ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode); + } + setupMode(); scheduler.addTask(_loopTask); @@ -167,11 +189,6 @@ void NetworkSettingsClass::setupMode() WiFi.mode(WIFI_MODE_NULL); } } - - if (PinMapping.isValidEthConfig()) { - PinMapping_t& pin = PinMapping.get(); - ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode); - } } void NetworkSettingsClass::enableAdminMode() @@ -399,6 +416,8 @@ String NetworkSettingsClass::macAddress() const { switch (_networkMode) { case network_mode::Ethernet: + if (_spiEth) + return ETHSPI.macAddress(); return ETH.macAddress(); break; case network_mode::WiFi: diff --git a/src/PinMapping.cpp b/src/PinMapping.cpp index 0c4a09843..840b2daa2 100644 --- a/src/PinMapping.cpp +++ b/src/PinMapping.cpp @@ -170,6 +170,30 @@ #define POWERMETER_PIN_DERE -1 #endif +#ifndef W5500_SCLK +#define W5500_SCLK -1 +#endif + +#ifndef W5500_MOSI +#define W5500_MOSI -1 +#endif + +#ifndef W5500_MISO +#define W5500_MISO -1 +#endif + +#ifndef W5500_CS +#define W5500_CS -1 +#endif + +#ifndef W5500_INT +#define W5500_INT -1 +#endif + +#ifndef W5500_RST +#define W5500_RST -1 +#endif + PinMappingClass PinMapping; PinMappingClass::PinMappingClass() @@ -189,6 +213,13 @@ PinMappingClass::PinMappingClass() _pinMapping.cmt_gpio3 = CMT_GPIO3; _pinMapping.cmt_sdio = CMT_SDIO; + _pinMapping.w5500_sclk = W5500_SCLK; + _pinMapping.w5500_mosi = W5500_MOSI; + _pinMapping.w5500_miso = W5500_MISO; + _pinMapping.w5500_cs = W5500_CS; + _pinMapping.w5500_int = W5500_INT; + _pinMapping.w5500_rst = W5500_RST; + #ifdef OPENDTU_ETHERNET _pinMapping.eth_enabled = true; #else @@ -276,6 +307,13 @@ bool PinMappingClass::init(const String& deviceMapping) _pinMapping.cmt_gpio3 = doc[i]["cmt"]["gpio3"] | CMT_GPIO3; _pinMapping.cmt_sdio = doc[i]["cmt"]["sdio"] | CMT_SDIO; + _pinMapping.w5500_sclk = doc[i]["w5500"]["sclk"] | W5500_SCLK; + _pinMapping.w5500_mosi = doc[i]["w5500"]["mosi"] | W5500_MOSI; + _pinMapping.w5500_miso = doc[i]["w5500"]["miso"] | W5500_MISO; + _pinMapping.w5500_cs = doc[i]["w5500"]["cs"] | W5500_CS; + _pinMapping.w5500_int = doc[i]["w5500"]["int"] | W5500_INT; + _pinMapping.w5500_rst = doc[i]["w5500"]["rst"] | W5500_RST; + #ifdef OPENDTU_ETHERNET _pinMapping.eth_enabled = doc[i]["eth"]["enabled"] | true; #else @@ -347,6 +385,16 @@ bool PinMappingClass::isValidCmt2300Config() const && _pinMapping.cmt_sdio >= 0; } +bool PinMappingClass::isValidW5500Config() const +{ + return _pinMapping.w5500_sclk >= 0 + && _pinMapping.w5500_mosi >= 0 + && _pinMapping.w5500_miso >= 0 + && _pinMapping.w5500_cs >= 0 + && _pinMapping.w5500_int >= 0 + && _pinMapping.w5500_rst >= 0; +} + bool PinMappingClass::isValidEthConfig() const { return _pinMapping.eth_enabled; diff --git a/src/WebApi_device.cpp b/src/WebApi_device.cpp index 9bed5e53e..29603e259 100644 --- a/src/WebApi_device.cpp +++ b/src/WebApi_device.cpp @@ -50,6 +50,14 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request) cmtPinObj["gpio2"] = pin.cmt_gpio2; cmtPinObj["gpio3"] = pin.cmt_gpio3; + auto w5500PinObj = curPin["w5500"].to(); + w5500PinObj["sclk"] = pin.w5500_sclk; + w5500PinObj["mosi"] = pin.w5500_mosi; + w5500PinObj["miso"] = pin.w5500_miso; + w5500PinObj["cs"] = pin.w5500_cs; + w5500PinObj["int"] = pin.w5500_int; + w5500PinObj["rst"] = pin.w5500_rst; + auto ethPinObj = curPin["eth"].to(); ethPinObj["enabled"] = pin.eth_enabled; ethPinObj["phy_addr"] = pin.eth_phy_addr; From ef808d20f672647101172da56d3f021370721dc3 Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 21:03:08 +0200 Subject: [PATCH 2/8] Implemented review comments for `NetworkSettings` --- src/NetworkSettings.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index c3a258280..a22e1500d 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -32,26 +32,6 @@ void NetworkSettingsClass::init(Scheduler& scheduler) WiFi.disconnect(true, true); WiFi.onEvent(std::bind(&NetworkSettingsClass::NetworkEvent, this, _1)); - - if (PinMapping.isValidW5500Config()) { - _spiEth = true; - - PinMapping_t& pin = PinMapping.get(); - if (PinMapping.isValidCmt2300Config() && PinMapping.isValidNrf24Config()) { - MessageOutput.println("No ETH connection possible with CMT and NRF enabled."); - } else { - auto oSPInum = SPIPortManager.allocatePort("ETHSPI"); - if (oSPInum) { - spi_host_device_t host_id = SPIPortManager.SPIhostNum(*oSPInum); - ETHSPI.begin(pin.w5500_sclk, pin.w5500_mosi, pin.w5500_miso, pin.w5500_cs, pin.w5500_int, pin.w5500_rst, - host_id); - } - } - } else if (PinMapping.isValidEthConfig()) { - PinMapping_t& pin = PinMapping.get(); - ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode); - } - setupMode(); scheduler.addTask(_loopTask); @@ -189,6 +169,21 @@ void NetworkSettingsClass::setupMode() WiFi.mode(WIFI_MODE_NULL); } } + + if (PinMapping.isValidEthConfig()) { + PinMapping_t& pin = PinMapping.get(); + ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode); + } else if (PinMapping.isValidW5500Config()) { + auto oSPInum = SPIPortManager.allocatePort("ETHSPI"); + + if (oSPInum) { + spi_host_device_t host_id = SPIPortManager.SPIhostNum(*oSPInum); + PinMapping_t& pin = PinMapping.get(); + ETHSPI.begin(pin.w5500_sclk, pin.w5500_mosi, pin.w5500_miso, pin.w5500_cs, pin.w5500_int, pin.w5500_rst, + host_id); + _spiEth = true; + } + } } void NetworkSettingsClass::enableAdminMode() @@ -416,9 +411,11 @@ String NetworkSettingsClass::macAddress() const { switch (_networkMode) { case network_mode::Ethernet: - if (_spiEth) + if (_spiEth) { return ETHSPI.macAddress(); - return ETH.macAddress(); + } else { + return ETH.macAddress(); + } break; case network_mode::WiFi: return WiFi.macAddress(); From 166d57945f30f86d22a5dacd8b73d574424fb83a Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 21:41:01 +0200 Subject: [PATCH 3/8] Fixed code style in `NetworkSettings#macAddress()`` --- src/NetworkSettings.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index a22e1500d..7e133f74d 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -413,9 +413,8 @@ String NetworkSettingsClass::macAddress() const case network_mode::Ethernet: if (_spiEth) { return ETHSPI.macAddress(); - } else { - return ETH.macAddress(); } + return ETH.macAddress(); break; case network_mode::WiFi: return WiFi.macAddress(); From 241e05f857a0201afbe5a54bcbcaeeb8a1423621 Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 21:35:53 +0200 Subject: [PATCH 4/8] Updated the opendtufusionv2 profile with the default W5500 pinout --- platformio.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platformio.ini b/platformio.ini index f9435984c..54b11e0d5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -261,5 +261,11 @@ build_flags = ${env.build_flags} -DCMT_GPIO2=3 -DCMT_GPIO3=8 -DCMT_SDIO=5 + -DW5500_SCLK=39 + -DW5500_MOSI=40 + -DW5500_MISO=41 + -DW5500_CS=42 + -DW5500_RST=43 + -DW5500_INT=44 -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 From a45d18c6f74967d41f3d64d9184ef9cfbcc7ea95 Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 21:39:53 +0200 Subject: [PATCH 5/8] Added attribution to AhoyDTU --- lib/ETHSPI/src/ETHSPI.cpp | 8 +++++++- lib/ETHSPI/src/ETHSPI.h | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ETHSPI/src/ETHSPI.cpp b/lib/ETHSPI/src/ETHSPI.cpp index 6673e65fe..2e2ff8189 100644 --- a/lib/ETHSPI/src/ETHSPI.cpp +++ b/lib/ETHSPI/src/ETHSPI.cpp @@ -1,3 +1,9 @@ +//----------------------------------------------------------------------------- +// 2024 Ahoy, https://ahoydtu.de +// adapted to OpenDTU-OnBattery +// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed +//----------------------------------------------------------------------------- + #include "ETHSPI.h" #include @@ -118,4 +124,4 @@ String ETHSPIClass::macAddress() return String(mac_addr_str); } -ETHSPIClass ETHSPI; \ No newline at end of file +ETHSPIClass ETHSPI; diff --git a/lib/ETHSPI/src/ETHSPI.h b/lib/ETHSPI/src/ETHSPI.h index 7ac0f6b23..38174b2fa 100644 --- a/lib/ETHSPI/src/ETHSPI.h +++ b/lib/ETHSPI/src/ETHSPI.h @@ -1,3 +1,9 @@ +//----------------------------------------------------------------------------- +// 2024 Ahoy, https://ahoydtu.de +// adapted to OpenDTU-OnBattery +// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed +//----------------------------------------------------------------------------- + #pragma once #include @@ -17,4 +23,4 @@ class ETHSPIClass String macAddress(); }; -extern ETHSPIClass ETHSPI; \ No newline at end of file +extern ETHSPIClass ETHSPI; From 6e57969854449bb0df6cd6513a6de69214543b2d Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 22:05:04 +0200 Subject: [PATCH 6/8] Moved the network initialization back to `init()` --- src/NetworkSettings.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index 7e133f74d..cd3b26f34 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -32,6 +32,22 @@ void NetworkSettingsClass::init(Scheduler& scheduler) WiFi.disconnect(true, true); WiFi.onEvent(std::bind(&NetworkSettingsClass::NetworkEvent, this, _1)); + + if (PinMapping.isValidEthConfig()) { + PinMapping_t& pin = PinMapping.get(); + ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode); + } else if (PinMapping.isValidW5500Config()) { + auto oSPInum = SPIPortManager.allocatePort("ETHSPI"); + + if (oSPInum) { + spi_host_device_t host_id = SPIPortManager.SPIhostNum(*oSPInum); + PinMapping_t& pin = PinMapping.get(); + ETHSPI.begin(pin.w5500_sclk, pin.w5500_mosi, pin.w5500_miso, pin.w5500_cs, pin.w5500_int, pin.w5500_rst, + host_id); + _spiEth = true; + } + } + setupMode(); scheduler.addTask(_loopTask); @@ -169,21 +185,6 @@ void NetworkSettingsClass::setupMode() WiFi.mode(WIFI_MODE_NULL); } } - - if (PinMapping.isValidEthConfig()) { - PinMapping_t& pin = PinMapping.get(); - ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode); - } else if (PinMapping.isValidW5500Config()) { - auto oSPInum = SPIPortManager.allocatePort("ETHSPI"); - - if (oSPInum) { - spi_host_device_t host_id = SPIPortManager.SPIhostNum(*oSPInum); - PinMapping_t& pin = PinMapping.get(); - ETHSPI.begin(pin.w5500_sclk, pin.w5500_mosi, pin.w5500_miso, pin.w5500_cs, pin.w5500_int, pin.w5500_rst, - host_id); - _spiEth = true; - } - } } void NetworkSettingsClass::enableAdminMode() From f372085f8860b4fd9c9f93f3c1613ac97cc5d7cc Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 22:41:44 +0200 Subject: [PATCH 7/8] Revert "Updated the opendtufusionv2 profile with the default W5500 pinout" This reverts commit 241e05f857a0201afbe5a54bcbcaeeb8a1423621. --- platformio.ini | 6 ------ 1 file changed, 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index 54b11e0d5..f9435984c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -261,11 +261,5 @@ build_flags = ${env.build_flags} -DCMT_GPIO2=3 -DCMT_GPIO3=8 -DCMT_SDIO=5 - -DW5500_SCLK=39 - -DW5500_MOSI=40 - -DW5500_MISO=41 - -DW5500_CS=42 - -DW5500_RST=43 - -DW5500_INT=44 -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 From c2694b32d5cf28411d1ce645a27c758347ace6a5 Mon Sep 17 00:00:00 2001 From: Arman Vartan Date: Thu, 12 Sep 2024 22:51:54 +0200 Subject: [PATCH 8/8] Added W5500 mappings to the `opendtu_fusion` device profile --- docs/DeviceProfiles/opendtu_fusion.json | 40 ++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/DeviceProfiles/opendtu_fusion.json b/docs/DeviceProfiles/opendtu_fusion.json index f33dc47db..cf20772da 100644 --- a/docs/DeviceProfiles/opendtu_fusion.json +++ b/docs/DeviceProfiles/opendtu_fusion.json @@ -186,5 +186,43 @@ "data": 2, "clk": 1 } + }, + { + "name": "OpenDTU Fusion v2 with NRF24 and W5500 ethernet", + "nrf24": { + "miso": 48, + "mosi": 35, + "clk": 36, + "irq": 47, + "en": 38, + "cs": 37 + }, + "w5500": { + "sclk": 39, + "mosi": 40, + "miso": 41, + "cs": 42, + "rst": 43, + "int": 44 + } + }, + { + "name": "OpenDTU Fusion v2 with CMT2300A and W5500 ethernet", + "cmt": { + "clk": 6, + "cs": 4, + "fcs": 21, + "sdio": 5, + "gpio2": 3, + "gpio3": 8 + }, + "w5500": { + "sclk": 39, + "mosi": 40, + "miso": 41, + "cs": 42, + "rst": 43, + "int": 44 + } } -] \ No newline at end of file +]