Merge branch 'fix/mcpwm_example_remove_io_loop_back' into 'master'

refactor(mcpwm): remove io_loop_back in example

See merge request espressif/esp-idf!34259
This commit is contained in:
Chen Ji Chang
2024-10-22 19:07:48 +08:00

View File

@@ -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 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -28,6 +28,12 @@ static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[])
// | | | // | | |
// v v v // v v v
// timer0 timer1 timer2 // timer0 timer1 timer2
gpio_config_t sync_gpio_conf = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = BIT(EXAMPLE_SYNC_GPIO),
};
ESP_ERROR_CHECK(gpio_config(&sync_gpio_conf));
ESP_LOGI(TAG, "Create GPIO sync source"); ESP_LOGI(TAG, "Create GPIO sync source");
mcpwm_sync_handle_t gpio_sync_source = NULL; mcpwm_sync_handle_t gpio_sync_source = NULL;
mcpwm_gpio_sync_src_config_t gpio_sync_config = { mcpwm_gpio_sync_src_config_t gpio_sync_config = {
@@ -35,7 +41,6 @@ static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[])
.gpio_num = EXAMPLE_SYNC_GPIO, .gpio_num = EXAMPLE_SYNC_GPIO,
.flags.pull_down = true, .flags.pull_down = true,
.flags.active_neg = false, // by default, a posedge pulse can trigger a sync event .flags.active_neg = false, // by default, a posedge pulse can trigger a sync event
.flags.io_loop_back = true, // then we can trigger a sync event using `gpio_set_level` on the same GPIO
}; };
ESP_ERROR_CHECK(mcpwm_new_gpio_sync_src(&gpio_sync_config, &gpio_sync_source)); ESP_ERROR_CHECK(mcpwm_new_gpio_sync_src(&gpio_sync_config, &gpio_sync_source));
@@ -50,8 +55,9 @@ static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[])
} }
ESP_LOGI(TAG, "Trigger a pulse on the GPIO as a sync event"); ESP_LOGI(TAG, "Trigger a pulse on the GPIO as a sync event");
gpio_set_level(EXAMPLE_SYNC_GPIO, 0); ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_SYNC_GPIO, 0));
gpio_set_level(EXAMPLE_SYNC_GPIO, 1); ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_SYNC_GPIO, 1));
ESP_ERROR_CHECK(gpio_reset_pin(EXAMPLE_SYNC_GPIO));
} }
#endif // CONFIG_EXAMPLE_SYNC_FROM_GPIO #endif // CONFIG_EXAMPLE_SYNC_FROM_GPIO