From 65a3b5f5242f2bc7ece632ce7deaf5c68042bb5c Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Fri, 13 Sep 2024 19:01:23 +0200 Subject: [PATCH] arch/arm/nrf{52|53|91}: fix read GPIO state for outputs when GPIO is configured as output, we have to read output state instead of input register --- arch/arm/src/nrf52/nrf52_gpio.c | 9 ++++++++- arch/arm/src/nrf53/nrf53_gpio.c | 9 ++++++++- arch/arm/src/nrf91/nrf91_gpio.c | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/nrf52/nrf52_gpio.c b/arch/arm/src/nrf52/nrf52_gpio.c index c43b925c3e..4da656da8f 100644 --- a/arch/arm/src/nrf52/nrf52_gpio.c +++ b/arch/arm/src/nrf52/nrf52_gpio.c @@ -409,7 +409,14 @@ bool nrf52_gpio_read(nrf52_pinset_t pinset) /* Get register address */ - offset = nrf52_gpio_regget(port, NRF52_GPIO_IN_OFFSET); + if ((pinset & GPIO_FUNC_MASK) == GPIO_OUTPUT) + { + offset = nrf52_gpio_regget(port, NRF52_GPIO_OUTSET_OFFSET); + } + else + { + offset = nrf52_gpio_regget(port, NRF52_GPIO_IN_OFFSET); + } /* Get register value */ diff --git a/arch/arm/src/nrf53/nrf53_gpio.c b/arch/arm/src/nrf53/nrf53_gpio.c index f5ad52ddb9..89d4e64dbb 100644 --- a/arch/arm/src/nrf53/nrf53_gpio.c +++ b/arch/arm/src/nrf53/nrf53_gpio.c @@ -468,7 +468,14 @@ bool nrf53_gpio_read(nrf53_pinset_t pinset) /* Get register address */ - offset = nrf53_gpio_regget(port, NRF53_GPIO_IN_OFFSET); + if ((pinset & GPIO_FUNC_MASK) == GPIO_OUTPUT) + { + offset = nrf53_gpio_regget(port, NRF53_GPIO_OUTSET_OFFSET); + } + else + { + offset = nrf53_gpio_regget(port, NRF53_GPIO_IN_OFFSET); + } /* Get register value */ diff --git a/arch/arm/src/nrf91/nrf91_gpio.c b/arch/arm/src/nrf91/nrf91_gpio.c index 56c222b50a..fe686b5b2b 100644 --- a/arch/arm/src/nrf91/nrf91_gpio.c +++ b/arch/arm/src/nrf91/nrf91_gpio.c @@ -401,7 +401,14 @@ bool nrf91_gpio_read(nrf91_pinset_t pinset) /* Get register address */ - offset = nrf91_gpio_regget(port, NRF91_GPIO_IN_OFFSET); + if ((pinset & GPIO_FUNC_MASK) == GPIO_OUTPUT) + { + offset = nrf91_gpio_regget(port, NRF91_GPIO_OUTSET_OFFSET); + } + else + { + offset = nrf91_gpio_regget(port, NRF91_GPIO_IN_OFFSET); + } /* Get register value */