feat: added gpio pullup on/off

This commit is contained in:
2026-01-27 10:24:09 +03:00
parent 121ba14a49
commit d1c61af0a7
3 changed files with 9 additions and 1 deletions

View File

@@ -24,6 +24,7 @@
.b_gpio_number = GPIO_NUM_MAX, \ .b_gpio_number = GPIO_NUM_MAX, \
.s_gpio_number = GPIO_NUM_MAX, \ .s_gpio_number = GPIO_NUM_MAX, \
.s_gpio_debounce_time = 10, \ .s_gpio_debounce_time = 10, \
.pullup = true, \
.encoder_min_value = -10, \ .encoder_min_value = -10, \
.encoder_max_value = 10, \ .encoder_max_value = 10, \
.encoder_step = 1, \ .encoder_step = 1, \
@@ -49,6 +50,7 @@ extern "C"
uint8_t a_gpio_number; /*!< Encoder A GPIO number. */ uint8_t a_gpio_number; /*!< Encoder A GPIO number. */
uint8_t b_gpio_number; /*!< Encoder B GPIO number. */ uint8_t b_gpio_number; /*!< Encoder B GPIO number. */
uint8_t s_gpio_number; /*!< Encoder button 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. */ 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. */ 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. */ uint16_t stack_size; /*!< Stack size for task for the encoder isr processing processing. @note The minimum size is configMINIMAL_STACK_SIZE. */

View File

@@ -1 +1 @@
2.0.0 2.1.0

View File

@@ -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); 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); 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."); 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_unit_handle = pcnt_unit_handle;
handle->pcnt_channel_a_handle = pcnt_channel_a_handle; handle->pcnt_channel_a_handle = pcnt_channel_a_handle;
handle->pcnt_channel_b_handle = pcnt_channel_b_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 = { gpio_config_t pin_config = {
.mode = GPIO_MODE_INPUT, .mode = GPIO_MODE_INPUT,
.pull_up_en = (config->pullup == true) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE,
.pin_bit_mask = (1ULL << config->s_gpio_number), .pin_bit_mask = (1ULL << config->s_gpio_number),
.intr_type = GPIO_INTR_ANYEDGE}; .intr_type = GPIO_INTR_ANYEDGE};
esp_err_t err = gpio_config(&pin_config); esp_err_t err = gpio_config(&pin_config);