1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Merge pull request #10863 from mikeller/add_n_channel_to_timer_show

This commit is contained in:
Michael Keller 2021-08-04 01:43:30 +12:00 committed by GitHub
commit 8a18651319
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 33 deletions

View file

@ -1588,7 +1588,7 @@ static void cliSerialPassthrough(const char *cmdName, char *cmdline)
for (unsigned i = 0; i < getMotorCount(); i++) { for (unsigned i = 0; i < getMotorCount(); i++) {
const ioTag_t tag = motorConfig()->dev.ioTags[i]; const ioTag_t tag = motorConfig()->dev.ioTags[i];
if (tag) { if (tag) {
const timerHardware_t *timerHardware = timerGetByTag(tag); const timerHardware_t *timerHardware = timerGetConfiguredByTag(tag);
if (timerHardware) { if (timerHardware) {
IO_t io = IOGetByTag(tag); IO_t io = IOGetByTag(tag);
IOInit(io, OWNER_MOTOR, 0); IOInit(io, OWNER_MOTOR, 0);
@ -5645,7 +5645,7 @@ static void cliDmaopt(const char *cmdName, char *cmdline)
#if defined(USE_TIMER_MGMT) #if defined(USE_TIMER_MGMT)
timerIoConfig = timerIoConfigByTag(ioTag); timerIoConfig = timerIoConfigByTag(ioTag);
#endif #endif
timer = timerGetByTag(ioTag); timer = timerGetConfiguredByTag(ioTag);
} }
// opt or list // opt or list
@ -5863,7 +5863,8 @@ static void showTimers(void)
cliPrintf("TIM%d:", timerNumber); cliPrintf("TIM%d:", timerNumber);
bool timerUsed = false; bool timerUsed = false;
for (unsigned timerIndex = 0; timerIndex < CC_CHANNELS_PER_TIMER; timerIndex++) { for (unsigned timerIndex = 0; timerIndex < CC_CHANNELS_PER_TIMER; timerIndex++) {
const resourceOwner_t *timerOwner = timerGetOwner(timerNumber, CC_CHANNEL_FROM_INDEX(timerIndex)); const timerHardware_t *timer = timerGetAllocatedByNumberAndChannel(timerNumber, CC_CHANNEL_FROM_INDEX(timerIndex));
const resourceOwner_t *timerOwner = timerGetOwner(timer);
if (timerOwner->owner) { if (timerOwner->owner) {
if (!timerUsed) { if (!timerUsed) {
timerUsed = true; timerUsed = true;
@ -5872,9 +5873,9 @@ static void showTimers(void)
} }
if (timerOwner->resourceIndex > 0) { if (timerOwner->resourceIndex > 0) {
cliPrintLinef(" CH%d: %s %d", timerIndex + 1, ownerNames[timerOwner->owner], timerOwner->resourceIndex); cliPrintLinef(" CH%d%s: %s %d", timerIndex + 1, timer->output & TIMER_OUTPUT_N_CHANNEL ? "N" : " ", ownerNames[timerOwner->owner], timerOwner->resourceIndex);
} else { } else {
cliPrintLinef(" CH%d: %s", timerIndex + 1, ownerNames[timerOwner->owner]); cliPrintLinef(" CH%d%s: %s", timerIndex + 1, timer->output & TIMER_OUTPUT_N_CHANNEL ? "N" : " ", ownerNames[timerOwner->owner]);
} }
} }
} }

View file

@ -476,7 +476,7 @@ static void validateAndFixConfig(void)
#if defined(USE_BEEPER) #if defined(USE_BEEPER)
#ifdef USE_TIMER #ifdef USE_TIMER
if (beeperDevConfig()->frequency && !timerGetByTag(beeperDevConfig()->ioTag)) { if (beeperDevConfig()->frequency && !timerGetConfiguredByTag(beeperDevConfig()->ioTag)) {
beeperDevConfigMutable()->frequency = 0; beeperDevConfigMutable()->frequency = 0;
} }
#endif #endif

View file

@ -245,11 +245,11 @@ static bbPort_t *bbAllocMotorPort(int portIndex)
return bbPort; return bbPort;
} }
const resourceOwner_t *dshotBitbangTimerGetOwner(int8_t timerNumber, uint16_t timerChannel) const resourceOwner_t *dshotBitbangTimerGetOwner(const timerHardware_t *timer)
{ {
for (int index = 0; index < usedMotorPorts; index++) { for (int index = 0; index < usedMotorPorts; index++) {
const timerHardware_t *timer = bbPorts[index].timhw; const timerHardware_t *bitbangTimer = bbPorts[index].timhw;
if (timerGetTIMNumber(timer->tim) == timerNumber && timer->channel == timerChannel) { if (bitbangTimer && bitbangTimer == timer) {
return &bbPorts[index].owner; return &bbPorts[index].owner;
} }
} }
@ -351,7 +351,8 @@ static void bbFindPacerTimer(void)
} }
bool timerConflict = false; bool timerConflict = false;
for (int channel = 0; channel < CC_CHANNELS_PER_TIMER; channel++) { for (int channel = 0; channel < CC_CHANNELS_PER_TIMER; channel++) {
const resourceOwner_e timerOwner = timerGetOwner(timNumber, CC_CHANNEL_FROM_INDEX(channel))->owner; const timerHardware_t *timer = timerGetAllocatedByNumberAndChannel(timNumber, CC_CHANNEL_FROM_INDEX(channel));
const resourceOwner_e timerOwner = timerGetOwner(timer)->owner;
if (timerOwner != OWNER_FREE && timerOwner != OWNER_DSHOT_BITBANG) { if (timerOwner != OWNER_FREE && timerOwner != OWNER_DSHOT_BITBANG) {
timerConflict = true; timerConflict = true;
break; break;
@ -709,7 +710,7 @@ motorDevice_t *dshotBitbangDevInit(const motorDevConfig_t *motorConfig, uint8_t
for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS && motorIndex < motorCount; motorIndex++) { for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS && motorIndex < motorCount; motorIndex++) {
const unsigned reorderedMotorIndex = motorConfig->motorOutputReordering[motorIndex]; const unsigned reorderedMotorIndex = motorConfig->motorOutputReordering[motorIndex];
const timerHardware_t *timerHardware = timerGetByTag(motorConfig->ioTags[reorderedMotorIndex]); const timerHardware_t *timerHardware = timerGetConfiguredByTag(motorConfig->ioTags[reorderedMotorIndex]);
const IO_t io = IOGetByTag(motorConfig->ioTags[reorderedMotorIndex]); const IO_t io = IOGetByTag(motorConfig->ioTags[reorderedMotorIndex]);
uint8_t output = motorConfig->motorPwmInversion ? timerHardware->output ^ TIMER_OUTPUT_INVERTED : timerHardware->output; uint8_t output = motorConfig->motorPwmInversion ? timerHardware->output ^ TIMER_OUTPUT_INVERTED : timerHardware->output;

View file

@ -39,4 +39,4 @@ struct motorDevConfig_s;
struct motorDevice_s; struct motorDevice_s;
struct motorDevice_s *dshotBitbangDevInit(const struct motorDevConfig_s *motorConfig, uint8_t motorCount); struct motorDevice_s *dshotBitbangDevInit(const struct motorDevConfig_s *motorConfig, uint8_t motorCount);
dshotBitbangStatus_e dshotBitbangGetStatus(); dshotBitbangStatus_e dshotBitbangGetStatus();
const resourceOwner_t *dshotBitbangTimerGetOwner(int8_t timerNumber, uint16_t timerChannel); const resourceOwner_t *dshotBitbangTimerGetOwner(const timerHardware_t *timer);

View file

@ -278,9 +278,10 @@ extern const resourceOwner_t freeOwner;
struct timerIOConfig_s; struct timerIOConfig_s;
struct timerIOConfig_s *timerIoConfigByTag(ioTag_t ioTag); struct timerIOConfig_s *timerIoConfigByTag(ioTag_t ioTag);
const resourceOwner_t *timerGetOwner(int8_t timerNumber, uint16_t timerChannel); const timerHardware_t *timerGetAllocatedByNumberAndChannel(int8_t timerNumber, uint16_t timerChannel);
const resourceOwner_t *timerGetOwner(const timerHardware_t *timer);
#endif #endif
const timerHardware_t *timerGetByTag(ioTag_t ioTag); const timerHardware_t *timerGetConfiguredByTag(ioTag_t ioTag);
const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8_t resourceIndex); const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8_t resourceIndex);
const timerHardware_t *timerGetByTagAndIndex(ioTag_t ioTag, unsigned timerIndex); const timerHardware_t *timerGetByTagAndIndex(ioTag_t ioTag, unsigned timerIndex);
ioTag_t timerioTagGetByUsage(timerUsageFlag_e usageFlag, uint8_t index); ioTag_t timerioTagGetByUsage(timerUsageFlag_e usageFlag, uint8_t index);

View file

@ -44,16 +44,6 @@ timerIOConfig_t *timerIoConfigByTag(ioTag_t ioTag)
return NULL; return NULL;
} }
static uint8_t timerIndexByTag(ioTag_t ioTag)
{
for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) {
if (timerIOConfig(i)->ioTag == ioTag) {
return timerIOConfig(i)->index;
}
}
return 0;
}
const timerHardware_t *timerGetByTagAndIndex(ioTag_t ioTag, unsigned timerIndex) const timerHardware_t *timerGetByTagAndIndex(ioTag_t ioTag, unsigned timerIndex)
{ {
@ -74,19 +64,38 @@ const timerHardware_t *timerGetByTagAndIndex(ioTag_t ioTag, unsigned timerIndex)
return NULL; return NULL;
} }
const timerHardware_t *timerGetByTag(ioTag_t ioTag) const timerHardware_t *timerGetConfiguredByTag(ioTag_t ioTag)
{ {
uint8_t timerIndex = timerIndexByTag(ioTag); uint8_t timerIndex = 0;
for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) {
if (timerIOConfig(i)->ioTag == ioTag) {
timerIndex = timerIOConfig(i)->index;
break;
}
}
return timerGetByTagAndIndex(ioTag, timerIndex); return timerGetByTagAndIndex(ioTag, timerIndex);
} }
const resourceOwner_t *timerGetOwner(int8_t timerNumber, uint16_t timerChannel) const timerHardware_t *timerGetAllocatedByNumberAndChannel(int8_t timerNumber, uint16_t timerChannel)
{
for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) {
const timerHardware_t *timer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index);
if (timer && timerGetTIMNumber(timer->tim) == timerNumber && timer->channel == timerChannel && timerOwners[i].owner) {
return timer;
}
}
return NULL;
}
const resourceOwner_t *timerGetOwner(const timerHardware_t *timer)
{ {
const resourceOwner_t *timerOwner = &freeOwner; const resourceOwner_t *timerOwner = &freeOwner;
for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) { for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) {
const timerHardware_t *timer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index); const timerHardware_t *assignedTimer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index);
if (timer && timerGetTIMNumber(timer->tim) == timerNumber && timer->channel == timerChannel) { if (assignedTimer && assignedTimer == timer) {
timerOwner = &timerOwners[i]; timerOwner = &timerOwners[i];
break; break;
@ -95,7 +104,7 @@ const resourceOwner_t *timerGetOwner(int8_t timerNumber, uint16_t timerChannel)
#if defined(USE_DSHOT_BITBANG) #if defined(USE_DSHOT_BITBANG)
if (!timerOwner->owner) { if (!timerOwner->owner) {
timerOwner = dshotBitbangTimerGetOwner(timerNumber, timerChannel); timerOwner = dshotBitbangTimerGetOwner(timer);
} }
#endif #endif
@ -112,7 +121,7 @@ const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8
if (timerIOConfig(i)->ioTag == ioTag) { if (timerIOConfig(i)->ioTag == ioTag) {
const timerHardware_t *timer = timerGetByTagAndIndex(ioTag, timerIOConfig(i)->index); const timerHardware_t *timer = timerGetByTagAndIndex(ioTag, timerIOConfig(i)->index);
if (timerGetOwner(timerGetTIMNumber(timer->tim), timer->channel)->owner) { if (timerGetOwner(timer)->owner) {
return NULL; return NULL;
} }
@ -127,7 +136,7 @@ const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8
} }
#else #else
const timerHardware_t *timerGetByTag(ioTag_t ioTag) const timerHardware_t *timerGetConfiguredByTag(ioTag_t ioTag)
{ {
#if TIMER_CHANNEL_COUNT > 0 #if TIMER_CHANNEL_COUNT > 0
for (unsigned i = 0; i < TIMER_CHANNEL_COUNT; i++) { for (unsigned i = 0; i < TIMER_CHANNEL_COUNT; i++) {
@ -146,7 +155,7 @@ const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8
UNUSED(owner); UNUSED(owner);
UNUSED(resourceIndex); UNUSED(resourceIndex);
return timerGetByTag(ioTag); return timerGetConfiguredByTag(ioTag);
} }
#endif #endif