From d753d01383c1e1c52f0db017fdf2b05925bffd61 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Mon, 17 Jun 2024 15:15:08 +0800 Subject: [PATCH] fix(gpio): upgrade the gpio func select api for legacy pcnt & ledc --- components/driver/deprecated/pcnt_legacy.c | 7 ++++--- components/esp_driver_ledc/src/ledc.c | 5 +++-- components/esp_driver_ledc/test_apps/ledc/main/test_ledc.c | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/driver/deprecated/pcnt_legacy.c b/components/driver/deprecated/pcnt_legacy.c index 1c33b4aa77..2cb09efb7a 100644 --- a/components/driver/deprecated/pcnt_legacy.c +++ b/components/driver/deprecated/pcnt_legacy.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,6 +15,7 @@ #include "hal/gpio_hal.h" #include "soc/pcnt_periph.h" #include "esp_rom_gpio.h" +#include "esp_private/gpio.h" #define PCNT_CHANNEL_ERR_STR "PCNT CHANNEL ERROR" #define PCNT_UNIT_ERR_STR "PCNT UNIT ERROR" @@ -86,14 +87,14 @@ static inline esp_err_t _pcnt_set_pin(pcnt_port_t pcnt_port, pcnt_unit_t unit, p PCNT_CHECK(GPIO_IS_VALID_GPIO(ctrl_io) || ctrl_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG); if (pulse_io >= 0) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[pulse_io], PIN_FUNC_GPIO); + gpio_func_sel(pulse_io, PIN_FUNC_GPIO); gpio_set_direction(pulse_io, GPIO_MODE_INPUT); gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY); esp_rom_gpio_connect_in_signal(pulse_io, pcnt_periph_signals.groups[pcnt_port].units[unit].channels[channel].pulse_sig, 0); } if (ctrl_io >= 0) { - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[ctrl_io], PIN_FUNC_GPIO); + gpio_func_sel(ctrl_io, PIN_FUNC_GPIO); gpio_set_direction(ctrl_io, GPIO_MODE_INPUT); gpio_set_pull_mode(ctrl_io, GPIO_PULLUP_ONLY); esp_rom_gpio_connect_in_signal(ctrl_io, pcnt_periph_signals.groups[pcnt_port].units[unit].channels[channel].control_sig, 0); diff --git a/components/esp_driver_ledc/src/ledc.c b/components/esp_driver_ledc/src/ledc.c index d67c2cdf66..f2b36f133e 100644 --- a/components/esp_driver_ledc/src/ledc.c +++ b/components/esp_driver_ledc/src/ledc.c @@ -22,6 +22,7 @@ #include "esp_rom_sys.h" #include "clk_ctrl_os.h" #include "esp_private/periph_ctrl.h" +#include "esp_private/gpio.h" #include "esp_memory_utils.h" static __attribute__((unused)) const char *LEDC_TAG = "ledc"; @@ -645,7 +646,7 @@ esp_err_t ledc_set_pin(int gpio_num, ledc_mode_t speed_mode, ledc_channel_t ledc LEDC_ARG_CHECK(ledc_channel < LEDC_CHANNEL_MAX, "ledc_channel"); LEDC_ARG_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "gpio_num"); LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode"); - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_num], PIN_FUNC_GPIO); + gpio_func_sel(gpio_num, PIN_FUNC_GPIO); gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT); esp_rom_gpio_connect_out_signal(gpio_num, ledc_periph_signal[speed_mode].sig_out0_idx + ledc_channel, 0, 0); return ESP_OK; @@ -709,7 +710,7 @@ esp_err_t ledc_channel_config(const ledc_channel_config_t *ledc_conf) ESP_LOGD(LEDC_TAG, "LEDC_PWM CHANNEL %"PRIu32"|GPIO %02u|Duty %04"PRIu32"|Time %"PRIu32, ledc_channel, gpio_num, duty, timer_select); /*set LEDC signal in gpio matrix*/ - gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_num], PIN_FUNC_GPIO); + gpio_func_sel(gpio_num, PIN_FUNC_GPIO); gpio_set_level(gpio_num, output_invert); gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT); esp_rom_gpio_connect_out_signal(gpio_num, ledc_periph_signal[speed_mode].sig_out0_idx + ledc_channel, output_invert, 0); diff --git a/components/esp_driver_ledc/test_apps/ledc/main/test_ledc.c b/components/esp_driver_ledc/test_apps/ledc/main/test_ledc.c index fe9e591810..45d775434b 100644 --- a/components/esp_driver_ledc/test_apps/ledc/main/test_ledc.c +++ b/components/esp_driver_ledc/test_apps/ledc/main/test_ledc.c @@ -14,6 +14,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "unity.h" +#include "hal/gpio_ll.h" #include "soc/gpio_periph.h" #include "soc/io_mux_reg.h" #include "esp_system.h" @@ -509,7 +510,7 @@ static void tear_testbench(void) static int wave_count(int last_time) { // The input ability of PULSE_IO is disabled after ledc driver install, so we need to re-enable it again - PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[PULSE_IO]); + gpio_ll_input_enable(&GPIO, PULSE_IO); int test_counter = 0; TEST_ESP_OK(pcnt_unit_clear_count(pcnt_unit)); TEST_ESP_OK(pcnt_unit_start(pcnt_unit));