mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-15 15:00:02 +01:00
esp_eth: SPI Ethernet modules initialization simplification
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -21,8 +21,9 @@ extern "C" {
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
spi_device_handle_t spi_hdl; /*!< Handle of SPI device driver */
|
||||
int int_gpio_num; /*!< Interrupt GPIO number */
|
||||
spi_host_device_t spi_host_id; /*!< SPI peripheral */
|
||||
spi_device_interface_config_t *spi_devcfg; /*!< SPI device configuration */
|
||||
int int_gpio_num; /*!< Interrupt GPIO number */
|
||||
} eth_enc28j60_config_t;
|
||||
|
||||
/**
|
||||
@@ -40,10 +41,11 @@ typedef enum {
|
||||
* @brief Default ENC28J60 specific configuration
|
||||
*
|
||||
*/
|
||||
#define ETH_ENC28J60_DEFAULT_CONFIG(spi_device) \
|
||||
{ \
|
||||
.spi_hdl = spi_device, \
|
||||
.int_gpio_num = 4, \
|
||||
#define ETH_ENC28J60_DEFAULT_CONFIG(spi_host, spi_devcfg_p) \
|
||||
{ \
|
||||
.spi_host_id = spi_host, \
|
||||
.spi_devcfg = spi_devcfg_p, \
|
||||
.int_gpio_num = 4, \
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1038,6 +1038,7 @@ static esp_err_t emac_enc28j60_del(esp_eth_mac_t *mac)
|
||||
{
|
||||
emac_enc28j60_t *emac = __containerof(mac, emac_enc28j60_t, parent);
|
||||
vTaskDelete(emac->rx_task_hdl);
|
||||
spi_bus_remove_device(emac->spi_hdl);
|
||||
vSemaphoreDelete(emac->spi_lock);
|
||||
vSemaphoreDelete(emac->reg_trans_lock);
|
||||
vSemaphoreDelete(emac->tx_ready_sem);
|
||||
@@ -1055,12 +1056,25 @@ esp_eth_mac_t *esp_eth_mac_new_enc28j60(const eth_enc28j60_config_t *enc28j60_co
|
||||
MAC_CHECK(emac, "calloc emac failed", err, NULL);
|
||||
/* enc28j60 driver is interrupt driven */
|
||||
MAC_CHECK(enc28j60_config->int_gpio_num >= 0, "error interrupt gpio number", err, NULL);
|
||||
/* SPI device init */
|
||||
spi_device_interface_config_t spi_devcfg;
|
||||
memcpy(&spi_devcfg, enc28j60_config->spi_devcfg, sizeof(spi_device_interface_config_t));
|
||||
if (enc28j60_config->spi_devcfg->command_bits == 0 && enc28j60_config->spi_devcfg->address_bits == 0) {
|
||||
/* configure default SPI frame format */
|
||||
spi_devcfg.command_bits = 3;
|
||||
spi_devcfg.address_bits = 5;
|
||||
} else {
|
||||
MAC_CHECK(enc28j60_config->spi_devcfg->command_bits == 3 || enc28j60_config->spi_devcfg->address_bits == 5,
|
||||
"incorrect SPI frame format (command_bits/address_bits)", err, NULL);
|
||||
}
|
||||
MAC_CHECK(spi_bus_add_device(enc28j60_config->spi_host_id, &spi_devcfg, &emac->spi_hdl) == ESP_OK,
|
||||
"adding device to SPI host #%d failed", err, NULL, enc28j60_config->spi_host_id + 1);
|
||||
|
||||
emac->last_bank = 0xFF;
|
||||
emac->next_packet_ptr = ENC28J60_BUF_RX_START;
|
||||
/* bind methods and attributes */
|
||||
emac->sw_reset_timeout_ms = mac_config->sw_reset_timeout_ms;
|
||||
emac->int_gpio_num = enc28j60_config->int_gpio_num;
|
||||
emac->spi_hdl = enc28j60_config->spi_hdl;
|
||||
emac->parent.set_mediator = emac_enc28j60_set_mediator;
|
||||
emac->parent.init = emac_enc28j60_init;
|
||||
emac->parent.deinit = emac_enc28j60_deinit;
|
||||
|
||||
Reference in New Issue
Block a user