|
41 | 41 | #include "esp_netif_types.h"
|
42 | 42 | #include "esp_netif_defaults.h"
|
43 | 43 | #include "esp_eth_phy.h"
|
| 44 | +#include "utility/enc28j60/esp_eth_enc28j60.h" |
44 | 45 |
|
45 | 46 | static ETHClass *_ethernets[3] = {NULL, NULL, NULL};
|
46 | 47 | 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
|
401 | 402 | }
|
402 | 403 | } else
|
403 | 404 | #endif
|
404 |
| - { |
| 405 | + if (_phy_type == ETH_PHY_ENC28J60) { |
| 406 | + _spi->write(cmd << 5 | addr); |
| 407 | + } else { |
405 | 408 | log_e("Unsupported PHY module: %d", _phy_type);
|
406 | 409 | digitalWrite(_pin_cs, HIGH);
|
407 | 410 | _spi->endTransaction();
|
@@ -442,7 +445,9 @@ esp_err_t ETHClass::eth_spi_write(uint32_t cmd, uint32_t addr, const void *data,
|
442 | 445 | }
|
443 | 446 | } else
|
444 | 447 | #endif
|
445 |
| - { |
| 448 | + if (_phy_type == ETH_PHY_ENC28J60) { |
| 449 | + _spi->write(cmd << 5 | addr); |
| 450 | + } else { |
446 | 451 | log_e("Unsupported PHY module: %d", _phy_type);
|
447 | 452 | digitalWrite(_pin_cs, HIGH);
|
448 | 453 | _spi->endTransaction();
|
@@ -644,7 +649,24 @@ bool ETHClass::beginSPI(
|
644 | 649 | phy = esp_eth_phy_new_ksz8851snl(&phy_config);
|
645 | 650 | } else
|
646 | 651 | #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, ð_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 { |
648 | 670 | log_e("Unsupported PHY module: %d", (int)type);
|
649 | 671 | return false;
|
650 | 672 | }
|
|
0 commit comments