Merge branch 'feature/mcpwm_cap_not_reset_io_at_exit' into 'master'

mcpwm: support not reset GPIO config at exit

Closes IDFGH-8916

See merge request espressif/esp-idf!21568
This commit is contained in:
morris 2023-01-12 13:20:47 +08:00
commit c83d1db2ed
3 changed files with 8 additions and 2 deletions

View File

@ -131,7 +131,7 @@ esp_err_t mcpwm_capture_timer_set_phase_on_sync(mcpwm_cap_timer_handle_t cap_tim
* @brief MCPWM capture channel configuration structure
*/
typedef struct {
int gpio_num; /*!< GPIO used capturing input signal */
int gpio_num; /*!< GPIO used capturing input signal */
uint32_t prescale; /*!< Prescale of input signal, effective frequency = cap_input_clk/prescale */
struct {
uint32_t pos_edge: 1; /*!< Whether to capture on positive edge */
@ -140,6 +140,8 @@ typedef struct {
uint32_t pull_down: 1; /*!< Whether to pull down internally */
uint32_t invert_cap_signal: 1; /*!< Invert the input capture signal */
uint32_t io_loop_back: 1; /*!< For debug/test, the signal output from the GPIO will be fed to the input path as well */
uint32_t keep_io_conf_at_exit: 1; /*!< For debug/test, whether to keep the GPIO configuration when capture channel is deleted.
By default, driver will reset the GPIO pin at exit. */
} flags; /*!< Extra configuration flags for capture channel */
} mcpwm_capture_channel_config_t;

View File

@ -276,6 +276,7 @@ esp_err_t mcpwm_new_capture_channel(mcpwm_cap_timer_handle_t cap_timer, const mc
cap_chan->gpio_num = config->gpio_num;
cap_chan->fsm = MCPWM_CAP_CHAN_FSM_INIT;
cap_chan->flags.reset_io_at_exit = !config->flags.keep_io_conf_at_exit && config->gpio_num >= 0;
*ret_cap_channel = cap_chan;
ESP_LOGD(TAG, "new capture channel (%d,%d) at %p", group->group_id, cap_chan_id, cap_chan);
return ESP_OK;
@ -296,7 +297,7 @@ esp_err_t mcpwm_del_capture_channel(mcpwm_cap_channel_handle_t cap_channel)
int cap_chan_id = cap_channel->cap_chan_id;
ESP_LOGD(TAG, "del capture channel (%d,%d)", group->group_id, cap_channel->cap_chan_id);
if (cap_channel->gpio_num >= 0) {
if (cap_channel->flags.reset_io_at_exit) {
gpio_reset_pin(cap_channel->gpio_num);
}

View File

@ -216,6 +216,9 @@ struct mcpwm_cap_channel_t {
intr_handle_t intr; // Interrupt handle
mcpwm_capture_event_cb_t on_cap; // Callback function which would be invoked in capture interrupt routine
void *user_data; // user data which would be passed to the capture callback
struct {
uint32_t reset_io_at_exit: 1; // Whether to reset the GPIO configuration when capture channel is deleted
} flags;
};
mcpwm_group_t *mcpwm_acquire_group_handle(int group_id);