Skip to content

Commit

Permalink
Add dshot_telemetry_start_margin setting (betaflight#12912)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveCEvans authored and freasy committed Jul 19, 2023
1 parent 76a7636 commit 50a5d2d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/cli/settings.c
Expand Up @@ -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) },
Expand Down
18 changes: 14 additions & 4 deletions src/main/drivers/dshot_bitbang_decode.c
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/pg/motor.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions src/main/pg/motor.h
Expand Up @@ -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 {
Expand Down

0 comments on commit 50a5d2d

Please sign in to comment.