diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 6de1c403fd2..49b9ffc8139 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -859,6 +859,7 @@ const clivalue_t valueTable[] = { #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) }, { "dshot_bitbang_timer", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_DSHOT_BITBANGED_TIMER }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useDshotBitbangedTimer) }, + { "dshot_telemetry_start_margin", VAR_UINT8 | HARDWARE_VALUE , .config.minmaxUnsigned = { 0, 100 }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.telemetryStartMargin) }, #endif #endif { PARAM_NAME_USE_UNSYNCED_PWM, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useUnsyncedPwm) }, diff --git a/src/main/drivers/dshot_bitbang_decode.c b/src/main/drivers/dshot_bitbang_decode.c index ba6249b3d4b..441391cd1fd 100644 --- a/src/main/drivers/dshot_bitbang_decode.c +++ b/src/main/drivers/dshot_bitbang_decode.c @@ -49,8 +49,6 @@ uint16_t bbBuffer[134]; #define BITBAND_SRAM_BASE 0x22000000 #define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + (((a)-BITBAND_SRAM_REF)<<5) + ((b)<<2))) // Convert SRAM address -#define DSHOT_TELEMETRY_START_MARGIN 10 - static uint8_t preambleSkip = 0; typedef struct bitBandWord_s { @@ -217,7 +215,13 @@ uint32_t decode_bb_bitband( uint16_t buffer[], uint32_t count, uint32_t bit) #endif // The anticipated edges were observed - preambleSkip = startMargin - DSHOT_TELEMETRY_START_MARGIN; + + // Attempt to skip the preamble ahead of the telemetry to save CPU + if (startMargin > motorConfig()->dev.telemetryStartMargin) { + preambleSkip = startMargin - motorConfig()->dev.telemetryStartMargin; + } else { + preambleSkip = 0; + } if (nlen > 0) { value <<= nlen; @@ -325,7 +329,13 @@ FAST_CODE uint32_t decode_bb( uint16_t buffer[], uint32_t count, uint32_t bit) } // The anticipated edges were observed - preambleSkip = startMargin - DSHOT_TELEMETRY_START_MARGIN; + + // Attempt to skip the preamble ahead of the telemetry to save CPU + if (startMargin > motorConfig()->dev.telemetryStartMargin) { + preambleSkip = startMargin - motorConfig()->dev.telemetryStartMargin; + } else { + preambleSkip = 0; + } if (nlen > 0) { value <<= nlen; diff --git a/src/main/pg/motor.c b/src/main/pg/motor.c index 10d341c7394..419e48b8e94 100644 --- a/src/main/pg/motor.c +++ b/src/main/pg/motor.c @@ -44,6 +44,10 @@ #define DEFAULT_DSHOT_BURST DSHOT_DMAR_OFF #endif +#if !defined(DSHOT_TELEMETRY_START_MARGIN) +#define DSHOT_TELEMETRY_START_MARGIN 10 +#endif + PG_REGISTER_WITH_RESET_FN(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 2); void pgResetFn_motorConfig(motorConfig_t *motorConfig) @@ -110,6 +114,7 @@ void pgResetFn_motorConfig(motorConfig_t *motorConfig) #ifdef USE_DSHOT_BITBANG motorConfig->dev.useDshotBitbang = DEFAULT_DSHOT_BITBANG; motorConfig->dev.useDshotBitbangedTimer = DSHOT_BITBANGED_TIMER_DEFAULT; + motorConfig->dev.telemetryStartMargin = DSHOT_TELEMETRY_START_MARGIN; #endif } diff --git a/src/main/pg/motor.h b/src/main/pg/motor.h index 8c55a87b848..135afd4b204 100644 --- a/src/main/pg/motor.h +++ b/src/main/pg/motor.h @@ -50,6 +50,7 @@ typedef struct motorDevConfig_s { uint8_t useDshotBitbang; uint8_t useDshotBitbangedTimer; uint8_t motorOutputReordering[MAX_SUPPORTED_MOTORS]; // Reindexing motors for "remap motors" feature in Configurator + uint8_t telemetryStartMargin; } motorDevConfig_t; typedef struct motorConfig_s {