Make gpio writes atomic

This commit is contained in:
Steins7 2023-05-08 21:03:52 +02:00
parent c44dc87f43
commit 0034dea774
2 changed files with 5 additions and 4 deletions

View File

@ -36,7 +36,7 @@ void gpio_configure(enum GpioPort port, enum GpioPin pin_mask,
rcc_enable(RCC_AHB_NONE, RCC_APB1_NONE, RCC_APB2_IOPA << port);
//reset outputs before configuring anything
regs->PORTS[port].BRR.word |= pin_mask;
regs->PORTS[port].BRR.word = pin_mask;
//clear config for selected port, then apply new config, 8 first pins
uint32_t mask = 0;
@ -72,9 +72,9 @@ void gpio_reset(enum GpioPort port, enum GpioPin pin_mask)
void gpio_write(enum GpioPort port, enum GpioPin pin_mask, bool value)
{
if (value) {
regs->PORTS[port].BSRR.word |= pin_mask;
regs->PORTS[port].BSRR.word = pin_mask;
} else {
regs->PORTS[port].BRR.word |= pin_mask;
regs->PORTS[port].BRR.word = pin_mask;
}
}

View File

@ -101,7 +101,8 @@ void gpio_reset(enum GpioPort port, enum GpioPin pin_mask);
/**
* Write a value to output gpios on a single port. The GpioPin enum can be used
* as mask to reset multiple pins at the same time. In push-pull input mode,
* configure the pull up/down. Has no effect otherwise
* configure the pull up/down. Has no effect otherwise. Writes are atomic
* operations
*/
void gpio_write(enum GpioPort port, enum GpioPin pin_mask, bool value);