From 151f030318fb085fd6437a69acd353871a3ef16f Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 11 Jul 2021 20:23:21 +0200 Subject: [PATCH] Fix return value of gpio::ReadPin The cast to Level is incorrect, since the expression returns either 0 or a positive value if the pin is set. The value is directly assigned to the underlying uint8_t, meaning that Level::high won't match for levels greater than 0. Return a boolean and cast that to Level instead. --- src/hal/gpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hal/gpio.h b/src/hal/gpio.h index e29546d..3d45e88 100644 --- a/src/hal/gpio.h +++ b/src/hal/gpio.h @@ -57,7 +57,7 @@ __attribute__((always_inline)) inline void WritePin(const GPIO_pin portPin, Leve } __attribute__((always_inline)) inline Level ReadPin(const GPIO_pin portPin) { - return (Level)(portPin.port->PINx & (1 << portPin.pin)); + return (Level)((portPin.port->PINx & (1 << portPin.pin)) != 0); } __attribute__((always_inline)) inline void TogglePin(const GPIO_pin portPin) {