mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 01:05:27 +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:
parent
4fcdc5b346
commit
708638f87b
1 changed files with 7 additions and 13 deletions
|
@ -50,7 +50,7 @@ const struct ioPortDef_s ioPortDefs[] = {
|
||||||
{ RCC_AHB1(GPIOD) },
|
{ RCC_AHB1(GPIOD) },
|
||||||
{ RCC_AHB1(GPIOE) },
|
{ RCC_AHB1(GPIOE) },
|
||||||
{ RCC_AHB1(GPIOF) },
|
{ RCC_AHB1(GPIOF) },
|
||||||
};
|
};
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
ioRec_t* IO_Rec(IO_t io)
|
ioRec_t* IO_Rec(IO_t io)
|
||||||
|
@ -116,7 +116,7 @@ uint32_t IO_EXTI_Line(IO_t io)
|
||||||
#elif defined(STM32F303xC)
|
#elif defined(STM32F303xC)
|
||||||
return IO_GPIOPinIdx(io);
|
return IO_GPIOPinIdx(io);
|
||||||
#elif defined(STM32F40_41xxx) || defined(STM32F411xE)
|
#elif defined(STM32F40_41xxx) || defined(STM32F411xE)
|
||||||
return 1 << IO_GPIOPinIdx(io);
|
return 1 << IO_GPIOPinIdx(io);
|
||||||
#else
|
#else
|
||||||
# error "Unknown target type"
|
# error "Unknown target type"
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
||||||
|
@ -210,7 +202,7 @@ resourceType_t IOGetResources(IO_t io)
|
||||||
return ioRec->resourcesUsed;
|
return ioRec->resourcesUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(STM32F10X)
|
#if defined(STM32F10X)
|
||||||
|
|
||||||
void IOConfigGPIO(IO_t io, ioConfig_t cfg)
|
void IOConfigGPIO(IO_t io, ioConfig_t cfg)
|
||||||
{
|
{
|
||||||
|
@ -275,13 +267,15 @@ 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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue