Fix gpio configuration mask not properly applied

This commit is contained in:
Steins7 2023-05-08 21:18:28 +02:00
parent 0034dea774
commit f0da0cd05c
2 changed files with 8 additions and 5 deletions

View File

@ -48,7 +48,7 @@ void gpio_configure(enum GpioPort port, enum GpioPin pin_mask,
}
}
regs->PORTS[port].CRL.word &= ~(0xF * mask);
regs->PORTS[port].CRL.word |= (config << 2) | (mode << 0) * mask;
regs->PORTS[port].CRL.word |= ((config << 2) | (mode << 0)) * mask;
//clear config for selected port, then apply new config, 8 last pins
mask = 0;
@ -61,7 +61,7 @@ void gpio_configure(enum GpioPort port, enum GpioPin pin_mask,
}
}
regs->PORTS[port].CRH.word &= ~(0xF * mask);
regs->PORTS[port].CRH.word |= (config << 2) | (mode << 0) * mask;
regs->PORTS[port].CRH.word |= ((config << 2) | (mode << 0)) * mask;
}
void gpio_reset(enum GpioPort port, enum GpioPin pin_mask)
@ -85,3 +85,4 @@ bool gpio_read(enum GpioPort port, enum GpioPin pin_mask)
//--local functions-------------------------------------------------------------

View File

@ -55,8 +55,9 @@ enum GpioPin {
};
/**
* Available modes for a pin. To have a pin in both modes simultaneously, see
* push-pull configuration in input mode
* Available modes for a pin. To have a pin in both modes simultaneously, use
* push-pull configuration in input mode but note that the power may be
* limited
*/
enum GpioMode {
GPIO_MODE_INPUT = 0,
@ -66,7 +67,7 @@ enum GpioMode {
};
/**
* Available configurations for a pin. Some configurations onlly apply in input
* Available configurations for a pin. Some configurations only apply in input
* mode (denoted "IN") while others only apply in output mode (denoted "OUT")
*/
enum GpioConfig {
@ -115,3 +116,4 @@ bool gpio_read(enum GpioPort port, enum GpioPin pin_mask);
#endif //_RCC_H_