Skip to content

Commit

Permalink
Relocate ethernet setup routine
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartF22 committed Aug 2, 2023
1 parent 3979aba commit 0c31dc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/ETHSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include <Arduino.h>
#include "MessageOutput.h"

extern void tcpipInit();
extern void add_esp_interface_netif(esp_interface_t interface, esp_netif_t* esp_netif); /* from WiFiGeneric */
// Functions from WiFiGeneric
void tcpipInit();
void add_esp_interface_netif(esp_interface_t interface, esp_netif_t* esp_netif);

ETHSPIClass::ETHSPIClass() :
eth_handle(nullptr),
Expand Down Expand Up @@ -99,7 +100,7 @@ void ETHSPIClass::begin(int8_t pin_sclk, int8_t pin_mosi, int8_t pin_miso, int8_

// Configure MAC address
uint8_t mac_addr[6];
esp_base_mac_addr_get(mac_addr);
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));

Expand Down
23 changes: 11 additions & 12 deletions src/NetworkSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ void NetworkSettingsClass::init()
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);

WiFi.onEvent(std::bind(&NetworkSettingsClass::NetworkEvent, this, _1));

if (PinMapping.isValidW5500Config()) {
_spiEth = true;

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);
} 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();
}

Expand Down Expand Up @@ -130,18 +141,6 @@ void NetworkSettingsClass::setupMode()
WiFi.mode(WIFI_MODE_NULL);
}
}

if (PinMapping.isValidW5500Config()) {
if (!_spiEth) {
_spiEth = true;

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);
}
} 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);
}
}

void NetworkSettingsClass::enableAdminMode()
Expand Down

0 comments on commit 0c31dc7

Please sign in to comment.