1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Made Dshot commands work in a non-blocking way.

This commit is contained in:
mikeller 2018-06-01 00:30:33 +12:00 committed by Michael Keller
parent 0045b36320
commit 51763a40f9
3 changed files with 11 additions and 10 deletions

View file

@ -435,9 +435,9 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t motorCount, uint8_t command, bo
} }
delayMicroseconds(timeDelayUs); delayMicroseconds(timeDelayUs);
} else { } else {
for (uint8_t i = 0; i < motorCount; i++) { if (!pwmIsProcessingDshotCommand()) {
if ((i == index) || (index == ALL_MOTORS)) { for (uint8_t i = 0; i < motorCount; i++) {
if (dshotCommandControl.command[i] == 0) { if ((index == i) || (index == ALL_MOTORS)) {
dshotCommandControl.command[i] = command; dshotCommandControl.command[i] = command;
dshotCommandControl.repeats = repeats; dshotCommandControl.repeats = repeats;
dshotCommandControl.nextCommandAt = timeNowUs + DSHOT_COMMAND_DELAY_US; dshotCommandControl.nextCommandAt = timeNowUs + DSHOT_COMMAND_DELAY_US;
@ -458,11 +458,11 @@ uint8_t pwmGetDshotCommand(uint8_t index)
return dshotCommandControl.command[index]; return dshotCommandControl.command[index];
} }
bool pwmProcessDshotCommand(uint8_t motorCount) bool FAST_CODE_NOINLINE pwmProcessDshotCommand(uint8_t motorCount)
{ {
timeUs_t timeNowUs = micros(); timeUs_t timeNowUs = micros();
if (cmpTimeUs(timeNowUs, dshotCommandControl.nextCommandAt) < 0) { if (cmpTimeUs(timeNowUs, dshotCommandControl.nextCommandAt) < 0) {
return true; //Skip motor update because it isn't time yet for a new command return false; //Skip motor update because it isn't time yet for a new command
} }
//Timed motor update happening with dshot command //Timed motor update happening with dshot command
@ -480,7 +480,7 @@ bool pwmProcessDshotCommand(uint8_t motorCount)
dshotCommandControl.delayAfterCommand = 0; dshotCommandControl.delayAfterCommand = 0;
} }
return false; return true;
} }
FAST_CODE uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, const uint16_t value) FAST_CODE uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, const uint16_t value)

View file

@ -97,7 +97,7 @@ void pwmCompleteDshotMotorUpdate(uint8_t motorCount)
UNUSED(motorCount); UNUSED(motorCount);
/* If there is a dshot command loaded up, time it correctly with motor update*/ /* If there is a dshot command loaded up, time it correctly with motor update*/
if (pwmProcessDshotCommand(motorCount)) { if (!pwmProcessDshotCommand(motorCount)) {
return; //Skip motor update return; //Skip motor update
} }

View file

@ -90,11 +90,12 @@ FAST_CODE void pwmCompleteDshotMotorUpdate(uint8_t motorCount)
UNUSED(motorCount); UNUSED(motorCount);
/* If there is a dshot command loaded up, time it correctly with motor update*/ /* If there is a dshot command loaded up, time it correctly with motor update*/
if (pwmProcessDshotCommand(motorCount)) { if (pwmIsProcessingDshotCommand()) {
return; //Skip motor update if (!pwmProcessDshotCommand(motorCount)) {
return;
}
} }
for (int i = 0; i < dmaMotorTimerCount; i++) { for (int i = 0; i < dmaMotorTimerCount; i++) {
#ifdef USE_DSHOT_DMAR #ifdef USE_DSHOT_DMAR
if (useBurstDshot) { if (useBurstDshot) {