mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
feat(gpio): add gpio_config_as_analog API
This commit is contained in:
parent
5b75572f23
commit
52c0278361
@ -17,9 +17,8 @@
|
||||
#include "esp_pm.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "sys/lock.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_private/adc_share_hw_ctrl.h"
|
||||
#include "esp_private/sar_periph_ctrl.h"
|
||||
#include "adc1_private.h"
|
||||
@ -175,7 +174,6 @@ static void adc_rtc_chan_init(adc_unit_t adc_unit)
|
||||
esp_err_t adc_common_gpio_init(adc_unit_t adc_unit, adc_channel_t channel)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(adc_unit), ESP_ERR_INVALID_ARG, ADC_TAG, "invalid channel");
|
||||
#if ADC_LL_RTC_GPIO_SUPPORTED
|
||||
gpio_num_t gpio_num = 0;
|
||||
//If called with `ADC_UNIT_BOTH (ADC_UNIT_1 | ADC_UNIT_2)`, both if blocks will be run
|
||||
if (adc_unit == ADC_UNIT_1) {
|
||||
@ -186,13 +184,7 @@ esp_err_t adc_common_gpio_init(adc_unit_t adc_unit, adc_channel_t channel)
|
||||
} else {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_init(gpio_num), ADC_TAG, "rtc_gpio_init fail");
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED), ADC_TAG, "rtc_gpio_set_direction fail");
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_pulldown_dis(gpio_num), ADC_TAG, "rtc_gpio_pulldown_dis fail");
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_pullup_dis(gpio_num), ADC_TAG, "rtc_gpio_pullup_dis fail");
|
||||
#endif
|
||||
return ESP_OK;
|
||||
return gpio_config_as_analog(gpio_num);
|
||||
}
|
||||
|
||||
esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en)
|
||||
@ -678,7 +670,6 @@ static int8_t adc_digi_get_io_num(adc_unit_t adc_unit, uint8_t adc_channel)
|
||||
static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint64_t gpio_mask = 0;
|
||||
uint32_t n = 0;
|
||||
int8_t io = 0;
|
||||
|
||||
@ -688,18 +679,11 @@ static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask)
|
||||
if (io < 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
gpio_mask |= BIT64(io);
|
||||
gpio_config_as_analog(io);
|
||||
}
|
||||
channel_mask = channel_mask >> 1;
|
||||
n++;
|
||||
}
|
||||
|
||||
gpio_config_t cfg = {
|
||||
.pin_bit_mask = gpio_mask,
|
||||
.mode = GPIO_MODE_DISABLE,
|
||||
};
|
||||
ret = gpio_config(&cfg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -7,7 +7,7 @@
|
||||
#include <string.h>
|
||||
#include "esp_check.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "driver/dac_types_legacy.h"
|
||||
#include "soc/dac_periph.h"
|
||||
#include "hal/gpio_types.h"
|
||||
@ -36,10 +36,7 @@ static esp_err_t dac_rtc_pad_init(dac_channel_t channel)
|
||||
|
||||
gpio_num_t gpio_num = 0;
|
||||
dac_pad_get_io_num(channel, &gpio_num);
|
||||
rtc_gpio_init(gpio_num);
|
||||
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED);
|
||||
rtc_gpio_pullup_dis(gpio_num);
|
||||
rtc_gpio_pulldown_dis(gpio_num);
|
||||
gpio_config_as_analog(gpio_num);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -111,17 +111,17 @@ void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool level)
|
||||
{
|
||||
TEST_ASSERT(channel < SOC_ADC_CHANNEL_NUM(unit) && "invalid channel");
|
||||
|
||||
#if !ADC_LL_RTC_GPIO_SUPPORTED
|
||||
uint32_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY)));
|
||||
#else
|
||||
gpio_num_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
if (level) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_dis(io_num));
|
||||
} else {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_dis(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(io_num)) {
|
||||
if (level) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_dis(io_num));
|
||||
} else {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_dis(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -15,9 +15,8 @@
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/timers.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "esp_private/rtc_ctrl.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "hal/touch_sensor_legacy_types.h"
|
||||
#include "hal/touch_sensor_hal.h"
|
||||
|
||||
@ -121,11 +120,7 @@ esp_err_t touch_pad_io_init(touch_pad_t touch_num)
|
||||
{
|
||||
TOUCH_CHANNEL_CHECK(touch_num);
|
||||
gpio_num_t gpio_num = TOUCH_GET_IO_NUM(touch_num);
|
||||
rtc_gpio_init(gpio_num);
|
||||
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED);
|
||||
rtc_gpio_pulldown_dis(gpio_num);
|
||||
rtc_gpio_pullup_dis(gpio_num);
|
||||
return ESP_OK;
|
||||
return gpio_config_as_analog(gpio_num);
|
||||
}
|
||||
|
||||
esp_err_t touch_pad_fsm_start(void)
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "esp_private/adc_share_hw_ctrl.h"
|
||||
#include "esp_private/sar_periph_ctrl.h"
|
||||
#include "esp_clk_tree.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "esp_adc/adc_continuous.h"
|
||||
#include "hal/adc_types.h"
|
||||
#include "hal/adc_hal.h"
|
||||
@ -132,15 +132,15 @@ static IRAM_ATTR bool adc_dma_intr(adc_continuous_ctx_t *adc_digi_ctx)
|
||||
|
||||
static int8_t adc_digi_get_io_num(adc_unit_t adc_unit, uint8_t adc_channel)
|
||||
{
|
||||
assert(adc_unit < SOC_ADC_PERIPH_NUM);
|
||||
uint8_t adc_n = (adc_unit == ADC_UNIT_1) ? 0 : 1;
|
||||
return adc_channel_io_map[adc_n][adc_channel];
|
||||
if (adc_unit >= 0 && adc_unit < SOC_ADC_PERIPH_NUM) {
|
||||
return adc_channel_io_map[adc_unit][adc_channel];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint64_t gpio_mask = 0;
|
||||
uint32_t n = 0;
|
||||
int8_t io = 0;
|
||||
|
||||
@ -150,18 +150,11 @@ static esp_err_t adc_digi_gpio_init(adc_unit_t adc_unit, uint16_t channel_mask)
|
||||
if (io < 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
gpio_mask |= BIT64(io);
|
||||
gpio_config_as_analog(io);
|
||||
}
|
||||
channel_mask = channel_mask >> 1;
|
||||
n++;
|
||||
}
|
||||
|
||||
gpio_config_t cfg = {
|
||||
.pin_bit_mask = gpio_mask,
|
||||
.mode = GPIO_MODE_DISABLE,
|
||||
};
|
||||
ret = gpio_config(&cfg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,7 @@
|
||||
#include "esp_check.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_clk_tree.h"
|
||||
#include "esp_private/adc_private.h"
|
||||
@ -293,27 +292,7 @@ esp_err_t adc_oneshot_get_calibrated_result(adc_oneshot_unit_handle_t handle, ad
|
||||
static esp_err_t s_adc_io_init(adc_unit_t unit, adc_channel_t channel)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(unit), ESP_ERR_INVALID_ARG, TAG, "invalid channel");
|
||||
|
||||
#if !ADC_LL_RTC_GPIO_SUPPORTED
|
||||
|
||||
uint32_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
gpio_config_t cfg = {
|
||||
.pin_bit_mask = BIT64(io_num),
|
||||
.mode = GPIO_MODE_DISABLE,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(gpio_config(&cfg), TAG, "IO config fail");
|
||||
#else
|
||||
gpio_num_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_init(io_num), TAG, "IO config fail");
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_DISABLED), TAG, "IO config fail");
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_pulldown_dis(io_num), TAG, "IO config fail");
|
||||
ESP_RETURN_ON_ERROR(rtc_gpio_pullup_dis(io_num), TAG, "IO config fail");
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
return gpio_config_as_analog(ADC_GET_IO_NUM(unit, channel));
|
||||
}
|
||||
|
||||
static bool s_adc_unit_claim(adc_unit_t unit)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -99,19 +99,18 @@ void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool level)
|
||||
{
|
||||
TEST_ASSERT(channel < SOC_ADC_CHANNEL_NUM(unit) && "invalid channel");
|
||||
|
||||
#if !ADC_LL_RTC_GPIO_SUPPORTED
|
||||
uint32_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY)));
|
||||
#else
|
||||
gpio_num_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
if (level) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_dis(io_num));
|
||||
} else {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_dis(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(io_num)) {
|
||||
if (level) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_dis(io_num));
|
||||
} else {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_dis(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
}
|
||||
}
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -120,14 +119,12 @@ void test_adc_set_io_middle(adc_unit_t unit, adc_channel_t channel)
|
||||
TEST_ASSERT(channel < SOC_ADC_CHANNEL_NUM(unit) && "invalid channel");
|
||||
|
||||
uint32_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
|
||||
#if !ADC_LL_RTC_GPIO_SUPPORTED
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, GPIO_PULLUP_PULLDOWN));
|
||||
#else
|
||||
TEST_ESP_OK(rtc_gpio_init(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_DISABLED));
|
||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(io_num)) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
}
|
||||
#endif
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -25,7 +25,7 @@
|
||||
#include "soc/ana_cmpr_periph.h"
|
||||
#include "hal/ana_cmpr_ll.h"
|
||||
#include "driver/ana_cmpr.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "esp_private/io_mux.h"
|
||||
#include "esp_private/esp_clk.h"
|
||||
|
||||
@ -96,18 +96,11 @@ static void IRAM_ATTR s_ana_cmpr_default_intr_handler(void *usr_data)
|
||||
|
||||
static esp_err_t s_ana_cmpr_init_gpio(ana_cmpr_handle_t cmpr, bool is_external_ref)
|
||||
{
|
||||
uint64_t pin_mask = BIT64(ana_cmpr_periph[cmpr->unit].src_gpio);
|
||||
if (is_external_ref) {
|
||||
pin_mask |= BIT64(ana_cmpr_periph[cmpr->unit].ext_ref_gpio);
|
||||
esp_err_t err = gpio_config_as_analog(ana_cmpr_periph[cmpr->unit].src_gpio);
|
||||
if (err == ESP_OK && is_external_ref) {
|
||||
err = gpio_config_as_analog(ana_cmpr_periph[cmpr->unit].ext_ref_gpio);
|
||||
}
|
||||
gpio_config_t ana_cmpr_gpio_cfg = {
|
||||
.pin_bit_mask = pin_mask,
|
||||
.mode = GPIO_MODE_DISABLE,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
return gpio_config(&ana_cmpr_gpio_cfg);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t ana_cmpr_new_unit(const ana_cmpr_config_t *config, ana_cmpr_handle_t *ret_cmpr)
|
||||
|
@ -50,8 +50,6 @@ TEST_CASE("ana_cmpr_unit_install_uninstall", "[ana_cmpr]")
|
||||
|
||||
TEST_CASE("ana_cmpr_internal_reference", "[ana_cmpr]")
|
||||
{
|
||||
int src_chan = test_init_src_chan_gpio(TEST_ANA_CMPR_UNIT_ID);
|
||||
|
||||
uint32_t cnt = 0;
|
||||
ana_cmpr_handle_t cmpr = NULL;
|
||||
ana_cmpr_config_t config = {
|
||||
@ -62,6 +60,7 @@ TEST_CASE("ana_cmpr_internal_reference", "[ana_cmpr]")
|
||||
.flags.io_loop_back = 1,
|
||||
};
|
||||
TEST_ESP_OK(ana_cmpr_new_unit(&config, &cmpr));
|
||||
int src_chan = test_init_src_chan_gpio(TEST_ANA_CMPR_UNIT_ID);
|
||||
ana_cmpr_internal_ref_config_t ref_cfg = {
|
||||
.ref_volt = ANA_CMPR_REF_VOLT_50_PCT_VDD,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -7,6 +7,7 @@
|
||||
#include "test_ana_cmpr.h"
|
||||
#include "hal/gpio_ll.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
bool IRAM_ATTR test_ana_cmpr_on_cross_callback(ana_cmpr_handle_t cmpr, const ana_cmpr_cross_event_data_t *edata, void *user_ctx)
|
||||
@ -21,15 +22,8 @@ int test_init_src_chan_gpio(int unit_id)
|
||||
int src_chan_num = -1;
|
||||
TEST_ESP_OK(ana_cmpr_get_gpio(unit_id, ANA_CMPR_SOURCE_CHAN, &src_chan_num));
|
||||
TEST_ASSERT(src_chan_num > 0);
|
||||
gpio_config_t io_conf = {
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = (1ULL << src_chan_num),
|
||||
.pull_down_en = false,
|
||||
.pull_up_en = false,
|
||||
};
|
||||
TEST_ESP_OK(gpio_config(&io_conf));
|
||||
TEST_ESP_OK(gpio_set_level(src_chan_num, 0));
|
||||
TEST_ESP_OK(gpio_output_enable(src_chan_num));
|
||||
return src_chan_num;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -11,7 +11,7 @@
|
||||
#include "soc/dac_periph.h"
|
||||
#include "hal/dac_types.h"
|
||||
#include "hal/dac_ll.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "esp_check.h"
|
||||
#include "dac_priv_common.h"
|
||||
|
||||
@ -70,10 +70,7 @@ esp_err_t dac_priv_enable_channel(dac_channel_t chan_id)
|
||||
ESP_RETURN_ON_FALSE(s_dac_chan[chan_id].in_use, ESP_ERR_INVALID_STATE, TAG, "the channel is not registered");
|
||||
|
||||
gpio_num_t gpio_num = (gpio_num_t)dac_periph_signal.dac_channel_io_num[chan_id];
|
||||
rtc_gpio_init(gpio_num);
|
||||
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED);
|
||||
rtc_gpio_pullup_dis(gpio_num);
|
||||
rtc_gpio_pulldown_dis(gpio_num);
|
||||
gpio_config_as_analog(gpio_num);
|
||||
DAC_RTC_ENTER_CRITICAL();
|
||||
dac_ll_power_on(chan_id);
|
||||
dac_ll_rtc_sync_by_adc(false);
|
||||
@ -87,8 +84,6 @@ esp_err_t dac_priv_disable_channel(dac_channel_t chan_id)
|
||||
ESP_RETURN_ON_FALSE(chan_id < SOC_DAC_CHAN_NUM, ESP_ERR_INVALID_ARG, TAG, "channel id is invalid");
|
||||
ESP_RETURN_ON_FALSE(s_dac_chan[chan_id].in_use, ESP_ERR_INVALID_STATE, TAG, "the channel is not registered");
|
||||
|
||||
gpio_num_t gpio_num = (gpio_num_t)dac_periph_signal.dac_channel_io_num[chan_id];
|
||||
rtc_gpio_deinit(gpio_num);
|
||||
DAC_RTC_ENTER_CRITICAL();
|
||||
dac_ll_power_down(chan_id);
|
||||
DAC_RTC_EXIT_CRITICAL();
|
||||
|
@ -23,3 +23,7 @@ If the signal is routed through IO MUX to the pin, then call `gpio_iomux_out` to
|
||||
If the signal is routed through GPIO Matrix to the pin, then first call `gpio_func_sel` to let the pin use `PIN_FUNC_GPIO` function, follow by calling `gpio_input_enable` and `esp_rom_gpio_connect_in_signal` to enable the input and connect the signal to the pin.
|
||||
|
||||
When a peripheral driver does de-initialization, to de-configure the pin as the peripheral signal input, use `esp_rom_gpio_connect_in_signal` to connect the signal to CONST_ONE or CONST_ZERO, so that it is disconnected from the pin. It is not desired to call `gpio_input_disable`, because there might be other drivers still using this pin as an input.
|
||||
|
||||
# Configure an IO as analog function
|
||||
|
||||
When the pin is used for analog purpose, the pin needs to be left floating, so that the external analog signal is directly connected to internal analog signal. A call to `gpio_config_as_analog` will handle all the necessary IO configurations.
|
||||
|
@ -96,6 +96,16 @@ esp_err_t gpio_od_disable(gpio_num_t gpio_num);
|
||||
*/
|
||||
esp_err_t gpio_od_enable(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Configure the pin to be used for analog purpose (such as ADC, touch, etc.)
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG GPIO number error
|
||||
*/
|
||||
esp_err_t gpio_config_as_analog(gpio_num_t gpio_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -433,6 +433,26 @@ esp_err_t gpio_config(const gpio_config_t *pGPIOConfig)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t gpio_config_as_analog(gpio_num_t gpio_num)
|
||||
{
|
||||
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
// To be used for analog function, the pin needs to be left floating
|
||||
gpio_input_disable(gpio_num);
|
||||
gpio_output_disable(gpio_num);
|
||||
gpio_pullup_dis(gpio_num);
|
||||
gpio_pulldown_dis(gpio_num);
|
||||
gpio_hal_func_sel(gpio_context.gpio_hal, gpio_num, PIN_FUNC_GPIO);
|
||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(gpio_num)) {
|
||||
rtc_gpio_deinit(gpio_num);
|
||||
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_DISABLED);
|
||||
rtc_gpio_pullup_dis(gpio_num);
|
||||
rtc_gpio_pulldown_dis(gpio_num);
|
||||
}
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t gpio_reset_pin(gpio_num_t gpio_num)
|
||||
{
|
||||
assert(GPIO_IS_VALID_GPIO(gpio_num));
|
||||
|
@ -239,8 +239,10 @@ esp_err_t rtc_gpio_force_hold_dis_all(void)
|
||||
esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(rtc_gpio_is_valid_gpio(gpio_num), ESP_ERR_INVALID_ARG, RTCIO_TAG, "RTCIO number error");
|
||||
int rtcio_num = rtc_io_number_get(gpio_num);
|
||||
RTCIO_ENTER_CRITICAL();
|
||||
rtcio_hal_isolate(rtc_io_number_get(gpio_num));
|
||||
rtcio_hal_isolate(rtcio_num);
|
||||
rtcio_hal_hold_enable(rtcio_num);
|
||||
RTCIO_EXIT_CRITICAL();
|
||||
|
||||
return ESP_OK;
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/clk_tree_defs.h"
|
||||
#include "soc/touch_sensor_periph.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "esp_private/gpio.h"
|
||||
#include "driver/touch_sens.h"
|
||||
|
||||
#if SOC_TOUCH_SENSOR_VERSION <= 2
|
||||
@ -42,10 +42,7 @@ touch_sensor_handle_t g_touch = NULL;
|
||||
static void touch_channel_pin_init(int id)
|
||||
{
|
||||
gpio_num_t pin = touch_sensor_channel_io_map[id];
|
||||
rtc_gpio_init(pin);
|
||||
rtc_gpio_set_direction(pin, RTC_GPIO_MODE_DISABLED);
|
||||
rtc_gpio_pulldown_dis(pin);
|
||||
rtc_gpio_pullup_dis(pin);
|
||||
gpio_config_as_analog(pin);
|
||||
}
|
||||
|
||||
static void s_touch_free_resource(touch_sensor_handle_t sens_handle)
|
||||
|
@ -31,7 +31,6 @@ extern "C" {
|
||||
#define ADC_LL_DATA_INVERT_DEFAULT(PERIPH_NUM) (1)
|
||||
#define ADC_LL_SAR_CLK_DIV_DEFAULT(PERIPH_NUM) (1)
|
||||
#define ADC_LL_DELAY_CYCLE_AFTER_DONE_SIGNAL (0)
|
||||
#define ADC_LL_RTC_GPIO_SUPPORTED (1)
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
DMA
|
||||
|
@ -42,7 +42,6 @@ extern "C" {
|
||||
#define ADC_LL_DATA_INVERT_DEFAULT(PERIPH_NUM) (0)
|
||||
#define ADC_LL_SAR_CLK_DIV_DEFAULT(PERIPH_NUM) (1)
|
||||
#define ADC_LL_DELAY_CYCLE_AFTER_DONE_SIGNAL (0)
|
||||
#define ADC_LL_RTC_GPIO_SUPPORTED (1)
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
DMA
|
||||
|
@ -44,7 +44,6 @@ extern "C" {
|
||||
#define ADC_LL_DATA_INVERT_DEFAULT(PERIPH_NUM) (0)
|
||||
#define ADC_LL_SAR_CLK_DIV_DEFAULT(PERIPH_NUM) (1)
|
||||
#define ADC_LL_DELAY_CYCLE_AFTER_DONE_SIGNAL (0)
|
||||
#define ADC_LL_RTC_GPIO_SUPPORTED (1)
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
DMA
|
||||
|
@ -77,15 +77,12 @@ void rtcio_hal_set_direction_in_sleep(int rtcio_num, rtc_gpio_mode_t mode)
|
||||
}
|
||||
}
|
||||
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED
|
||||
void rtcio_hal_isolate(int rtcio_num)
|
||||
{
|
||||
rtcio_ll_pullup_disable(rtcio_num);
|
||||
rtcio_ll_pulldown_disable(rtcio_num);
|
||||
rtcio_ll_output_disable(rtcio_num);
|
||||
rtcio_ll_input_disable(rtcio_num);
|
||||
rtcio_ll_force_hold_enable(rtcio_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "ulp_lp_core_lp_adc_shared.h"
|
||||
#include "soc/adc_periph.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "driver/temperature_sensor.h"
|
||||
|
||||
#include "unity.h"
|
||||
@ -33,17 +34,17 @@ static void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool l
|
||||
{
|
||||
TEST_ASSERT(channel < SOC_ADC_CHANNEL_NUM(unit) && "invalid channel");
|
||||
|
||||
#if !ADC_LL_RTC_GPIO_SUPPORTED
|
||||
uint32_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY)));
|
||||
#else
|
||||
gpio_num_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
if (level) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_dis(io_num));
|
||||
} else {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_dis(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(io_num)) {
|
||||
if (level) {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_dis(io_num));
|
||||
} else {
|
||||
TEST_ESP_OK(rtc_gpio_pullup_dis(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user