From 1f6bdab556a64dd84c94c021488961ec59e64a71 Mon Sep 17 00:00:00 2001 From: TD-er Date: Sat, 18 Nov 2023 22:40:48 +0100 Subject: [PATCH] [ESP-IDF5.1] Update to the latest Arduino/ESP32 commits for IDF5.1.2 --- docs/source/Plugin/P002.rst | 6 +++--- platformio_core_defs.ini | 10 ++++------ platformio_esp32_solo1.ini | 18 +++++++----------- src/include/esp32x_fixes.h | 4 +++- src/src/Helpers/Hardware_ADC.h | 9 +++++++++ src/src/Helpers/Hardware_ADC_cali.cpp | 2 ++ src/src/Helpers/Hardware_ADC_cali.h | 4 ++++ src/src/PluginStructs/P002_data_struct.cpp | 17 ++++++++++++++--- src/src/PluginStructs/P002_data_struct.h | 9 +++++++++ 9 files changed, 55 insertions(+), 24 deletions(-) diff --git a/docs/source/Plugin/P002.rst b/docs/source/Plugin/P002.rst index 885a56b143..fe795c8266 100644 --- a/docs/source/Plugin/P002.rst +++ b/docs/source/Plugin/P002.rst @@ -74,7 +74,7 @@ ESP32 ^^^^^ All ESP32 versions allow for changing the range per pin (channel) by setting some attentuation resistor active. -The default active attentuation is 11 dB, which allows for a maximum input voltage of 3.1V +The default active attentuation is 12 dB, which allows for a maximum input voltage of 3.1V Upto roughly 2.5V the ADC does show a nearly linear response. Suggested ranges ESP32: @@ -91,7 +91,7 @@ Suggested ranges ESP32: | ESP32 +-------------+-----------------+ | | 6 | 150 ~ 1750 | | +-------------+-----------------+ - | | 11 | 150 ~ 2450 | + | | 12 | 150 ~ 2450 | +----------+-------------+-----------------+ | | 0 | 0 ~ 750 | | +-------------+-----------------+ @@ -99,7 +99,7 @@ Suggested ranges ESP32: | ESP32-S2 +-------------+-----------------+ | | 6 | 0 ~ 1300 | | +-------------+-----------------+ - | | 11 | 0 ~ 2500 | + | | 12 | 0 ~ 2500 | +----------+-------------+-----------------+ N.B. The ESP32 cannot measure down to 0V. The minimum Voltage depends on the set attenuation. diff --git a/platformio_core_defs.ini b/platformio_core_defs.ini index 2bea6bf092..7b2773e54f 100644 --- a/platformio_core_defs.ini +++ b/platformio_core_defs.ini @@ -206,12 +206,10 @@ lib_ignore = ; ESP_IDF 5.1 [core_esp32_IDF5_1__3_0_0] -;platform = https://github.com/Jason2866/platform-espressif32.git#ae949bcf416213717662095f67cd76d85a810529 -;platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF5 -;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1732/framework-arduinoespressif32-release_v5.1-4cafc60a00.zip -;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1752/framework-arduinoespressif32-release_v5.1_no_SECP256R1-e97d377907.zip -platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.12/platform-espressif32.zip -platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1787/framework-arduinoespressif32-release_v5.1-f61c914469.zip +;platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.12/platform-espressif32.zip +;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1787/framework-arduinoespressif32-release_v5.1-f61c914469.zip +platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.11.11/platform-espressif32.zip +platform_packages = build_flags = -DESP32_STAGE -DESP_IDF_VERSION_MAJOR=5 -DLIBRARIES_NO_LOG=1 diff --git a/platformio_esp32_solo1.ini b/platformio_esp32_solo1.ini index d3df195099..07dd775924 100644 --- a/platformio_esp32_solo1.ini +++ b/platformio_esp32_solo1.ini @@ -1,7 +1,7 @@ - +; IDF 4.4 [esp32_solo1_common] extends = esp32_base platform_packages = framework-arduino-solo1 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1646/framework-arduinoespressif32-solo1-release_v4.4_spiffs-e3fc63b439.zip @@ -16,7 +16,7 @@ extra_scripts = ${esp32_base.extra_scripts} build_unflags = ${esp32_base.build_unflags} -fexceptions - +; IDF 5.1.2 [esp32_solo1_common_LittleFS] extends = esp32_base_idf5 build_flags = ${esp32_base_idf5.build_flags} @@ -28,7 +28,7 @@ build_unflags = ${esp32_base_idf5.build_unflags} board_build.filesystem = littlefs -[env:custom_ESP32solo1_4M316k] +[env:custom_ESP32solo1_4M316k_LittleFS] extends = esp32_solo1_common board = esp32_solo1_4M build_flags = ${esp32_solo1_common.build_flags} @@ -37,23 +37,19 @@ extra_scripts = ${esp32_solo1_common.extra_scripts} pre:tools/pio/pre_custom_esp32.py -[env:normal_ESP32solo1_4M316k] -extends = esp32_solo1_common -board = esp32_solo1_4M - [env:normal_ESP32solo1_4M316k_LittleFS] extends = esp32_solo1_common_LittleFS board = esp32_solo1_4M -[env:energy_ESP32solo1_4M316k] -extends = esp32_solo1_common +[env:energy_ESP32solo1_4M316k_LittleFS] +extends = esp32_solo1_common_LittleFS board = esp32_solo1_4M build_flags = ${esp32_solo1_common.build_flags} -D PLUGIN_ENERGY_COLLECTION -[env:climate_ESP32solo1_4M316k] -extends = esp32_solo1_common +[env:climate_ESP32solo1_4M316k_LittleFS] +extends = esp32_solo1_common_LittleFS board = esp32_solo1_4M build_flags = ${esp32_solo1_common.build_flags} -D PLUGIN_CLIMATE_COLLECTION diff --git a/src/include/esp32x_fixes.h b/src/include/esp32x_fixes.h index 8bf04469f1..4c5a5e780b 100644 --- a/src/include/esp32x_fixes.h +++ b/src/include/esp32x_fixes.h @@ -64,7 +64,9 @@ # define HSPI_HOST SPI3_HOST # define VSPI_HOST SPI3_HOST # ifndef REG_SPI_BASE -# define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i) > 1) ? (((i) * 0x1000) + 0x20000) : (((~(i)) & 1) * 0x1000))) +# if ESP_IDF_VERSION_MAJOR < 5 +# define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i) > 1) ? (((i) * 0x1000) + 0x20000) : (((~(i)) & 1) * 0x1000))) +# endif // SPI_MOSI_DLEN_REG is not defined anymore in esp32s3, instead use SPI_MS_DLEN_REG # define SPI_MOSI_DLEN_REG(x) SPI_MS_DLEN_REG(x) diff --git a/src/src/Helpers/Hardware_ADC.h b/src/src/Helpers/Hardware_ADC.h index de154bd054..e01ae17023 100644 --- a/src/src/Helpers/Hardware_ADC.h +++ b/src/src/Helpers/Hardware_ADC.h @@ -30,7 +30,12 @@ class Hardware_ADC_t { ~Hardware_ADC_t(); bool init(int pin, +#if ESP_IDF_VERSION_MAJOR >= 5 + adc_atten_t attenuation = ADC_ATTEN_DB_12); +#else adc_atten_t attenuation = ADC_ATTEN_DB_11); +#endif + // Return whether factory calibration is actually enabled. // Cannot enable factory calibration when no calibration is present. @@ -49,7 +54,11 @@ class Hardware_ADC_t { bool _isTouchPin = false; # endif // if HAS_TOUCH_GPIO bool _useFactoryCalibration = false; +#if ESP_IDF_VERSION_MAJOR >= 5 + adc_atten_t _attenuation = ADC_ATTEN_DB_12; +#else adc_atten_t _attenuation = ADC_ATTEN_DB_11; +#endif // ADC Factory calibration definition diff --git a/src/src/Helpers/Hardware_ADC_cali.cpp b/src/src/Helpers/Hardware_ADC_cali.cpp index 909bea7911..913e799793 100644 --- a/src/src/Helpers/Hardware_ADC_cali.cpp +++ b/src/src/Helpers/Hardware_ADC_cali.cpp @@ -27,6 +27,8 @@ bool Hardware_ADC_cali_t::init(int pin, { # if ESP_IDF_VERSION_MAJOR >= 5 && ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED _useHighResInterpolation = false; +# elif ESP_IDF_VERSION_MAJOR >= 5 + _useHighResInterpolation = attenuation != adc_atten_t::ADC_ATTEN_DB_12; # else // if ESP_IDF_VERSION_MAJOR >= 5 && ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED _useHighResInterpolation = attenuation != adc_atten_t::ADC_ATTEN_DB_11; # endif // if ESP_IDF_VERSION_MAJOR >= 5 && ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED diff --git a/src/src/Helpers/Hardware_ADC_cali.h b/src/src/Helpers/Hardware_ADC_cali.h index a1c13f6e6f..824ad553d2 100644 --- a/src/src/Helpers/Hardware_ADC_cali.h +++ b/src/src/Helpers/Hardware_ADC_cali.h @@ -41,7 +41,11 @@ class Hardware_ADC_cali_t { // Return whether factory calibration is actually enabled. // Cannot enable factory calibration when no calibration is present. bool init(int pin, +#if ESP_IDF_VERSION_MAJOR >= 5 + adc_atten_t attenuation = ADC_ATTEN_DB_12); +#else adc_atten_t attenuation = ADC_ATTEN_DB_11); +#endif bool initialized() const { return _initialized; } diff --git a/src/src/PluginStructs/P002_data_struct.cpp b/src/src/PluginStructs/P002_data_struct.cpp index dcde1c48f9..2e0d5c0b9e 100644 --- a/src/src/PluginStructs/P002_data_struct.cpp +++ b/src/src/PluginStructs/P002_data_struct.cpp @@ -142,7 +142,7 @@ void P002_data_struct::webformLoad(struct EventStruct *event) { const __FlashStringHelper *outputOptions[] = { - F("11 dB"), + F("12 dB"), F("6 dB"), F("2.5 dB"), F("0 dB") @@ -390,7 +390,13 @@ void P002_data_struct::webformLoad_calibrationCurve(struct EventStruct *event) size_t current_attenuation = getAttenuation(event); - if (current_attenuation >= P002_ADC_ATTEN_MAX) { current_attenuation = ADC_ATTEN_DB_11; } + if (current_attenuation >= P002_ADC_ATTEN_MAX) { +#if ESP_IDF_VERSION_MAJOR >= 5 + current_attenuation = ADC_ATTEN_DB_12; +#else + current_attenuation = ADC_ATTEN_DB_11; +#endif + } for (size_t att = 0; att < P002_ADC_ATTEN_MAX; ++att) { @@ -577,7 +583,7 @@ void P002_data_struct::format_2point_calib_statistics(const __FlashStringHelper # ifdef ESP32 const __FlashStringHelper * P002_data_struct::AttenuationToString(adc_atten_t attenuation) { - const __FlashStringHelper *datalabels[] = { F("0 dB"), F("2.5 dB"), F("6 dB"), F("11 dB") }; + const __FlashStringHelper *datalabels[] = { F("0 dB"), F("2.5 dB"), F("6 dB"), F("12 dB") }; if (attenuation < 4) { return datalabels[attenuation]; } return F("Unknown"); @@ -589,7 +595,12 @@ adc_atten_t P002_data_struct::getAttenuation(struct EventStruct *event) { return static_cast(P002_ATTENUATION - 10); } P002_ATTENUATION = P002_ADC_11db; + +#if ESP_IDF_VERSION_MAJOR >= 5 + return ADC_ATTEN_DB_12; +#else return ADC_ATTEN_DB_11; +#endif } # endif // ifdef ESP32 diff --git a/src/src/PluginStructs/P002_data_struct.h b/src/src/PluginStructs/P002_data_struct.h index 5c271b0368..18d529811f 100644 --- a/src/src/PluginStructs/P002_data_struct.h +++ b/src/src/PluginStructs/P002_data_struct.h @@ -56,7 +56,11 @@ # define P002_ADC_0db (ADC_ATTEN_DB_0 + 10) # define P002_ADC_2_5db (ADC_ATTEN_DB_2_5 + 10) # define P002_ADC_6db (ADC_ATTEN_DB_6 + 10) +#if ESP_IDF_VERSION_MAJOR >= 5 +# define P002_ADC_11db (ADC_ATTEN_DB_12 + 10) +#else # define P002_ADC_11db (ADC_ATTEN_DB_11 + 10) +#endif struct P002_ADC_Value_pair { @@ -263,7 +267,12 @@ struct P002_data_struct : public PluginTaskData_base { # endif // ifndef LIMIT_BUILD_SIZE # ifdef ESP32 bool _useFactoryCalibration = false; + +#if ESP_IDF_VERSION_MAJOR >= 5 + adc_atten_t _attenuation = ADC_ATTEN_DB_12; +#else adc_atten_t _attenuation = ADC_ATTEN_DB_11; +#endif # endif // ifdef ESP32 };