forked from espressif/esp-idf
fix(gpio): upgrade the gpio func select api for legacy pcnt & ledc
This commit is contained in:
@@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "hal/gpio_hal.h"
|
#include "hal/gpio_hal.h"
|
||||||
#include "soc/pcnt_periph.h"
|
#include "soc/pcnt_periph.h"
|
||||||
#include "esp_rom_gpio.h"
|
#include "esp_rom_gpio.h"
|
||||||
|
#include "esp_private/gpio.h"
|
||||||
|
|
||||||
#define PCNT_CHANNEL_ERR_STR "PCNT CHANNEL ERROR"
|
#define PCNT_CHANNEL_ERR_STR "PCNT CHANNEL ERROR"
|
||||||
#define PCNT_UNIT_ERR_STR "PCNT UNIT 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);
|
PCNT_CHECK(GPIO_IS_VALID_GPIO(ctrl_io) || ctrl_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||||
|
|
||||||
if (pulse_io >= 0) {
|
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_direction(pulse_io, GPIO_MODE_INPUT);
|
||||||
gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);
|
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);
|
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) {
|
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_direction(ctrl_io, GPIO_MODE_INPUT);
|
||||||
gpio_set_pull_mode(ctrl_io, GPIO_PULLUP_ONLY);
|
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);
|
esp_rom_gpio_connect_in_signal(ctrl_io, pcnt_periph_signals.groups[pcnt_port].units[unit].channels[channel].control_sig, 0);
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
#include "clk_ctrl_os.h"
|
#include "clk_ctrl_os.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
|
#include "esp_private/gpio.h"
|
||||||
#include "esp_memory_utils.h"
|
#include "esp_memory_utils.h"
|
||||||
|
|
||||||
static __attribute__((unused)) const char *LEDC_TAG = "ledc";
|
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(ledc_channel < LEDC_CHANNEL_MAX, "ledc_channel");
|
||||||
LEDC_ARG_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "gpio_num");
|
LEDC_ARG_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "gpio_num");
|
||||||
LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode");
|
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);
|
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);
|
esp_rom_gpio_connect_out_signal(gpio_num, ledc_periph_signal[speed_mode].sig_out0_idx + ledc_channel, 0, 0);
|
||||||
return ESP_OK;
|
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,
|
ESP_LOGD(LEDC_TAG, "LEDC_PWM CHANNEL %"PRIu32"|GPIO %02u|Duty %04"PRIu32"|Time %"PRIu32,
|
||||||
ledc_channel, gpio_num, duty, timer_select);
|
ledc_channel, gpio_num, duty, timer_select);
|
||||||
/*set LEDC signal in gpio matrix*/
|
/*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_level(gpio_num, output_invert);
|
||||||
gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT);
|
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);
|
esp_rom_gpio_connect_out_signal(gpio_num, ledc_periph_signal[speed_mode].sig_out0_idx + ledc_channel, output_invert, 0);
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
#include "hal/gpio_ll.h"
|
||||||
#include "soc/gpio_periph.h"
|
#include "soc/gpio_periph.h"
|
||||||
#include "soc/io_mux_reg.h"
|
#include "soc/io_mux_reg.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
@@ -509,7 +510,7 @@ static void tear_testbench(void)
|
|||||||
static int wave_count(int last_time)
|
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
|
// 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;
|
int test_counter = 0;
|
||||||
TEST_ESP_OK(pcnt_unit_clear_count(pcnt_unit));
|
TEST_ESP_OK(pcnt_unit_clear_count(pcnt_unit));
|
||||||
TEST_ESP_OK(pcnt_unit_start(pcnt_unit));
|
TEST_ESP_OK(pcnt_unit_start(pcnt_unit));
|
||||||
|
Reference in New Issue
Block a user