@@ -224,40 +224,30 @@ esp_err_t rotary_encoder_create(const rotary_encoder_config_t *config, rotary_en
224224 }
225225#endif
226226
227- // setup GPIO
228- gpio_config_t io_conf ;
229- memset ( & io_conf , 0 , sizeof ( gpio_config_t )) ;
230- io_conf . mode = GPIO_MODE_INPUT ;
231- if ( config -> enable_internal_pullup )
227+ // setup GPIO pins as inputs
228+ gpio_num_t pins [] = { re -> pin_a , re -> pin_b , re -> pin_btn } ;
229+ int num_pins = PIN_VALID ( re -> pin_btn ) ? 3 : 2 ;
230+ esp_err_t err ;
231+ for ( int i = 0 ; i < num_pins ; i ++ )
232232 {
233- if (re -> btn_pressed_level == 0 )
233+ err = gpio_set_direction (pins [i ], GPIO_MODE_INPUT );
234+ if (err != ESP_OK )
234235 {
235- io_conf .pull_up_en = GPIO_PULLUP_ENABLE ;
236- io_conf .pull_down_en = GPIO_PULLDOWN_DISABLE ;
236+ vSemaphoreDelete (re -> lock );
237+ free (re );
238+ return err ;
237239 }
238- else
240+ if ( config -> enable_internal_pullup )
239241 {
240- io_conf .pull_up_en = GPIO_PULLUP_DISABLE ;
241- io_conf .pull_down_en = GPIO_PULLDOWN_ENABLE ;
242+ err = gpio_set_pull_mode (pins [i ], GPIO_PULLUP_ONLY );
243+ if (err != ESP_OK )
244+ {
245+ vSemaphoreDelete (re -> lock );
246+ free (re );
247+ return err ;
248+ }
242249 }
243250 }
244- else
245- {
246- io_conf .pull_up_en = GPIO_PULLUP_DISABLE ;
247- io_conf .pull_down_en = GPIO_PULLDOWN_DISABLE ;
248- }
249- io_conf .intr_type = GPIO_INTR_DISABLE ;
250- io_conf .pin_bit_mask = GPIO_BIT (re -> pin_a ) | GPIO_BIT (re -> pin_b );
251- if (PIN_VALID (re -> pin_btn ))
252- io_conf .pin_bit_mask |= GPIO_BIT (re -> pin_btn );
253-
254- esp_err_t err = gpio_config (& io_conf );
255- if (err != ESP_OK )
256- {
257- vSemaphoreDelete (re -> lock );
258- free (re );
259- return err ;
260- }
261251
262252 // Create and start per-encoder timer
263253 const esp_timer_create_args_t timer_args =
0 commit comments