From 4d246baa46d0b21ef51733db00e1cbc0c6dcb2f5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 4 Nov 2021 13:28:30 +0100 Subject: [PATCH] esp_adc_cal: update h2 code to use esp_check.h Same changes as in commit c45c6f52f for c3. --- components/esp_adc_cal/esp_adc_cal_esp32h2.c | 22 +++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/components/esp_adc_cal/esp_adc_cal_esp32h2.c b/components/esp_adc_cal/esp_adc_cal_esp32h2.c index c87415bbfa..265a88782b 100644 --- a/components/esp_adc_cal/esp_adc_cal_esp32h2.c +++ b/components/esp_adc_cal/esp_adc_cal_esp32h2.c @@ -10,19 +10,12 @@ #include "esp_types.h" #include "esp_err.h" #include "esp_log.h" +#include "esp_check.h" #include "driver/adc.h" #include "hal/adc_ll.h" #include "esp_efuse_rtc_calib.h" #include "esp_adc_cal.h" - -#define ADC_CALIB_CHECK(cond, err_msg, ret) do {\ - if (!(cond)) { \ - ESP_LOGE(LOG_TAG, err_msg); \ - return (ret); \ - } \ - } while(0) - const static char LOG_TAG[] = "adc_calib"; @@ -102,13 +95,13 @@ esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, esp_err_t ret; adc_calib_parsed_info efuse_parsed_data = {0}; // Check parameters - ADC_CALIB_CHECK(adc_num == ADC_UNIT_1 || adc_num == ADC_UNIT_2, "Invalid unit num", ESP_ADC_CAL_VAL_NOT_SUPPORTED); - ADC_CALIB_CHECK(chars != NULL, "Invalid characteristic", ESP_ADC_CAL_VAL_NOT_SUPPORTED); - ADC_CALIB_CHECK(bit_width == ADC_WIDTH_BIT_12, "Invalid bit_width", ESP_ADC_CAL_VAL_NOT_SUPPORTED); - ADC_CALIB_CHECK(atten < 4, "Invalid attenuation", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + ESP_RETURN_ON_FALSE(adc_num == ADC_UNIT_1 || adc_num == ADC_UNIT_2, ESP_ADC_CAL_VAL_NOT_SUPPORTED, LOG_TAG, "Invalid unit num"); + ESP_RETURN_ON_FALSE(chars != NULL, ESP_ADC_CAL_VAL_NOT_SUPPORTED, LOG_TAG, "Ivalid characteristic"); + ESP_RETURN_ON_FALSE(bit_width == ADC_WIDTH_BIT_12, ESP_ADC_CAL_VAL_NOT_SUPPORTED, LOG_TAG, "Invalid bit_width"); + ESP_RETURN_ON_FALSE(atten < 4, ESP_ADC_CAL_VAL_NOT_SUPPORTED, LOG_TAG, "Invalid attenuation"); int version_num = esp_efuse_rtc_calib_get_ver(); - ADC_CALIB_CHECK(version_num == 1, "No calibration efuse burnt", ESP_ADC_CAL_VAL_NOT_SUPPORTED); + ESP_RETURN_ON_FALSE(version_num == 1, ESP_ADC_CAL_VAL_NOT_SUPPORTED, LOG_TAG, "No calibration efuse burnt"); memset(chars, 0, sizeof(esp_adc_cal_characteristics_t)); @@ -132,7 +125,6 @@ esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, uint32_t esp_adc_cal_raw_to_voltage(uint32_t adc_reading, const esp_adc_cal_characteristics_t *chars) { - ADC_CALIB_CHECK(chars != NULL, "No characteristic input.", ESP_ERR_INVALID_ARG); - + assert(chars != NULL); return adc_reading * chars->coeff_a / coeff_a_scaling + chars->coeff_b / coeff_b_scaling; }