From 8e77720d7f103d18682e7af59039e50a4003169a Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Tue, 27 Jan 2026 10:24:09 +0300 Subject: [PATCH] feat: added gpio pullup on/off --- include/zh_encoder.h | 2 ++ version.txt | 2 +- zh_encoder.c | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/zh_encoder.h b/include/zh_encoder.h index fc1a60a..51f9218 100644 --- a/include/zh_encoder.h +++ b/include/zh_encoder.h @@ -24,6 +24,7 @@ .b_gpio_number = GPIO_NUM_MAX, \ .s_gpio_number = GPIO_NUM_MAX, \ .s_gpio_debounce_time = 10, \ + .pullup = true, \ .encoder_min_value = -10, \ .encoder_max_value = 10, \ .encoder_step = 1, \ @@ -49,6 +50,7 @@ extern "C" uint8_t a_gpio_number; /*!< Encoder A GPIO number. */ uint8_t b_gpio_number; /*!< Encoder B GPIO number. */ uint8_t s_gpio_number; /*!< Encoder button GPIO number. */ + bool pullup; /*!< Pullup GPIO enable/disable. */ uint16_t s_gpio_debounce_time; /*!< Encoder button debounce_time. @note In microseconds. */ uint8_t encoder_number; /*!< Unique encoder number. @note Must be greater than 0. */ uint16_t stack_size; /*!< Stack size for task for the encoder isr processing processing. @note The minimum size is configMINIMAL_STACK_SIZE. */ diff --git a/version.txt b/version.txt index 359a5b9..50aea0e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.0 \ No newline at end of file +2.1.0 \ No newline at end of file diff --git a/zh_encoder.c b/zh_encoder.c index 667aa5d..5804c6b 100644 --- a/zh_encoder.c +++ b/zh_encoder.c @@ -247,6 +247,11 @@ static esp_err_t _zh_encoder_pcnt_init(const zh_encoder_init_config_t *config, z err = pcnt_unit_start(pcnt_unit_handle); ZH_ERROR_CHECK(err == ESP_OK, err, pcnt_unit_disable(pcnt_unit_handle); pcnt_del_channel(pcnt_channel_a_handle); pcnt_del_channel(pcnt_channel_b_handle); pcnt_del_unit(pcnt_unit_handle), "PCNT initialization failed."); + if (config->pullup == false) + { + gpio_pullup_dis((gpio_num_t)config->a_gpio_number); + gpio_pullup_dis((gpio_num_t)config->b_gpio_number); + } handle->pcnt_unit_handle = pcnt_unit_handle; handle->pcnt_channel_a_handle = pcnt_channel_a_handle; handle->pcnt_channel_b_handle = pcnt_channel_b_handle; @@ -262,6 +267,7 @@ static esp_err_t _zh_encoder_gpio_init(const zh_encoder_init_config_t *config, z { gpio_config_t pin_config = { .mode = GPIO_MODE_INPUT, + .pull_up_en = (config->pullup == true) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE, .pin_bit_mask = (1ULL << config->s_gpio_number), .intr_type = GPIO_INTR_ANYEDGE}; esp_err_t err = gpio_config(&pin_config);