Skip to content

Commit

Permalink
Merge branch 'feature/mcpwm_cap_not_reset_io_at_exit' into 'master'
Browse files Browse the repository at this point in the history
mcpwm: support not reset GPIO config at exit

Closes IDFGH-8916

See merge request espressif/esp-idf!21568
  • Loading branch information
suda-morris committed Jan 12, 2023
2 parents d8af042 + f0bea3c commit c83d1db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion components/driver/include/driver/mcpwm_cap.h
Expand Up @@ -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 */
Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion components/driver/mcpwm/mcpwm_cap.c
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions components/driver/mcpwm/mcpwm_private.h
Expand Up @@ -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);
Expand Down

0 comments on commit c83d1db

Please sign in to comment.