mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-18 13:02:21 +02:00
ethernet: add gpio number into config structure
* Original commit: espressif/esp-idf@05d71319de
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
1734e59057
commit
cd3cc0be3b
@ -33,7 +33,7 @@ menu "Example Connection Configuration"
|
|||||||
choice EXAMPLE_USE_ETHERNET
|
choice EXAMPLE_USE_ETHERNET
|
||||||
prompt "Ethernet Type"
|
prompt "Ethernet Type"
|
||||||
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
default EXAMPLE_USE_INTERNAL_ETHERNET if IDF_TARGET_ESP32
|
||||||
default EXAMPLE_USE_SPI_ETHERNET if !IDF_TARGET_ESP32
|
default EXAMPLE_USE_DM9051 if !IDF_TARGET_ESP32
|
||||||
help
|
help
|
||||||
Select which kind of Ethernet will be used in the example.
|
Select which kind of Ethernet will be used in the example.
|
||||||
|
|
||||||
@ -44,9 +44,10 @@ menu "Example Connection Configuration"
|
|||||||
help
|
help
|
||||||
Select internal Ethernet MAC controller.
|
Select internal Ethernet MAC controller.
|
||||||
|
|
||||||
config EXAMPLE_USE_SPI_ETHERNET
|
config EXAMPLE_USE_DM9051
|
||||||
bool "SPI Ethernet Module"
|
bool "DM9051 Module"
|
||||||
select ETH_USE_SPI_ETHERNET
|
select ETH_USE_SPI_ETHERNET
|
||||||
|
select ETH_SPI_ETHERNET_DM9051
|
||||||
help
|
help
|
||||||
Select external SPI-Ethernet module.
|
Select external SPI-Ethernet module.
|
||||||
|
|
||||||
@ -93,51 +94,84 @@ menu "Example Connection Configuration"
|
|||||||
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver.
|
||||||
Goto http://www.ti.com/product/DP83848J for more information about it.
|
Goto http://www.ti.com/product/DP83848J for more information about it.
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
config EXAMPLE_ETH_MDC_GPIO
|
||||||
|
int "SMI MDC GPIO number"
|
||||||
|
default 23
|
||||||
|
help
|
||||||
|
Set the GPIO number used by SMI MDC.
|
||||||
|
|
||||||
|
config EXAMPLE_ETH_MDIO_GPIO
|
||||||
|
int "SMI MDIO GPIO number"
|
||||||
|
default 18
|
||||||
|
help
|
||||||
|
Set the GPIO number used by SMI MDIO.
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if EXAMPLE_USE_SPI_ETHERNET
|
if EXAMPLE_USE_DM9051
|
||||||
config EXAMPLE_ETH_SPI_HOST
|
config EXAMPLE_DM9051_SPI_HOST
|
||||||
int "SPI Host Number"
|
int "SPI Host Number"
|
||||||
range 0 2
|
range 0 2
|
||||||
default 1
|
default 1
|
||||||
help
|
help
|
||||||
Set the SPI host used to communicate with DM9051.
|
Set the SPI host used to communicate with DM9051.
|
||||||
|
|
||||||
config EXAMPLE_ETH_SCLK_GPIO
|
config EXAMPLE_DM9051_SCLK_GPIO
|
||||||
int "SPI SCLK GPIO number"
|
int "SPI SCLK GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 19
|
default 19
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI SCLK.
|
Set the GPIO number used by SPI SCLK.
|
||||||
|
|
||||||
config EXAMPLE_ETH_MOSI_GPIO
|
config EXAMPLE_DM9051_MOSI_GPIO
|
||||||
int "SPI MOSI GPIO number"
|
int "SPI MOSI GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 23
|
default 23
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MOSI.
|
Set the GPIO number used by SPI MOSI.
|
||||||
|
|
||||||
config EXAMPLE_ETH_MISO_GPIO
|
config EXAMPLE_DM9051_MISO_GPIO
|
||||||
int "SPI MISO GPIO number"
|
int "SPI MISO GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 25
|
default 25
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI MISO.
|
Set the GPIO number used by SPI MISO.
|
||||||
|
|
||||||
config EXAMPLE_ETH_CS_GPIO
|
config EXAMPLE_DM9051_CS_GPIO
|
||||||
int "SPI CS GPIO number"
|
int "SPI CS GPIO number"
|
||||||
range 0 33
|
range 0 33
|
||||||
default 22
|
default 22
|
||||||
help
|
help
|
||||||
Set the GPIO number used by SPI CS.
|
Set the GPIO number used by SPI CS.
|
||||||
|
|
||||||
config EXAMPLE_ETH_SPI_CLOCK_MHZ
|
config EXAMPLE_DM9051_SPI_CLOCK_MHZ
|
||||||
int "SPI clock speed (MHz)"
|
int "SPI clock speed (MHz)"
|
||||||
range 20 80
|
range 20 80
|
||||||
default 20
|
default 20
|
||||||
help
|
help
|
||||||
Set the clock speed (MHz) of SPI interface.
|
Set the clock speed (MHz) of SPI interface.
|
||||||
|
|
||||||
|
config EXAMPLE_DM9051_INT_GPIO
|
||||||
|
int "Interrupt GPIO number"
|
||||||
|
default 4
|
||||||
|
help
|
||||||
|
Set the GPIO number used by DM9051 interrupt.
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
config EXAMPLE_ETH_PHY_RST_GPIO
|
||||||
|
int "PHY Reset GPIO number"
|
||||||
|
default 5
|
||||||
|
help
|
||||||
|
Set the GPIO number used to reset PHY chip.
|
||||||
|
Set to -1 to disable PHY chip hardware reset.
|
||||||
|
|
||||||
|
config EXAMPLE_ETH_PHY_ADDR
|
||||||
|
int "PHY Address"
|
||||||
|
range 0 31 if EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
range 1 1 if !EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
default 1
|
||||||
|
help
|
||||||
|
Set PHY address according your board schematic.
|
||||||
endif
|
endif
|
||||||
|
|
||||||
config EXAMPLE_CONNECT_IPV6
|
config EXAMPLE_CONNECT_IPV6
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
@ -227,7 +228,11 @@ static void start(void)
|
|||||||
#endif
|
#endif
|
||||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||||
|
phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR;
|
||||||
|
phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO;
|
||||||
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
#if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET
|
||||||
|
mac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO;
|
||||||
|
mac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO;
|
||||||
s_mac = esp_eth_mac_new_esp32(&mac_config);
|
s_mac = esp_eth_mac_new_esp32(&mac_config);
|
||||||
#if CONFIG_EXAMPLE_ETH_PHY_IP101
|
#if CONFIG_EXAMPLE_ETH_PHY_IP101
|
||||||
s_phy = esp_eth_phy_new_ip101(&phy_config);
|
s_phy = esp_eth_phy_new_ip101(&phy_config);
|
||||||
@ -238,28 +243,29 @@ static void start(void)
|
|||||||
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
#elif CONFIG_EXAMPLE_ETH_PHY_DP83848
|
||||||
s_phy = esp_eth_phy_new_dp83848(&phy_config);
|
s_phy = esp_eth_phy_new_dp83848(&phy_config);
|
||||||
#endif
|
#endif
|
||||||
#elif CONFIG_EXAMPLE_USE_SPI_ETHERNET
|
#elif CONFIG_EXAMPLE_USE_DM9051
|
||||||
gpio_install_isr_service(0);
|
gpio_install_isr_service(0);
|
||||||
spi_device_handle_t spi_handle = NULL;
|
spi_device_handle_t spi_handle = NULL;
|
||||||
spi_bus_config_t buscfg = {
|
spi_bus_config_t buscfg = {
|
||||||
.miso_io_num = CONFIG_EXAMPLE_ETH_MISO_GPIO,
|
.miso_io_num = CONFIG_EXAMPLE_DM9051_MISO_GPIO,
|
||||||
.mosi_io_num = CONFIG_EXAMPLE_ETH_MOSI_GPIO,
|
.mosi_io_num = CONFIG_EXAMPLE_DM9051_MOSI_GPIO,
|
||||||
.sclk_io_num = CONFIG_EXAMPLE_ETH_SCLK_GPIO,
|
.sclk_io_num = CONFIG_EXAMPLE_DM9051_SCLK_GPIO,
|
||||||
.quadwp_io_num = -1,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1));
|
ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_DM9051_SPI_HOST, &buscfg, 1));
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 1,
|
.command_bits = 1,
|
||||||
.address_bits = 7,
|
.address_bits = 7,
|
||||||
.mode = 0,
|
.mode = 0,
|
||||||
.clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000,
|
.clock_speed_hz = CONFIG_EXAMPLE_DM9051_SPI_CLOCK_MHZ * 1000 * 1000,
|
||||||
.spics_io_num = CONFIG_EXAMPLE_ETH_CS_GPIO,
|
.spics_io_num = CONFIG_EXAMPLE_DM9051_CS_GPIO,
|
||||||
.queue_size = 20
|
.queue_size = 20
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle));
|
ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_DM9051_SPI_HOST, &devcfg, &spi_handle));
|
||||||
/* dm9051 ethernet driver is based on spi driver */
|
/* dm9051 ethernet driver is based on spi driver */
|
||||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
|
dm9051_config.int_gpio_num = CONFIG_EXAMPLE_DM9051_INT_GPIO;
|
||||||
s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||||
s_phy = esp_eth_phy_new_dm9051(&phy_config);
|
s_phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||||
#elif CONFIG_EXAMPLE_USE_OPENETH
|
#elif CONFIG_EXAMPLE_USE_OPENETH
|
||||||
|
Reference in New Issue
Block a user