Skip to content

Commit 8acc346

Browse files
committed
Fixes compilation errors that occurred depending on the ESP-IDF version
1 parent a7c6793 commit 8acc346

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/m5_unit_component/adapter_gpio.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#include "adapter_gpio.hpp"
1212
#include <driver/gpio.h>
13+
#include <esp_idf_version.h>
1314

1415
#if defined(M5_UNIT_UNIFIED_USING_RMT_V2)
1516
#pragma message "Using RMT v2,Oneshot"
@@ -19,6 +20,16 @@
1920
#include <driver/adc.h>
2021
#endif
2122

23+
// ADC_ATTEN_DB_12 was introduced in ESP-IDF v4.4.7 / v5.1.3
24+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 3) \
25+
|| (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 7) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
26+
#pragma message "Exists ADC_ATTEN_DB_12"
27+
constexpr auto M5_ADC_ATTEN_DB = ADC_ATTEN_DB_12;
28+
#else
29+
#pragma message "Not exists ADC_ATTEN_DB_12"
30+
constexpr auto M5_ADC_ATTEN_DB = ADC_ATTEN_DB_11;
31+
#endif
32+
2233
#if defined(SOC_DAC_SUPPORTED) && SOC_DAC_SUPPORTED
2334
#pragma message "DAC supported"
2435

@@ -422,7 +433,7 @@ m5::hal::error::error_t AdapterGPIOBase::GPIOImpl::read_analog(uint16_t& value,
422433
}
423434

424435
adc_oneshot_chan_cfg_t chan_config = {
425-
.atten = ADC_ATTEN_DB_12, // 0~3.3V
436+
.atten = M5_ADC_ATTEN_DB, // 0~3.3V
426437
.bitwidth = ADC_BITWIDTH_DEFAULT // 12bit
427438
};
428439

@@ -454,7 +465,7 @@ m5::hal::error::error_t AdapterGPIOBase::GPIOImpl::read_analog(uint16_t& value,
454465
// ADC1
455466
adc1_channel_t channel = static_cast<adc1_channel_t>(ch);
456467
adc1_config_width(ADC_WIDTH_BIT_12);
457-
adc1_config_channel_atten(channel, ADC_ATTEN_DB_12);
468+
adc1_config_channel_atten(channel, M5_ADC_ATTEN_DB);
458469
value = static_cast<uint16_t>(adc1_get_raw(channel));
459470
return m5::hal::error::error_t::OK;
460471
#endif

0 commit comments

Comments
 (0)