#include "esp_adc_cal.h"
/* ----------------------------- Configuration ------------------------------ */
-
#ifdef CONFIG_ADC_CAL_EFUSE_TP_ENABLE
#define EFUSE_TP_ENABLED 1
#else
#else
#define LUT_ENABLED 0
#endif
-/*
- * By default, ESP32s that have Two Point values burned to BLOCK3 will also
- * set the EFUSE_BLK3_PART_RESERVE flag to indicate this. However, some ESP32s
- * with Two Point values do not set this flag. Set the following definition
- * to 0 if this is the case.
+
+/* ESP32s with both Two Point Values and Vref burned into eFuse are required to
+ * also also burn the EFUSE_BLK3_PART_RESERVE flag. A limited set of ESP32s
+ * (not available through regular sales channel) DO NOT have the
+ * EFUSE_BLK3_PART_RESERVE burned. Moreover, this set of ESP32s represents Vref
+ * in Two's Complement format. If this is the case, modify the preprocessor
+ * definitions below as follows...
+ * #define CHECK_BLK3_FLAG 0 //Do not check BLK3 flag as it is not burned
+ * #define VREF_FORMAT 1 //eFuse Vref is in Two's Complement format
*/
#define CHECK_BLK3_FLAG 1
-/*
- * By default, Vref is burned into eFuse of ESP32s in Sign-Magnitude format.
- * However some chips have Vref burned in two's complement format. Set the following
- * definition to 1 if this is the case.
- */
#define VREF_FORMAT 0
/* ------------------------------ eFuse Access ----------------------------- */
-
-#define BLK3_RESERVED_REG EFUSE_BLK0_RDATA4_REG
+#define BLK3_RESERVED_REG EFUSE_BLK0_RDATA3_REG
#define VREF_REG EFUSE_BLK0_RDATA4_REG
#define VREF_MASK 0x1F
#define TP_STEP_SIZE 4
/* ----------------------- Raw to Voltage Constants ------------------------- */
-
#define LIN_COEFF_A_SCALE 65536
#define LIN_COEFF_A_ROUND (LIN_COEFF_A_SCALE/2)
})
/* ------------------------ Characterization Constants ---------------------- */
-
static const uint32_t adc1_tp_atten_scale[4] = {65504, 86975, 120389, 224310};
static const uint32_t adc2_tp_atten_scale[4] = {65467, 86861, 120416, 224708};
static const uint32_t adc1_tp_atten_offset[4] = {0, 1, 27, 54};
2971, 2996, 3020, 3043, 3067, 3092, 3116, 3139, 3162, 3185};
/* ----------------------- EFuse Access Functions --------------------------- */
-
static bool check_efuse_vref()
{
//Check if Vref is burned in eFuse
}
/* ----------------------- Characterization Functions ----------------------- */
-
static void characterize_using_two_point(adc_unit_t adc_num,
adc_atten_t atten,
uint32_t high,
}
/* ------------------------ Conversion Functions --------------------------- */
-
static uint32_t calculate_voltage_linear(uint32_t adc_reading, uint32_t coeff_a, uint32_t coeff_b)
{
//Where voltage = coeff_a * adc_reading + coeff_b
}
/* ------------------------- Public API ------------------------------------- */
-
esp_err_t esp_adc_cal_check_efuse(esp_adc_cal_value_t source)
{
if (source == ESP_ADC_CAL_VAL_EFUSE_TP) {
chars->adc_num = adc_num;
chars->atten = atten;
chars->bit_width = bit_width;
- chars->vref = (efuse_vref_present) ? read_efuse_vref() : default_vref;
+ chars->vref = (EFUSE_VREF_ENABLED && efuse_vref_present) ? read_efuse_vref() : default_vref;
//Initialize fields for lookup table if necessary
if (LUT_ENABLED && atten == ADC_ATTEN_DB_11) {
chars->low_curve = (adc_num == ADC_UNIT_1) ? lut_adc1_low : lut_adc2_low;
}
/* ------------------------ Deprecated API --------------------------------- */
-
void esp_adc_cal_get_characteristics(uint32_t vref,
adc_atten_t atten,
adc_bits_width_t bit_width,