mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/ethernet_phy_power' into 'master'
ethernet: add a gpio to enable/disable phy power ethernet board v2 use gpio 17 . See merge request !495
This commit is contained in:
commit
6c139c8ffb
@ -75,6 +75,7 @@ struct emac_config_data {
|
|||||||
bool emac_flow_ctrl_enable;
|
bool emac_flow_ctrl_enable;
|
||||||
bool emac_flow_ctrl_partner_support;
|
bool emac_flow_ctrl_partner_support;
|
||||||
eth_phy_get_partner_pause_enable_func emac_phy_get_partner_pause_enable;
|
eth_phy_get_partner_pause_enable_func emac_phy_get_partner_pause_enable;
|
||||||
|
eth_phy_power_enable_func emac_phy_power_enable;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum emac_post_type {
|
enum emac_post_type {
|
||||||
|
@ -225,6 +225,7 @@ static void emac_set_user_config_data(eth_config_t *config )
|
|||||||
emac_config.emac_flow_ctrl_enable = false;
|
emac_config.emac_flow_ctrl_enable = false;
|
||||||
#endif
|
#endif
|
||||||
emac_config.emac_phy_get_partner_pause_enable = config->phy_get_partner_pause_enable;
|
emac_config.emac_phy_get_partner_pause_enable = config->phy_get_partner_pause_enable;
|
||||||
|
emac_config.emac_phy_power_enable = config->phy_power_enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emac_enable_intr()
|
static void emac_enable_intr()
|
||||||
@ -291,6 +292,11 @@ static esp_err_t emac_verify_args(void)
|
|||||||
ret = ESP_FAIL;
|
ret = ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(emac_config.emac_phy_power_enable == NULL) {
|
||||||
|
ESP_LOGE(TAG, "phy power enable func is null");
|
||||||
|
ret = ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -943,6 +949,8 @@ esp_err_t esp_eth_init(eth_config_t *config)
|
|||||||
emac_set_user_config_data(config);
|
emac_set_user_config_data(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emac_config.emac_phy_power_enable(true);
|
||||||
|
|
||||||
ret = emac_verify_args();
|
ret = emac_verify_args();
|
||||||
|
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
|
@ -80,7 +80,7 @@ typedef void (*eth_phy_func)(void);
|
|||||||
typedef esp_err_t (*eth_tcpip_input_func)(void *buffer, uint16_t len, void *eb);
|
typedef esp_err_t (*eth_tcpip_input_func)(void *buffer, uint16_t len, void *eb);
|
||||||
typedef void (*eth_gpio_config_func)(void);
|
typedef void (*eth_gpio_config_func)(void);
|
||||||
typedef bool (*eth_phy_get_partner_pause_enable_func)(void);
|
typedef bool (*eth_phy_get_partner_pause_enable_func)(void);
|
||||||
|
typedef void (*eth_phy_power_enable_func)(bool enable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ethernet configuration
|
* @brief ethernet configuration
|
||||||
@ -98,6 +98,7 @@ typedef struct {
|
|||||||
eth_gpio_config_func gpio_config; /*!< gpio config func */
|
eth_gpio_config_func gpio_config; /*!< gpio config func */
|
||||||
bool flow_ctrl_enable; /*!< flag of flow ctrl enable */
|
bool flow_ctrl_enable; /*!< flag of flow ctrl enable */
|
||||||
eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable; /*!< get partner pause enable */
|
eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable; /*!< get partner pause enable */
|
||||||
|
eth_phy_power_enable_func phy_power_enable; /*!< enable or disable phy power */
|
||||||
|
|
||||||
} eth_config_t;
|
} eth_config_t;
|
||||||
|
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
static const char *TAG = "eth_demo";
|
static const char *TAG = "eth_demo";
|
||||||
|
|
||||||
#define DEFAULT_PHY_CONFIG (AUTO_MDIX_ENABLE|AUTO_NEGOTIATION_ENABLE|AN_1|AN_0|LED_CFG)
|
#define DEFAULT_PHY_CONFIG (AUTO_MDIX_ENABLE|AUTO_NEGOTIATION_ENABLE|AN_1|AN_0|LED_CFG)
|
||||||
|
#define PIN_PHY_POWER 17
|
||||||
|
#define PIN_SMI_MDC 23
|
||||||
|
#define PIN_SMI_MDIO 18
|
||||||
|
|
||||||
void phy_tlk110_check_phy_init(void)
|
void phy_tlk110_check_phy_init(void)
|
||||||
{
|
{
|
||||||
@ -87,6 +90,17 @@ void phy_enable_flow_ctrl(void)
|
|||||||
esp_eth_smi_write(AUTO_NEG_ADVERTISEMENT_REG,data|ASM_DIR|PAUSE);
|
esp_eth_smi_write(AUTO_NEG_ADVERTISEMENT_REG,data|ASM_DIR|PAUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void phy_tlk110_power_enable(bool enable)
|
||||||
|
{
|
||||||
|
gpio_pad_select_gpio(PIN_PHY_POWER);
|
||||||
|
gpio_set_direction(PIN_PHY_POWER,GPIO_MODE_OUTPUT);
|
||||||
|
if(enable == true) {
|
||||||
|
gpio_set_level(PIN_PHY_POWER, 1);
|
||||||
|
} else {
|
||||||
|
gpio_set_level(PIN_PHY_POWER, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void phy_tlk110_init(void)
|
void phy_tlk110_init(void)
|
||||||
{
|
{
|
||||||
esp_eth_smi_write(PHY_RESET_CONTROL_REG, SOFTWARE_RESET);
|
esp_eth_smi_write(PHY_RESET_CONTROL_REG, SOFTWARE_RESET);
|
||||||
@ -117,11 +131,11 @@ void eth_gpio_config_rmii(void)
|
|||||||
//rmii clk ,can not change
|
//rmii clk ,can not change
|
||||||
gpio_set_direction(0, GPIO_MODE_INPUT);
|
gpio_set_direction(0, GPIO_MODE_INPUT);
|
||||||
|
|
||||||
//mdc to gpio4
|
//mdc to gpio23
|
||||||
gpio_matrix_out(4, EMAC_MDC_O_IDX, 0, 0);
|
gpio_matrix_out(PIN_SMI_MDC, EMAC_MDC_O_IDX, 0, 0);
|
||||||
//mdio to gpio2
|
//mdio to gpio18
|
||||||
gpio_matrix_out(2, EMAC_MDO_O_IDX, 0, 0);
|
gpio_matrix_out(PIN_SMI_MDIO, EMAC_MDO_O_IDX, 0, 0);
|
||||||
gpio_matrix_in(2, EMAC_MDI_I_IDX, 0);
|
gpio_matrix_in(PIN_SMI_MDIO, EMAC_MDI_I_IDX, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void eth_task(void *pvParameter)
|
void eth_task(void *pvParameter)
|
||||||
@ -163,6 +177,7 @@ void app_main()
|
|||||||
//Only FULLDUPLEX mode support flow ctrl now!
|
//Only FULLDUPLEX mode support flow ctrl now!
|
||||||
config.flow_ctrl_enable = true;
|
config.flow_ctrl_enable = true;
|
||||||
config.phy_get_partner_pause_enable = phy_tlk110_get_partner_pause_enable;
|
config.phy_get_partner_pause_enable = phy_tlk110_get_partner_pause_enable;
|
||||||
|
config.phy_power_enable = phy_tlk110_power_enable;
|
||||||
|
|
||||||
ret = esp_eth_init(&config);
|
ret = esp_eth_init(&config);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user