diff --git a/components/driver/include/driver/ledc.h b/components/driver/include/driver/ledc.h index 2ffcbd74c8..69660f3dda 100644 --- a/components/driver/include/driver/ledc.h +++ b/components/driver/include/driver/ledc.h @@ -76,6 +76,7 @@ esp_err_t ledc_update_duty(ledc_mode_t speed_mode, ledc_channel_t channel); /** * @brief Set LEDC output gpio. + * @deprecated This function is redundant, please use ledc_channel_config to set gpio pins. * * @param gpio_num The LEDC output gpio * @param speed_mode Select the LEDC channel group with specified speed mode. Note that not all targets support high speed mode. @@ -85,8 +86,8 @@ esp_err_t ledc_update_duty(ledc_mode_t speed_mode, ledc_channel_t channel); * - ESP_OK Success * - ESP_ERR_INVALID_ARG Parameter error */ -esp_err_t ledc_set_pin(int gpio_num, ledc_mode_t speed_mode, ledc_channel_t ledc_channel); - +esp_err_t ledc_set_pin(int gpio_num, ledc_mode_t speed_mode, ledc_channel_t ledc_channel) + __attribute__((deprecated("use ledc_channel_config instead"))); /** * @brief LEDC stop. * Disable LEDC output, and set idle level diff --git a/components/driver/ledc.c b/components/driver/ledc.c index 79e942b6d9..80b6c0439b 100644 --- a/components/driver/ledc.c +++ b/components/driver/ledc.c @@ -372,6 +372,7 @@ esp_err_t ledc_channel_config(const ledc_channel_config_t* ledc_conf) uint32_t intr_type = ledc_conf->intr_type; uint32_t duty = ledc_conf->duty; uint32_t hpoint = ledc_conf->hpoint; + bool output_invert = ledc_conf->flags.output_invert; LEDC_ARG_CHECK(ledc_channel < LEDC_CHANNEL_MAX, "ledc_channel"); LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode"); LEDC_ARG_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "gpio_num"); @@ -405,7 +406,7 @@ esp_err_t ledc_channel_config(const ledc_channel_config_t* ledc_conf) /*set LEDC signal in gpio matrix*/ gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[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); + esp_rom_gpio_connect_out_signal(gpio_num, ledc_periph_signal[speed_mode].sig_out0_idx + ledc_channel, output_invert, 0); return ret; } diff --git a/components/hal/include/hal/ledc_types.h b/components/hal/include/hal/ledc_types.h index fa05ef41b5..0ddcf18c63 100644 --- a/components/hal/include/hal/ledc_types.h +++ b/components/hal/include/hal/ledc_types.h @@ -134,6 +134,10 @@ typedef struct { ledc_timer_t timer_sel; /*!< Select the timer source of channel (0 - 3) */ uint32_t duty; /*!< LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)] */ int hpoint; /*!< LEDC channel hpoint value, the max value is 0xfffff */ + struct { + unsigned int output_invert: 1;/*!< Enable (1) or disable (0) gpio output invert */ + } flags; /*!< LEDC flags */ + } ledc_channel_config_t; /** diff --git a/examples/peripherals/ledc/main/ledc_example_main.c b/examples/peripherals/ledc/main/ledc_example_main.c index 9f5124f195..c65329e501 100644 --- a/examples/peripherals/ledc/main/ledc_example_main.c +++ b/examples/peripherals/ledc/main/ledc_example_main.c @@ -102,7 +102,8 @@ void app_main(void) .gpio_num = LEDC_HS_CH0_GPIO, .speed_mode = LEDC_HS_MODE, .hpoint = 0, - .timer_sel = LEDC_HS_TIMER + .timer_sel = LEDC_HS_TIMER, + .flags.output_invert = 0 }, { .channel = LEDC_HS_CH1_CHANNEL, @@ -110,7 +111,8 @@ void app_main(void) .gpio_num = LEDC_HS_CH1_GPIO, .speed_mode = LEDC_HS_MODE, .hpoint = 0, - .timer_sel = LEDC_HS_TIMER + .timer_sel = LEDC_HS_TIMER, + .flags.output_invert = 0 }, #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 { @@ -119,7 +121,8 @@ void app_main(void) .gpio_num = LEDC_LS_CH0_GPIO, .speed_mode = LEDC_LS_MODE, .hpoint = 0, - .timer_sel = LEDC_LS_TIMER + .timer_sel = LEDC_LS_TIMER, + .flags.output_invert = 0 }, { .channel = LEDC_LS_CH1_CHANNEL, @@ -127,7 +130,8 @@ void app_main(void) .gpio_num = LEDC_LS_CH1_GPIO, .speed_mode = LEDC_LS_MODE, .hpoint = 0, - .timer_sel = LEDC_LS_TIMER + .timer_sel = LEDC_LS_TIMER, + .flags.output_invert = 0 }, #endif { @@ -136,7 +140,8 @@ void app_main(void) .gpio_num = LEDC_LS_CH2_GPIO, .speed_mode = LEDC_LS_MODE, .hpoint = 0, - .timer_sel = LEDC_LS_TIMER + .timer_sel = LEDC_LS_TIMER, + .flags.output_invert = 1 }, { .channel = LEDC_LS_CH3_CHANNEL, @@ -144,7 +149,8 @@ void app_main(void) .gpio_num = LEDC_LS_CH3_GPIO, .speed_mode = LEDC_LS_MODE, .hpoint = 0, - .timer_sel = LEDC_LS_TIMER + .timer_sel = LEDC_LS_TIMER, + .flags.output_invert = 1 }, };