1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Motor code refactor (Phase 1)

This commit is contained in:
jflyper 2019-06-29 03:30:05 +09:00
parent f4bb75180e
commit 542146c702
41 changed files with 1543 additions and 975 deletions

View file

@ -43,6 +43,9 @@
#endif
#include "pwm_output.h"
#include "drivers/dshot.h"
#include "drivers/dshot_dpwm.h"
#include "drivers/dshot_command.h"
#include "pwm_output_dshot_shared.h"
@ -106,7 +109,7 @@ FAST_CODE void pwmWriteDshotInt(uint8_t index, uint16_t value)
}
/*If there is a command ready to go overwrite the value and send that instead*/
if (pwmDshotCommandIsProcessing()) {
if (dshotCommandIsProcessing()) {
value = pwmGetDshotCommand(index);
#ifdef USE_DSHOT_TELEMETRY
// reset telemetry debug statistics every time telemetry is enabled
@ -116,13 +119,13 @@ FAST_CODE void pwmWriteDshotInt(uint8_t index, uint16_t value)
}
#endif
if (value) {
motor->requestTelemetry = true;
motor->protocolControl.requestTelemetry = true;
}
}
motor->value = value;
motor->protocolControl.value = value;
uint16_t packet = prepareDshotPacket(motor);
uint16_t packet = prepareDshotPacket(&motor->protocolControl);
uint8_t bufferSize;
#ifdef USE_DSHOT_DMAR
@ -238,7 +241,7 @@ void updateDshotTelemetryQuality(dshotTelemetryQuality_t *qualityStats, bool pac
}
#endif // USE_DSHOT_TELEMETRY_STATS
bool pwmStartDshotMotorUpdate(uint8_t motorCount)
bool pwmStartDshotMotorUpdate(void)
{
if (!useDshotTelemetry) {
return true;
@ -246,7 +249,7 @@ bool pwmStartDshotMotorUpdate(uint8_t motorCount)
#ifdef USE_DSHOT_TELEMETRY_STATS
const timeMs_t currentTimeMs = millis();
#endif
for (int i = 0; i < motorCount; i++) {
for (int i = 0; i < dshotPwmDevice.count; i++) {
if (dmaMotors[i].hasTelemetry) {
#ifdef STM32F7
uint32_t edges = LL_EX_DMA_GetDataLength(dmaMotors[i].dmaRef);
@ -296,7 +299,7 @@ bool pwmStartDshotMotorUpdate(uint8_t motorCount)
}
pwmDshotSetDirectionOutput(&dmaMotors[i], true);
}
dshotEnableChannels(motorCount);
dshotEnableChannels(dshotPwmDevice.count);
return true;
}
@ -305,6 +308,16 @@ bool isDshotMotorTelemetryActive(uint8_t motorIndex)
return dmaMotors[motorIndex].dshotTelemetryActive;
}
bool isDshotTelemetryActive(void)
{
for (unsigned i = 0; i < dshotPwmDevice.count; i++) {
if (!isDshotMotorTelemetryActive(i)) {
return false;
}
}
return true;
}
#ifdef USE_DSHOT_TELEMETRY_STATS
int16_t getDshotTelemetryMotorInvalidPercent(uint8_t motorIndex)
{