mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-15 06:26:49 +00:00
feat(esp_eth): added SPI Ethernet module polling mode
Closes https://github.com/espressif/esp-idf/issues/12682
This commit is contained in:
@@ -198,23 +198,54 @@ menu "Example Ethernet Configuration"
|
||||
|
||||
config EXAMPLE_ETH_SPI_INT0_GPIO
|
||||
int "Interrupt GPIO number SPI Ethernet module #1"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
|
||||
range -1 ENV_GPIO_IN_RANGE_MAX
|
||||
default 4 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
default 4 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C6
|
||||
default 10 if IDF_TARGET_ESP32H2
|
||||
help
|
||||
Set the GPIO number used by the first SPI Ethernet module interrupt line.
|
||||
Set -1 to use SPI Ethernet module in polling mode.
|
||||
|
||||
config EXAMPLE_ETH_SPI_INT1_GPIO
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int "Interrupt GPIO number SPI Ethernet module #2"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
|
||||
range -1 ENV_GPIO_IN_RANGE_MAX
|
||||
default 33 if IDF_TARGET_ESP32
|
||||
default 5 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C2
|
||||
default 5 if IDF_TARGET_ESP32C6
|
||||
default 9 if IDF_TARGET_ESP32H2
|
||||
help
|
||||
Set the GPIO number used by the second SPI Ethernet module interrupt line.
|
||||
Set -1 to use SPI Ethernet module in polling mode.
|
||||
|
||||
config EXAMPLE_ETH_SPI_POLLING0_MS_VAL
|
||||
depends on EXAMPLE_ETH_SPI_INT0_GPIO < 0
|
||||
int "Polling period in msec of SPI Ethernet Module #1"
|
||||
default 10
|
||||
help
|
||||
Set SPI Ethernet module polling period.
|
||||
|
||||
config EXAMPLE_ETH_SPI_POLLING1_MS_VAL
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1 && EXAMPLE_ETH_SPI_INT1_GPIO < 0
|
||||
int "Polling period in msec of SPI Ethernet Module #2"
|
||||
default 10
|
||||
help
|
||||
Set SPI Ethernet module polling period.
|
||||
|
||||
# Hidden variable to ensure that polling period option is visible only when interrupt is set disabled and
|
||||
# it is set to known value (0) when interrupt is enabled at the same time.
|
||||
config EXAMPLE_ETH_SPI_POLLING0_MS
|
||||
int
|
||||
default EXAMPLE_ETH_SPI_POLLING0_MS_VAL if EXAMPLE_ETH_SPI_POLLING0_MS_VAL > 0
|
||||
default 0
|
||||
|
||||
# Hidden variable to ensure that polling period option is visible only when interrupt is set disabled and
|
||||
# it is set to known value (0) when interrupt is enabled at the same time.
|
||||
config EXAMPLE_ETH_SPI_POLLING1_MS
|
||||
depends on EXAMPLE_SPI_ETHERNETS_NUM > 1
|
||||
int
|
||||
default EXAMPLE_ETH_SPI_POLLING1_MS_VAL if EXAMPLE_ETH_SPI_POLLING1_MS_VAL > 0
|
||||
default 0
|
||||
|
||||
config EXAMPLE_ETH_SPI_PHY_RST0_GPIO
|
||||
int "PHY Reset GPIO number of SPI Ethernet Module #1"
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -31,13 +31,15 @@ static const char *TAG = "example_eth_init";
|
||||
do { \
|
||||
eth_module_config[num].spi_cs_gpio = CONFIG_EXAMPLE_ETH_SPI_CS ##num## _GPIO; \
|
||||
eth_module_config[num].int_gpio = CONFIG_EXAMPLE_ETH_SPI_INT ##num## _GPIO; \
|
||||
eth_module_config[num].polling_ms = CONFIG_EXAMPLE_ETH_SPI_POLLING ##num## _MS; \
|
||||
eth_module_config[num].phy_reset_gpio = CONFIG_EXAMPLE_ETH_SPI_PHY_RST ##num## _GPIO; \
|
||||
eth_module_config[num].phy_addr = CONFIG_EXAMPLE_ETH_SPI_PHY_ADDR ##num; \
|
||||
} while(0)
|
||||
|
||||
typedef struct {
|
||||
uint8_t spi_cs_gpio;
|
||||
uint8_t int_gpio;
|
||||
int8_t int_gpio;
|
||||
uint32_t polling_ms;
|
||||
int8_t phy_reset_gpio;
|
||||
uint8_t phy_addr;
|
||||
uint8_t *mac_addr;
|
||||
@@ -187,16 +189,19 @@ static esp_eth_handle_t eth_init_spi(spi_eth_module_config_t *spi_eth_module_con
|
||||
#if CONFIG_EXAMPLE_USE_KSZ8851SNL
|
||||
eth_ksz8851snl_config_t ksz8851snl_config = ETH_KSZ8851SNL_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
|
||||
ksz8851snl_config.int_gpio_num = spi_eth_module_config->int_gpio;
|
||||
ksz8851snl_config.poll_period_ms = spi_eth_module_config->polling_ms;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_ksz8851snl(&ksz8851snl_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_ksz8851snl(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_USE_DM9051
|
||||
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
|
||||
dm9051_config.int_gpio_num = spi_eth_module_config->int_gpio;
|
||||
dm9051_config.poll_period_ms = spi_eth_module_config->polling_ms;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config);
|
||||
#elif CONFIG_EXAMPLE_USE_W5500
|
||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg);
|
||||
w5500_config.int_gpio_num = spi_eth_module_config->int_gpio;
|
||||
w5500_config.poll_period_ms = spi_eth_module_config->polling_ms;
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
|
||||
#endif //CONFIG_EXAMPLE_USE_W5500
|
||||
|
Reference in New Issue
Block a user