diff --git a/boards/esp32-wemos-lolin-d32-pro/include/arduino_board.h b/boards/esp32-wemos-lolin-d32-pro/include/arduino_board.h index 162ff6a340..a1d9e0d5c8 100644 --- a/boards/esp32-wemos-lolin-d32-pro/include/arduino_board.h +++ b/boards/esp32-wemos-lolin-d32-pro/include/arduino_board.h @@ -29,7 +29,7 @@ extern "C" { #endif /** - * @brief The on-board LED is connected to pin 2 on this board + * @brief The on-board LED is connected to Arduino pin 10 on this board */ #define ARDUINO_LED (10) diff --git a/cpu/esp32/periph/gpio.c b/cpu/esp32/periph/gpio.c index bf1070261c..d3cf21ed2c 100644 --- a/cpu/esp32/periph/gpio.c +++ b/cpu/esp32/periph/gpio.c @@ -239,6 +239,7 @@ const char* _gpio_pin_usage_str[] = #define GPIO_PIN_SET(b) if (b < 32) GPIO.out_w1ts = BIT(b); else GPIO.out1_w1ts.val = BIT(b-32) #define GPIO_PIN_CLR(b) if (b < 32) GPIO.out_w1tc = BIT(b); else GPIO.out1_w1tc.val = BIT(b-32) +#define GPIO_PIN_GET(b) (b < 32) ? (GPIO.out >> b) & 1 : (GPIO.out1.val >> (b-32)) & 1 #define GPIO_REG_BIT_GET(l,h,b) ((b < 32) ? GPIO.l & BIT(b) : GPIO.h.val & BIT(b-32)) #define GPIO_REG_BIT_SET(l,h,b) if (b < 32) GPIO.l |= BIT(b); else GPIO.h.val |= BIT(b-32) @@ -447,7 +448,18 @@ void gpio_irq_disable (gpio_t pin) int gpio_read (gpio_t pin) { CHECK_PARAM_RET(pin < GPIO_PIN_NUMOF, -1); - return GPIO_REG_BIT_GET(in, in1, pin) ? 1 : 0; + int value; + + if (REG_GET_BIT(_gpio_to_iomux_reg[pin], FUN_IE)) { + /* in case the pin is any kind of input, read from input register */ + value = GPIO_REG_BIT_GET(in, in1, pin) ? 1 : 0; + } + else { + /* otherwise read the last value written to the output register */ + value = GPIO_PIN_GET(pin); + } + DEBUG("%s gpio=%u val=%d\n", __func__, pin, value); + return value; } void gpio_write (gpio_t pin, int value)