esp32/network_lan: Add support for LAN8670 PHY.

This adds support for LAN8670 to the esp32 port.  Enabled conditionally for
the esp32 target, if ESP-IDF version is new enough (v5.3 or newer).

Fixes issue #15731.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2025-02-05 10:42:55 +11:00
committed by Damien George
parent f48b981567
commit 10f6c0699e
4 changed files with 36 additions and 1 deletions

View File

@@ -5,5 +5,10 @@ dependencies:
rules: rules:
- if: "target in [esp32s2, esp32s3]" - if: "target in [esp32s2, esp32s3]"
version: "~1.0.0" version: "~1.0.0"
espressif/lan867x:
version: "~1.0.0"
rules:
- if: "target == esp32"
- if: "idf_version >=5.3"
idf: idf:
version: ">=5.2.0" version: ">=5.2.0"

View File

@@ -28,7 +28,22 @@
#include "esp_netif.h" #include "esp_netif.h"
enum { PHY_LAN8710, PHY_LAN8720, PHY_IP101, PHY_RTL8201, PHY_DP83848, PHY_KSZ8041, PHY_KSZ8081, PHY_KSZ8851SNL = 100, PHY_DM9051, PHY_W5500 }; // lan867x component requires newer IDF version
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) && CONFIG_IDF_TARGET_ESP32
#define PHY_LAN867X_ENABLED (1)
#else
#define PHY_LAN867X_ENABLED (0)
#endif
enum {
// PHYs supported by the internal Ethernet MAC:
PHY_LAN8710, PHY_LAN8720, PHY_IP101, PHY_RTL8201, PHY_DP83848, PHY_KSZ8041, PHY_KSZ8081,
#if PHY_LAN867X_ENABLED
PHY_LAN8670,
#endif
// PHYs which are actually SPI Ethernet MAC+PHY chips:
PHY_KSZ8851SNL = 100, PHY_DM9051, PHY_W5500
};
#define IS_SPI_PHY(NUM) (NUM >= 100) #define IS_SPI_PHY(NUM) (NUM >= 100)
enum { ETH_INITIALIZED, ETH_STARTED, ETH_STOPPED, ETH_CONNECTED, ETH_DISCONNECTED, ETH_GOT_IP }; enum { ETH_INITIALIZED, ETH_STARTED, ETH_STOPPED, ETH_CONNECTED, ETH_DISCONNECTED, ETH_GOT_IP };

View File

@@ -47,6 +47,9 @@
{ MP_ROM_QSTR(MP_QSTR_PHY_DP83848), MP_ROM_INT(PHY_DP83848) }, { MP_ROM_QSTR(MP_QSTR_PHY_DP83848), MP_ROM_INT(PHY_DP83848) },
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8041), MP_ROM_INT(PHY_KSZ8041) }, { MP_ROM_QSTR(MP_QSTR_PHY_KSZ8041), MP_ROM_INT(PHY_KSZ8041) },
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8081), MP_ROM_INT(PHY_KSZ8081) }, { MP_ROM_QSTR(MP_QSTR_PHY_KSZ8081), MP_ROM_INT(PHY_KSZ8081) },
#if PHY_LAN867X_ENABLED
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8670), MP_ROM_INT(PHY_LAN8670) },
#endif
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8851SNL), MP_ROM_INT(PHY_KSZ8851SNL) }, { MP_ROM_QSTR(MP_QSTR_PHY_KSZ8851SNL), MP_ROM_INT(PHY_KSZ8851SNL) },

View File

@@ -45,6 +45,10 @@
#include "modnetwork.h" #include "modnetwork.h"
#include "extmod/modnetwork.h" #include "extmod/modnetwork.h"
#if PHY_LAN867X_ENABLED
#include "esp_eth_phy_lan867x.h"
#endif
typedef struct _lan_if_obj_t { typedef struct _lan_if_obj_t {
base_if_obj_t base; base_if_obj_t base;
bool initialized; bool initialized;
@@ -156,6 +160,9 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
args[ARG_phy_type].u_int != PHY_RTL8201 && args[ARG_phy_type].u_int != PHY_RTL8201 &&
args[ARG_phy_type].u_int != PHY_KSZ8041 && args[ARG_phy_type].u_int != PHY_KSZ8041 &&
args[ARG_phy_type].u_int != PHY_KSZ8081 && args[ARG_phy_type].u_int != PHY_KSZ8081 &&
#if PHY_LAN867X_ENABLED
args[ARG_phy_type].u_int != PHY_LAN8670 &&
#endif
#if CONFIG_ETH_USE_SPI_ETHERNET #if CONFIG_ETH_USE_SPI_ETHERNET
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
args[ARG_phy_type].u_int != PHY_KSZ8851SNL && args[ARG_phy_type].u_int != PHY_KSZ8851SNL &&
@@ -231,7 +238,12 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
case PHY_KSZ8081: case PHY_KSZ8081:
self->phy = esp_eth_phy_new_ksz80xx(&phy_config); self->phy = esp_eth_phy_new_ksz80xx(&phy_config);
break; break;
#if PHY_LAN867X_ENABLED
case PHY_LAN8670:
self->phy = esp_eth_phy_new_lan867x(&phy_config);
break;
#endif #endif
#endif // CONFIG_IDF_TARGET_ESP32
#if CONFIG_ETH_USE_SPI_ETHERNET #if CONFIG_ETH_USE_SPI_ETHERNET
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL #if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
case PHY_KSZ8851SNL: { case PHY_KSZ8851SNL: {