1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 19:40:31 +03:00

Use the cached value of useDshotTelemetry to ensure consistent runtime use if dshot_bidir is changed (#13589)

This commit is contained in:
Steve Evans 2024-04-28 00:31:50 +01:00 committed by GitHub
parent 54377940e0
commit 565de1b68b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 19 additions and 20 deletions

View file

@ -469,7 +469,7 @@ static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
case CONDITION(MOTOR_6_HAS_RPM): case CONDITION(MOTOR_6_HAS_RPM):
case CONDITION(MOTOR_7_HAS_RPM): case CONDITION(MOTOR_7_HAS_RPM):
case CONDITION(MOTOR_8_HAS_RPM): case CONDITION(MOTOR_8_HAS_RPM):
return (getMotorCount() >= condition - CONDITION(MOTOR_1_HAS_RPM) + 1) && (motorConfig()->dev.useDshotTelemetry) && isFieldEnabled(FIELD_SELECT(RPM)); return (getMotorCount() >= condition - CONDITION(MOTOR_1_HAS_RPM) + 1) && useDshotTelemetry && isFieldEnabled(FIELD_SELECT(RPM));
#endif #endif
case CONDITION(TRICOPTER): case CONDITION(TRICOPTER):
@ -1524,7 +1524,7 @@ static bool blackboxWriteSysinfo(void)
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DYN_NOTCH_MIN_HZ, "%d", dynNotchConfig()->dyn_notch_min_hz); BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DYN_NOTCH_MIN_HZ, "%d", dynNotchConfig()->dyn_notch_min_hz);
#endif #endif
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DSHOT_BIDIR, "%d", motorConfig()->dev.useDshotTelemetry); BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DSHOT_BIDIR, "%d", useDshotTelemetry);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_MOTOR_POLES, "%d", motorConfig()->motorPoleCount); BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_MOTOR_POLES, "%d", motorConfig()->motorPoleCount);
#endif #endif
#ifdef USE_RPM_FILTER #ifdef USE_RPM_FILTER

View file

@ -291,7 +291,7 @@ static void dshotUpdateTelemetryData(uint8_t motorIndex, dshotTelemetryType_t ty
FAST_CODE_NOINLINE void updateDshotTelemetry(void) FAST_CODE_NOINLINE void updateDshotTelemetry(void)
{ {
if (!motorConfig()->dev.useDshotTelemetry) { if (!useDshotTelemetry) {
return; return;
} }

View file

@ -89,9 +89,9 @@ float dshotConvertFromExternal(uint16_t externalValue);
uint16_t dshotConvertToExternal(float motorValue); uint16_t dshotConvertToExternal(float motorValue);
uint16_t prepareDshotPacket(dshotProtocolControl_t *pcb); uint16_t prepareDshotPacket(dshotProtocolControl_t *pcb);
extern bool useDshotTelemetry;
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
extern bool useDshotTelemetry;
typedef struct dshotTelemetryMotorState_s { typedef struct dshotTelemetryMotorState_s {
uint16_t rawValue; uint16_t rawValue;

View file

@ -63,7 +63,7 @@ void motorWriteAll(float *values)
#ifdef USE_PWM_OUTPUT #ifdef USE_PWM_OUTPUT
if (motorDevice->enabled) { if (motorDevice->enabled) {
#ifdef USE_DSHOT_BITBANG #ifdef USE_DSHOT_BITBANG
if (isDshotBitbangActive(&motorConfig()->dev)) { if (useDshotTelemetry && isDshotBitbangActive(&motorConfig()->dev)) {
// Initialise the output buffers // Initialise the output buffers
if (motorDevice->vTable.updateInit) { if (motorDevice->vTable.updateInit) {
motorDevice->vTable.updateInit(); motorDevice->vTable.updateInit();
@ -297,7 +297,7 @@ bool isMotorProtocolDshot(void)
bool isMotorProtocolBidirDshot(void) bool isMotorProtocolBidirDshot(void)
{ {
return isMotorProtocolDshot() && motorConfig()->dev.useDshotTelemetry; return isMotorProtocolDshot() && useDshotTelemetry;
} }
void motorDevInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount) void motorDevInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount)

View file

@ -363,7 +363,7 @@ void updateArmingStatus(void)
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
// If Dshot Telemetry is enabled and any motor isn't providing telemetry, then disable arming // If Dshot Telemetry is enabled and any motor isn't providing telemetry, then disable arming
if (motorConfig()->dev.useDshotTelemetry && !isDshotTelemetryActive()) { if (useDshotTelemetry && !isDshotTelemetryActive()) {
setArmingDisabled(ARMING_DISABLED_DSHOT_TELEM); setArmingDisabled(ARMING_DISABLED_DSHOT_TELEM);
} else { } else {
unsetArmingDisabled(ARMING_DISABLED_DSHOT_TELEM); unsetArmingDisabled(ARMING_DISABLED_DSHOT_TELEM);
@ -371,7 +371,7 @@ void updateArmingStatus(void)
#endif #endif
#ifdef USE_DSHOT_BITBANG #ifdef USE_DSHOT_BITBANG
if (isDshotBitbangActive(&motorConfig()->dev) && dshotBitbangGetStatus() != DSHOT_BITBANG_STATUS_OK) { if (useDshotTelemetry && isDshotBitbangActive(&motorConfig()->dev) && dshotBitbangGetStatus() != DSHOT_BITBANG_STATUS_OK) {
setArmingDisabled(ARMING_DISABLED_DSHOT_BITBANG); setArmingDisabled(ARMING_DISABLED_DSHOT_BITBANG);
} else { } else {
unsetArmingDisabled(ARMING_DISABLED_DSHOT_BITBANG); unsetArmingDisabled(ARMING_DISABLED_DSHOT_BITBANG);
@ -514,7 +514,7 @@ void tryArm(void)
if (isMotorProtocolDshot()) { if (isMotorProtocolDshot()) {
#if defined(USE_ESC_SENSOR) && defined(USE_DSHOT_TELEMETRY) #if defined(USE_ESC_SENSOR) && defined(USE_DSHOT_TELEMETRY)
// Try to activate extended DSHOT telemetry only if no esc sensor exists and dshot telemetry is active // Try to activate extended DSHOT telemetry only if no esc sensor exists and dshot telemetry is active
if (!featureIsEnabled(FEATURE_ESC_SENSOR) && motorConfig()->dev.useDshotTelemetry) { if (!featureIsEnabled(FEATURE_ESC_SENSOR) && useDshotTelemetry) {
dshotCleanTelemetryData(); dshotCleanTelemetryData();
if (motorConfig()->dev.useDshotEdt) { if (motorConfig()->dev.useDshotEdt) {
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_EXTENDED_TELEMETRY_ENABLE, DSHOT_CMD_TYPE_INLINE); dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_EXTENDED_TELEMETRY_ENABLE, DSHOT_CMD_TYPE_INLINE);

View file

@ -680,7 +680,7 @@ FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs)
#endif #endif
#ifdef USE_RPM_LIMIT #ifdef USE_RPM_LIMIT
if (RPM_LIMIT_ACTIVE && motorConfig()->dev.useDshotTelemetry && ARMING_FLAG(ARMED)) { if (RPM_LIMIT_ACTIVE && useDshotTelemetry && ARMING_FLAG(ARMED)) {
applyRpmLimiter(&mixerRuntime); applyRpmLimiter(&mixerRuntime);
} }
#endif #endif

View file

@ -328,7 +328,7 @@ void initEscEndpoints(void)
void mixerInitProfile(void) void mixerInitProfile(void)
{ {
#ifdef USE_DYN_IDLE #ifdef USE_DYN_IDLE
if (motorConfigMutable()->dev.useDshotTelemetry) { if (useDshotTelemetry) {
mixerRuntime.dynIdleMinRps = currentPidProfile->dyn_idle_min_rpm * 100.0f / 60.0f; mixerRuntime.dynIdleMinRps = currentPidProfile->dyn_idle_min_rpm * 100.0f / 60.0f;
} else { } else {
mixerRuntime.dynIdleMinRps = 0.0f; mixerRuntime.dynIdleMinRps = 0.0f;

View file

@ -68,7 +68,6 @@ FAST_DATA_ZERO_INIT static int notchUpdatesPerIteration;
FAST_DATA_ZERO_INIT static int motorIndex; FAST_DATA_ZERO_INIT static int motorIndex;
FAST_DATA_ZERO_INIT static int harmonicIndex; FAST_DATA_ZERO_INIT static int harmonicIndex;
void rpmFilterInit(const rpmFilterConfig_t *config, const timeUs_t looptimeUs) void rpmFilterInit(const rpmFilterConfig_t *config, const timeUs_t looptimeUs)
{ {
motorIndex = 0; motorIndex = 0;
@ -76,7 +75,7 @@ void rpmFilterInit(const rpmFilterConfig_t *config, const timeUs_t looptimeUs)
rpmFilter.numHarmonics = 0; // disable RPM Filtering rpmFilter.numHarmonics = 0; // disable RPM Filtering
// if bidirectional DShot is not available // if bidirectional DShot is not available
if (!motorConfig()->dev.useDshotTelemetry) { if (!useDshotTelemetry) {
return; return;
} }
@ -112,7 +111,7 @@ void rpmFilterInit(const rpmFilterConfig_t *config, const timeUs_t looptimeUs)
FAST_CODE_NOINLINE void rpmFilterUpdate(void) FAST_CODE_NOINLINE void rpmFilterUpdate(void)
{ {
if (!motorConfig()->dev.useDshotTelemetry) { if (!useDshotTelemetry) {
return; return;
} }

View file

@ -1218,7 +1218,7 @@ case MSP_NAME:
bool rpmDataAvailable = false; bool rpmDataAvailable = false;
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
if (motorConfig()->dev.useDshotTelemetry) { if (useDshotTelemetry) {
rpm = lrintf(getDshotRpm(i)); rpm = lrintf(getDshotRpm(i));
rpmDataAvailable = true; rpmDataAvailable = true;
invalidPct = 10000; // 100.00% invalidPct = 10000; // 100.00%
@ -1448,7 +1448,7 @@ case MSP_NAME:
sbufWriteU8(dst, getMotorCount()); sbufWriteU8(dst, getMotorCount());
sbufWriteU8(dst, motorConfig()->motorPoleCount); sbufWriteU8(dst, motorConfig()->motorPoleCount);
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
sbufWriteU8(dst, motorConfig()->dev.useDshotTelemetry); sbufWriteU8(dst, useDshotTelemetry);
#else #else
sbufWriteU8(dst, 0); sbufWriteU8(dst, 0);
#endif #endif
@ -1479,7 +1479,7 @@ case MSP_NAME:
} else } else
#endif #endif
#if defined(USE_DSHOT_TELEMETRY) #if defined(USE_DSHOT_TELEMETRY)
if (motorConfig()->dev.useDshotTelemetry) { if (useDshotTelemetry) {
sbufWriteU8(dst, getMotorCount()); sbufWriteU8(dst, getMotorCount());
for (int i = 0; i < getMotorCount(); i++) { for (int i = 0; i < getMotorCount(); i++) {
sbufWriteU8(dst, dshotTelemetryState.motorState[i].telemetryData[DSHOT_TELEMETRY_TYPE_TEMPERATURE]); sbufWriteU8(dst, dshotTelemetryState.motorState[i].telemetryData[DSHOT_TELEMETRY_TYPE_TEMPERATURE]);

View file

@ -608,7 +608,7 @@ static int32_t getAverageEscRpm(void)
} }
#endif #endif
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
if (motorConfig()->dev.useDshotTelemetry) { if (useDshotTelemetry) {
return lrintf(getDshotRpmAverage()); return lrintf(getDshotRpmAverage());
} }
#endif #endif

View file

@ -267,7 +267,7 @@ typedef int (*getEscRpmOrFreqFnPtr)(int i);
static int getEscRpm(int i) static int getEscRpm(int i)
{ {
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
if (motorConfig()->dev.useDshotTelemetry) { if (useDshotTelemetry) {
return lrintf(getDshotRpm(i)); return lrintf(getDshotRpm(i));
} }
#endif #endif
@ -2064,7 +2064,7 @@ void osdAddActiveElements(void)
#endif // GPS #endif // GPS
#if defined(USE_DSHOT_TELEMETRY) || defined(USE_ESC_SENSOR) #if defined(USE_DSHOT_TELEMETRY) || defined(USE_ESC_SENSOR)
if ((featureIsEnabled(FEATURE_ESC_SENSOR)) || (motorConfig()->dev.useDshotTelemetry)) { if ((featureIsEnabled(FEATURE_ESC_SENSOR)) || useDshotTelemetry) {
osdAddActiveElement(OSD_ESC_TMP); osdAddActiveElement(OSD_ESC_TMP);
osdAddActiveElement(OSD_ESC_RPM); osdAddActiveElement(OSD_ESC_RPM);
osdAddActiveElement(OSD_ESC_RPM_FREQ); osdAddActiveElement(OSD_ESC_RPM_FREQ);