Merge pull request #11950 from gschorcht/cpu/esp32/periph-gpio_read-fix

cpu/esp32: fix of gpio_read for output ports
This commit is contained in:
Martine Lenders 2019-09-24 20:20:40 +02:00 committed by GitHub
commit 1598c8c6f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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)

View File

@ -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)