|
21 | 21 | #include "esp_adc/adc_continuous.h" |
22 | 22 | #include "esp_adc/adc_cali_scheme.h" |
23 | 23 |
|
| 24 | +#if CONFIG_IDF_TARGET_ESP32P4 && CONFIG_ESP32P4_REV_MIN_FULL >= 300 |
| 25 | +// NOTE: These weak definitions allow successful linkage if the real efuse calibration functions are missing. |
| 26 | +// This is a workaround for the ESP32P4 rev 3.0+, which is missing efuse calibration functions in the IDF. |
| 27 | +__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_ver(void) |
| 28 | +{ |
| 29 | + return 0; |
| 30 | +} |
| 31 | + |
| 32 | +__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_init_code(uint32_t atten, uint32_t *code) |
| 33 | +{ |
| 34 | + if (code) { |
| 35 | + *code = 0; |
| 36 | + } |
| 37 | + return 0; // 0 means success in ESP-IDF conventions |
| 38 | +} |
| 39 | + |
| 40 | +__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_chan_compens(uint32_t atten, uint32_t *comp) |
| 41 | +{ |
| 42 | + if (comp) { |
| 43 | + *comp = 0; |
| 44 | + } |
| 45 | + return 0; |
| 46 | +} |
| 47 | + |
| 48 | +__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_cal_voltage(uint32_t atten, uint32_t *voltage) |
| 49 | +{ |
| 50 | + if (voltage) { |
| 51 | + *voltage = 0; |
| 52 | + } |
| 53 | + return 0; |
| 54 | +} |
| 55 | +#endif |
| 56 | + |
24 | 57 | // ESP32-C2 does not define those two for some reason |
25 | 58 | #ifndef SOC_ADC_DIGI_RESULT_BYTES |
26 | 59 | #define SOC_ADC_DIGI_RESULT_BYTES (4) |
@@ -75,7 +108,7 @@ static bool adcDetachBus(void *pin) { |
75 | 108 | if (err != ESP_OK) { |
76 | 109 | return false; |
77 | 110 | } |
78 | | -#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) |
| 111 | +#elif //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
79 | 112 | err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); |
80 | 113 | if (err != ESP_OK) { |
81 | 114 | return false; |
@@ -127,7 +160,7 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i |
127 | 160 | log_e("adc_cali_create_scheme_curve_fitting failed with error: %d", err); |
128 | 161 | return err; |
129 | 162 | } |
130 | | -#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
| 163 | +#elif //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
131 | 164 | log_d("Deleting ADC_UNIT_%d line cali handle", adc_unit); |
132 | 165 | err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); |
133 | 166 | if (err != ESP_OK) { |
@@ -310,7 +343,7 @@ uint32_t __analogReadMilliVolts(uint8_t pin) { |
310 | 343 | .bitwidth = __analogWidth, |
311 | 344 | }; |
312 | 345 | err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); |
313 | | -#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
| 346 | +#elif //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
314 | 347 | adc_cali_line_fitting_config_t cali_config = { |
315 | 348 | .unit_id = adc_unit, |
316 | 349 | .bitwidth = __analogWidth, |
@@ -379,7 +412,7 @@ static bool adcContinuousDetachBus(void *adc_unit_number) { |
379 | 412 | if (err != ESP_OK) { |
380 | 413 | return false; |
381 | 414 | } |
382 | | -#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) |
| 415 | +#elif //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
383 | 416 | err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle); |
384 | 417 | if (err != ESP_OK) { |
385 | 418 | return false; |
@@ -552,7 +585,7 @@ bool analogContinuous(const uint8_t pins[], size_t pins_count, uint32_t conversi |
552 | 585 | .bitwidth = __adcContinuousWidth, |
553 | 586 | }; |
554 | 587 | err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle); |
555 | | -#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
| 588 | +#elif //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED |
556 | 589 | adc_cali_line_fitting_config_t cali_config = { |
557 | 590 | .unit_id = adc_unit, |
558 | 591 | .bitwidth = __adcContinuousWidth, |
|
0 commit comments