Skip to content

Commit

Permalink
[ESP-IDF5.1] Update to the latest Arduino/ESP32 commits for IDF5.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Nov 18, 2023
1 parent 7bccf03 commit 1f6bdab
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 24 deletions.
6 changes: 3 additions & 3 deletions docs/source/Plugin/P002.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -91,15 +91,15 @@ Suggested ranges ESP32:
| ESP32 +-------------+-----------------+
| | 6 | 150 ~ 1750 |
| +-------------+-----------------+
| | 11 | 150 ~ 2450 |
| | 12 | 150 ~ 2450 |
+----------+-------------+-----------------+
| | 0 | 0 ~ 750 |
| +-------------+-----------------+
| | 2.5 | 0 ~ 1050 |
| 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.
Expand Down
10 changes: 4 additions & 6 deletions platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions platformio_esp32_solo1.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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
4 changes: 3 additions & 1 deletion src/include/esp32x_fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/src/Helpers/Hardware_ADC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/src/Helpers/Hardware_ADC_cali.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/src/Helpers/Hardware_ADC_cali.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
17 changes: 14 additions & 3 deletions src/src/PluginStructs/P002_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand All @@ -589,7 +595,12 @@ adc_atten_t P002_data_struct::getAttenuation(struct EventStruct *event) {
return static_cast<adc_atten_t>(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
Expand Down
9 changes: 9 additions & 0 deletions src/src/PluginStructs/P002_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

};
Expand Down

0 comments on commit 1f6bdab

Please sign in to comment.