Skip to content

Commit

Permalink
Merge branch 'pr2333' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Oct 6, 2024
2 parents b5ca2cf + 6d048ae commit eaa2f07
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/PinMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

struct PinMapping_t {
char name[MAPPING_NAME_STRLEN + 1];

int8_t nrf24_miso;
int8_t nrf24_mosi;
int8_t nrf24_clk;
Expand All @@ -33,18 +34,22 @@ struct PinMapping_t {
int8_t w5500_int;
int8_t w5500_rst;

#if CONFIG_ETH_USE_ESP32_EMAC
int8_t eth_phy_addr;
bool eth_enabled;
int eth_power;
int eth_mdc;
int eth_mdio;
eth_phy_type_t eth_type;
eth_clock_mode_t eth_clk_mode;
#endif

uint8_t display_type;
uint8_t display_data;
uint8_t display_clk;
uint8_t display_cs;
uint8_t display_reset;

int8_t led[PINMAPPING_LED_COUNT];
};

Expand All @@ -57,7 +62,9 @@ class PinMappingClass {
bool isValidNrf24Config() const;
bool isValidCmt2300Config() const;
bool isValidW5500Config() const;
#if CONFIG_ETH_USE_ESP32_EMAC
bool isValidEthConfig() const;
#endif

private:
PinMapping_t _pinMapping;
Expand Down
5 changes: 4 additions & 1 deletion src/NetworkSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ void NetworkSettingsClass::init(Scheduler& scheduler)
MessageOutput.println("W5500: Connection successful");
else
MessageOutput.println("W5500: Connection error!!");
} else if (PinMapping.isValidEthConfig()) {
}
#if CONFIG_ETH_USE_ESP32_EMAC
else if (PinMapping.isValidEthConfig()) {
PinMapping_t& pin = PinMapping.get();
#if ESP_ARDUINO_VERSION_MAJOR < 3
ETH.begin(pin.eth_phy_addr, pin.eth_power, pin.eth_mdc, pin.eth_mdio, pin.eth_type, pin.eth_clk_mode);
#else
ETH.begin(pin.eth_type, pin.eth_phy_addr, pin.eth_mdc, pin.eth_mdio, pin.eth_power, pin.eth_clk_mode);
#endif
}
#endif

setupMode();

Expand Down
12 changes: 10 additions & 2 deletions src/PinMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
#define W5500_RST -1
#endif

#if CONFIG_ETH_USE_ESP32_EMAC

#ifndef ETH_PHY_ADDR
#define ETH_PHY_ADDR -1
#endif
Expand All @@ -132,6 +134,8 @@
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#endif

#endif

PinMappingClass PinMapping;

PinMappingClass::PinMappingClass()
Expand All @@ -158,18 +162,19 @@ PinMappingClass::PinMappingClass()
_pinMapping.w5500_int = W5500_INT;
_pinMapping.w5500_rst = W5500_RST;

#if CONFIG_ETH_USE_ESP32_EMAC
#ifdef OPENDTU_ETHERNET
_pinMapping.eth_enabled = true;
#else
_pinMapping.eth_enabled = false;
#endif

_pinMapping.eth_phy_addr = ETH_PHY_ADDR;
_pinMapping.eth_power = ETH_PHY_POWER;
_pinMapping.eth_mdc = ETH_PHY_MDC;
_pinMapping.eth_mdio = ETH_PHY_MDIO;
_pinMapping.eth_type = ETH_PHY_TYPE;
_pinMapping.eth_clk_mode = ETH_CLK_MODE;
#endif

_pinMapping.display_type = DISPLAY_TYPE;
_pinMapping.display_data = DISPLAY_DATA;
Expand Down Expand Up @@ -226,18 +231,19 @@ bool PinMappingClass::init(const String& deviceMapping)
_pinMapping.w5500_int = doc[i]["w5500"]["int"] | W5500_INT;
_pinMapping.w5500_rst = doc[i]["w5500"]["rst"] | W5500_RST;

#if CONFIG_ETH_USE_ESP32_EMAC
#ifdef OPENDTU_ETHERNET
_pinMapping.eth_enabled = doc[i]["eth"]["enabled"] | true;
#else
_pinMapping.eth_enabled = doc[i]["eth"]["enabled"] | false;
#endif

_pinMapping.eth_phy_addr = doc[i]["eth"]["phy_addr"] | ETH_PHY_ADDR;
_pinMapping.eth_power = doc[i]["eth"]["power"] | ETH_PHY_POWER;
_pinMapping.eth_mdc = doc[i]["eth"]["mdc"] | ETH_PHY_MDC;
_pinMapping.eth_mdio = doc[i]["eth"]["mdio"] | ETH_PHY_MDIO;
_pinMapping.eth_type = doc[i]["eth"]["type"] | ETH_PHY_TYPE;
_pinMapping.eth_clk_mode = doc[i]["eth"]["clk_mode"] | ETH_CLK_MODE;
#endif

_pinMapping.display_type = doc[i]["display"]["type"] | DISPLAY_TYPE;
_pinMapping.display_data = doc[i]["display"]["data"] | DISPLAY_DATA;
Expand Down Expand Up @@ -283,9 +289,11 @@ bool PinMappingClass::isValidW5500Config() const
&& _pinMapping.w5500_rst >= 0;
}

#if CONFIG_ETH_USE_ESP32_EMAC
bool PinMappingClass::isValidEthConfig() const
{
return _pinMapping.eth_enabled
&& _pinMapping.eth_mdc >= 0
&& _pinMapping.eth_mdio >= 0;
}
#endif
2 changes: 2 additions & 0 deletions src/WebApi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request)
w5500PinObj["int"] = pin.w5500_int;
w5500PinObj["rst"] = pin.w5500_rst;

#if CONFIG_ETH_USE_ESP32_EMAC
auto ethPinObj = curPin["eth"].to<JsonObject>();
ethPinObj["enabled"] = pin.eth_enabled;
ethPinObj["phy_addr"] = pin.eth_phy_addr;
Expand All @@ -66,6 +67,7 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request)
ethPinObj["mdio"] = pin.eth_mdio;
ethPinObj["type"] = pin.eth_type;
ethPinObj["clk_mode"] = pin.eth_clk_mode;
#endif

auto displayPinObj = curPin["display"].to<JsonObject>();
displayPinObj["type"] = pin.display_type;
Expand Down

0 comments on commit eaa2f07

Please sign in to comment.