From 3ce7f7a1e0f6d98cd4bd1cd6f20bbe89f154015e Mon Sep 17 00:00:00 2001 From: kedeng Date: Fri, 11 Jul 2025 20:27:48 +0800 Subject: [PATCH] add FORCE option to dshot_edt, remove dshot_edt_always_decode --- src/main/cli/settings.c | 12 ++++++++++-- src/main/cli/settings.h | 3 +++ src/main/drivers/dshot.c | 2 +- src/main/pg/motor.c | 6 +++--- src/main/pg/motor.h | 7 ++++++- src/test/unit/pg_unittest.cc | 1 - 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 950960367d..259c162f65 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -223,6 +223,12 @@ const char * const lookupTableOffOn[] = { "OFF", "ON" }; +#ifdef USE_DSHOT_TELEMETRY +static const char * const lookupTableDshotEdt[] = { + "OFF", "ON", "FORCE" +}; +#endif + static const char * const lookupTableCrashRecovery[] = { "OFF", "ON" ,"BEEP", "DISARM" }; @@ -643,6 +649,9 @@ const lookupTableEntry_t lookupTables[] = { #endif LOOKUP_TABLE_ENTRY(debugModeNames), LOOKUP_TABLE_ENTRY(lookupTablePwmProtocol), +#ifdef USE_DSHOT_TELEMETRY + LOOKUP_TABLE_ENTRY(lookupTableDshotEdt), +#endif LOOKUP_TABLE_ENTRY(lookupTableLowpassType), LOOKUP_TABLE_ENTRY(lookupTableDtermLowpassType), LOOKUP_TABLE_ENTRY(lookupTableFailsafe), @@ -955,8 +964,7 @@ const clivalue_t valueTable[] = { #endif #ifdef USE_DSHOT_TELEMETRY { PARAM_NAME_DSHOT_BIDIR, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotTelemetry) }, - { "dshot_edt", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotEdt) }, - { "dshot_edt_always_decode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotEdtAlwaysDecode) }, + { "dshot_edt", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_DSHOT_EDT }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotEdt) }, #endif #ifdef USE_DSHOT_BITBANG { "dshot_bitbang", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON_AUTO }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotBitbang) }, diff --git a/src/main/cli/settings.h b/src/main/cli/settings.h index 8c79b54aa2..763643e4ed 100644 --- a/src/main/cli/settings.h +++ b/src/main/cli/settings.h @@ -64,6 +64,9 @@ typedef enum { #endif TABLE_DEBUG, TABLE_MOTOR_PWM_PROTOCOL, +#ifdef USE_DSHOT_TELEMETRY + TABLE_DSHOT_EDT, +#endif TABLE_GYRO_LPF_TYPE, TABLE_DTERM_LPF_TYPE, TABLE_FAILSAFE, diff --git a/src/main/drivers/dshot.c b/src/main/drivers/dshot.c index 3c50dbaba5..29c7cfd3ee 100644 --- a/src/main/drivers/dshot.c +++ b/src/main/drivers/dshot.c @@ -181,7 +181,7 @@ void initDshotTelemetry(const timeUs_t looptimeUs) // erpmToHz is used by bidir dshot and ESC telemetry erpmToHz = ERPM_PER_LSB / SECONDS_PER_MINUTE / (motorConfig()->motorPoleCount / 2.0f); - edtAlwaysDecode = motorConfig()->dev.useDshotEdtAlwaysDecode; + edtAlwaysDecode = (motorConfig()->dev.useDshotEdt == DSHOT_EDT_FORCE); #ifdef USE_RPM_FILTER if (motorConfig()->dev.useDshotTelemetry) { diff --git a/src/main/pg/motor.c b/src/main/pg/motor.c index c34fe2e560..78771ca2ad 100644 --- a/src/main/pg/motor.c +++ b/src/main/pg/motor.c @@ -47,8 +47,8 @@ #define DEFAULT_DSHOT_TELEMETRY DSHOT_TELEMETRY_OFF #endif -#if !defined(DEFAULT_DSHOT_EDT_ALWAYS_DECODE) -#define DEFAULT_DSHOT_EDT_ALWAYS_DECODE false +#if !defined(DEFAULT_DSHOT_EDT) +#define DEFAULT_DSHOT_EDT DSHOT_EDT_OFF #endif PG_REGISTER_WITH_RESET_FN(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 4); @@ -116,7 +116,7 @@ void pgResetFn_motorConfig(motorConfig_t *motorConfig) #ifdef USE_DSHOT_TELEMETRY motorConfig->dev.useDshotTelemetry = DEFAULT_DSHOT_TELEMETRY; - motorConfig->dev.useDshotEdtAlwaysDecode = DEFAULT_DSHOT_EDT_ALWAYS_DECODE; + motorConfig->dev.useDshotEdt = DEFAULT_DSHOT_EDT; #endif #ifdef USE_DSHOT_BITBANG diff --git a/src/main/pg/motor.h b/src/main/pg/motor.h index 6161f43833..b9af4ebaa9 100644 --- a/src/main/pg/motor.h +++ b/src/main/pg/motor.h @@ -57,6 +57,12 @@ typedef enum { DSHOT_TELEMETRY_ON, } dshotTelemetry_e; +typedef enum { + DSHOT_EDT_OFF = 0, + DSHOT_EDT_ON = 1, + DSHOT_EDT_FORCE = 2, +} dshotEdt_e; + typedef struct motorDevConfig_s { uint16_t motorPwmRate; // The update rate of motor outputs (50-498Hz) uint8_t motorProtocol; // Pwm Protocol @@ -65,7 +71,6 @@ typedef struct motorDevConfig_s { uint8_t useBurstDshot; uint8_t useDshotTelemetry; uint8_t useDshotEdt; - uint8_t useDshotEdtAlwaysDecode; ioTag_t ioTags[MAX_SUPPORTED_MOTORS]; uint8_t motorTransportProtocol; uint8_t useDshotBitbang; diff --git a/src/test/unit/pg_unittest.cc b/src/test/unit/pg_unittest.cc index 866e9d0485..8d0fd935db 100644 --- a/src/test/unit/pg_unittest.cc +++ b/src/test/unit/pg_unittest.cc @@ -43,7 +43,6 @@ PG_RESET_TEMPLATE(motorConfig_t, motorConfig, .useBurstDshot = 0, .useDshotTelemetry = 0, .useDshotEdt = 0, - .useDshotEdtAlwaysDecode = 0, .ioTags = {IO_TAG_NONE, IO_TAG_NONE, IO_TAG_NONE, IO_TAG_NONE}, .motorTransportProtocol = 0, .useDshotBitbang = 0,