digio: Make digio check if an port to set is an output port.

This commit is contained in:
Mario Hüttel 2021-12-26 20:40:28 +01:00
parent a8a622df25
commit 3bb4607798

View File

@ -67,12 +67,22 @@ void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func)
void digio_set(uint8_t num, int val)
{
uint8_t pin;
if (num >= COUNT_OF(digio_pins))
return;
pin = digio_pins[num];
/* Check if port is an output. If not, do noting. */
if ((DIGIO_PORT->MODER & (0x3<<pin)) != OUTPUT(pin)) {
return;
}
if (val)
DIGIO_PORT->ODR |= (1<<digio_pins[num]);
DIGIO_PORT->ODR |= (1<<pin);
else
DIGIO_PORT->ODR &= ~(1<<digio_pins[num]);
DIGIO_PORT->ODR &= ~(1<<pin);
}
int digio_get(uint8_t num)