Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "esp_eth.h"
- #include "eth_phy/phy.h"
- #include "eth_phy/phy_lan8720.h"
- #include <WiFi.h>
- #include "IPAddress.h"
- #define ETH_PHY_CONF phy_lan8720_default_ethernet_config
- #define ETH_PHY_ADDR PHY1
- #define PIN_PHY_POWER 17
- #define PIN_SMI_MDC 23
- #define PIN_SMI_MDIO 18
- static eth_config_t eth_config = ETH_PHY_CONF;
- boolean gotip = false;
- static void ethernet_config_gpio(void){
- // RMII data pinek fixek:
- // CRS_DRV = GPIO27 PULL-UP 2,2k
- // TXD0 = GPIO19
- // TXD1 = GPIO22
- // TX_EN = GPIO21
- // RXD0 = GPIO25 PULL-UP 2,2k
- // RXD1 = GPIO26 PULL-UP 2,2k
- // CLK == GPIO0
- phy_rmii_configure_data_interface_pins();
- // MDC == GPIO 23
- // MDIO == GPIO 18 PULL-UP 2,2k
- phy_rmii_smi_configure_pins(PIN_SMI_MDC, PIN_SMI_MDIO);
- }
- static void ethernet_power_enable(bool enable){
- pinMode(PIN_PHY_POWER, OUTPUT);
- digitalWrite(PIN_PHY_POWER, enable);
- delay(1);// Kis delay hogy a power up/down működjön, min 300us
- }
- extern void tcpipInit();
- void ETH_begin(){
- eth_config.phy_addr = ETH_PHY_ADDR;
- eth_config.gpio_config = ethernet_config_gpio;
- eth_config.tcpip_input = tcpip_adapter_eth_input;
- eth_config.phy_power_enable = ethernet_power_enable;
- tcpipInit();
- esp_err_t err = esp_eth_init(ð_config);
- if(!err){
- err = esp_eth_enable();
- }
- }
- IPAddress ETH_localIP()
- {
- tcpip_adapter_ip_info_t ip;
- tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
- return IPAddress(ip.ip.addr);
- }
- IPAddress ETH_subnetMask()
- {
- tcpip_adapter_ip_info_t ip;
- tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
- return IPAddress(ip.netmask.addr);
- }
- IPAddress ETH_gatewayIP()
- {
- tcpip_adapter_ip_info_t ip;
- tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
- return IPAddress(ip.gw.addr);
- }
- bool ETH_setHostname(const char * hostname)
- {
- return tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_ETH, hostname) == 0;
- }
- bool ETH_fullDuplex()
- {
- return eth_config.phy_get_duplex_mode();
- }
- uint8_t ETH_linkSpeed()
- {
- return eth_config.phy_get_speed_mode()?100:10;
- }
- String ETH_macAddress(void)
- {
- uint8_t mac[6];
- char macStr[18] = { 0 };
- esp_eth_get_mac(mac);
- sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- return String(macStr);
- }
- void WiFiEvent(WiFiEvent_t event){
- switch(event) {
- case SYSTEM_EVENT_ETH_START:
- //set eth hostname here
- ETH_setHostname("esp32-eth");
- break;
- case SYSTEM_EVENT_ETH_CONNECTED:
- //ethernet connected (if manual IP)
- break;
- case SYSTEM_EVENT_ETH_GOT_IP:
- //Serial.print("ETH IPv4: ");
- //Serial.println(ETH_localIP());
- gotip = true;
- //Serial.println("......................");
- break;
- case SYSTEM_EVENT_ETH_DISCONNECTED:
- //disconnected
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement