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:
commit
1598c8c6f8
@ -29,7 +29,7 @@ extern "C" {
|
|||||||
#endif
|
#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)
|
#define ARDUINO_LED (10)
|
||||||
|
|
||||||
|
|||||||
@ -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_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_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_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)
|
#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)
|
int gpio_read (gpio_t pin)
|
||||||
{
|
{
|
||||||
CHECK_PARAM_RET(pin < GPIO_PIN_NUMOF, -1);
|
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)
|
void gpio_write (gpio_t pin, int value)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user