1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/esp32: remove ESP-IDF adc interface API

This commit is contained in:
Gunar Schorcht 2023-03-27 01:34:36 +02:00
parent 97ad22eed6
commit d93972c369
4 changed files with 14 additions and 141 deletions

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2022 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_esp32_esp_idf_api
* @{
*
* @file
* @brief Interface for the ESP-IDF ADC HAL API
*
* @author Gunar Schorcht <gunar@schorcht.net>
* @}
*/
#include <stdbool.h>
#include "driver/adc.h"
void esp_idf_adc_power_acquire(void)
{
adc_power_acquire();
}
void esp_idf_adc_power_release(void)
{
adc_power_release();
}
esp_err_t esp_idf_adc1_config_width(adc_bits_width_t width_bit)
{
return adc1_config_width(width_bit);
}
esp_err_t esp_idf_adc1_config_channel_atten(adc_channel_t channel,
adc_atten_t atten)
{
return adc1_config_channel_atten(channel, atten);
}
int esp_idf_adc1_get_raw(adc1_channel_t channel)
{
return adc1_get_raw(channel);
}
esp_err_t esp_idf_adc2_config_channel_atten(adc_channel_t channel,
adc_atten_t atten)
{
return adc2_config_channel_atten(channel, atten);
}
esp_err_t esp_idf_adc2_get_raw(adc2_channel_t channel,
adc_bits_width_t width_bit, int *raw_out)
{
return adc2_get_raw(channel, width_bit, raw_out);
}
esp_err_t esp_idf_adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio)
{
return adc_vref_to_gpio(adc_unit, gpio);
}

View File

@ -34,10 +34,9 @@ extern "C" {
#include "periph/adc.h"
#include "periph/gpio.h"
#include "driver/adc.h"
#include "hal/adc_types.h"
#include "esp_idf_api/adc.h"
/**
* @brief Attenuations that can be set for ADC lines
*
@ -112,9 +111,9 @@ int adc_line_vref_to_gpio(adc_t line, gpio_t gpio);
* @return 0 on success
* @return -1 on invalid ADC line
*/
static inline int adc_vref_to_gpio25 (void)
static inline int adc_vref_to_gpio25(void)
{
return esp_idf_adc_vref_to_gpio(ADC_UNIT_2, GPIO25);
return adc_vref_to_gpio(ADC_UNIT_2, GPIO25);
}
#endif

View File

@ -1,57 +0,0 @@
/*
* Copyright (C) 2022 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_esp32_esp_idf_api
* @{
*
* @file
* @brief Interface for the ESP-IDF ADC HAL API
*
* @author Gunar Schorcht <gunar@schorcht.net>
* @}
*/
#ifndef ESP_IDF_API_ADC_H
#define ESP_IDF_API_ADC_H
#include "esp_err.h"
#include "hal/adc_types.h"
#include "hal/gpio_types.h"
#ifndef DOXYGEN /* Hide implementation details from doxygen */
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name ESP-IDF interface mapper functions
* @{
*/
/** @} */
void esp_idf_adc_power_acquire(void);
void esp_idf_adc_power_release(void);
esp_err_t esp_idf_adc1_config_width(adc_bits_width_t width_bit);
esp_err_t esp_idf_adc1_config_channel_atten(adc_channel_t channel,
adc_atten_t atten);
int esp_idf_adc1_get_raw(adc_channel_t channel);
esp_err_t esp_idf_adc2_config_channel_atten(adc_channel_t channel,
adc_atten_t atten);
esp_err_t esp_idf_adc2_get_raw(adc_channel_t channel,
adc_bits_width_t width_bit, int *raw_out);
esp_err_t esp_idf_adc_vref_to_gpio(adc_unit_t adc_unit, gpio_num_t gpio);
#ifdef __cplusplus
}
#endif
#endif /* DOXYGEN */
#endif /* ESP_IDF_API_ADC_H */

View File

@ -36,7 +36,7 @@
#include "esp_common.h"
#include "gpio_arch.h"
#include "esp_idf_api/adc.h"
#include "driver/adc.h"
#define ENABLE_DEBUG 0
#include "debug.h"
@ -134,15 +134,13 @@ int adc_init(adc_t line)
/* initialize the ADC1 unit if needed */
_adc1_ctrl_init();
/* set the attenuation and configure its associated GPIO pin mux */
esp_idf_adc1_config_channel_atten(_adc_hw[rtcio].adc_channel,
ADC_ATTEN_DB_11);
adc1_config_channel_atten(_adc_hw[rtcio].adc_channel, ADC_ATTEN_DB_11);
}
else if (_adc_hw[rtcio].adc_ctrl == ADC_UNIT_2) {
/* initialize the ADC2 unit if needed */
_adc2_ctrl_init();
/* set the attenuation and configure its associated GPIO pin mux */
esp_idf_adc2_config_channel_atten(_adc_hw[rtcio].adc_channel,
ADC_ATTEN_DB_11);
adc2_config_channel_atten(_adc_hw[rtcio].adc_channel, ADC_ATTEN_DB_11);
}
else {
return -1;
@ -166,15 +164,15 @@ int32_t adc_sample(adc_t line, adc_res_t res)
int raw;
if (_adc_hw[rtcio].adc_ctrl == ADC_UNIT_1) {
esp_idf_adc1_config_width(_adc_esp_res_map[res].res);
raw = esp_idf_adc1_get_raw(_adc_hw[rtcio].adc_channel);
adc1_config_width(_adc_esp_res_map[res].res);
raw = adc1_get_raw(_adc_hw[rtcio].adc_channel);
if (raw < 0) {
return -1;
}
}
else if (_adc_hw[rtcio].adc_ctrl == ADC_UNIT_2) {
if (esp_idf_adc2_get_raw(_adc_hw[rtcio].adc_channel,
_adc_esp_res_map[res].res, &raw) < 0) {
if (adc2_get_raw(_adc_hw[rtcio].adc_channel,
_adc_esp_res_map[res].res, &raw) < 0) {
return -1;
}
}
@ -191,12 +189,10 @@ int adc_set_attenuation(adc_t line, adc_atten_t atten)
assert(rtcio != RTCIO_NA);
if (_adc_hw[rtcio].adc_ctrl == ADC_UNIT_1) {
return esp_idf_adc1_config_channel_atten(_adc_hw[rtcio].adc_channel,
atten);
return adc1_config_channel_atten(_adc_hw[rtcio].adc_channel, atten);
}
else if (_adc_hw[rtcio].adc_ctrl == ADC_UNIT_2) {
return esp_idf_adc2_config_channel_atten(_adc_hw[rtcio].adc_channel,
atten);
return adc2_config_channel_atten(_adc_hw[rtcio].adc_channel, atten);
}
return -1;
@ -221,10 +217,10 @@ int adc_line_vref_to_gpio(adc_t line, gpio_t gpio)
esp_err_t res = ESP_OK;
if (_adc_hw[rtcio_vref].adc_ctrl == ADC_UNIT_1) {
res = esp_idf_adc_vref_to_gpio(ADC_UNIT_1, gpio);
res = adc_vref_to_gpio(ADC_UNIT_1, gpio);
}
else if (_adc_hw[rtcio_vref].adc_ctrl == ADC_UNIT_2) {
res = esp_idf_adc_vref_to_gpio(ADC_UNIT_2, gpio);
res = adc_vref_to_gpio(ADC_UNIT_2, gpio);
}
if (res != ESP_OK) {
LOG_TAG_ERROR("adc", "Could not route Vref of ADC line %d to GPIO%d\n",