From dae43416877c2eb11994271a3ad136e3affd1e72 Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Wed, 17 Jul 2024 13:55:08 +0200 Subject: [PATCH] hw/mcu/nordic: Fix GPIO read bug hal_gpio_read was always returning state of IN register even if GPIO pin was configured as output pin --- hw/mcu/nordic/nrf_common/src/hal_gpio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/mcu/nordic/nrf_common/src/hal_gpio.c b/hw/mcu/nordic/nrf_common/src/hal_gpio.c index 6edd378f70..dc4f6acf35 100644 --- a/hw/mcu/nordic/nrf_common/src/hal_gpio.c +++ b/hw/mcu/nordic/nrf_common/src/hal_gpio.c @@ -141,7 +141,11 @@ hal_gpio_write(int pin, int val) int hal_gpio_read(int pin) { - return nrf_gpio_pin_read(pin); + if (nrf_gpio_pin_dir_get(pin) == NRF_GPIO_PIN_DIR_OUTPUT) { + return nrf_gpio_pin_out_read(pin); + } else { + return nrf_gpio_pin_read(pin); + } } /** @@ -157,7 +161,7 @@ int hal_gpio_toggle(int pin) { nrf_gpio_pin_toggle(pin); - return nrf_gpio_pin_read(pin); + return hal_gpio_read(pin); } /*