Skip to content

Commit 10f6c06

Browse files
projectgusdpgeorge
authored andcommitted
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 micropython#15731. Signed-off-by: Damien George <[email protected]> Signed-off-by: Angus Gratton <[email protected]>
1 parent f48b981 commit 10f6c06

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

ports/esp32/main/idf_component.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ dependencies:
55
rules:
66
- if: "target in [esp32s2, esp32s3]"
77
version: "~1.0.0"
8+
espressif/lan867x:
9+
version: "~1.0.0"
10+
rules:
11+
- if: "target == esp32"
12+
- if: "idf_version >=5.3"
813
idf:
914
version: ">=5.2.0"

ports/esp32/modnetwork.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@
2828

2929
#include "esp_netif.h"
3030

31-
enum { PHY_LAN8710, PHY_LAN8720, PHY_IP101, PHY_RTL8201, PHY_DP83848, PHY_KSZ8041, PHY_KSZ8081, PHY_KSZ8851SNL = 100, PHY_DM9051, PHY_W5500 };
31+
// lan867x component requires newer IDF version
32+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) && CONFIG_IDF_TARGET_ESP32
33+
#define PHY_LAN867X_ENABLED (1)
34+
#else
35+
#define PHY_LAN867X_ENABLED (0)
36+
#endif
37+
38+
enum {
39+
// PHYs supported by the internal Ethernet MAC:
40+
PHY_LAN8710, PHY_LAN8720, PHY_IP101, PHY_RTL8201, PHY_DP83848, PHY_KSZ8041, PHY_KSZ8081,
41+
#if PHY_LAN867X_ENABLED
42+
PHY_LAN8670,
43+
#endif
44+
// PHYs which are actually SPI Ethernet MAC+PHY chips:
45+
PHY_KSZ8851SNL = 100, PHY_DM9051, PHY_W5500
46+
};
3247
#define IS_SPI_PHY(NUM) (NUM >= 100)
3348
enum { ETH_INITIALIZED, ETH_STARTED, ETH_STOPPED, ETH_CONNECTED, ETH_DISCONNECTED, ETH_GOT_IP };
3449

ports/esp32/modnetwork_globals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
{ MP_ROM_QSTR(MP_QSTR_PHY_DP83848), MP_ROM_INT(PHY_DP83848) },
4848
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8041), MP_ROM_INT(PHY_KSZ8041) },
4949
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8081), MP_ROM_INT(PHY_KSZ8081) },
50+
#if PHY_LAN867X_ENABLED
51+
{ MP_ROM_QSTR(MP_QSTR_PHY_LAN8670), MP_ROM_INT(PHY_LAN8670) },
52+
#endif
5053

5154
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
5255
{ MP_ROM_QSTR(MP_QSTR_PHY_KSZ8851SNL), MP_ROM_INT(PHY_KSZ8851SNL) },

ports/esp32/network_lan.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#include "modnetwork.h"
4646
#include "extmod/modnetwork.h"
4747

48+
#if PHY_LAN867X_ENABLED
49+
#include "esp_eth_phy_lan867x.h"
50+
#endif
51+
4852
typedef struct _lan_if_obj_t {
4953
base_if_obj_t base;
5054
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
156160
args[ARG_phy_type].u_int != PHY_RTL8201 &&
157161
args[ARG_phy_type].u_int != PHY_KSZ8041 &&
158162
args[ARG_phy_type].u_int != PHY_KSZ8081 &&
163+
#if PHY_LAN867X_ENABLED
164+
args[ARG_phy_type].u_int != PHY_LAN8670 &&
165+
#endif
159166
#if CONFIG_ETH_USE_SPI_ETHERNET
160167
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
161168
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
231238
case PHY_KSZ8081:
232239
self->phy = esp_eth_phy_new_ksz80xx(&phy_config);
233240
break;
241+
#if PHY_LAN867X_ENABLED
242+
case PHY_LAN8670:
243+
self->phy = esp_eth_phy_new_lan867x(&phy_config);
244+
break;
234245
#endif
246+
#endif // CONFIG_IDF_TARGET_ESP32
235247
#if CONFIG_ETH_USE_SPI_ETHERNET
236248
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
237249
case PHY_KSZ8851SNL: {

0 commit comments

Comments
 (0)