1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 05:15:25 +03:00

Fixed problems with bitbanged Dshot and lazily allocated timers.

This commit is contained in:
mikeller 2019-09-10 01:48:25 +12:00
parent 534dc31ab3
commit 2b98f137db
5 changed files with 20 additions and 0 deletions

View file

@ -477,6 +477,10 @@ static const char* const lookupTableInterpolatedSetpoint[] = {
"OFF", "ON", "AVERAGED" "OFF", "ON", "AVERAGED"
}; };
static const char* const lookupTableDshotBitbangedTimer[] = {
"AUTO", "TIM1", "TIM8"
};
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) } #define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
@ -594,6 +598,7 @@ const lookupTableEntry_t lookupTables[] = {
LOOKUP_TABLE_ENTRY(lookupTablePositionAltSource), LOOKUP_TABLE_ENTRY(lookupTablePositionAltSource),
LOOKUP_TABLE_ENTRY(lookupTableOffOnAuto), LOOKUP_TABLE_ENTRY(lookupTableOffOnAuto),
LOOKUP_TABLE_ENTRY(lookupTableInterpolatedSetpoint), LOOKUP_TABLE_ENTRY(lookupTableInterpolatedSetpoint),
LOOKUP_TABLE_ENTRY(lookupTableDshotBitbangedTimer),
}; };
#undef LOOKUP_TABLE_ENTRY #undef LOOKUP_TABLE_ENTRY
@ -768,6 +773,7 @@ const clivalue_t valueTable[] = {
#endif #endif
#ifdef USE_DSHOT_BITBANG #ifdef USE_DSHOT_BITBANG
{ "dshot_bitbang", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON_AUTO }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotBitbang) }, { "dshot_bitbang", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON_AUTO }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotBitbang) },
{ "dshot_bitbang_timer", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_DSHOT_BITBANGED_TIMER }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotBitbangedTimer) },
#endif #endif
#endif #endif
{ "use_unsynced_pwm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useUnsyncedPwm) }, { "use_unsynced_pwm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useUnsyncedPwm) },

View file

@ -137,6 +137,7 @@ typedef enum {
TABLE_POSITION_ALT_SOURCE, TABLE_POSITION_ALT_SOURCE,
TABLE_OFF_ON_AUTO, TABLE_OFF_ON_AUTO,
TABLE_INTERPOLATED_SP, TABLE_INTERPOLATED_SP,
TABLE_DSHOT_BITBANGED_TIMER,
LOOKUP_TABLE_COUNT LOOKUP_TABLE_COUNT
} lookupTableIndex_e; } lookupTableIndex_e;

View file

@ -311,6 +311,10 @@ static void bbFindPacerTimer(void)
for (unsigned timerIndex = 0; timerIndex < ARRAYLEN(bbTimerHardware); timerIndex++) { for (unsigned timerIndex = 0; timerIndex < ARRAYLEN(bbTimerHardware); timerIndex++) {
timer = &bbTimerHardware[timerIndex]; timer = &bbTimerHardware[timerIndex];
int timNumber = timerGetTIMNumber(timer->tim); int timNumber = timerGetTIMNumber(timer->tim);
if ((motorConfig()->dev.useDshotBitbangedTimer == DSHOT_BITBANGED_TIMER_TIM1 && timNumber != 1)
|| (motorConfig()->dev.useDshotBitbangedTimer == DSHOT_BITBANGED_TIMER_TIM8 && timNumber != 8)) {
continue;
}
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 resourceOwner_e timerOwner = timerGetOwner(timNumber, CC_CHANNEL_FROM_INDEX(channel))->owner;
@ -334,6 +338,7 @@ static void bbFindPacerTimer(void)
if (dmaGetOwner(dmaIdentifier)->owner == OWNER_FREE && if (dmaGetOwner(dmaIdentifier)->owner == OWNER_FREE &&
!usedTimerChannels[timNumber][timer->channel]) { !usedTimerChannels[timNumber][timer->channel]) {
usedTimerChannels[timNumber][timer->channel] = true; usedTimerChannels[timNumber][timer->channel] = true;
break; break;
} }
} }

View file

@ -76,6 +76,7 @@ void pgResetFn_motorConfig(motorConfig_t *motorConfig)
#ifdef USE_DSHOT_BITBANG #ifdef USE_DSHOT_BITBANG
motorConfig->dev.useDshotBitbang = DSHOT_BITBANG_AUTO; motorConfig->dev.useDshotBitbang = DSHOT_BITBANG_AUTO;
motorConfig->dev.useDshotBitbangedTimer = DSHOT_BITBANGED_TIMER_AUTO;
#endif #endif
} }

View file

@ -25,6 +25,12 @@
#include "drivers/io.h" #include "drivers/io.h"
#include "drivers/dshot_bitbang.h" #include "drivers/dshot_bitbang.h"
typedef enum {
DSHOT_BITBANGED_TIMER_AUTO = 0,
DSHOT_BITBANGED_TIMER_TIM1,
DSHOT_BITBANGED_TIMER_TIM8,
} dshotBitbangedTimer_e;
typedef struct motorDevConfig_s { typedef struct motorDevConfig_s {
uint16_t motorPwmRate; // The update rate of motor outputs (50-498Hz) uint16_t motorPwmRate; // The update rate of motor outputs (50-498Hz)
uint8_t motorPwmProtocol; // Pwm Protocol uint8_t motorPwmProtocol; // Pwm Protocol
@ -35,6 +41,7 @@ typedef struct motorDevConfig_s {
ioTag_t ioTags[MAX_SUPPORTED_MOTORS]; ioTag_t ioTags[MAX_SUPPORTED_MOTORS];
uint8_t motorTransportProtocol; uint8_t motorTransportProtocol;
uint8_t useDshotBitbang; uint8_t useDshotBitbang;
uint8_t useDshotBitbangedTimer;
} motorDevConfig_t; } motorDevConfig_t;
typedef struct motorConfig_s { typedef struct motorConfig_s {