mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
Fixed Dshot command sending to all motors.
This commit is contained in:
parent
cda31ef88a
commit
91ffa4b88c
7 changed files with 39 additions and 36 deletions
|
@ -372,11 +372,9 @@ uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwmWriteDshotCommand(uint8_t index, uint8_t command)
|
void pwmWriteDshotCommand(uint8_t index, uint8_t motorCount, uint8_t command)
|
||||||
{
|
{
|
||||||
if (isDshot && (command <= DSHOT_MAX_COMMAND)) {
|
if (isDshot && (command <= DSHOT_MAX_COMMAND)) {
|
||||||
motorDmaOutput_t *const motor = getMotorDmaOutput(index);
|
|
||||||
|
|
||||||
unsigned repeats;
|
unsigned repeats;
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case DSHOT_CMD_SPIN_DIRECTION_1:
|
case DSHOT_CMD_SPIN_DIRECTION_1:
|
||||||
|
@ -394,8 +392,17 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t command)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; repeats; repeats--) {
|
for (; repeats; repeats--) {
|
||||||
|
for (uint8_t i = 0; i < motorCount; i++) {
|
||||||
|
if ((i == index) || (index == ALL_MOTORS)) {
|
||||||
|
motorDmaOutput_t *const motor = getMotorDmaOutput(i);
|
||||||
motor->requestTelemetry = true;
|
motor->requestTelemetry = true;
|
||||||
pwmWriteDshotInt(index, command);
|
pwmWriteDshotInt(i, command);
|
||||||
|
} else {
|
||||||
|
// Needed to avoid DMA errors
|
||||||
|
pwmWriteDshotInt(i, DSHOT_CMD_MOTOR_STOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pwmCompleteDshotMotorUpdate(0);
|
pwmCompleteDshotMotorUpdate(0);
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define ALL_MOTORS 255
|
||||||
|
|
||||||
#define DSHOT_MAX_COMMAND 47
|
#define DSHOT_MAX_COMMAND 47
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -168,7 +170,7 @@ uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, uint16_t value);
|
||||||
extern loadDmaBufferFn *loadDmaBuffer;
|
extern loadDmaBufferFn *loadDmaBuffer;
|
||||||
|
|
||||||
uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType);
|
uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType);
|
||||||
void pwmWriteDshotCommand(uint8_t index, uint8_t command);
|
void pwmWriteDshotCommand(uint8_t index, uint8_t motorCount, uint8_t command);
|
||||||
void pwmWriteDshotInt(uint8_t index, uint16_t value);
|
void pwmWriteDshotInt(uint8_t index, uint16_t value);
|
||||||
void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output);
|
void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output);
|
||||||
void pwmCompleteDshotMotorUpdate(uint8_t motorCount);
|
void pwmCompleteDshotMotorUpdate(uint8_t motorCount);
|
||||||
|
|
|
@ -2339,24 +2339,18 @@ void printEscInfo(const uint8_t *escInfoBytes, uint8_t bytesRead)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeDshotCommand(uint8_t escIndex, uint8_t command)
|
static void executeEscInfoCommand(uint8_t escIndex)
|
||||||
{
|
{
|
||||||
uint8_t escInfoBuffer[ESC_INFO_V2_EXPECTED_FRAME_SIZE];
|
uint8_t escInfoBuffer[ESC_INFO_V2_EXPECTED_FRAME_SIZE];
|
||||||
if (command == DSHOT_CMD_ESC_INFO) {
|
|
||||||
cliPrintLinef("Info for ESC %d:", escIndex);
|
cliPrintLinef("Info for ESC %d:", escIndex);
|
||||||
|
|
||||||
delay(10); // Wait for potential ESC telemetry transmission to finish
|
|
||||||
|
|
||||||
startEscDataRead(escInfoBuffer, ESC_INFO_V2_EXPECTED_FRAME_SIZE);
|
startEscDataRead(escInfoBuffer, ESC_INFO_V2_EXPECTED_FRAME_SIZE);
|
||||||
}
|
|
||||||
|
|
||||||
pwmWriteDshotCommand(escIndex, command);
|
pwmWriteDshotCommand(escIndex, getMotorCount(), DSHOT_CMD_ESC_INFO);
|
||||||
|
|
||||||
if (command == DSHOT_CMD_ESC_INFO) {
|
delay(5);
|
||||||
delay(10);
|
|
||||||
|
|
||||||
printEscInfo(escInfoBuffer, getNumberEscBytesRead());
|
printEscInfo(escInfoBuffer, getNumberEscBytesRead());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliDshotProg(char *cmdline)
|
static void cliDshotProg(char *cmdline)
|
||||||
|
@ -2385,18 +2379,26 @@ static void cliDshotProg(char *cmdline)
|
||||||
|
|
||||||
int command = atoi(pch);
|
int command = atoi(pch);
|
||||||
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
|
if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
|
||||||
if (escIndex == ALL_MOTORS) {
|
if (command == DSHOT_CMD_ESC_INFO) {
|
||||||
for (unsigned i = 0; i < getMotorCount(); i++) {
|
delay(5); // Wait for potential ESC telemetry transmission to finish
|
||||||
writeDshotCommand(i, command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command != DSHOT_CMD_ESC_INFO) {
|
||||||
|
pwmWriteDshotCommand(escIndex, getMotorCount(), command);
|
||||||
} else {
|
} else {
|
||||||
writeDshotCommand(escIndex, command);
|
if (escIndex != ALL_MOTORS) {
|
||||||
|
executeEscInfoCommand(escIndex);
|
||||||
|
} else {
|
||||||
|
for (uint8_t i = 0; i < getMotorCount(); i++) {
|
||||||
|
executeEscInfoCommand(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cliPrintLinef("Command %d written.", command);
|
cliPrintLinef("Command %d written.", command);
|
||||||
|
|
||||||
if (command <= 5) {
|
if (command <= 5) {
|
||||||
delay(10); // wait for sound output to finish
|
delay(20); // wait for sound output to finish
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cliPrintLinef("Invalid command, range 1 to %d.", DSHOT_MIN_THROTTLE - 1);
|
cliPrintLinef("Invalid command, range 1 to %d.", DSHOT_MIN_THROTTLE - 1);
|
||||||
|
|
|
@ -264,14 +264,10 @@ void tryArm(void)
|
||||||
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXDSHOTREVERSE)) {
|
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXDSHOTREVERSE)) {
|
||||||
if (!IS_RC_MODE_ACTIVE(BOXDSHOTREVERSE)) {
|
if (!IS_RC_MODE_ACTIVE(BOXDSHOTREVERSE)) {
|
||||||
reverseMotors = false;
|
reverseMotors = false;
|
||||||
for (unsigned index = 0; index < getMotorCount(); index++) {
|
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_NORMAL);
|
||||||
pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_NORMAL);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
reverseMotors = true;
|
reverseMotors = true;
|
||||||
for (unsigned index = 0; index < getMotorCount(); index++) {
|
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SPIN_DIRECTION_REVERSED);
|
||||||
pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_REVERSED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -102,8 +102,6 @@ PG_DECLARE(motorConfig_t, motorConfig);
|
||||||
|
|
||||||
#define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF
|
#define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF
|
||||||
|
|
||||||
#define ALL_MOTORS 255
|
|
||||||
|
|
||||||
extern const mixer_t mixers[];
|
extern const mixer_t mixers[];
|
||||||
extern float motor[MAX_SUPPORTED_MOTORS];
|
extern float motor[MAX_SUPPORTED_MOTORS];
|
||||||
extern float motor_disarmed[MAX_SUPPORTED_MOTORS];
|
extern float motor_disarmed[MAX_SUPPORTED_MOTORS];
|
||||||
|
|
|
@ -364,9 +364,7 @@ void beeperUpdate(timeUs_t currentTimeUs)
|
||||||
|
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
if (!ARMING_FLAG(ARMED) && beeperConfig()->dshotForward && currentBeeperEntry->mode == BEEPER_RX_SET) {
|
if (!ARMING_FLAG(ARMED) && beeperConfig()->dshotForward && currentBeeperEntry->mode == BEEPER_RX_SET) {
|
||||||
for (unsigned index = 0; index < getMotorCount(); index++) {
|
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_BEEP3);
|
||||||
pwmWriteDshotCommand(index, DSHOT_CMD_BEEP3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ void escSensorProcess(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
const timeMs_t currentTimeMs = currentTimeUs / 1000;
|
const timeMs_t currentTimeMs = currentTimeUs / 1000;
|
||||||
|
|
||||||
if (!escSensorPort) {
|
if (!escSensorPort || !pwmAreMotorsEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue