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.
pull/56/head
Yuri D'Elia 2021-07-11 20:23:21 +02:00 committed by DRracer
parent 6ba7d510ca
commit 151f030318
1 changed files with 1 additions and 1 deletions

View File

@ -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) { __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) { __attribute__((always_inline)) inline void TogglePin(const GPIO_pin portPin) {