Initial IDF-4.0 port

SmartConfig and ETH need some work to adapt to the new API
This commit is contained in:
me-no-dev
2020-01-25 05:44:14 +02:00
parent be4d3b6cb8
commit 1bf59ac227
48 changed files with 401 additions and 267 deletions

View File

@ -19,14 +19,21 @@
*/
#include "ETH.h"
#include "eth_phy/phy.h"
#include "eth_phy/phy_tlk110.h"
#include "eth_phy/phy_lan8720.h"
#include "esp_system.h"
#ifdef ESP_IDF_VERSION_MAJOR
#include "esp_eth.h"
#include "esp_eth_phy.h"
#else
#include "eth_phy/phy.h"
#include "eth_phy/phy_tlk110.h"
#include "eth_phy/phy_lan8720.h"
#endif
#include "lwip/err.h"
#include "lwip/dns.h"
extern void tcpipInit();
#ifndef ESP_IDF_VERSION_MAJOR
static int _eth_phy_mdc_pin = -1;
static int _eth_phy_mdio_pin = -1;
static int _eth_phy_power_pin = -1;
@ -48,6 +55,7 @@ static void _eth_phy_power_enable(bool enable)
digitalWrite(_eth_phy_power_pin, enable);
delay(1);
}
#endif
ETHClass::ETHClass():initialized(false),started(false),staticIP(false)
{
@ -56,6 +64,11 @@ ETHClass::ETHClass():initialized(false),started(false),staticIP(false)
ETHClass::~ETHClass()
{}
#ifdef ESP_IDF_VERSION_MAJOR
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type){
return false;
}
#else
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode)
{
esp_err_t err;
@ -108,6 +121,7 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
}
return false;
}
#endif
bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
{
@ -240,17 +254,29 @@ bool ETHClass::setHostname(const char * hostname)
bool ETHClass::fullDuplex()
{
#ifdef ESP_IDF_VERSION_MAJOR
return true;//todo
#else
return eth_config.phy_get_duplex_mode();
#endif
}
bool ETHClass::linkUp()
{
#ifdef ESP_IDF_VERSION_MAJOR
return true;//todo
#else
return eth_config.phy_check_link();
#endif
}
uint8_t ETHClass::linkSpeed()
{
#ifdef ESP_IDF_VERSION_MAJOR
return 100;//ToDo
#else
return eth_config.phy_get_speed_mode()?100:10;
#endif
}
bool ETHClass::enableIpV6()
@ -272,15 +298,23 @@ uint8_t * macAddress(uint8_t* mac)
if(!mac){
return NULL;
}
#ifdef ESP_IDF_VERSION_MAJOR
//ToDo
#else
esp_eth_get_mac(mac);
#endif
return mac;
}
String ETHClass::macAddress(void)
{
uint8_t mac[6];
uint8_t mac[6] = {0,0,0,0,0,0};//ToDo
char macStr[18] = { 0 };
#ifdef ESP_IDF_VERSION_MAJOR
//ToDo
#else
esp_eth_get_mac(mac);
#endif
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(macStr);
}

View File

@ -22,6 +22,7 @@
#define _ETH_H_
#include "WiFi.h"
#include "esp_system.h"
#include "esp_eth.h"
#ifndef ETH_PHY_ADDR
@ -45,8 +46,12 @@
#endif
#ifndef ETH_CLK_MODE
#ifdef ESP_IDF_VERSION_MAJOR
#define ETH_CLK_MODE ESP_ETH_CLOCK_GPIO0_IN
#else
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#endif
#endif
typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_MAX } eth_phy_type_t;
@ -55,13 +60,21 @@ class ETHClass {
bool initialized;
bool started;
bool staticIP;
#ifdef ESP_IDF_VERSION_MAJOR
esp_eth_config_t eth_config;
#else
eth_config_t eth_config;
#endif
public:
ETHClass();
~ETHClass();
#ifdef ESP_IDF_VERSION_MAJOR
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE);
#else
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
#endif
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
const char * getHostname();

View File

@ -46,7 +46,11 @@ private:
return 0;
}
int count;
#ifdef ESP_IDF_VERSION_MAJOR
int res = lwip_ioctl(_fd, FIONREAD, &count);
#else
int res = lwip_ioctl_r(_fd, FIONREAD, &count);
#endif
if(res < 0) {
_failed = true;
return 0;
@ -227,7 +231,11 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
tv.tv_sec = 0;
tv.tv_usec = timeout * 1000;
#ifdef ESP_IDF_VERSION_MAJOR
int res = lwip_connect(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
#else
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
#endif
if (res < 0 && errno != EINPROGRESS) {
log_e("connect on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
close(sockfd);

View File

@ -687,7 +687,12 @@ bool WiFiSTAClass::beginSmartConfig() {
esp_wifi_disconnect();
esp_err_t err;
#ifdef ESP_IDF_VERSION_MAJOR
smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT();
err = esp_smartconfig_start(&conf);
#else
err = esp_smartconfig_start(reinterpret_cast<sc_callback_t>(&WiFiSTAClass::_smartConfigCallback), 1);
#endif
if (err == ESP_OK) {
_smartConfigStarted = true;
_smartConfigDone = false;
@ -734,6 +739,7 @@ const char * sc_type_strings[] = {
#endif
void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
#ifndef ESP_IDF_VERSION_MAJOR //todo
smartconfig_status_t status = (smartconfig_status_t) st;
log_d("Status: %s", sc_status_strings[st % 5]);
if (status == SC_STATUS_GETTING_SSID_PSWD) {
@ -757,4 +763,5 @@ void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
}
WiFi.stopSmartConfig();
}
#endif
}

View File

@ -49,7 +49,11 @@ WiFiClient WiFiServer::available(){
else {
struct sockaddr_in _client;
int cs = sizeof(struct sockaddr_in);
#ifdef ESP_IDF_VERSION_MAJOR
client_sock = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs);
#else
client_sock = lwip_accept_r(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs);
#endif
}
if(client_sock >= 0){
int val = 1;
@ -99,7 +103,11 @@ bool WiFiServer::hasClient() {
}
struct sockaddr_in _client;
int cs = sizeof(struct sockaddr_in);
#ifdef ESP_IDF_VERSION_MAJOR
_accepted_sockfd = lwip_accept(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs);
#else
_accepted_sockfd = lwip_accept_r(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs);
#endif
if (_accepted_sockfd >= 0) {
return true;
}
@ -107,7 +115,11 @@ bool WiFiServer::hasClient() {
}
void WiFiServer::end(){
#ifdef ESP_IDF_VERSION_MAJOR
lwip_close(sockfd);
#else
lwip_close_r(sockfd);
#endif
sockfd = -1;
_listening = false;
}