Skip to content

Commit

Permalink
[MAINT] Add dshot_telemetry_start_margin setting (#12912) (#12964)
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Jul 17, 2023
1 parent a35fa26 commit c8e6124
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/cli/settings.c
Expand Up @@ -847,6 +847,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
17 changes: 14 additions & 3 deletions src/main/drivers/dshot_bitbang_decode.c
Expand Up @@ -49,7 +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 @@ -220,7 +219,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 @@ -330,7 +335,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
19 changes: 18 additions & 1 deletion src/main/pg/motor.c
Expand Up @@ -33,7 +33,23 @@
#include "pg/pg_ids.h"
#include "pg/motor.h"

PG_REGISTER_WITH_RESET_FN(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 1);
#if !defined(DEFAULT_DSHOT_BITBANG)
#define DEFAULT_DSHOT_BITBANG DSHOT_BITBANG_AUTO
#endif

#if !defined(DSHOT_BITBANGED_TIMER_DEFAULT)
#define DSHOT_BITBANGED_TIMER_DEFAULT DSHOT_BITBANGED_TIMER_AUTO
#endif

#if !defined(DEFAULT_DSHOT_BURST)
#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 @@ -81,6 +97,7 @@ void pgResetFn_motorConfig(motorConfig_t *motorConfig)
#ifdef USE_DSHOT_BITBANG
motorConfig->dev.useDshotBitbang = DSHOT_BITBANG_DEFAULT;
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 c8e6124

Please sign in to comment.