From 8c723be1359e3253329d4458c61009018a6b78fa Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 25 Jan 2020 05:44:14 +0200 Subject: [PATCH 1/7] Initial IDF-4.0 port SmartConfig and ETH need some work to adapt to the new API --- .github/scripts/install-arduino-core-esp32.sh | 4 +- .github/scripts/on-push.sh | 7 +- .gitmodules | 3 - CMakeLists.txt | 62 +---------- cores/esp32/Arduino.h | 2 + cores/esp32/Esp.cpp | 12 +- cores/esp32/MD5Builder.h | 10 ++ cores/esp32/esp32-hal-adc.c | 15 ++- cores/esp32/esp32-hal-cpu.c | 12 +- cores/esp32/esp32-hal-dac.c | 15 ++- cores/esp32/esp32-hal-gpio.c | 18 ++- cores/esp32/esp32-hal-i2c.c | 14 ++- cores/esp32/esp32-hal-ledc.c | 12 +- cores/esp32/esp32-hal-matrix.c | 10 ++ cores/esp32/esp32-hal-misc.c | 12 +- cores/esp32/esp32-hal-psram.c | 25 ++++- cores/esp32/esp32-hal-rmt.c | 1 - cores/esp32/esp32-hal-sigmadelta.c | 12 +- cores/esp32/esp32-hal-spi.c | 30 +++-- cores/esp32/esp32-hal-timer.c | 13 ++- cores/esp32/esp32-hal-touch.c | 15 ++- cores/esp32/esp32-hal-uart.c | 19 +++- cores/esp32/esp32-hal.h | 1 + libraries/AzureIoT | 1 - libraries/BLE/src/BLEAdvertisedDevice.cpp | 2 +- libraries/BLE/src/BLEDevice.cpp | 12 +- libraries/BLE/src/BLERemoteService.cpp | 4 +- libraries/BLE/src/BLERemoteService.h | 2 +- libraries/BLE/src/FreeRTOS.cpp | 7 +- libraries/BLE/src/FreeRTOS.h | 6 +- .../SerialToSerialBTM/SerialToSerialBTM.ino | 2 +- .../BluetoothSerial/src/BluetoothSerial.cpp | 14 ++- .../examples/eeprom_class/eeprom_class.ino | 4 +- .../Camera/CameraWebServer/app_httpd.cpp | 4 +- .../examples/ResetReason/ResetReason.ino | 10 +- .../HTTPClientEnterprise.ino | 3 +- libraries/SD/src/sd_diskio.cpp | 6 +- .../ETH_LAN8720_internal_clock.ino | 103 ------------------ libraries/WiFi/examples/WPS/WPS.ino | 1 - .../WiFiClientEnterprise.ino | 3 +- libraries/WiFi/src/ETH.cpp | 47 +++++++- libraries/WiFi/src/ETH.h | 15 ++- libraries/WiFi/src/WiFiClient.cpp | 8 ++ libraries/WiFi/src/WiFiSTA.cpp | 12 ++ libraries/WiFi/src/WiFiServer.cpp | 12 ++ .../WiFiClientSecureEnterprise.ino | 3 +- package/package_esp32_index.template.json | 42 +++---- platform.txt | 6 +- tools/platformio-build.py | 24 +++- 49 files changed, 414 insertions(+), 263 deletions(-) delete mode 160000 libraries/AzureIoT delete mode 100644 libraries/WiFi/examples/ETH_LAN8720_internal_clock/ETH_LAN8720_internal_clock.ino diff --git a/.github/scripts/install-arduino-core-esp32.sh b/.github/scripts/install-arduino-core-esp32.sh index cf1026d6a71..374d0401547 100755 --- a/.github/scripts/install-arduino-core-esp32.sh +++ b/.github/scripts/install-arduino-core-esp32.sh @@ -23,9 +23,9 @@ if [ ! -d "$ARDUINO_ESP32_PATH" ]; then git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1 fi - echo "Updating Submodules ..." + #echo "Updating Submodules ..." cd esp32 - git submodule update --init --recursive > /dev/null 2>&1 + #git submodule update --init --recursive > /dev/null 2>&1 echo "Installing Platform Tools ..." cd tools && python get.py diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index e0e14ec2b26..669a67b099e 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -30,8 +30,8 @@ elif [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then BUILD_PIO=1 fi -echo "Updating submodules ..." -git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1 +#echo "Updating submodules ..." +#git -C "$GITHUB_WORKSPACE" submodule update --init --recursive > /dev/null 2>&1 if [ "$BUILD_PIO" -eq 0 ]; then # ArduinoIDE Test @@ -41,14 +41,12 @@ if [ "$BUILD_PIO" -eq 0 ]; then if [ "$OS_IS_WINDOWS" == "1" ]; then build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \ build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" elif [ "$OS_IS_MACOS" == "1" ]; then build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \ build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \ build_sketch "$FQBN" "$ARDUINO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" else # CMake Test @@ -65,7 +63,6 @@ else build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino" && \ build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino" && \ build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \ - build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/AzureIoT/examples/GetStarted/GetStarted.ino" && \ build_pio_sketch "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino" #build_pio_sketches esp32dev "$PLATFORMIO_ESP32_PATH/libraries" fi diff --git a/.gitmodules b/.gitmodules index c9e5e6fd92e..e69de29bb2d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "libraries/AzureIoT"] - path = libraries/AzureIoT - url = https://github.com/VSChina/ESP32_AzureIoT_Arduino diff --git a/CMakeLists.txt b/CMakeLists.txt index cf8981f9aad..c4557b52c5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,66 +78,6 @@ set(LIBRARY_SRCS libraries/Wire/src/Wire.cpp ) -set(AZURE_SRCS - libraries/AzureIoT/src/az_iot/azureiotcerts.c - libraries/AzureIoT/src/az_iot/c-utility/pal/agenttime.c - libraries/AzureIoT/src/az_iot/c-utility/pal/dns_async.c - libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/lock.c - libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/threadapi.c - libraries/AzureIoT/src/az_iot/c-utility/pal/freertos/tickcounter.c - libraries/AzureIoT/src/az_iot/c-utility/pal/lwip/sntp_lwip.c - libraries/AzureIoT/src/az_iot/c-utility/pal/socket_async.c - libraries/AzureIoT/src/az_iot/c-utility/pal/src/platform_openssl_compact.c - libraries/AzureIoT/src/az_iot/c-utility/pal/src/tlsio_openssl_compact.c - libraries/AzureIoT/src/az_iot/c-utility/pal/tlsio_options.c - libraries/AzureIoT/src/az_iot/c-utility/src/base64.c - libraries/AzureIoT/src/az_iot/c-utility/src/buffer.c - libraries/AzureIoT/src/az_iot/c-utility/src/connection_string_parser.c - libraries/AzureIoT/src/az_iot/c-utility/src/consolelogger.c - libraries/AzureIoT/src/az_iot/c-utility/src/constbuffer.c - libraries/AzureIoT/src/az_iot/c-utility/src/constmap.c - libraries/AzureIoT/src/az_iot/c-utility/src/crt_abstractions.c - libraries/AzureIoT/src/az_iot/c-utility/src/doublylinkedlist.c - libraries/AzureIoT/src/az_iot/c-utility/src/gballoc.c - libraries/AzureIoT/src/az_iot/c-utility/src/gb_stdio.c - libraries/AzureIoT/src/az_iot/c-utility/src/gb_time.c - libraries/AzureIoT/src/az_iot/c-utility/src/hmac.c - libraries/AzureIoT/src/az_iot/c-utility/src/hmacsha256.c - libraries/AzureIoT/src/az_iot/c-utility/src/httpapiex.c - libraries/AzureIoT/src/az_iot/c-utility/src/httpapiexsas.c - libraries/AzureIoT/src/az_iot/c-utility/src/httpheaders.c - libraries/AzureIoT/src/az_iot/c-utility/src/http_proxy_io.c - libraries/AzureIoT/src/az_iot/c-utility/src/map.c - libraries/AzureIoT/src/az_iot/c-utility/src/optionhandler.c - libraries/AzureIoT/src/az_iot/c-utility/src/sastoken.c - libraries/AzureIoT/src/az_iot/c-utility/src/sha1.c - libraries/AzureIoT/src/az_iot/c-utility/src/sha224.c - libraries/AzureIoT/src/az_iot/c-utility/src/sha384-512.c - libraries/AzureIoT/src/az_iot/c-utility/src/singlylinkedlist.c - libraries/AzureIoT/src/az_iot/c-utility/src/strings.c - libraries/AzureIoT/src/az_iot/c-utility/src/string_tokenizer.c - libraries/AzureIoT/src/az_iot/c-utility/src/urlencode.c - libraries/AzureIoT/src/az_iot/c-utility/src/usha.c - libraries/AzureIoT/src/az_iot/c-utility/src/vector.c - libraries/AzureIoT/src/az_iot/c-utility/src/xio.c - libraries/AzureIoT/src/az_iot/c-utility/src/xlogging.c - libraries/AzureIoT/src/az_iot/iothub_client/src/blob.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_authorization.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_ll.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_client_retry_control.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothub_message.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransportmqtt.c - libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport_mqtt_common.c - libraries/AzureIoT/src/az_iot/iothub_client/src/version.c - libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_client.c - libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_codec.c - libraries/AzureIoT/src/az_iot/umqtt/src/mqtt_message.c - libraries/AzureIoT/src/AzureIotHub.cpp - libraries/AzureIoT/src/Esp32MQTTClient.cpp - ) - set(BLE_SRCS libraries/BLE/src/BLE2902.cpp libraries/BLE/src/BLE2904.cpp @@ -170,7 +110,7 @@ set(BLE_SRCS libraries/BLE/src/GeneralUtils.cpp ) -set(COMPONENT_SRCS ${CORE_SRCS} ${LIBRARY_SRCS} ${AZURE_SRCS} ${BLE_SRCS}) +set(COMPONENT_SRCS ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS}) set(COMPONENT_ADD_INCLUDEDIRS variants/esp32/ diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index 645b407034f..079510efe37 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -118,7 +118,9 @@ typedef unsigned int word; void setup(void); void loop(void); +#ifdef __cplusplus long random(long, long); +#endif void randomSeed(unsigned long); long map(long, long, long, long, long); diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index 54451127ef3..c77e0a542c9 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -19,7 +19,6 @@ #include "Arduino.h" #include "Esp.h" -#include "rom/spi_flash.h" #include "esp_sleep.h" #include "esp_spi_flash.h" #include @@ -32,6 +31,17 @@ extern "C" { } #include +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/spi_flash.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/spi_flash.h" +#endif + /** * User-defined Literals * usage: diff --git a/cores/esp32/MD5Builder.h b/cores/esp32/MD5Builder.h index 5429d9aea60..db244743ba5 100644 --- a/cores/esp32/MD5Builder.h +++ b/cores/esp32/MD5Builder.h @@ -21,7 +21,17 @@ #include #include + +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/md5_hash.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 #include "rom/md5_hash.h" +#endif class MD5Builder { diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index ab9e7622c3a..71a68697628 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -15,9 +15,7 @@ #include "esp32-hal-adc.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "rom/ets_sys.h" #include "esp_attr.h" -#include "esp_intr.h" #include "soc/rtc_io_reg.h" #include "soc/rtc_cntl_reg.h" #include "soc/sens_reg.h" @@ -25,6 +23,19 @@ #include "driver/adc.h" #include "esp_adc_cal.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp_intr_alloc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#include "esp_intr.h" +#endif + #define DEFAULT_VREF 1100 static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL}; static uint8_t __analogAttenuation = 3;//11db diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index db002858827..6b1302d6d11 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -21,12 +21,22 @@ #include "esp_log.h" #include "soc/rtc.h" #include "soc/rtc_cntl_reg.h" -#include "rom/rtc.h" #include "soc/apb_ctrl_reg.h" #include "soc/efuse_reg.h" #include "esp32-hal.h" #include "esp32-hal-cpu.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/rtc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/rtc.h" +#endif + typedef struct apb_change_cb_s { struct apb_change_cb_s * prev; struct apb_change_cb_s * next; diff --git a/cores/esp32/esp32-hal-dac.c b/cores/esp32/esp32-hal-dac.c index e407c221116..5901b271c52 100644 --- a/cores/esp32/esp32-hal-dac.c +++ b/cores/esp32/esp32-hal-dac.c @@ -15,13 +15,24 @@ #include "esp32-hal-dac.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "rom/ets_sys.h" #include "esp_attr.h" -#include "esp_intr.h" #include "soc/rtc_io_reg.h" #include "soc/rtc_cntl_reg.h" #include "soc/sens_reg.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp_intr_alloc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#include "esp_intr.h" +#endif + void IRAM_ATTR __dacWrite(uint8_t pin, uint8_t value) { if(pin < 25 || pin > 26){ diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 4da7272c597..ca8d06340f5 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -15,15 +15,27 @@ #include "esp32-hal-gpio.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "rom/ets_sys.h" #include "esp_attr.h" -#include "esp_intr.h" -#include "rom/gpio.h" #include "soc/gpio_reg.h" #include "soc/io_mux_reg.h" #include "soc/gpio_struct.h" #include "soc/rtc_io_reg.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp32/rom/gpio.h" +#include "esp_intr_alloc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#include "rom/gpio.h" +#include "esp_intr.h" +#endif + const int8_t esp32_adc2gpio[20] = {36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26}; const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={ diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index d85919cfdb3..99f367a4630 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -18,13 +18,25 @@ #include "freertos/task.h" #include "freertos/semphr.h" #include "freertos/event_groups.h" -#include "rom/ets_sys.h" #include "driver/periph_ctrl.h" #include "soc/i2c_reg.h" #include "soc/i2c_struct.h" #include "soc/dport_reg.h" #include "esp_attr.h" #include "esp32-hal-cpu.h" // cpu clock change support 31DEC2018 + +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#endif + + //#define I2C_DEV(i) (volatile i2c_dev_t *)((i)?DR_REG_I2C1_EXT_BASE:DR_REG_I2C_EXT_BASE) //#define I2C_DEV(i) ((i2c_dev_t *)(REG_I2C_BASE(i))) #define I2C_SCL_IDX(p) ((p==0)?I2CEXT0_SCL_OUT_IDX:((p==1)?I2CEXT1_SCL_OUT_IDX:0)) diff --git a/cores/esp32/esp32-hal-ledc.c b/cores/esp32/esp32-hal-ledc.c index 24bbf329404..42f5b8152fa 100644 --- a/cores/esp32/esp32-hal-ledc.c +++ b/cores/esp32/esp32-hal-ledc.c @@ -16,12 +16,22 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" -#include "rom/ets_sys.h" #include "esp32-hal-matrix.h" #include "soc/dport_reg.h" #include "soc/ledc_reg.h" #include "soc/ledc_struct.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#endif + #if CONFIG_DISABLE_HAL_LOCKS #define LEDC_MUTEX_LOCK() #define LEDC_MUTEX_UNLOCK() diff --git a/cores/esp32/esp32-hal-matrix.c b/cores/esp32/esp32-hal-matrix.c index fb1b498c4c8..02d59ed029d 100644 --- a/cores/esp32/esp32-hal-matrix.c +++ b/cores/esp32/esp32-hal-matrix.c @@ -14,7 +14,17 @@ #include "esp32-hal-matrix.h" #include "esp_attr.h" + +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/gpio.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 #include "rom/gpio.h" +#endif #define MATRIX_DETACH_OUT_SIG 0x100 #define MATRIX_DETACH_IN_LOW_PIN 0x30 diff --git a/cores/esp32/esp32-hal-misc.c b/cores/esp32/esp32-hal-misc.c index be08e4b7313..7b4f980168a 100644 --- a/cores/esp32/esp32-hal-misc.c +++ b/cores/esp32/esp32-hal-misc.c @@ -31,10 +31,20 @@ #include "soc/rtc.h" #include "soc/rtc_cntl_reg.h" #include "soc/apb_ctrl_reg.h" -#include "rom/rtc.h" #include "esp_task_wdt.h" #include "esp32-hal.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/rtc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/rtc.h" +#endif + //Undocumented!!! Get chip temperature in Farenheit //Source: https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_int_temp_sensor/ESP32_int_temp_sensor.ino uint8_t temprature_sens_read(); diff --git a/cores/esp32/esp32-hal-psram.c b/cores/esp32/esp32-hal-psram.c index 905cb96a313..51fadfbacbf 100644 --- a/cores/esp32/esp32-hal-psram.c +++ b/cores/esp32/esp32-hal-psram.c @@ -1,11 +1,34 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "esp32-hal.h" #if CONFIG_SPIRAM_SUPPORT -#include "esp_spiram.h" #include "soc/efuse_reg.h" #include "esp_heap_caps.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/spiram.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "esp_spiram.h" +#endif + static volatile bool spiramDetected = false; static volatile bool spiramFailed = false; diff --git a/cores/esp32/esp32-hal-rmt.c b/cores/esp32/esp32-hal-rmt.c index 2a36a5e742e..46f9ec07fac 100644 --- a/cores/esp32/esp32-hal-rmt.c +++ b/cores/esp32/esp32-hal-rmt.c @@ -240,7 +240,6 @@ bool rmtLoop(rmt_obj_t* rmt, rmt_data_t* data, size_t size) return false; } - int channel = rmt->channel; int allocated_size = MAX_DATA_PER_CHANNEL * rmt->buffers; if (size > allocated_size) { diff --git a/cores/esp32/esp32-hal-sigmadelta.c b/cores/esp32/esp32-hal-sigmadelta.c index 098181c77ae..8d1d8a815f2 100644 --- a/cores/esp32/esp32-hal-sigmadelta.c +++ b/cores/esp32/esp32-hal-sigmadelta.c @@ -16,11 +16,21 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" -#include "rom/ets_sys.h" #include "esp32-hal-matrix.h" #include "soc/gpio_sd_reg.h" #include "soc/gpio_sd_struct.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#endif + #if CONFIG_DISABLE_HAL_LOCKS #define SD_MUTEX_LOCK() diff --git a/cores/esp32/esp32-hal-spi.c b/cores/esp32/esp32-hal-spi.c index cf302cac88f..59b33ec5578 100644 --- a/cores/esp32/esp32-hal-spi.c +++ b/cores/esp32/esp32-hal-spi.c @@ -17,10 +17,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" -#include "rom/ets_sys.h" #include "esp_attr.h" -#include "esp_intr.h" -#include "rom/gpio.h" #include "soc/spi_reg.h" #include "soc/spi_struct.h" #include "soc/io_mux_reg.h" @@ -28,6 +25,21 @@ #include "soc/dport_reg.h" #include "soc/rtc.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp32/rom/gpio.h" +#include "esp_intr_alloc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#include "rom/gpio.h" +#include "esp_intr.h" +#endif + #define SPI_CLK_IDX(p) ((p==0)?SPICLK_OUT_IDX:((p==1)?SPICLK_OUT_IDX:((p==2)?HSPICLK_OUT_IDX:((p==3)?VSPICLK_OUT_IDX:0)))) #define SPI_MISO_IDX(p) ((p==0)?SPIQ_OUT_IDX:((p==1)?SPIQ_OUT_IDX:((p==2)?HSPIQ_OUT_IDX:((p==3)?VSPIQ_OUT_IDX:0)))) #define SPI_MOSI_IDX(p) ((p==0)?SPID_IN_IDX:((p==1)?SPID_IN_IDX:((p==2)?HSPID_IN_IDX:((p==3)?VSPID_IN_IDX:0)))) @@ -421,14 +433,14 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_ #endif if(spi_num == HSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST); + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST); } else if(spi_num == VSPI) { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_2); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_2); + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI3_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI3_RST); } else { - DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI_CLK_EN_1); - DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_1); + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI01_CLK_EN); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI01_RST); } spiStopBus(spi); diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index ed804d4e348..0a59bcfbd43 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -16,11 +16,22 @@ #include "freertos/FreeRTOS.h" #include "freertos/xtensa_api.h" #include "freertos/task.h" -#include "rom/ets_sys.h" #include "soc/timer_group_struct.h" #include "soc/dport_reg.h" #include "esp_attr.h" + +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp_intr_alloc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" #include "esp_intr.h" +#endif #define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock) #define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock) diff --git a/cores/esp32/esp32-hal-touch.c b/cores/esp32/esp32-hal-touch.c index 94e8a8b8ac3..404de5846f3 100644 --- a/cores/esp32/esp32-hal-touch.c +++ b/cores/esp32/esp32-hal-touch.c @@ -15,13 +15,24 @@ #include "esp32-hal-touch.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "rom/ets_sys.h" #include "esp_attr.h" -#include "esp_intr.h" #include "soc/rtc_io_reg.h" #include "soc/rtc_cntl_reg.h" #include "soc/sens_reg.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp_intr_alloc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#include "esp_intr.h" +#endif + static uint16_t __touchSleepCycles = 0x1000; static uint16_t __touchMeasureCycles = 0x1000; diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 90acf54f2b1..10f95e1efa6 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -18,10 +18,7 @@ #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/semphr.h" -#include "rom/ets_sys.h" #include "esp_attr.h" -#include "esp_intr.h" -#include "rom/uart.h" #include "soc/uart_reg.h" #include "soc/uart_struct.h" #include "soc/io_mux_reg.h" @@ -30,6 +27,20 @@ #include "soc/rtc.h" #include "esp_intr_alloc.h" +#include "esp_system.h" +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/ets_sys.h" +#include "esp32/rom/uart.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/ets_sys.h" +#include "rom/uart.h" +#include "esp_intr.h" +#endif + #define UART_REG_BASE(u) ((u==0)?DR_REG_UART_BASE:( (u==1)?DR_REG_UART1_BASE:( (u==2)?DR_REG_UART2_BASE:0))) #define UART_RXD_IDX(u) ((u==0)?U0RXD_IN_IDX:( (u==1)?U1RXD_IN_IDX:( (u==2)?U2RXD_IN_IDX:0))) #define UART_TXD_IDX(u) ((u==0)?U0TXD_OUT_IDX:( (u==1)?U1TXD_OUT_IDX:( (u==2)?U2TXD_OUT_IDX:0))) @@ -252,7 +263,7 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) { vQueueDelete(uart->queue); uart->queue = xQueueCreate(new_size, sizeof(uint8_t)); if(uart->queue == NULL) { - return NULL; + return 0; } } UART_MUTEX_UNLOCK(); diff --git a/cores/esp32/esp32-hal.h b/cores/esp32/esp32-hal.h index 4b5fb2c2ebb..576b4fb7053 100644 --- a/cores/esp32/esp32-hal.h +++ b/cores/esp32/esp32-hal.h @@ -34,6 +34,7 @@ extern "C" { #include #include "sdkconfig.h" #include "esp_system.h" +#include "esp_sleep.h" #ifndef F_CPU #define F_CPU (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000U) diff --git a/libraries/AzureIoT b/libraries/AzureIoT deleted file mode 160000 index 67dfa4f31ef..00000000000 --- a/libraries/AzureIoT +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 67dfa4f31ef88b0938dd87d955612100dea5562e diff --git a/libraries/BLE/src/BLEAdvertisedDevice.cpp b/libraries/BLE/src/BLEAdvertisedDevice.cpp index f27ba6f6c7c..8aa74491d87 100644 --- a/libraries/BLE/src/BLEAdvertisedDevice.cpp +++ b/libraries/BLE/src/BLEAdvertisedDevice.cpp @@ -538,7 +538,7 @@ std::string BLEAdvertisedDevice::toString() { } } if (haveTXPower()) { - char val[4]; + char val[6]; snprintf(val, sizeof(val), "%d", getTXPower()); res += ", txPower: "; res += val; diff --git a/libraries/BLE/src/BLEDevice.cpp b/libraries/BLE/src/BLEDevice.cpp index 128ede98d84..29f59854e75 100644 --- a/libraries/BLE/src/BLEDevice.cpp +++ b/libraries/BLE/src/BLEDevice.cpp @@ -499,7 +499,11 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr; */ void BLEDevice::whiteListAdd(BLEAddress address) { log_v(">> whiteListAdd: %s", address.toString().c_str()); - esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry. +#ifdef ESP_IDF_VERSION_MAJOR + esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! True to add an entry. +#else + esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry. +#endif if (errRc != ESP_OK) { log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } @@ -513,7 +517,11 @@ void BLEDevice::whiteListAdd(BLEAddress address) { */ void BLEDevice::whiteListRemove(BLEAddress address) { log_v(">> whiteListRemove: %s", address.toString().c_str()); - esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry. +#ifdef ESP_IDF_VERSION_MAJOR + esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative(), BLE_WL_ADDR_TYPE_PUBLIC); // HACK!!! False to remove an entry. +#else + esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry. +#endif if (errRc != ESP_OK) { log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); } diff --git a/libraries/BLE/src/BLERemoteService.cpp b/libraries/BLE/src/BLERemoteService.cpp index 278e9c1cab4..e9d1c58f848 100644 --- a/libraries/BLE/src/BLERemoteService.cpp +++ b/libraries/BLE/src/BLERemoteService.cpp @@ -243,8 +243,8 @@ std::map* BLERemoteService::getCharacteristi /** * @brief This function is designed to get characteristics map when we have multiple characteristics with the same UUID */ -void BLERemoteService::getCharacteristics(std::map* pCharacteristicMap) { - pCharacteristicMap = &m_characteristicMapByHandle; +void BLERemoteService::getCharacteristics(std::map** pCharacteristicMap) { + *pCharacteristicMap = &m_characteristicMapByHandle; } // Get the characteristics map. /** diff --git a/libraries/BLE/src/BLERemoteService.h b/libraries/BLE/src/BLERemoteService.h index 2ab86738452..1ad6b1134ea 100644 --- a/libraries/BLE/src/BLERemoteService.h +++ b/libraries/BLE/src/BLERemoteService.h @@ -34,7 +34,7 @@ class BLERemoteService { BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference. std::map* getCharacteristics(); std::map* getCharacteristicsByHandle(); // Get the characteristics map. - void getCharacteristics(std::map* pCharacteristicMap); + void getCharacteristics(std::map** pCharacteristicMap); BLEClient* getClient(void); // Get a reference to the client associated with this service. uint16_t getHandle(); // Get the handle of this service. diff --git a/libraries/BLE/src/FreeRTOS.cpp b/libraries/BLE/src/FreeRTOS.cpp index 2f52b99d389..3f79c9d22d0 100644 --- a/libraries/BLE/src/FreeRTOS.cpp +++ b/libraries/BLE/src/FreeRTOS.cpp @@ -257,7 +257,12 @@ void FreeRTOS::Semaphore::setName(std::string name) { * @param [in] length The amount of storage to allocate for the ring buffer. * @param [in] type The type of buffer. One of RINGBUF_TYPE_NOSPLIT, RINGBUF_TYPE_ALLOWSPLIT, RINGBUF_TYPE_BYTEBUF. */ -Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) { +#ifdef ESP_IDF_VERSION_MAJOR +Ringbuffer::Ringbuffer(size_t length, RingbufferType_t type) +#else +Ringbuffer::Ringbuffer(size_t length, ringbuf_type_t type) +#endif +{ m_handle = ::xRingbufferCreate(length, type); } // Ringbuffer diff --git a/libraries/BLE/src/FreeRTOS.h b/libraries/BLE/src/FreeRTOS.h index 4d089c81db6..0c093925daf 100644 --- a/libraries/BLE/src/FreeRTOS.h +++ b/libraries/BLE/src/FreeRTOS.h @@ -60,7 +60,11 @@ class FreeRTOS { */ class Ringbuffer { public: - Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT); +#ifdef ESP_IDF_VERSION_MAJOR + Ringbuffer(size_t length, RingbufferType_t type = RINGBUF_TYPE_NOSPLIT); +#else + Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT); +#endif ~Ringbuffer(); void* receive(size_t* size, TickType_t wait = portMAX_DELAY); diff --git a/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino b/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino index 73f3dc058b4..3d17fb9005a 100644 --- a/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino +++ b/libraries/BluetoothSerial/examples/SerialToSerialBTM/SerialToSerialBTM.ino @@ -14,7 +14,7 @@ String MACadd = "AA:BB:CC:11:22:33"; uint8_t address[6] = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33}; //uint8_t address[6] = {0x00, 0x1D, 0xA5, 0x02, 0xC3, 0x22}; String name = "OBDII"; -char *pin = "1234"; //<- standard pin would be provided by default +const char *pin = "1234"; //<- standard pin would be provided by default bool connected; void setup() { diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.cpp b/libraries/BluetoothSerial/src/BluetoothSerial.cpp index a52e48d8615..f4167d4053e 100755 --- a/libraries/BluetoothSerial/src/BluetoothSerial.cpp +++ b/libraries/BluetoothSerial/src/BluetoothSerial.cpp @@ -223,7 +223,11 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { case ESP_SPP_INIT_EVT: log_i("ESP_SPP_INIT_EVT"); +#ifdef ESP_IDF_VERSION_MAJOR + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); +#else esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); +#endif if (!_isMaster) { log_i("ESP_SPP_INIT_EVT: slave: start"); esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name); @@ -717,7 +721,11 @@ bool BluetoothSerial::connect(String remoteName) _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0; log_i("master : remoteName"); // will first resolve name to address - esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); +#ifdef ESP_IDF_VERSION_MAJOR + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); +#else + esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); +#endif if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { return waitForConnect(SCAN_TIMEOUT); } @@ -757,7 +765,11 @@ bool BluetoothSerial::connect() disconnect(); log_i("master : remoteName"); // will resolve name to address first - it may take a while +#ifdef ESP_IDF_VERSION_MAJOR + esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); +#else esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); +#endif if (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK) { return waitForConnect(SCAN_TIMEOUT); } diff --git a/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino b/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino index f5301f4ef1d..8be574abd43 100644 --- a/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino +++ b/libraries/EEPROM/examples/eeprom_class/eeprom_class.ino @@ -52,10 +52,10 @@ void setup() { Serial.println("------------------------------------\n"); // Clear variables - name = '\0'; + rname[0] = '\0'; height = 0; age = 0; - Serial.print("name: "); Serial.println(name); + Serial.print("name: "); Serial.println(rname); Serial.print("height: "); Serial.println(height); Serial.print("age: "); Serial.println(age); Serial.println("------------------------------------\n"); diff --git a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp index 07d29ee7175..9c4f11c9d8e 100644 --- a/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp +++ b/libraries/ESP32/examples/Camera/CameraWebServer/app_httpd.cpp @@ -56,11 +56,11 @@ static ra_filter_t ra_filter; httpd_handle_t stream_httpd = NULL; httpd_handle_t camera_httpd = NULL; -static mtmn_config_t mtmn_config = {0}; +static mtmn_config_t mtmn_config; static int8_t detection_enabled = 0; static int8_t recognition_enabled = 0; static int8_t is_enrolling = 0; -static face_id_list id_list = {0}; +static face_id_list id_list; static ra_filter_t * ra_filter_init(ra_filter_t * filter, size_t sample_size){ memset(filter, 0, sizeof(ra_filter_t)); diff --git a/libraries/ESP32/examples/ResetReason/ResetReason.ino b/libraries/ESP32/examples/ResetReason/ResetReason.ino index 3fc457d1f4a..9232b1105f4 100644 --- a/libraries/ESP32/examples/ResetReason/ResetReason.ino +++ b/libraries/ESP32/examples/ResetReason/ResetReason.ino @@ -12,7 +12,15 @@ * Evandro Luis Copercini - 2017 */ -#include +#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 +#include "esp32/rom/rtc.h" +#else +#error Target CONFIG_IDF_TARGET is not supported +#endif +#else // ESP32 Before IDF 4.0 +#include "rom/rtc.h" +#endif #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ diff --git a/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino b/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino index b28501bb3ea..b229a8687bb 100644 --- a/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino +++ b/libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino @@ -45,8 +45,7 @@ void setup() { esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password - esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default - esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function + esp_wifi_sta_wpa2_ent_enable(); WiFi.begin(ssid); //connect to wifi while (WiFi.status() != WL_CONNECTED) { delay(500); diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index 0a9c86cc5f0..1d1922be465 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -12,10 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "sd_diskio.h" +#include "esp_system.h" extern "C" { - #include "diskio.h" #include "ffconf.h" #include "ff.h" + #include "diskio.h" +#ifdef ESP_IDF_VERSION_MAJOR + #include "diskio_impl.h" +#endif //#include "esp_vfs.h" #include "esp_vfs_fat.h" char CRC7(const char* data, int length); diff --git a/libraries/WiFi/examples/ETH_LAN8720_internal_clock/ETH_LAN8720_internal_clock.ino b/libraries/WiFi/examples/ETH_LAN8720_internal_clock/ETH_LAN8720_internal_clock.ino deleted file mode 100644 index 6e726b7080e..00000000000 --- a/libraries/WiFi/examples/ETH_LAN8720_internal_clock/ETH_LAN8720_internal_clock.ino +++ /dev/null @@ -1,103 +0,0 @@ -/* - This sketch shows how to configure different external or internal clock sources for the Ethernet PHY -*/ - -#include - -/* - * ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator - * ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720 - * ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720 - * ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720 -*/ -#ifdef ETH_CLK_MODE -#undef ETH_CLK_MODE -#endif -#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT - -// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source) -#define ETH_POWER_PIN -1 - -// Type of the Ethernet PHY (LAN8720 or TLK110) -#define ETH_TYPE ETH_PHY_LAN8720 - -// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) -#define ETH_ADDR 0 - -// Pin# of the I²C clock signal for the Ethernet PHY -#define ETH_MDC_PIN 15 - -// Pin# of the I²C IO signal for the Ethernet PHY -#define ETH_MDIO_PIN 2 - - -static bool eth_connected = false; - -void WiFiEvent(WiFiEvent_t event) { - switch (event) { - case SYSTEM_EVENT_ETH_START: - Serial.println("ETH Started"); - //set eth hostname here - ETH.setHostname("esp32-ethernet"); - break; - case SYSTEM_EVENT_ETH_CONNECTED: - Serial.println("ETH Connected"); - break; - case SYSTEM_EVENT_ETH_GOT_IP: - Serial.print("ETH MAC: "); - Serial.print(ETH.macAddress()); - Serial.print(", IPv4: "); - Serial.print(ETH.localIP()); - if (ETH.fullDuplex()) { - Serial.print(", FULL_DUPLEX"); - } - Serial.print(", "); - Serial.print(ETH.linkSpeed()); - Serial.println("Mbps"); - eth_connected = true; - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - Serial.println("ETH Disconnected"); - eth_connected = false; - break; - case SYSTEM_EVENT_ETH_STOP: - Serial.println("ETH Stopped"); - eth_connected = false; - break; - default: - break; - } -} - -void testClient(const char * host, uint16_t port) { - Serial.print("\nconnecting to "); - Serial.println(host); - - WiFiClient client; - if (!client.connect(host, port)) { - Serial.println("connection failed"); - return; - } - client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); - while (client.connected() && !client.available()); - while (client.available()) { - Serial.write(client.read()); - } - - Serial.println("closing connection\n"); - client.stop(); -} - -void setup() { - Serial.begin(115200); - WiFi.onEvent(WiFiEvent); - ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); -} - - -void loop() { - if (eth_connected) { - testClient("google.com", 80); - } - delay(10000); -} diff --git a/libraries/WiFi/examples/WPS/WPS.ino b/libraries/WiFi/examples/WPS/WPS.ino index 06ccbb38438..e57df0fdc0b 100644 --- a/libraries/WiFi/examples/WPS/WPS.ino +++ b/libraries/WiFi/examples/WPS/WPS.ino @@ -31,7 +31,6 @@ WPS static esp_wps_config_t config; void wpsInitConfig(){ - config.crypto_funcs = &g_wifi_default_wps_crypto_funcs; config.wps_type = ESP_WPS_MODE; strcpy(config.factory_info.manufacturer, ESP_MANUFACTURER); strcpy(config.factory_info.model_number, ESP_MODEL_NUMBER); diff --git a/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino b/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino index 0c861cddcf0..d7a2d0ad3cf 100644 --- a/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino +++ b/libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino @@ -16,8 +16,7 @@ void setup() { esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password - esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default - esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function + esp_wifi_sta_wpa2_ent_enable(); WiFi.begin(ssid); //connect to wifi while (WiFi.status() != WL_CONNECTED) { delay(500); diff --git a/libraries/WiFi/src/ETH.cpp b/libraries/WiFi/src/ETH.cpp index 2ffea758ded..8b0dcb29809 100644 --- a/libraries/WiFi/src/ETH.cpp +++ b/libraries/WiFi/src/ETH.cpp @@ -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) { @@ -193,8 +207,13 @@ IPAddress ETHClass::gatewayIP() IPAddress ETHClass::dnsIP(uint8_t dns_no) { +#ifdef ESP_IDF_VERSION_MAJOR + const ip_addr_t * dns_ip = dns_getserver(dns_no); + return IPAddress(dns_ip->u_addr.ip4.addr); +#else ip_addr_t dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip.u_addr.ip4.addr); +#endif } IPAddress ETHClass::broadcastIP() @@ -240,17 +259,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 +303,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); } diff --git a/libraries/WiFi/src/ETH.h b/libraries/WiFi/src/ETH.h index f5441a9d0ed..af918772b8c 100644 --- a/libraries/WiFi/src/ETH.h +++ b/libraries/WiFi/src/ETH.h @@ -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(); diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index e422b63673d..5cebcdd9e36 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -46,7 +46,11 @@ class WiFiClientRxBuffer { 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); diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index db5e019af31..d8561c35abb 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -488,8 +488,13 @@ IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no) if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){ return IPAddress(); } +#ifdef ESP_IDF_VERSION_MAJOR + const ip_addr_t * dns_ip = dns_getserver(dns_no); + return IPAddress(dns_ip->u_addr.ip4.addr); +#else ip_addr_t dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip.u_addr.ip4.addr); +#endif } /** @@ -687,7 +692,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(&WiFiSTAClass::_smartConfigCallback), 1); +#endif if (err == ESP_OK) { _smartConfigStarted = true; _smartConfigDone = false; @@ -734,6 +744,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 +768,5 @@ void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) { } WiFi.stopSmartConfig(); } +#endif } diff --git a/libraries/WiFi/src/WiFiServer.cpp b/libraries/WiFi/src/WiFiServer.cpp index 75c2872bb78..b91bff96e86 100644 --- a/libraries/WiFi/src/WiFiServer.cpp +++ b/libraries/WiFi/src/WiFiServer.cpp @@ -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; } diff --git a/libraries/WiFiClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino b/libraries/WiFiClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino index d4e389c2440..63a3d84e476 100644 --- a/libraries/WiFiClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino +++ b/libraries/WiFiClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino @@ -61,8 +61,7 @@ void setup() { esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password - esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); - esp_wifi_sta_wpa2_ent_enable(&config); + esp_wifi_sta_wpa2_ent_enable(); WiFi.begin(ssid); //connect to wifi while (WiFi.status() != WL_CONNECTED) { delay(500); diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 2e6533eda9d..92795318f19 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -54,42 +54,42 @@ "tools": [ { "name": "xtensa-esp32-elf-gcc", - "version": "1.22.0-80-g6c4433a-5.2.0", + "version": "gcc8_2_0-esp-2019r2", "systems": [ { "host": "i686-mingw32", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip", - "archiveFileName": "xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip", - "checksum": "SHA-256:f217fccbeaaa8c92db239036e0d6202458de4488b954a3a38f35ac2ec48058a4", - "size": "125719261" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip", + "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip", + "checksum": "SHA-256:c9d5776a22516f0825a7c68d835ffacc2392f913136893b7646e1288937cc65e", + "size": "103850448" }, { "host": "x86_64-apple-darwin", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz", - "checksum": "SHA-256:a4307a97945d2f2f2745f415fbe80d727750e19f91f9a1e7e2f8a6065652f9da", - "size": "46517409" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-macos.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-macos.tar.gz", + "checksum": "SHA-256:dc62be8dd16c6d9d28d64e2b3f831fa208f3548c2ca73cdbcbdf68f474d59521", + "size": "92150978" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz", - "checksum": "SHA-256:3fe96c151d46c1d4e5edc6ed690851b8e53634041114bad04729bc16b0445156", - "size": "44219107" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz", + "checksum": "SHA-256:e6d47c1dbd8c8cbfe37271e5e2aac53ee88c9e347ae937e22bf0c73f530efbdf", + "size": "85459985" }, { "host": "i686-pc-linux-gnu", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz", - "checksum": "SHA-256:b4055695ffc2dfc0bcb6dafdc2572a6e01151c4179ef5fa972b3fcb2183eb155", - "size": "45566336" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-i686.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-i686.tar.gz", + "checksum": "SHA-256:36a9648c414dbd1c518c687ce5587d9f8eaa94324f45d92e9ec31a1433a04df8", + "size": "87438500" }, { "host": "arm-linux-gnueabihf", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux-armel-1.22.0-87-gb57bad3-5.2.0.tar.gz", - "archiveFileName": "xtensa-esp32-elf-linux-armel-1.22.0-87-gb57bad3-5.2.0.tar.gz", - "checksum": "SHA-256:9c68c87bb23b1256dc0a1859b515946763e5292dcab4a4159a52fae5618ce861", - "size": "50655584" + "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-armel.tar.gz", + "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-armel.tar.gz", + "checksum": "SHA-256:54a199c28f591da2466b21741911bc2ba77ddf82d3d2b66c6ce03c1a0c6835f0", + "size": "83647538" } ] }, diff --git a/platform.txt b/platform.txt index 6583ee771e7..b905a4eba7d 100644 --- a/platform.txt +++ b/platform.txt @@ -25,16 +25,16 @@ compiler.sdk.path={runtime.platform.path}/tools/sdk compiler.cpreprocessor.flags=-DESP_PLATFORM -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DHAVE_CONFIG_H -DGCC_NOT_5_2_0=0 -DWITH_POSIX "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/app_trace" "-I{compiler.sdk.path}/include/app_update" "-I{compiler.sdk.path}/include/asio" "-I{compiler.sdk.path}/include/bootloader_support" "-I{compiler.sdk.path}/include/bt" "-I{compiler.sdk.path}/include/coap" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/driver" "-I{compiler.sdk.path}/include/efuse" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp32" "-I{compiler.sdk.path}/include/esp_adc_cal" "-I{compiler.sdk.path}/include/esp_event" "-I{compiler.sdk.path}/include/esp_http_client" "-I{compiler.sdk.path}/include/esp_http_server" "-I{compiler.sdk.path}/include/esp_https_ota" "-I{compiler.sdk.path}/include/esp_https_server" "-I{compiler.sdk.path}/include/esp_ringbuf" "-I{compiler.sdk.path}/include/espcoredump" "-I{compiler.sdk.path}/include/ethernet" "-I{compiler.sdk.path}/include/expat" "-I{compiler.sdk.path}/include/fatfs" "-I{compiler.sdk.path}/include/freemodbus" "-I{compiler.sdk.path}/include/freertos" "-I{compiler.sdk.path}/include/heap" "-I{compiler.sdk.path}/include/idf_test" "-I{compiler.sdk.path}/include/jsmn" "-I{compiler.sdk.path}/include/json" "-I{compiler.sdk.path}/include/libsodium" "-I{compiler.sdk.path}/include/log" "-I{compiler.sdk.path}/include/lwip" "-I{compiler.sdk.path}/include/mbedtls" "-I{compiler.sdk.path}/include/mdns" "-I{compiler.sdk.path}/include/micro-ecc" "-I{compiler.sdk.path}/include/mqtt" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/nghttp" "-I{compiler.sdk.path}/include/nimble" "-I{compiler.sdk.path}/include/nvs_flash" "-I{compiler.sdk.path}/include/openssl" "-I{compiler.sdk.path}/include/protobuf-c" "-I{compiler.sdk.path}/include/protocomm" "-I{compiler.sdk.path}/include/pthread" "-I{compiler.sdk.path}/include/sdmmc" "-I{compiler.sdk.path}/include/smartconfig_ack" "-I{compiler.sdk.path}/include/soc" "-I{compiler.sdk.path}/include/spi_flash" "-I{compiler.sdk.path}/include/spiffs" "-I{compiler.sdk.path}/include/tcp_transport" "-I{compiler.sdk.path}/include/tcpip_adapter" "-I{compiler.sdk.path}/include/ulp" "-I{compiler.sdk.path}/include/unity" "-I{compiler.sdk.path}/include/vfs" "-I{compiler.sdk.path}/include/wear_levelling" "-I{compiler.sdk.path}/include/wifi_provisioning" "-I{compiler.sdk.path}/include/wpa_supplicant" "-I{compiler.sdk.path}/include/xtensa-debug-module" "-I{compiler.sdk.path}/include/esp-face" "-I{compiler.sdk.path}/include/esp32-camera" "-I{compiler.sdk.path}/include/esp-face" "-I{compiler.sdk.path}/include/fb_gfx" compiler.c.cmd=xtensa-esp32-elf-gcc -compiler.c.flags=-std=gnu99 -Os -g3 -fstack-protector -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wpointer-arith {compiler.warning_flags} -Wno-maybe-uninitialized -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration -MMD -c +compiler.c.flags=-std=gnu99 -Os -g3 -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -fstack-protector {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -Wwrite-strings -Wno-old-style-declaration -Wno-implicit-fallthrough -mfix-esp32-psram-cache-issue -MMD -c compiler.cpp.cmd=xtensa-esp32-elf-g++ -compiler.cpp.flags=-std=gnu++11 -Os -g3 -Wpointer-arith -fexceptions -fstack-protector -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib {compiler.warning_flags} -Wno-error=maybe-uninitialized -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-but-set-parameter -Wno-missing-field-initializers -Wno-sign-compare -fno-rtti -MMD -c +compiler.cpp.flags=-std=gnu++11 -Os -g3 -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -fstack-protector {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -Wwrite-strings -fexceptions -fno-rtti -mfix-esp32-psram-cache-issue -MMD -c compiler.S.cmd=xtensa-esp32-elf-gcc compiler.S.flags=-c -g3 -x assembler-with-cpp -MMD -mlongcalls compiler.c.elf.cmd=xtensa-esp32-elf-gcc -compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.project.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.libgcc.ld -T esp32.rom.spiram_incompatible_fns.ld -u ld_include_panic_highint_hdl -u call_user_start_cpu0 -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority -u __cxa_guard_dummy -u __cxx_fatal_exception +compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.project.ld -T esp32.peripherals.ld -T esp32.rom.ld -T esp32.rom.libgcc.ld -T esp32.rom.syscalls.ld -T esp32.rom.newlib-data.ld -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority -u call_user_start_cpu0 -u __cxa_guard_dummy -u ld_include_panic_highint_hdl -u newlib_include_locks_impl -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -fno-rtti -mfix-esp32-psram-cache-issue compiler.c.elf.libs=-lgcc -lfreertos -lmesh -lod -lwear_levelling -lfb_gfx -lesp_adc_cal -lc_nano -lesp32 -ldriver -lhal -ljsmn -lsmartconfig -lesp_http_server -lprotocomm -lface_recognition -lespnow -ltcpip_adapter -lface_detection -lunity -lc -llibsodium -lesp_http_client -lapp_update -lnewlib -lcxx -ltcp_transport -lm -lefuse -lopenssl -lwifi_provisioning -lespcoredump -llog -lmbedtls -lesp_ringbuf -lwps -lnet80211 -lmqtt -lesp_https_server -lapp_trace -lesp_event -lesp32-camera -lsoc -lheap -llwip -lwpa -lrtc -lxtensa-debug-module -lspi_flash -lphy -lfr -lconsole -lcoap -lbtdm_app -lsdmmc -lfd -lmicro-ecc -ljson -lcore -lprotobuf-c -lethernet -lspiffs -lnvs_flash -lwpa_supplicant -lvfs -lasio -lwpa2 -lpp -lbootloader_support -limage_util -ldl_lib -lulp -lnghttp -lpthread -lfreemodbus -lexpat -lfatfs -lsmartconfig_ack -lmdns -lcoexist -lesp-tls -lesp_https_ota -lbt -lstdc++ compiler.as.cmd=xtensa-esp32-elf-as diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 60e9402ef09..f6f78084fef 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -39,7 +39,8 @@ CFLAGS=[ "-std=gnu99", - "-Wno-old-style-declaration" + "-Wno-old-style-declaration", + "-Wno-implicit-fallthrough" ], CCFLAGS=[ @@ -58,9 +59,13 @@ "-Wno-error=unused-function", "-Wno-unused-parameter", "-Wno-sign-compare", + "-Wno-frame-address", + "-Wwrite-strings", + "-mfix-esp32-psram-cache-issue", "-fstack-protector", "-fexceptions", - "-Werror=reorder" + "-Werror=reorder", + "-MMD" ], CXXFLAGS=[ @@ -76,14 +81,21 @@ "-Wl,--undefined=uxTopUsedPriority", "-Wl,--gc-sections", "-Wl,-EL", + "-T", "esp32_out.ld", "-T", "esp32.project.ld", - "-T", "esp32.rom.ld", "-T", "esp32.peripherals.ld", + "-T", "esp32.rom.ld", "-T", "esp32.rom.libgcc.ld", - "-T", "esp32.rom.spiram_incompatible_fns.ld", + "-T", "esp32.rom.syscalls.ld", + "-T", "esp32.rom.newlib-data.ld", "-u", "ld_include_panic_highint_hdl", "-u", "__cxa_guard_dummy", - "-u", "__cxx_fatal_exception" + "-u", "newlib_include_locks_impl", + "-u", "newlib_include_heap_impl", + "-u", "newlib_include_syscalls_impl", + "-u", "pthread_include_pthread_impl", + "-u", "pthread_include_pthread_cond_impl", + "-u", "pthread_include_pthread_local_storage_impl" ], CPPDEFINES=[ @@ -91,6 +103,8 @@ "ESP_PLATFORM", ("F_CPU", "$BOARD_F_CPU"), "HAVE_CONFIG_H", + "_GNU_SOURCE", + ("GCC_NOT_5_2_0", 1), ("MBEDTLS_CONFIG_FILE", '\\"mbedtls/esp_config.h\\"'), ("ARDUINO", 10805), "ARDUINO_ARCH_ESP32", From 251d5ef92b3dd94fbe69d755ac306487e44d9d5c Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sat, 25 Jan 2020 22:41:03 +0200 Subject: [PATCH 2/7] Update CMakeLists.txt --- CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4557b52c5f..8a6f3532d89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,6 @@ set(COMPONENT_ADD_INCLUDEDIRS cores/esp32/ libraries/ArduinoOTA/src libraries/AsyncUDP/src - libraries/AzureIoT/src libraries/BLE/src libraries/BluetoothSerial/src libraries/DNSServer/src @@ -145,12 +144,7 @@ set(COMPONENT_ADD_INCLUDEDIRS set(COMPONENT_PRIV_INCLUDEDIRS cores/esp32/libb64) -set(COMPONENT_REQUIRES spi_flash mbedtls mdns ethernet esp_adc_cal) +set(COMPONENT_REQUIRES spi_flash mbedtls mdns esp_adc_cal) set(COMPONENT_PRIV_REQUIRES fatfs nvs_flash app_update spiffs bootloader_support openssl bt) register_component() - -set_source_files_properties(libraries/AzureIoT/src/az_iot/iothub_client/src/iothubtransport_mqtt_common.c - PROPERTIES COMPILE_FLAGS - -Wno-maybe-uninitialized -) From 4bb60f68da945955baae8e56ed01d5ffe52d0158 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 27 Jan 2020 13:50:33 +0200 Subject: [PATCH 3/7] Update package_esp32_index.template.json --- package/package_esp32_index.template.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package/package_esp32_index.template.json b/package/package_esp32_index.template.json index 92795318f19..4cfc31efabb 100644 --- a/package/package_esp32_index.template.json +++ b/package/package_esp32_index.template.json @@ -58,35 +58,35 @@ "systems": [ { "host": "i686-mingw32", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2019r2/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip", "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-win32.zip", "checksum": "SHA-256:c9d5776a22516f0825a7c68d835ffacc2392f913136893b7646e1288937cc65e", "size": "103850448" }, { "host": "x86_64-apple-darwin", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-macos.tar.gz", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2019r2/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-macos.tar.gz", "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-macos.tar.gz", "checksum": "SHA-256:dc62be8dd16c6d9d28d64e2b3f831fa208f3548c2ca73cdbcbdf68f474d59521", "size": "92150978" }, { "host": "x86_64-pc-linux-gnu", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2019r2/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz", "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-amd64.tar.gz", "checksum": "SHA-256:e6d47c1dbd8c8cbfe37271e5e2aac53ee88c9e347ae937e22bf0c73f530efbdf", "size": "85459985" }, { "host": "i686-pc-linux-gnu", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-i686.tar.gz", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2019r2/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-i686.tar.gz", "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-i686.tar.gz", "checksum": "SHA-256:36a9648c414dbd1c518c687ce5587d9f8eaa94324f45d92e9ec31a1433a04df8", "size": "87438500" }, { "host": "arm-linux-gnueabihf", - "url": "https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-armel.tar.gz", + "url": "https://github.com/espressif/crosstool-NG/releases/download/esp-2019r2/xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-armel.tar.gz", "archiveFileName": "xtensa-esp32-elf-gcc8_2_0-esp-2019r2-linux-armel.tar.gz", "checksum": "SHA-256:54a199c28f591da2466b21741911bc2ba77ddf82d3d2b66c6ce03c1a0c6835f0", "size": "83647538" From 1c4966566c23cafd95e7141467732a2043b92e83 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 27 Jan 2020 16:22:07 +0200 Subject: [PATCH 4/7] make ETH work --- libraries/WiFi/src/ETH.cpp | 160 ++++++++++++++++++++++++++--- libraries/WiFi/src/ETH.h | 15 +-- libraries/WiFi/src/WiFiGeneric.cpp | 6 ++ 3 files changed, 161 insertions(+), 20 deletions(-) diff --git a/libraries/WiFi/src/ETH.cpp b/libraries/WiFi/src/ETH.cpp index 8b0dcb29809..d3b127c6e9a 100644 --- a/libraries/WiFi/src/ETH.cpp +++ b/libraries/WiFi/src/ETH.cpp @@ -21,8 +21,11 @@ #include "ETH.h" #include "esp_system.h" #ifdef ESP_IDF_VERSION_MAJOR + #include "esp_event.h" #include "esp_eth.h" #include "esp_eth_phy.h" + #include "esp_eth_mac.h" + #include "esp_eth_com.h" #else #include "eth_phy/phy.h" #include "eth_phy/phy_tlk110.h" @@ -33,7 +36,62 @@ extern void tcpipInit(); -#ifndef ESP_IDF_VERSION_MAJOR +#ifdef ESP_IDF_VERSION_MAJOR + +/** +* @brief Callback function invoked when lowlevel initialization is finished +* +* @param[in] eth_handle: handle of Ethernet driver +* +* @return +* - ESP_OK: process extra lowlevel initialization successfully +* - ESP_FAIL: error occurred when processing extra lowlevel initialization +*/ +//static esp_err_t on_lowlevel_init_done(esp_eth_handle_t eth_handle){ +//#define PIN_PHY_POWER 2 +// pinMode(PIN_PHY_POWER, OUTPUT); +// digitalWrite(PIN_PHY_POWER, HIGH); +// delay(100); +// return ESP_OK; +//} + +/** +* @brief Callback function invoked when lowlevel deinitialization is finished +* +* @param[in] eth_handle: handle of Ethernet driver +* +* @return +* - ESP_OK: process extra lowlevel deinitialization successfully +* - ESP_FAIL: error occurred when processing extra lowlevel deinitialization +*/ +//static esp_err_t on_lowlevel_deinit_done(esp_eth_handle_t eth_handle){ +// return ESP_OK; +//} + + +// Event handler for Ethernet +void ETHClass::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) +{ + switch (event_id) { + case ETHERNET_EVENT_CONNECTED: + ((ETHClass*)(arg))->eth_link = ETH_LINK_UP; + break; + case ETHERNET_EVENT_DISCONNECTED: + ((ETHClass*)(arg))->eth_link = ETH_LINK_DOWN; + break; + case ETHERNET_EVENT_START: + ((ETHClass*)(arg))->started = true; + break; + case ETHERNET_EVENT_STOP: + ((ETHClass*)(arg))->started = false; + break; + default: + break; + } +} + + +#else static int _eth_phy_mdc_pin = -1; static int _eth_phy_mdio_pin = -1; static int _eth_phy_power_pin = -1; @@ -57,7 +115,11 @@ static void _eth_phy_power_enable(bool enable) } #endif -ETHClass::ETHClass():initialized(false),started(false),staticIP(false) +ETHClass::ETHClass() + :initialized(false) + ,staticIP(false) + ,started(false) + ,eth_link(ETH_LINK_DOWN) { } @@ -66,7 +128,79 @@ 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; + + tcpipInit(); + + esp_event_loop_create_default(); + tcpip_adapter_set_default_eth_handlers(); + esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, this); + //ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL)); + + eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); + mac_config.smi_mdc_gpio_num = mdc; + mac_config.smi_mdio_gpio_num = mdio; + //mac_config.sw_reset_timeout_ms = 1000; + esp_eth_mac_t *eth_mac = NULL; +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + if(type == ETH_PHY_DM9051){ + return false;//todo + } else { +#endif + eth_mac = esp_eth_mac_new_esp32(&mac_config); +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + } +#endif + + if(eth_mac == NULL){ + log_e("esp_eth_mac_new_esp32 failed"); + return false; + } + + eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); + phy_config.phy_addr = phy_addr; + phy_config.reset_gpio_num = power; + esp_eth_phy_t *eth_phy = NULL; + switch(type){ + case ETH_PHY_LAN8720: + eth_phy = esp_eth_phy_new_lan8720(&phy_config); + break; + case ETH_PHY_TLK110: + eth_phy = esp_eth_phy_new_ip101(&phy_config); + break; + case ETH_PHY_RTL8201: + eth_phy = esp_eth_phy_new_rtl8201(&phy_config); + break; + case ETH_PHY_DP83848: + eth_phy = esp_eth_phy_new_dp83848(&phy_config); + break; +#if CONFIG_ETH_SPI_ETHERNET_DM9051 + case ETH_PHY_DM9051: + eth_phy = esp_eth_phy_new_dm9051(&phy_config); + break; +#endif + default: + break; + } + if(eth_phy == NULL){ + log_e("esp_eth_phy_new failed"); + return false; + } + + eth_handle = NULL; + esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, eth_phy); + //eth_config.on_lowlevel_init_done = on_lowlevel_init_done; + //eth_config.on_lowlevel_deinit_done = on_lowlevel_deinit_done; + if(esp_eth_driver_install(ð_config, ð_handle) != ESP_OK || eth_handle == NULL){ + log_e("esp_eth_driver_install failed"); + return false; + } + + if(esp_eth_start(eth_handle) != ESP_OK){ + log_e("esp_eth_start failed"); + return false; + } + + return true; } #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) @@ -260,7 +394,7 @@ bool ETHClass::setHostname(const char * hostname) bool ETHClass::fullDuplex() { #ifdef ESP_IDF_VERSION_MAJOR - return true;//todo + return true;//todo: do not see an API for this #else return eth_config.phy_get_duplex_mode(); #endif @@ -269,7 +403,7 @@ bool ETHClass::fullDuplex() bool ETHClass::linkUp() { #ifdef ESP_IDF_VERSION_MAJOR - return true;//todo + return eth_link == ETH_LINK_UP; #else return eth_config.phy_check_link(); #endif @@ -278,7 +412,9 @@ bool ETHClass::linkUp() uint8_t ETHClass::linkSpeed() { #ifdef ESP_IDF_VERSION_MAJOR - return 100;//ToDo + eth_speed_t link_speed; + esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &link_speed); + return (link_speed == ETH_SPEED_10M)?10:100; #else return eth_config.phy_get_speed_mode()?100:10; #endif @@ -298,13 +434,13 @@ IPv6Address ETHClass::localIPv6() return IPv6Address(addr.addr); } -uint8_t * macAddress(uint8_t* mac) +uint8_t * ETHClass::macAddress(uint8_t* mac) { if(!mac){ return NULL; } #ifdef ESP_IDF_VERSION_MAJOR - //ToDo + esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac); #else esp_eth_get_mac(mac); #endif @@ -313,13 +449,9 @@ uint8_t * macAddress(uint8_t* mac) String ETHClass::macAddress(void) { - uint8_t mac[6] = {0,0,0,0,0,0};//ToDo + uint8_t mac[6] = {0,0,0,0,0,0}; char macStr[18] = { 0 }; -#ifdef ESP_IDF_VERSION_MAJOR - //ToDo -#else - esp_eth_get_mac(mac); -#endif + macAddress(mac); sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return String(macStr); } diff --git a/libraries/WiFi/src/ETH.h b/libraries/WiFi/src/ETH.h index af918772b8c..a0bd6cd524b 100644 --- a/libraries/WiFi/src/ETH.h +++ b/libraries/WiFi/src/ETH.h @@ -45,24 +45,27 @@ #define ETH_PHY_MDIO 18 #endif +#ifndef ESP_IDF_VERSION_MAJOR #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; +typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_DM9051, ETH_PHY_MAX } eth_phy_type_t; class ETHClass { private: bool initialized; - bool started; bool staticIP; #ifdef ESP_IDF_VERSION_MAJOR - esp_eth_config_t eth_config; + esp_eth_handle_t eth_handle; + + protected: + bool started; + eth_link_t eth_link; + static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); #else + bool started; eth_config_t eth_config; #endif public: diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 50fb56f4962..d6e9baa9805 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -102,6 +102,12 @@ void tcpipInit(){ static bool initialized = false; if(!initialized && _start_network_event_task()){ initialized = true; +#ifdef ESP_IDF_VERSION_MAJOR + uint8_t mac[8]; + if(esp_efuse_mac_get_default(mac) == ESP_OK){ + esp_base_mac_addr_set(mac); + } +#endif tcpip_adapter_init(); } } From 354e485c4b6705d8a3e21036fbaee2ab07cfdb06 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 27 Jan 2020 17:34:30 +0200 Subject: [PATCH 5/7] get smart config to work as well --- libraries/WiFi/src/ETH.cpp | 3 +- libraries/WiFi/src/WiFiGeneric.cpp | 1 + libraries/WiFi/src/WiFiSTA.cpp | 49 +++++++++++++++++++++++++----- libraries/WiFi/src/WiFiSTA.h | 7 +++++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/libraries/WiFi/src/ETH.cpp b/libraries/WiFi/src/ETH.cpp index d3b127c6e9a..1d5b3106444 100644 --- a/libraries/WiFi/src/ETH.cpp +++ b/libraries/WiFi/src/ETH.cpp @@ -69,6 +69,7 @@ extern void tcpipInit(); //} + // Event handler for Ethernet void ETHClass::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { @@ -118,6 +119,7 @@ static void _eth_phy_power_enable(bool enable) ETHClass::ETHClass() :initialized(false) ,staticIP(false) + ,eth_handle(NULL) ,started(false) ,eth_link(ETH_LINK_DOWN) { @@ -131,7 +133,6 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ tcpipInit(); - esp_event_loop_create_default(); tcpip_adapter_set_default_eth_handlers(); esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, this); //ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL)); diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index d6e9baa9805..4d9af95aa0b 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -107,6 +107,7 @@ void tcpipInit(){ if(esp_efuse_mac_get_default(mac) == ESP_OK){ esp_base_mac_addr_set(mac); } + esp_event_loop_create_default(); #endif tcpip_adapter_init(); } diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index d8561c35abb..fdbadbc60b6 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -693,6 +693,7 @@ bool WiFiSTAClass::beginSmartConfig() { esp_err_t err; #ifdef ESP_IDF_VERSION_MAJOR + esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, _smartConfigCallback, this); smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT(); err = esp_smartconfig_start(&conf); #else @@ -727,6 +728,45 @@ bool WiFiSTAClass::smartConfigDone() { return _smartConfigDone; } +#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG +const char * sc_type_strings[] = { + "ESPTOUCH", + "AIRKISS", + "ESPTOUCH_AIRKISS" +}; +#endif + + +#ifdef ESP_IDF_VERSION_MAJOR //todo +void WiFiSTAClass::_smartConfigCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data){ + smartconfig_event_t event = (smartconfig_event_t)event_id; + switch(event){ + case SC_EVENT_SCAN_DONE: + log_d("smartconfig has finished to scan for APs"); + break; + case SC_EVENT_FOUND_CHANNEL: + log_d("smartconfig has found the channel of the target AP"); + break; + case SC_EVENT_GOT_SSID_PSWD: + { + log_d("smartconfig got the SSID and password"); + smartconfig_event_got_ssid_pswd_t * data = (smartconfig_event_got_ssid_pswd_t*)event_data; + log_d("Type: %s", sc_type_strings[data->type]); + log_d("SSID: %s", (const char *)data->ssid); + log_d("Password: %s", (const char *)data->password); + log_d("Sender IP: " IPSTR, data->cellphone_ip[3], data->cellphone_ip[2], data->cellphone_ip[1], data->cellphone_ip[0]); + WiFi.begin((const char *)data->ssid, (const char *)data->password); + } + break; + case SC_EVENT_SEND_ACK_DONE: + log_d("smartconfig has sent ACK to the sender"); + WiFi.stopSmartConfig(); + break; + default: break; + } +} +#else + #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG const char * sc_status_strings[] = { "WAIT", @@ -735,16 +775,9 @@ const char * sc_status_strings[] = { "LINK", "LINK_OVER" }; - -const char * sc_type_strings[] = { - "ESPTOUCH", - "AIRKISS", - "ESPTOUCH_AIRKISS" -}; #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) { @@ -768,5 +801,5 @@ void WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) { } WiFi.stopSmartConfig(); } -#endif } +#endif diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index d9140101593..59010fae8b4 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -26,6 +26,9 @@ #include "WiFiType.h" #include "WiFiGeneric.h" +#ifdef ESP_IDF_VERSION_MAJOR +#include "esp_event.h" +#endif class WiFiSTAClass @@ -98,7 +101,11 @@ class WiFiSTAClass protected: static bool _smartConfigStarted; static bool _smartConfigDone; +#ifdef ESP_IDF_VERSION_MAJOR //todo + static void _smartConfigCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); +#else static void _smartConfigCallback(uint32_t status, void* result); +#endif }; From 856e596c791d19d342f146e2ce137693daa33183 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 27 Jan 2020 18:03:03 +0200 Subject: [PATCH 6/7] Pass ethernet events to the main handler --- libraries/WiFi/src/ETH.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/WiFi/src/ETH.cpp b/libraries/WiFi/src/ETH.cpp index 1d5b3106444..0de771cd622 100644 --- a/libraries/WiFi/src/ETH.cpp +++ b/libraries/WiFi/src/ETH.cpp @@ -73,22 +73,28 @@ extern void tcpipInit(); // Event handler for Ethernet void ETHClass::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { + system_event_t event; switch (event_id) { case ETHERNET_EVENT_CONNECTED: + event.event_id = SYSTEM_EVENT_ETH_CONNECTED; ((ETHClass*)(arg))->eth_link = ETH_LINK_UP; break; case ETHERNET_EVENT_DISCONNECTED: + event.event_id = SYSTEM_EVENT_ETH_DISCONNECTED; ((ETHClass*)(arg))->eth_link = ETH_LINK_DOWN; break; case ETHERNET_EVENT_START: + event.event_id = SYSTEM_EVENT_ETH_START; ((ETHClass*)(arg))->started = true; break; case ETHERNET_EVENT_STOP: + event.event_id = SYSTEM_EVENT_ETH_STOP; ((ETHClass*)(arg))->started = false; break; default: break; } + WiFi._eventCallback(arg, &event); } From 93d77859d9a13156570e96e6cd717729bf5f7552 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 7 Apr 2020 01:34:13 +0300 Subject: [PATCH 7/7] Add fixes --- libraries/SD/src/sd_diskio.cpp | 3 +-- libraries/WiFi/src/ETH.cpp | 15 +++++++-------- libraries/WiFi/src/ETH.h | 6 +++--- libraries/WiFi/src/WiFiSTA.cpp | 5 ----- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index 1d1922be465..b98b98d1364 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -14,10 +14,9 @@ #include "sd_diskio.h" #include "esp_system.h" extern "C" { - #include "ffconf.h" #include "ff.h" #include "diskio.h" -#ifdef ESP_IDF_VERSION_MAJOR +#if ESP_IDF_VERSION_MAJOR > 3 #include "diskio_impl.h" #endif //#include "esp_vfs.h" diff --git a/libraries/WiFi/src/ETH.cpp b/libraries/WiFi/src/ETH.cpp index 0de771cd622..d1c3cc5a1e4 100644 --- a/libraries/WiFi/src/ETH.cpp +++ b/libraries/WiFi/src/ETH.cpp @@ -125,9 +125,13 @@ static void _eth_phy_power_enable(bool enable) ETHClass::ETHClass() :initialized(false) ,staticIP(false) - ,eth_handle(NULL) - ,started(false) - ,eth_link(ETH_LINK_DOWN) +#if ESP_IDF_VERSION_MAJOR > 3 + ,eth_handle(NULL) +#endif + ,started(false) +#if ESP_IDF_VERSION_MAJOR > 3 + ,eth_link(ETH_LINK_DOWN) +#endif { } @@ -348,13 +352,8 @@ IPAddress ETHClass::gatewayIP() IPAddress ETHClass::dnsIP(uint8_t dns_no) { -#ifdef ESP_IDF_VERSION_MAJOR const ip_addr_t * dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip->u_addr.ip4.addr); -#else - ip_addr_t dns_ip = dns_getserver(dns_no); - return IPAddress(dns_ip.u_addr.ip4.addr); -#endif } IPAddress ETHClass::broadcastIP() diff --git a/libraries/WiFi/src/ETH.h b/libraries/WiFi/src/ETH.h index a0bd6cd524b..9a944401039 100644 --- a/libraries/WiFi/src/ETH.h +++ b/libraries/WiFi/src/ETH.h @@ -45,7 +45,7 @@ #define ETH_PHY_MDIO 18 #endif -#ifndef ESP_IDF_VERSION_MAJOR +#if ESP_IDF_VERSION_MAJOR < 4 #ifndef ETH_CLK_MODE #define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN #endif @@ -57,7 +57,7 @@ class ETHClass { private: bool initialized; bool staticIP; -#ifdef ESP_IDF_VERSION_MAJOR +#if ESP_IDF_VERSION_MAJOR > 3 esp_eth_handle_t eth_handle; protected: @@ -72,7 +72,7 @@ class ETHClass { ETHClass(); ~ETHClass(); -#ifdef ESP_IDF_VERSION_MAJOR +#if ESP_IDF_VERSION_MAJOR > 3 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); diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index fdbadbc60b6..3269cabf138 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -488,13 +488,8 @@ IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no) if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){ return IPAddress(); } -#ifdef ESP_IDF_VERSION_MAJOR const ip_addr_t * dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip->u_addr.ip4.addr); -#else - ip_addr_t dns_ip = dns_getserver(dns_no); - return IPAddress(dns_ip.u_addr.ip4.addr); -#endif } /**