diff --git a/include/NetworkSettings.h b/include/NetworkSettings.h index 51ec10757..6c1c217d8 100644 --- a/include/NetworkSettings.h +++ b/include/NetworkSettings.h @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once +#include "W5500.h" #include #include #include #include -#include "W5500.h" enum class network_mode { WiFi, diff --git a/include/W5500.h b/include/W5500.h index f4ee9d2a0..fc0c66148 100644 --- a/include/W5500.h +++ b/include/W5500.h @@ -1,19 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-or-later #pragma once -#include - #include +#include class W5500 { public: explicit W5500(int8_t pin_mosi, int8_t pin_miso, int8_t pin_sclk, int8_t pin_cs, int8_t pin_int, int8_t pin_rst); W5500(const W5500&) = delete; - W5500 &operator=(const W5500&) = delete; + W5500& operator=(const W5500&) = delete; ~W5500(); String macAddress(); private: esp_eth_handle_t eth_handle; - esp_netif_t *eth_netif; + esp_netif_t* eth_netif; }; diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index f754ea3ff..d1edcc82a 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -7,10 +7,10 @@ #include "MessageOutput.h" #include "PinMapping.h" #include "Utils.h" +#include "__compiled_constants.h" #include "defaults.h" #include #include -#include "__compiled_constants.h" NetworkSettingsClass::NetworkSettingsClass() : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&NetworkSettingsClass::loop, this)) @@ -404,8 +404,9 @@ String NetworkSettingsClass::macAddress() const { switch (_networkMode) { case network_mode::Ethernet: - if (_w5500) + if (_w5500) { return _w5500->macAddress(); + } return ETH.macAddress(); break; case network_mode::WiFi: diff --git a/src/W5500.cpp b/src/W5500.cpp index 3f2742041..0f5b57398 100644 --- a/src/W5500.cpp +++ b/src/W5500.cpp @@ -1,16 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2024 Thomas Basler and others + */ + #include "W5500.h" #include - #include // Internal Arduino functions from WiFiGeneric void tcpipInit(); -void add_esp_interface_netif(esp_interface_t interface, esp_netif_t *esp_netif); +void add_esp_interface_netif(esp_interface_t interface, esp_netif_t* esp_netif); -W5500::W5500(int8_t pin_mosi, int8_t pin_miso, int8_t pin_sclk, int8_t pin_cs, int8_t pin_int, int8_t pin_rst) : - eth_handle(nullptr), - eth_netif(nullptr) +W5500::W5500(int8_t pin_mosi, int8_t pin_miso, int8_t pin_sclk, int8_t pin_cs, int8_t pin_int, int8_t pin_rst) + : eth_handle(nullptr) + , eth_netif(nullptr) { gpio_reset_pin(static_cast(pin_rst)); gpio_set_level(static_cast(pin_rst), 0); @@ -26,8 +30,7 @@ W5500::W5500(int8_t pin_mosi, int8_t pin_miso, int8_t pin_sclk, int8_t pin_cs, i auto bus_config = std::make_shared( static_cast(pin_mosi), static_cast(pin_miso), - static_cast(pin_sclk) - ); + static_cast(pin_sclk)); spi_device_interface_config_t device_config { .command_bits = 16, // actually address phase @@ -65,11 +68,11 @@ W5500::W5500(int8_t pin_mosi, int8_t pin_miso, int8_t pin_sclk, int8_t pin_cs, i 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); + 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_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)); @@ -90,18 +93,19 @@ W5500::W5500(int8_t pin_mosi, int8_t pin_miso, int8_t pin_sclk, int8_t pin_cs, i ESP_ERROR_CHECK(esp_eth_start(eth_handle)); } -W5500::~W5500() { +W5500::~W5500() +{ // TODO(LennartF22): support cleanup at some point? } -String W5500::macAddress() { +String W5500::macAddress() +{ uint8_t mac_addr[6] = {}; esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr); char mac_addr_str[18]; 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] - ); + mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); return String(mac_addr_str); }