mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Debug - Separate pin config from runtime state/implementation details.
This commit is contained in:
parent
8913458041
commit
13a0037b18
2 changed files with 28 additions and 15 deletions
|
@ -25,30 +25,39 @@
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
#include "drivers/io_impl.h"
|
#include "drivers/io_impl.h"
|
||||||
|
|
||||||
typedef struct dbgPin_s {
|
#include "debug_pin.h"
|
||||||
ioTag_t tag;
|
|
||||||
|
typedef struct dbgPinState_s {
|
||||||
GPIO_TypeDef *gpio;
|
GPIO_TypeDef *gpio;
|
||||||
uint32_t setBSRR;
|
uint32_t setBSRR;
|
||||||
uint32_t resetBSRR;
|
uint32_t resetBSRR;
|
||||||
} dbgPin_t;
|
} dbgPinState_t;
|
||||||
|
|
||||||
__weak dbgPin_t dbgPins[] = {
|
#ifndef DEBUG_PIN_COUNT
|
||||||
|
#define DEBUG_PIN_COUNT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Provide a non-weak reference in target.c or elsewhere
|
||||||
|
__weak dbgPin_t dbgPins[DEBUG_PIN_COUNT] = {
|
||||||
{ .tag = IO_TAG(NONE) },
|
{ .tag = IO_TAG(NONE) },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dbgPinState_t dbgPinStates[DEBUG_PIN_COUNT] = { 0 };
|
||||||
|
|
||||||
void dbgPinInit(void)
|
void dbgPinInit(void)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < ARRAYLEN(dbgPins); i++) {
|
for (unsigned i = 0; i < ARRAYLEN(dbgPins); i++) {
|
||||||
dbgPin_t *dbgPin = &dbgPins[i];
|
dbgPin_t *dbgPin = &dbgPins[i];
|
||||||
|
dbgPinState_t *dbgPinState = &dbgPinStates[i];
|
||||||
IO_t io = IOGetByTag(dbgPin->tag);
|
IO_t io = IOGetByTag(dbgPin->tag);
|
||||||
if (!io) {
|
if (!io) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IOConfigGPIO(io, IOCFG_OUT_PP);
|
IOConfigGPIO(io, IOCFG_OUT_PP);
|
||||||
dbgPin->gpio = IO_GPIO(io);
|
dbgPinState->gpio = IO_GPIO(io);
|
||||||
int pinSrc = IO_GPIO_PinSource(io);
|
int pinSrc = IO_GPIO_PinSource(io);
|
||||||
dbgPin->setBSRR = (1 << pinSrc);
|
dbgPinState->setBSRR = (1 << pinSrc);
|
||||||
dbgPin->resetBSRR = (1 << (pinSrc + 16));
|
dbgPinState->resetBSRR = (1 << (pinSrc + 16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,12 +67,12 @@ void dbgPinHi(int index)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgPin_t *dbgPin = &dbgPins[index];
|
dbgPinState_t *dbgPinState = &dbgPinStates[index];
|
||||||
if (dbgPin->gpio) {
|
if (dbgPinState->gpio) {
|
||||||
#if defined(STM32F7) || defined(STM32H7)
|
#if defined(STM32F7) || defined(STM32H7)
|
||||||
dbgPin->gpio->BSRR = dbgPin->setBSRR;
|
dbgPinState->gpio->BSRR = dbgPinState->setBSRR;
|
||||||
#else
|
#else
|
||||||
dbgPin->gpio->BSRRL = dbgPin->setBSRR;
|
dbgPinState->gpio->BSRRL = dbgPinState->setBSRR;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,13 +83,13 @@ void dbgPinLo(int index)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgPin_t *dbgPin = &dbgPins[index];
|
dbgPinState_t *dbgPinState = &dbgPinStates[index];
|
||||||
|
|
||||||
if (dbgPin->gpio) {
|
if (dbgPinState->gpio) {
|
||||||
#if defined(STM32F7) || defined(STM32H7)
|
#if defined(STM32F7) || defined(STM32H7)
|
||||||
dbgPin->gpio->BSRR = dbgPin->resetBSRR;
|
dbgPinState->gpio->BSRR = dbgPinState->resetBSRR;
|
||||||
#else
|
#else
|
||||||
dbgPin->gpio->BSRRL = dbgPin->resetBSRR;
|
dbgPinState->gpio->BSRRL = dbgPinState->resetBSRR;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct dbgPin_s {
|
||||||
|
ioTag_t tag;
|
||||||
|
} dbgPin_t;
|
||||||
|
|
||||||
void dbgPinInit(void);
|
void dbgPinInit(void);
|
||||||
void dbgPinHi(int index);
|
void dbgPinHi(int index);
|
||||||
void dbgPinLo(int index);
|
void dbgPinLo(int index);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue