Fixed EthType for Core3 (#21317)

This commit is contained in:
s-hadinger 2024-05-02 14:46:28 +02:00 committed by GitHub
parent dbafe1e167
commit f7e285ab11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 27 deletions

View File

@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file.
- Berry `web_add_handler` called before `Webserver` is initialized - Berry `web_add_handler` called before `Webserver` is initialized
- Put back wifi IPv6 workaround - Put back wifi IPv6 workaround
- Berry `math.inf`, `math.isinf()` and fixed json ouput for `inf` and `nan` - Berry `math.inf`, `math.isinf()` and fixed json ouput for `inf` and `nan`
- `EthType` for Core3
### Removed ### Removed
- LVGL disabled vector graphics - LVGL disabled vector graphics

View File

@ -78,7 +78,7 @@
#endif #endif
#ifndef ETH_TYPE #ifndef ETH_TYPE
#define ETH_TYPE 0 // 0 = LAN8720, 1 = TLK110/IP101, 2 = RTL8201, 3 = DP83848, 4 = RFU, 5 = KSZ8081, 6 = KSZ8041, 7 = JL1101, 8 = W5500, 9 = KSZ8851, 10 = DM9051 #define ETH_TYPE 0 // 0 = LAN8720, 1 = TLK110/IP101, 2 = RTL8201, 3 = DP83848, 4 = DM9051, 5 = KSZ8081, 6 = KSZ8041, 7 = JL1101, 8 = W5500, 9 = KSZ8851
#endif #endif
#ifndef ETH_CLKMODE #ifndef ETH_CLKMODE
@ -88,18 +88,30 @@
#include <ETH.h> #include <ETH.h>
#define ETH_USES_SPI 0x80 // Use the highest significant bit to mark SPI Ethernet
const uint8_t eth_type_xtable[] = { const uint8_t eth_type_xtable[] = {
#if CONFIG_ETH_USE_ESP32_EMAC
ETH_PHY_LAN8720, // 0 = LAN8720
ETH_PHY_TLK110, // 1 = TLK110/IP101
ETH_PHY_RTL8201, // 2 = RTL8201
ETH_PHY_DP83848, // 3 = DP83848
ETH_PHY_DM9051 | ETH_USES_SPI, // 4 = 10 = DM9051
ETH_PHY_KSZ8081, // 5 = KSZ8081
ETH_PHY_KSZ8041, // 6 = KSZ8041
ETH_PHY_JL1101, // 7 = JL1101
#else
0, // 0 = LAN8720 0, // 0 = LAN8720
1, // 1 = TLK110/IP101 0, // 1 = TLK110/IP101
2, // 2 = RTL8201 0, // 2 = RTL8201
4, // 3 = DP83848 (is 4 in core3) 0, // 3 = DP83848
0, // 4 = RFU - Reserved for Future Use ETH_PHY_DM9051 | ETH_USES_SPI, // 4 = 10 = DM9051
6, // 5 = KSZ8081 (is 6 in core3) 0, // 5 = KSZ8081
5, // 6 = KSZ8041 (is 5 in core3) 0, // 6 = KSZ8041
3, // 7 = JL1101 (is 3 in core3) 0, // 7 = JL1101
8, // 8 = W5500 (is new in core3 and using SPI) #endif // CONFIG_ETH_USE_ESP32_EMAC
9, // 9 = KSZ8851 (is new in core3 and using SPI) ETH_PHY_W5500 | ETH_USES_SPI, // 8 = W5500
7 // 10 = DM9051 (is 7 in core3 and using SPI) ETH_PHY_KSZ8851 | ETH_USES_SPI, // 9 = KSZ8851
}; };
char eth_hostname[sizeof(TasmotaGlobal.hostname)]; char eth_hostname[sizeof(TasmotaGlobal.hostname)];
uint8_t eth_config_change; uint8_t eth_config_change;
@ -187,30 +199,27 @@ void EthernetSetIp(void) {
void EthernetInit(void) { void EthernetInit(void) {
if (!Settings->flag4.network_ethernet) { return; } if (!Settings->flag4.network_ethernet) { return; }
int eth_type = eth_type_xtable[Settings->eth_type]; int32_t eth_type = (Settings->eth_type < sizeof(eth_type_xtable)) ? eth_type_xtable[Settings->eth_type] : 0; // make sure we don't overflow
bool eth_uses_spi = (eth_type & ETH_USES_SPI);
eth_type = eth_type & 0x7F; // remove SPI flag
#if CONFIG_ETH_USE_ESP32_EMAC #if CONFIG_ETH_USE_ESP32_EMAC
if (WT32_ETH01 == TasmotaGlobal.module_type) { if (WT32_ETH01 == TasmotaGlobal.module_type) {
Settings->eth_address = 1; // EthAddress Settings->eth_address = 1; // EthAddress
Settings->eth_type = 0; // EthType 0 = LAN8720 Settings->eth_type = ETH_PHY_LAN8720; // EthType 0 = LAN8720
Settings->eth_clk_mode = 0; // EthClockMode 0 = ETH_CLOCK_GPIO0_IN Settings->eth_clk_mode = 0; // EthClockMode 0 = ETH_CLOCK_GPIO0_IN
} }
#else // No CONFIG_ETH_USE_ESP32_EMAC
if (Settings->eth_type < 7) {
Settings->eth_type = 8; // Select W5500 (SPI) for non-EMAC hardware
}
eth_type = eth_type_xtable[Settings->eth_type] -7; // As No EMAC support substract EMAC enums (According ETH.cpp debug info)
#endif // CONFIG_ETH_USE_ESP32_EMAC #endif // CONFIG_ETH_USE_ESP32_EMAC
if (Settings->eth_type < 7) { if (eth_uses_spi) {
// CONFIG_ETH_USE_ESP32_EMAC // Uses SPI Ethernat
if (!PinUsed(GPIO_ETH_PHY_MDC) && !PinUsed(GPIO_ETH_PHY_MDIO)) { // && should be || but keep for backward compatibility if (!PinUsed(GPIO_ETH_PHY_MDC) || !PinUsed(GPIO_ETH_PHY_MDIO) || !PinUsed(GPIO_ETH_PHY_POWER)) {
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ETH "No ETH MDC and ETH MDIO GPIO defined")); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ETH "No ETH MDC (SPI CS), ETH MDIO (SPI IRQ) and ETH POWER (SPI RST) GPIO defined"));
return; return;
} }
} else { } else {
// ETH_SPI_SUPPORTS_CUSTOM // Native ESP32
if (!PinUsed(GPIO_ETH_PHY_MDC) || !PinUsed(GPIO_ETH_PHY_MDIO) || !PinUsed(GPIO_ETH_PHY_POWER)) { if (!PinUsed(GPIO_ETH_PHY_MDC) && !PinUsed(GPIO_ETH_PHY_MDIO)) { // && should be || but keep for backward compatibility
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ETH "No ETH MDC (SPI CS), ETH MDIO (SPI IRQ) and ETH POWER (SPI RST) GPIO defined")); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ETH "No ETH MDC and ETH MDIO GPIO defined"));
return; return;
} }
} }
@ -231,7 +240,7 @@ void EthernetInit(void) {
#endif // USE_IPV6 #endif // USE_IPV6
bool init_ok = false; bool init_ok = false;
if (Settings->eth_type < 7) { if (!eth_uses_spi) {
#if CONFIG_ETH_USE_ESP32_EMAC #if CONFIG_ETH_USE_ESP32_EMAC
init_ok = (ETH.begin((eth_phy_type_t)eth_type, Settings->eth_address, eth_mdc, eth_mdio, eth_power, (eth_clock_mode_t)Settings->eth_clk_mode)); init_ok = (ETH.begin((eth_phy_type_t)eth_type, Settings->eth_address, eth_mdc, eth_mdio, eth_power, (eth_clock_mode_t)Settings->eth_clk_mode));
#endif // CONFIG_ETH_USE_ESP32_EMAC #endif // CONFIG_ETH_USE_ESP32_EMAC