Skip to content

Commit a5460a8

Browse files
committed
feat(eth): Ethernet - enc28j60 driver added
1 parent ce15aed commit a5460a8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

libraries/Ethernet/src/ETH.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "esp_netif_types.h"
4242
#include "esp_netif_defaults.h"
4343
#include "esp_eth_phy.h"
44+
#include "utility/enc28j60/esp_eth_enc28j60.h"
4445

4546
static ETHClass *_ethernets[3] = {NULL, NULL, NULL};
4647
static esp_event_handler_instance_t _eth_ev_instance = NULL;
@@ -401,7 +402,9 @@ esp_err_t ETHClass::eth_spi_read(uint32_t cmd, uint32_t addr, void *data, uint32
401402
}
402403
} else
403404
#endif
404-
{
405+
if (_phy_type == ETH_PHY_ENC28J60) {
406+
_spi->write(cmd << 5 | addr);
407+
} else {
405408
log_e("Unsupported PHY module: %d", _phy_type);
406409
digitalWrite(_pin_cs, HIGH);
407410
_spi->endTransaction();
@@ -442,7 +445,9 @@ esp_err_t ETHClass::eth_spi_write(uint32_t cmd, uint32_t addr, const void *data,
442445
}
443446
} else
444447
#endif
445-
{
448+
if (_phy_type == ETH_PHY_ENC28J60) {
449+
_spi->write(cmd << 5 | addr);
450+
} else {
446451
log_e("Unsupported PHY module: %d", _phy_type);
447452
digitalWrite(_pin_cs, HIGH);
448453
_spi->endTransaction();
@@ -644,7 +649,24 @@ bool ETHClass::beginSPI(
644649
phy = esp_eth_phy_new_ksz8851snl(&phy_config);
645650
} else
646651
#endif
647-
{
652+
if (type == ETH_PHY_ENC28J60) {
653+
spi_devcfg.cs_ena_posttrans = enc28j60_cal_spi_cs_hold_time(_spi_freq_mhz);
654+
eth_enc28j60_config_t mac_config = ETH_ENC28J60_DEFAULT_CONFIG(spi_host, &spi_devcfg);
655+
mac_config.int_gpio_num = _pin_irq;
656+
if (_pin_irq < 0) {
657+
mac_config.poll_period_ms = 10;
658+
}
659+
if (_spi != NULL) {
660+
mac_config.custom_spi_driver.config = this;
661+
mac_config.custom_spi_driver.init = _eth_spi_init;
662+
mac_config.custom_spi_driver.deinit = _eth_spi_deinit;
663+
mac_config.custom_spi_driver.read = _eth_spi_read;
664+
mac_config.custom_spi_driver.write = _eth_spi_write;
665+
}
666+
mac = esp_eth_mac_new_enc28j60(&mac_config, &eth_mac_config);
667+
phy_config.autonego_timeout_ms = 0; // ENC28J60 doesn't support auto-negotiation
668+
phy = esp_eth_phy_new_enc28j60(&phy_config);
669+
} else {
648670
log_e("Unsupported PHY module: %d", (int)type);
649671
return false;
650672
}

libraries/Ethernet/src/ETH.h

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ typedef enum {
114114
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
115115
ETH_PHY_KSZ8851,
116116
#endif
117+
ETH_PHY_ENC28J60,
117118
ETH_PHY_MAX
118119
} eth_phy_type_t;
119120

0 commit comments

Comments
 (0)