From d302091267735f3c581dc3c0142e2088ab0e71fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 9 May 2022 22:14:59 +0200 Subject: [PATCH] Changed pinMode() default interrupt type DISABLED to previously set (#6695) * Changed in pinMode() default intr_type pins default configuration has intr_type = GPIO_INTR_DISABLE With this implementation, it will set the intr_type to previously set intr_type. It will no longer disable interrupt, when pinmode is called multiple times on same pin with interrupt enabled. --- cores/esp32/esp32-hal-gpio.c | 50 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index e21063a8..359682c3 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -91,30 +91,34 @@ static InterruptHandle_t __pinInterruptHandlers[SOC_GPIO_PIN_COUNT] = {0,}; extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) { - if (!GPIO_IS_VALID_GPIO(pin)) { + if (!GPIO_IS_VALID_GPIO(pin)) { log_e("Invalid pin selected"); - return; - } - gpio_config_t conf = { - .pin_bit_mask = (1ULL<pin[pin].int_type /*!< GPIO interrupt type - previously set */ + }; + if (mode < 0x20) {//io + conf.mode = mode & (INPUT | OUTPUT); + if (mode & OPEN_DRAIN) { + conf.mode |= GPIO_MODE_DEF_OD; + } + if (mode & PULLUP) { + conf.pull_up_en = GPIO_PULLUP_ENABLE; + } + if (mode & PULLDOWN) { + conf.pull_down_en = GPIO_PULLDOWN_ENABLE; + } + } + if(gpio_config(&conf) != ESP_OK) { log_e("GPIO config failed"); return;