Skip to content

Commit 9d2a0ba

Browse files
committed
Port the ENC28J60 examples to the ESP-IDF 5.x ethernet API
1 parent 38bd138 commit 9d2a0ba

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

ESP32/TLS13-ENC28J60-client/main/enc28j60_example_main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,6 @@ int init_ENC28J60() {
996996
enc28j60_config.int_gpio_num = CONFIG_EXAMPLE_ENC28J60_INT_GPIO;
997997

998998
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
999-
mac_config.smi_mdc_gpio_num = -1; // ENC28J60 doesn't have SMI interface
1000-
mac_config.smi_mdio_gpio_num = -1;
1001999
esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config);
10021000

10031001
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();

ESP32/TLS13-ENC28J60-client/main/esp_eth_phy_enc28j60.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <sys/cdefs.h>
1717
#include "esp_log.h"
1818
#include "esp_eth.h"
19-
#include "eth_phy_regs_struct.h"
2019
#include "freertos/FreeRTOS.h"
2120
#include "freertos/task.h"
2221
#include "driver/gpio.h"
@@ -57,6 +56,25 @@ typedef union {
5756
* @brief PHSTAT2(PHY Status Register 2)
5857
*
5958
*/
59+
/* IDF 5.x removed eth_phy_regs_struct.h; this is the standard 802.3 BMCR */
60+
typedef union {
61+
struct {
62+
uint32_t reserved_5_0 : 6; // Reserved
63+
uint32_t speed_select_msb : 1;// Speed select MSB
64+
uint32_t collision_test : 1; // Collision test
65+
uint32_t duplex_mode : 1; // Duplex mode
66+
uint32_t restart_auto_nego : 1; // Restart auto negotiation
67+
uint32_t isolate : 1; // Isolate
68+
uint32_t power_down : 1; // Power down
69+
uint32_t en_auto_nego : 1; // Enable auto negotiation
70+
uint32_t speed_select : 1; // Speed select LSB
71+
uint32_t loopback : 1; // Loopback
72+
uint32_t reset : 1; // Reset
73+
};
74+
uint32_t val;
75+
} bmcr_reg_t;
76+
#define ETH_PHY_BMCR_REG_ADDR (0x00)
77+
6078
typedef union {
6179
struct {
6280
uint32_t reserved_4_0 : 5; // Reserved

ESP32/TLS13-ENC28J60-server/main/enc28j60_example_main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,6 @@ int init_ENC28J60() {
10161016
enc28j60_config.int_gpio_num = CONFIG_EXAMPLE_ENC28J60_INT_GPIO;
10171017

10181018
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
1019-
mac_config.smi_mdc_gpio_num = -1; // ENC28J60 doesn't have SMI interface
1020-
mac_config.smi_mdio_gpio_num = -1;
10211019
esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config);
10221020

10231021
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();

ESP32/TLS13-ENC28J60-server/main/esp_eth_phy_enc28j60.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <sys/cdefs.h>
1717
#include "esp_log.h"
1818
#include "esp_eth.h"
19-
#include "eth_phy_regs_struct.h"
2019
#include "freertos/FreeRTOS.h"
2120
#include "freertos/task.h"
2221
#include "driver/gpio.h"
@@ -57,6 +56,25 @@ typedef union {
5756
* @brief PHSTAT2(PHY Status Register 2)
5857
*
5958
*/
59+
/* IDF 5.x removed eth_phy_regs_struct.h; this is the standard 802.3 BMCR */
60+
typedef union {
61+
struct {
62+
uint32_t reserved_5_0 : 6; // Reserved
63+
uint32_t speed_select_msb : 1;// Speed select MSB
64+
uint32_t collision_test : 1; // Collision test
65+
uint32_t duplex_mode : 1; // Duplex mode
66+
uint32_t restart_auto_nego : 1; // Restart auto negotiation
67+
uint32_t isolate : 1; // Isolate
68+
uint32_t power_down : 1; // Power down
69+
uint32_t en_auto_nego : 1; // Enable auto negotiation
70+
uint32_t speed_select : 1; // Speed select LSB
71+
uint32_t loopback : 1; // Loopback
72+
uint32_t reset : 1; // Reset
73+
};
74+
uint32_t val;
75+
} bmcr_reg_t;
76+
#define ETH_PHY_BMCR_REG_ADDR (0x00)
77+
6078
typedef union {
6179
struct {
6280
uint32_t reserved_4_0 : 5; // Reserved

0 commit comments

Comments
 (0)