diff --git a/src/main/drivers/dshot_bitbang.c b/src/main/drivers/dshot_bitbang.c index d2fad40c06..d39218a02b 100644 --- a/src/main/drivers/dshot_bitbang.c +++ b/src/main/drivers/dshot_bitbang.c @@ -238,6 +238,18 @@ static bbPort_t *bbAllocMotorPort(int portIndex) return bbPort; } +const timerHardware_t *dshotBitbangTimerGetAllocatedByNumberAndChannel(int8_t timerNumber, uint16_t timerChannel) +{ + for (int index = 0; index < usedMotorPorts; index++) { + const timerHardware_t *bitbangTimer = bbPorts[index].timhw; + if (bitbangTimer && timerGetTIMNumber(bitbangTimer->tim) == timerNumber && bitbangTimer->channel == timerChannel && bbPorts[index].owner.owner) { + return bitbangTimer; + } + } + + return NULL; +} + const resourceOwner_t *dshotBitbangTimerGetOwner(const timerHardware_t *timer) { for (int index = 0; index < usedMotorPorts; index++) { @@ -280,7 +292,7 @@ static void bbAllocDma(bbPort_t *bbPort) #endif dmaIdentifier_e dmaIdentifier = dmaGetIdentifier(bbPort->dmaResource); - dmaInit(dmaIdentifier, OWNER_DSHOT_BITBANG, bbPort->owner.resourceIndex); + dmaInit(dmaIdentifier, bbPort->owner.owner, bbPort->owner.resourceIndex); bbPort->dmaSource = timerDmaSource(timhw->channel); bbPacer_t *bbPacer = bbFindMotorPacer(timhw->tim); diff --git a/src/main/drivers/dshot_bitbang.h b/src/main/drivers/dshot_bitbang.h index 8bfffe5476..b24a8f446b 100644 --- a/src/main/drivers/dshot_bitbang.h +++ b/src/main/drivers/dshot_bitbang.h @@ -39,4 +39,5 @@ struct motorDevConfig_s; struct motorDevice_s; struct motorDevice_s *dshotBitbangDevInit(const struct motorDevConfig_s *motorConfig, uint8_t motorCount); dshotBitbangStatus_e dshotBitbangGetStatus(); +const timerHardware_t *dshotBitbangTimerGetAllocatedByNumberAndChannel(int8_t timerNumber, uint16_t timerChannel); const resourceOwner_t *dshotBitbangTimerGetOwner(const timerHardware_t *timer); diff --git a/src/main/drivers/timer_common.c b/src/main/drivers/timer_common.c index 661baf60df..7f8084ecde 100644 --- a/src/main/drivers/timer_common.c +++ b/src/main/drivers/timer_common.c @@ -87,28 +87,27 @@ const timerHardware_t *timerGetAllocatedByNumberAndChannel(int8_t timerNumber, u } } +#if defined(USE_DSHOT_BITBANG) + return dshotBitbangTimerGetAllocatedByNumberAndChannel(timerNumber, timerChannel); +#else return NULL; +#endif } const resourceOwner_t *timerGetOwner(const timerHardware_t *timer) { - const resourceOwner_t *timerOwner = &freeOwner; for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) { const timerHardware_t *assignedTimer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index); if (assignedTimer && assignedTimer == timer) { - timerOwner = &timerOwners[i]; - - break; + return &timerOwners[i]; } } #if defined(USE_DSHOT_BITBANG) - if (!timerOwner->owner) { - timerOwner = dshotBitbangTimerGetOwner(timer); - } -#endif - + return dshotBitbangTimerGetOwner(timer); +#else return timerOwner; +#endif } const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8_t resourceIndex)