Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ menu.EraseFlash=Erase All Flash Before Sketch Upload
menu.JTAGAdapter=JTAG Adapter
menu.ZigbeeMode=Zigbee Mode
menu.PinNumbers=Pin Numbering
menu.ChipVariant=Chip Variant

# Custom options
menu.Revision=Board Revision
Expand Down Expand Up @@ -398,6 +399,7 @@ esp32p4.build.target=esp
esp32p4.build.mcu=esp32p4
esp32p4.build.core=esp32
esp32p4.build.variant=esp32p4
esp32p4.build.chip_variant=esp32p4_es
esp32p4.build.board=ESP32P4_DEV
esp32p4.build.bootloader_addr=0x2000

Expand All @@ -414,6 +416,13 @@ esp32p4.build.boot=qio
esp32p4.build.partitions=default
esp32p4.build.defines=

esp32p4.menu.ChipVariant.prev3=Before v3.00
esp32p4.menu.ChipVariant.prev3.build.chip_variant=esp32p4_es
esp32p4.menu.ChipVariant.prev3.build.f_cpu=360000000L
esp32p4.menu.ChipVariant.postv3=v3.00 or newer
esp32p4.menu.ChipVariant.postv3.build.chip_variant=esp32p4
esp32p4.menu.ChipVariant.postv3.build.f_cpu=400000000L

## IDE 2.0 Seems to not update the value
esp32p4.menu.JTAGAdapter.default=Disabled
esp32p4.menu.JTAGAdapter.default.build.copy_jtag_files=0
Expand Down Expand Up @@ -512,12 +521,6 @@ esp32p4.menu.PartitionScheme.custom=Custom
esp32p4.menu.PartitionScheme.custom.build.partitions=
esp32p4.menu.PartitionScheme.custom.upload.maximum_size=16777216

## From https://docs.espressif.com/projects/esp-idf/en/latest/esp32p4/api-reference/kconfig.html#config-esp-default-cpu-freq-mhz
esp32p4.menu.CPUFreq.360=360MHz
esp32p4.menu.CPUFreq.360.build.f_cpu=360000000L
esp32p4.menu.CPUFreq.40=40MHz
esp32p4.menu.CPUFreq.40.build.f_cpu=40000000L

esp32p4.menu.FlashMode.qio=QIO
esp32p4.menu.FlashMode.qio.build.flash_mode=dio
esp32p4.menu.FlashMode.qio.build.boot=qio
Expand Down
60 changes: 52 additions & 8 deletions cores/esp32/esp32-hal-adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@
#include "esp_adc/adc_continuous.h"
#include "esp_adc/adc_cali_scheme.h"

#if CONFIG_IDF_TARGET_ESP32P4 && CONFIG_ESP32P4_REV_MIN_FULL >= 300
// NOTE: These weak definitions allow successful linkage if the real efuse calibration functions are missing.
// This is a workaround for the ESP32P4 rev 3.0+, which is missing efuse calibration functions in the IDF.
__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_ver(void) {
return 0;
}

__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_init_code(uint32_t atten, uint32_t *code) {
if (code) {
*code = 0;
}
return 0; // 0 means success in ESP-IDF conventions
}

__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_chan_compens(uint32_t atten, uint32_t *comp) {
if (comp) {
*comp = 0;
}
return 0;
}

__attribute__((weak)) uint32_t esp_efuse_rtc_calib_get_cal_voltage(uint32_t atten, uint32_t *voltage) {
if (voltage) {
*voltage = 0;
}
return 0;
}
#endif

// ESP32-C2 does not define those two for some reason
#ifndef SOC_ADC_DIGI_RESULT_BYTES
#define SOC_ADC_DIGI_RESULT_BYTES (4)
Expand Down Expand Up @@ -75,11 +104,14 @@ static bool adcDetachBus(void *pin) {
if (err != ESP_OK) {
return false;
}
#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4))
#elif ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if (err != ESP_OK) {
return false;
}
#else
log_e("ADC Calibration scheme is not supported!");
return false;
#endif
}
adc_handle[adc_unit].adc_cali_handle = NULL;
Expand Down Expand Up @@ -127,7 +159,7 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i
log_e("adc_cali_create_scheme_curve_fitting failed with error: %d", err);
return err;
}
#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
#elif ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
log_d("Deleting ADC_UNIT_%d line cali handle", adc_unit);
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if (err != ESP_OK) {
Expand All @@ -145,6 +177,9 @@ esp_err_t __analogChannelConfig(adc_bitwidth_t width, adc_attenuation_t atten, i
log_e("adc_cali_create_scheme_line_fitting failed with error: %d", err);
return err;
}
#else
log_e("ADC Calibration scheme is not supported!");
return ESP_ERR_NOT_SUPPORTED;
#endif
}
}
Expand Down Expand Up @@ -310,13 +345,16 @@ uint32_t __analogReadMilliVolts(uint8_t pin) {
.bitwidth = __analogWidth,
};
err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle);
#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
#elif ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
adc_cali_line_fitting_config_t cali_config = {
.unit_id = adc_unit,
.bitwidth = __analogWidth,
.atten = __analogAttenuation,
};
err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle);
#else
log_e("ADC Calibration scheme is not supported!");
return value;
#endif
if (err != ESP_OK) {
log_e("adc_cali_create_scheme_x failed!");
Expand Down Expand Up @@ -360,7 +398,7 @@ static uint8_t __adcContinuousAtten = ADC_11db;
static uint8_t __adcContinuousWidth = SOC_ADC_DIGI_MAX_BITWIDTH;

static uint8_t used_adc_channels = 0;
adc_continuous_data_t *adc_result = NULL;
adc_continuous_result_t *adc_result = NULL;

static bool adcContinuousDetachBus(void *adc_unit_number) {
adc_unit_t adc_unit = (adc_unit_t)adc_unit_number - 1;
Expand All @@ -379,11 +417,14 @@ static bool adcContinuousDetachBus(void *adc_unit_number) {
if (err != ESP_OK) {
return false;
}
#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4))
#elif ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
err = adc_cali_delete_scheme_line_fitting(adc_handle[adc_unit].adc_cali_handle);
if (err != ESP_OK) {
return false;
}
#else
log_e("ADC Calibration scheme is not supported!");
return false;
#endif
}
adc_handle[adc_unit].adc_cali_handle = NULL;
Expand Down Expand Up @@ -536,7 +577,7 @@ bool analogContinuous(const uint8_t pins[], size_t pins_count, uint32_t conversi
}

//Allocate and prepare result structure for adc readings
adc_result = malloc(pins_count * sizeof(adc_continuous_data_t));
adc_result = malloc(pins_count * sizeof(adc_continuous_result_t));
for (int k = 0; k < pins_count; k++) {
adc_result[k].pin = pins[k];
adc_result[k].channel = channel[k];
Expand All @@ -552,13 +593,16 @@ bool analogContinuous(const uint8_t pins[], size_t pins_count, uint32_t conversi
.bitwidth = __adcContinuousWidth,
};
err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle);
#elif (!defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)) //ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
#elif ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
adc_cali_line_fitting_config_t cali_config = {
.unit_id = adc_unit,
.bitwidth = __adcContinuousWidth,
.atten = __adcContinuousAtten,
};
err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_handle[adc_unit].adc_cali_handle);
#else
log_e("ADC Calibration scheme is not supported!");
return false;
#endif
if (err != ESP_OK) {
log_e("adc_cali_create_scheme_x failed!");
Expand All @@ -577,7 +621,7 @@ bool analogContinuous(const uint8_t pins[], size_t pins_count, uint32_t conversi
return true;
}

bool analogContinuousRead(adc_continuous_data_t **buffer, uint32_t timeout_ms) {
bool analogContinuousRead(adc_continuous_result_t **buffer, uint32_t timeout_ms) {
if (adc_handle[ADC_UNIT_1].adc_continuous_handle != NULL) {
uint32_t bytes_read = 0;
uint32_t read_raw[used_adc_channels];
Expand Down
4 changes: 2 additions & 2 deletions cores/esp32/esp32-hal-adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typedef struct {
uint8_t channel; /*!<ADC channel */
int avg_read_raw; /*!<ADC average raw data */
int avg_read_mvolts; /*!<ADC average voltage in mV */
} adc_continuous_data_t;
} adc_continuous_result_t;

/*
* Setup ADC continuous peripheral
Expand All @@ -96,7 +96,7 @@ bool analogContinuous(const uint8_t pins[], size_t pins_count, uint32_t conversi
/*
* Read ADC continuous conversion data
* */
bool analogContinuousRead(adc_continuous_data_t **buffer, uint32_t timeout_ms);
bool analogContinuousRead(adc_continuous_result_t **buffer, uint32_t timeout_ms);

/*
* Start ADC continuous conversions
Expand Down
10 changes: 5 additions & 5 deletions docs/en/api/adc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ ADC Continuous mode is an API designed for performing analog conversions on mult
with the feature of receiving a callback upon completion of these conversions to access the results.

This API allows you to specify the desired number of conversions per pin within a single cycle, along with its corresponding sampling rate.
The outcome of the ``analogContinuousRead`` function is an array of ``adc_continuous_data_t`` structures.
The outcome of the ``analogContinuousRead`` function is an array of ``adc_continuous_result_t`` structures.
These structures hold both the raw average value and the average value in millivolts for each pin.

analogContinuous
Expand All @@ -186,7 +186,7 @@ If ``false`` is returned, error occurs and ADC continuous was not configured.
analogContinuousRead
^^^^^^^^^^^^^^^^^^^^

This function is used to read ADC continuous data to the result buffer. The result buffer is an array of ``adc_continuous_data_t``.
This function is used to read ADC continuous data to the result buffer. The result buffer is an array of ``adc_continuous_result_t``.

.. code-block:: arduino

Expand All @@ -195,13 +195,13 @@ This function is used to read ADC continuous data to the result buffer. The resu
uint8_t channel; /*!<ADC channel */
int avg_read_raw; /*!<ADC average raw data */
int avg_read_mvolts; /*!<ADC average voltage in mV */
} adc_continuous_data_t;
} adc_continuous_result_t;

.. code-block:: arduino

bool analogContinuousRead(adc_continuous_data_t ** buffer, uint32_t timeout_ms);
bool analogContinuousRead(adc_continuous_result_t ** buffer, uint32_t timeout_ms);

* ``buffer`` conversion result buffer to read from ADC in adc_continuous_data_t format.
* ``buffer`` conversion result buffer to read from ADC in adc_continuous_result_t format.
* ``timeout_ms`` time to wait for data in milliseconds.

This function will return ``true`` if reading is successful and ``buffer`` is filled with data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ uint8_t adc_pins_count = sizeof(adc_pins) / sizeof(uint8_t);
volatile bool adc_coversion_done = false;

// Result structure for ADC Continuous reading
adc_continuous_data_t *result = NULL;
adc_continuous_result_t *result = NULL;

// ISR Function that will be triggered when ADC conversion is done
void ARDUINO_ISR_ATTR adcComplete() {
Expand Down
Loading
Loading