From 87ae1616d602839033923dca24459c9d4c33ba05 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Wed, 5 Jul 2017 06:21:36 +0100 Subject: [PATCH] Further better use of pwmAreMotorsEnabled --- src/main/drivers/pwm_output.c | 8 +++++--- src/main/drivers/pwm_output.h | 2 -- src/main/drivers/pwm_output_dshot.c | 4 ---- src/main/flight/mixer.c | 3 +-- src/main/target/SITL/target.c | 2 +- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index cf86734c6..27fb8fc07 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -45,8 +45,8 @@ static pwmOutputPort_t beeperPwm; static uint16_t freqBeep = 0; #endif -bool pwmMotorsEnabled = false; -bool isDshot = false; +static bool pwmMotorsEnabled = false; +static bool isDshot = false; static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value, uint8_t output) { @@ -395,7 +395,9 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t command) for (; repeats; repeats--) { motor->requestTelemetry = true; pwmWriteDshotInt(index, command); - pwmCompleteMotorUpdate(0); + if (pwmMotorsEnabled) { + pwmCompleteDshotMotorUpdate(0); + } delay(1); } diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index 601161fe8..5c2b3cf7c 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -125,8 +125,6 @@ typedef struct { motorDmaOutput_t *getMotorDmaOutput(uint8_t index); -extern bool pwmMotorsEnabled; - struct timerHardware_s; typedef void pwmWriteFunc(uint8_t index, float value); // function pointer used to write motors typedef void pwmCompleteWriteFunc(uint8_t motorCount); // function pointer used after motors are written diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index 3236c9cfd..ff3843093 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -74,10 +74,6 @@ void pwmCompleteDshotMotorUpdate(uint8_t motorCount) { UNUSED(motorCount); - if (!pwmMotorsEnabled) { - return; - } - for (int i = 0; i < dmaMotorTimerCount; i++) { TIM_SetCounter(dmaMotorTimers[i].timer, 0); TIM_DMACmd(dmaMotorTimers[i].timer, dmaMotorTimers[i].timerDmaSources, ENABLE); diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index 41dafd5ec..fc5f5531f 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -469,9 +469,8 @@ void writeMotors(void) for (int i = 0; i < motorCount; i++) { pwmWriteMotor(i, motor[i]); } + pwmCompleteMotorUpdate(motorCount); } - - pwmCompleteMotorUpdate(motorCount); } static void writeAllMotors(int16_t mc) diff --git a/src/main/target/SITL/target.c b/src/main/target/SITL/target.c index 0ec676edd..f7802a1f6 100644 --- a/src/main/target/SITL/target.c +++ b/src/main/target/SITL/target.c @@ -374,7 +374,7 @@ int timeval_sub(struct timespec *result, struct timespec *x, struct timespec *y) // PWM part -bool pwmMotorsEnabled = false; +static bool pwmMotorsEnabled = false; static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS]; static pwmOutputPort_t servos[MAX_SUPPORTED_SERVOS];