mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 09:39:10 -04:00
Merge branch 'feature/adc_oneshot_api_calibrated_result' into 'master'
esp_adc: added an all-in-one API to get calibrated voltage Closes IDF-6651 See merge request espressif/esp-idf!22055
This commit is contained in:
commit
8f82c5cdee
@ -226,6 +226,15 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t adc_oneshot_get_calibrated_result(adc_oneshot_unit_handle_t handle, adc_cali_handle_t cali_handle, adc_channel_t chan, int *cali_result)
|
||||
{
|
||||
int raw = 0;
|
||||
ESP_RETURN_ON_ERROR(adc_oneshot_read(handle, chan, &raw), TAG, "adc oneshot read fail");
|
||||
ESP_LOGD(TAG, "raw: 0d%d", raw);
|
||||
ESP_RETURN_ON_ERROR(adc_cali_raw_to_voltage(cali_handle, raw, cali_result), TAG, "adc calibration fail");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#define ADC_GET_IO_NUM(unit, channel) (adc_channel_io_map[unit][channel])
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -10,6 +10,8 @@
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "hal/adc_types.h"
|
||||
#include "adc_cali.h"
|
||||
#include "adc_cali_scheme.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -125,6 +127,24 @@ esp_err_t adc_oneshot_io_to_channel(int io_num, adc_unit_t *unit_id, adc_channel
|
||||
*/
|
||||
esp_err_t adc_oneshot_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, int *io_num);
|
||||
|
||||
/**
|
||||
* @brief Convenience function to get ADC calibrated result
|
||||
*
|
||||
* This is an all-in-one function which does:
|
||||
* - oneshot read ADC raw result
|
||||
* - calibrate the raw result and convert it into calibrated result (in mV)
|
||||
*
|
||||
* @param[in] handle ADC oneshot handle, you should call adc_oneshot_new_unit() to get this handle
|
||||
* @param[in] cali_handle ADC calibration handle, you should call adc_cali_create_scheme_x() in adc_cali_scheme.h to create a handle
|
||||
* @param[in] chan ADC channel
|
||||
* @param[out] cali_result Calibrated ADC result (in mV)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* Other return errors from adc_oneshot_read() and adc_cali_raw_to_voltage()
|
||||
*/
|
||||
esp_err_t adc_oneshot_get_calibrated_result(adc_oneshot_unit_handle_t handle, adc_cali_handle_t cali_handle, adc_channel_t chan, int *cali_result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user