1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

Fix IOToggle. The F1 and F3 implementation didn't work because mask is 16 bits and not 32.

This commit is contained in:
Scott Shawcroft 2016-06-11 22:03:29 -07:00
parent 4fcdc5b346
commit 708638f87b

View file

@ -171,16 +171,8 @@ void IOToggle(IO_t io)
{ {
if (!io) if (!io)
return; return;
// check pin state and use BSRR accordinly to avoid race condition
uint16_t mask = IO_Pin(io); uint16_t mask = IO_Pin(io);
#if defined(STM32F40_41xxx) || defined(STM32F411xE)
IO_GPIO(io)->ODR ^= mask; IO_GPIO(io)->ODR ^= mask;
#else
if (IO_GPIO(io)->ODR & mask)
mask <<= 16; // bit is set, shift mask to reset half
IO_GPIO(io)->BSRR = mask;
#endif
} }
// claim IO pin, set owner and resources // claim IO pin, set owner and resources
@ -275,14 +267,16 @@ ioRec_t ioRecs[DEFIO_IO_USED_COUNT];
void IOInitGlobal(void) { void IOInitGlobal(void) {
ioRec_t *ioRec = ioRecs; ioRec_t *ioRec = ioRecs;
for (unsigned port = 0; port < ARRAYLEN(ioDefUsedMask); port++) for (unsigned port = 0; port < ARRAYLEN(ioDefUsedMask); port++) {
for (unsigned pin = 0; pin < sizeof(ioDefUsedMask[0]) * 8; pin++) for (unsigned pin = 0; pin < sizeof(ioDefUsedMask[0]) * 8; pin++) {
if (ioDefUsedMask[port] & (1 << pin)) { if (ioDefUsedMask[port] & (1 << pin)) {
ioRec->gpio = (GPIO_TypeDef *)(GPIOA_BASE + (port << 10)); // ports are 0x400 apart ioRec->gpio = (GPIO_TypeDef *)(GPIOA_BASE + (port << 10)); // ports are 0x400 apart
ioRec->pin = 1 << pin; ioRec->pin = 1 << pin;
ioRec++; ioRec++;
} }
} }
}
}
IO_t IOGetByTag(ioTag_t tag) IO_t IOGetByTag(ioTag_t tag)
{ {