mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Merge pull request #9712 from etracer65/fix_blocking_dshot_command
Fix blocking DSHOT commands
This commit is contained in:
commit
e060a0d507
5 changed files with 28 additions and 21 deletions
|
@ -3803,7 +3803,7 @@ static void executeEscInfoCommand(const char *cmdName, uint8_t escIndex)
|
||||||
|
|
||||||
startEscDataRead(escInfoBuffer, ESC_INFO_BLHELI32_EXPECTED_FRAME_SIZE);
|
startEscDataRead(escInfoBuffer, ESC_INFO_BLHELI32_EXPECTED_FRAME_SIZE);
|
||||||
|
|
||||||
dshotCommandWrite(escIndex, getMotorCount(), DSHOT_CMD_ESC_INFO, true);
|
dshotCommandWrite(escIndex, getMotorCount(), DSHOT_CMD_ESC_INFO, DSHOT_CMD_TYPE_BLOCKING);
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
|
@ -3811,9 +3811,6 @@ static void executeEscInfoCommand(const char *cmdName, uint8_t escIndex)
|
||||||
}
|
}
|
||||||
#endif // USE_ESC_SENSOR && USE_ESC_SENSOR_INFO
|
#endif // USE_ESC_SENSOR && USE_ESC_SENSOR_INFO
|
||||||
|
|
||||||
|
|
||||||
// XXX Review dshotprog command under refactored motor handling
|
|
||||||
|
|
||||||
static void cliDshotProg(const char *cmdName, char *cmdline)
|
static void cliDshotProg(const char *cmdName, char *cmdline)
|
||||||
{
|
{
|
||||||
if (isEmpty(cmdline) || !isMotorProtocolDshot()) {
|
if (isEmpty(cmdline) || !isMotorProtocolDshot()) {
|
||||||
|
@ -3854,7 +3851,7 @@ static void cliDshotProg(const char *cmdName, char *cmdline)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command != DSHOT_CMD_ESC_INFO) {
|
if (command != DSHOT_CMD_ESC_INFO) {
|
||||||
dshotCommandWrite(escIndex, getMotorCount(), command, true);
|
dshotCommandWrite(escIndex, getMotorCount(), command, DSHOT_CMD_TYPE_BLOCKING);
|
||||||
} else {
|
} else {
|
||||||
#if defined(USE_ESC_SENSOR) && defined(USE_ESC_SENSOR_INFO)
|
#if defined(USE_ESC_SENSOR) && defined(USE_ESC_SENSOR_INFO)
|
||||||
if (featureIsEnabled(FEATURE_ESC_SENSOR)) {
|
if (featureIsEnabled(FEATURE_ESC_SENSOR)) {
|
||||||
|
|
|
@ -151,18 +151,23 @@ static bool allMotorsAreIdle(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dshotCommandsAreEnabled(void)
|
bool dshotCommandsAreEnabled(dshotCommandType_e commandType)
|
||||||
{
|
{
|
||||||
if (motorIsEnabled() && motorGetMotorEnableTimeMs() && millis() > motorGetMotorEnableTimeMs() + DSHOT_PROTOCOL_DETECTION_DELAY_MS) {
|
bool ret = false;
|
||||||
return true;
|
|
||||||
} else {
|
if (commandType == DSHOT_CMD_TYPE_BLOCKING) {
|
||||||
return false;
|
ret = !motorIsEnabled();
|
||||||
|
} else if (commandType == DSHOT_CMD_TYPE_INLINE) {
|
||||||
|
if (motorIsEnabled() && motorGetMotorEnableTimeMs() && millis() > motorGetMotorEnableTimeMs() + DSHOT_PROTOCOL_DETECTION_DELAY_MS) {
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, bool blocking)
|
void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, dshotCommandType_e commandType)
|
||||||
{
|
{
|
||||||
if (!isMotorProtocolDshot() || !dshotCommandsAreEnabled() || (command > DSHOT_MAX_COMMAND) || dshotCommandQueueFull()) {
|
if (!isMotorProtocolDshot() || !dshotCommandsAreEnabled(commandType) || (command > DSHOT_MAX_COMMAND) || dshotCommandQueueFull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +197,7 @@ void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, bool
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocking) {
|
if (commandType == DSHOT_CMD_TYPE_BLOCKING) {
|
||||||
delayMicroseconds(DSHOT_INITIAL_DELAY_US - DSHOT_COMMAND_DELAY_US);
|
delayMicroseconds(DSHOT_INITIAL_DELAY_US - DSHOT_COMMAND_DELAY_US);
|
||||||
for (; repeats; repeats--) {
|
for (; repeats; repeats--) {
|
||||||
delayMicroseconds(DSHOT_COMMAND_DELAY_US);
|
delayMicroseconds(DSHOT_COMMAND_DELAY_US);
|
||||||
|
@ -213,7 +218,7 @@ void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, bool
|
||||||
dshotPwmDevice.vTable.updateComplete();
|
dshotPwmDevice.vTable.updateComplete();
|
||||||
}
|
}
|
||||||
delayMicroseconds(delayAfterCommandUs);
|
delayMicroseconds(delayAfterCommandUs);
|
||||||
} else {
|
} else if (commandType == DSHOT_CMD_TYPE_INLINE) {
|
||||||
dshotCommandControl_t *commandControl = addCommand();
|
dshotCommandControl_t *commandControl = addCommand();
|
||||||
if (commandControl) {
|
if (commandControl) {
|
||||||
commandControl->repeats = repeats;
|
commandControl->repeats = repeats;
|
||||||
|
|
|
@ -62,10 +62,15 @@ typedef enum {
|
||||||
DSHOT_CMD_MAX = 47
|
DSHOT_CMD_MAX = 47
|
||||||
} dshotCommands_e;
|
} dshotCommands_e;
|
||||||
|
|
||||||
void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, bool blocking);
|
typedef enum {
|
||||||
|
DSHOT_CMD_TYPE_INLINE = 0, // dshot commands sent inline with motor signal (motors must be enabled)
|
||||||
|
DSHOT_CMD_TYPE_BLOCKING // dshot commands sent in blocking method (motors must be disabled)
|
||||||
|
} dshotCommandType_e;
|
||||||
|
|
||||||
|
void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, dshotCommandType_e commandType);
|
||||||
void dshotSetPidLoopTime(uint32_t pidLoopTime);
|
void dshotSetPidLoopTime(uint32_t pidLoopTime);
|
||||||
bool dshotCommandQueueEmpty(void);
|
bool dshotCommandQueueEmpty(void);
|
||||||
bool dshotCommandIsProcessing(void);
|
bool dshotCommandIsProcessing(void);
|
||||||
uint8_t dshotCommandGetCurrent(uint8_t index);
|
uint8_t dshotCommandGetCurrent(uint8_t index);
|
||||||
bool dshotCommandOutputIsEnabled(uint8_t motorCount);
|
bool dshotCommandOutputIsEnabled(uint8_t motorCount);
|
||||||
bool dshotCommandsAreEnabled(void);
|
bool dshotCommandsAreEnabled(dshotCommandType_e commandType);
|
||||||
|
|
|
@ -277,7 +277,7 @@ void updateArmingStatus(void)
|
||||||
// We also need to prevent arming until it's possible to send DSHOT commands.
|
// We also need to prevent arming until it's possible to send DSHOT commands.
|
||||||
// Otherwise if the initial arming is in crash-flip the motor direction commands
|
// Otherwise if the initial arming is in crash-flip the motor direction commands
|
||||||
// might not be sent.
|
// might not be sent.
|
||||||
&& dshotCommandsAreEnabled()
|
&& dshotCommandsAreEnabled(DSHOT_CMD_TYPE_INLINE)
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
// If so, unset the grace time arming disable flag
|
// If so, unset the grace time arming disable flag
|
||||||
|
@ -458,7 +458,7 @@ void disarm(flightLogDisarmReason_e reason)
|
||||||
BEEP_OFF;
|
BEEP_OFF;
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
if (isMotorProtocolDshot() && flipOverAfterCrashActive && !featureIsEnabled(FEATURE_3D)) {
|
if (isMotorProtocolDshot() && flipOverAfterCrashActive && !featureIsEnabled(FEATURE_3D)) {
|
||||||
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL, false);
|
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL, DSHOT_CMD_TYPE_INLINE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
flipOverAfterCrashActive = false;
|
flipOverAfterCrashActive = false;
|
||||||
|
@ -509,7 +509,7 @@ void tryArm(void)
|
||||||
if (!(IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) || (tryingToArm == ARMING_DELAYED_CRASHFLIP))) {
|
if (!(IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) || (tryingToArm == ARMING_DELAYED_CRASHFLIP))) {
|
||||||
flipOverAfterCrashActive = false;
|
flipOverAfterCrashActive = false;
|
||||||
if (!featureIsEnabled(FEATURE_3D)) {
|
if (!featureIsEnabled(FEATURE_3D)) {
|
||||||
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL, false);
|
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL, DSHOT_CMD_TYPE_INLINE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
flipOverAfterCrashActive = true;
|
flipOverAfterCrashActive = true;
|
||||||
|
@ -517,7 +517,7 @@ void tryArm(void)
|
||||||
runawayTakeoffCheckDisabled = false;
|
runawayTakeoffCheckDisabled = false;
|
||||||
#endif
|
#endif
|
||||||
if (!featureIsEnabled(FEATURE_3D)) {
|
if (!featureIsEnabled(FEATURE_3D)) {
|
||||||
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_REVERSED, false);
|
dshotCommandWrite(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_REVERSED, DSHOT_CMD_TYPE_INLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,7 +401,7 @@ void beeperUpdate(timeUs_t currentTimeUs)
|
||||||
|
|
||||||
if ((currentTimeUs - getLastDisarmTimeUs() > DSHOT_BEACON_GUARD_DELAY_US) && !isTryingToArm()) {
|
if ((currentTimeUs - getLastDisarmTimeUs() > DSHOT_BEACON_GUARD_DELAY_US) && !isTryingToArm()) {
|
||||||
lastDshotBeaconCommandTimeUs = currentTimeUs;
|
lastDshotBeaconCommandTimeUs = currentTimeUs;
|
||||||
dshotCommandWrite(ALL_MOTORS, getMotorCount(), beeperConfig()->dshotBeaconTone, false);
|
dshotCommandWrite(ALL_MOTORS, getMotorCount(), beeperConfig()->dshotBeaconTone, DSHOT_CMD_TYPE_INLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue