1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

Merge pull request #3435 from martinbudden/bf_motor_enable

Remove duplication in motor enable/disable
This commit is contained in:
Michael Keller 2017-07-08 10:12:59 +12:00 committed by GitHub
commit 2cc1bb309f
9 changed files with 17 additions and 29 deletions

View file

@ -45,8 +45,8 @@ static pwmOutputPort_t beeperPwm;
static uint16_t freqBeep = 0; static uint16_t freqBeep = 0;
#endif #endif
bool pwmMotorsEnabled = false; static bool pwmMotorsEnabled = false;
bool isDshot = false; static bool isDshot = false;
static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value, uint8_t output) static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value, uint8_t output)
{ {
@ -169,9 +169,7 @@ static uint8_t loadDmaBufferProshot(motorDmaOutput_t *const motor, uint16_t pack
void pwmWriteMotor(uint8_t index, float value) void pwmWriteMotor(uint8_t index, float value)
{ {
if (pwmMotorsEnabled) { pwmWrite(index, value);
pwmWrite(index, value);
}
} }
void pwmShutdownPulsesForAllMotors(uint8_t motorCount) void pwmShutdownPulsesForAllMotors(uint8_t motorCount)
@ -397,8 +395,7 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t command)
for (; repeats; repeats--) { for (; repeats; repeats--) {
motor->requestTelemetry = true; motor->requestTelemetry = true;
pwmWriteDshotInt(index, command); pwmWriteDshotInt(index, command);
pwmCompleteMotorUpdate(0); pwmCompleteDshotMotorUpdate(0);
delay(1); delay(1);
} }
} }

View file

@ -125,8 +125,6 @@ typedef struct {
motorDmaOutput_t *getMotorDmaOutput(uint8_t index); motorDmaOutput_t *getMotorDmaOutput(uint8_t index);
extern bool pwmMotorsEnabled;
struct timerHardware_s; struct timerHardware_s;
typedef void pwmWriteFunc(uint8_t index, float value); // function pointer used to write motors 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 typedef void pwmCompleteWriteFunc(uint8_t motorCount); // function pointer used after motors are written
@ -134,11 +132,11 @@ typedef void pwmCompleteWriteFunc(uint8_t motorCount); // function pointer use
typedef struct { typedef struct {
volatile timCCR_t *ccr; volatile timCCR_t *ccr;
TIM_TypeDef *tim; TIM_TypeDef *tim;
float pulseScale;
float pulseOffset;
bool forceOverflow; bool forceOverflow;
bool enabled; bool enabled;
IO_t io; IO_t io;
float pulseScale;
float pulseOffset;
} pwmOutputPort_t; } pwmOutputPort_t;
typedef struct motorDevConfig_s { typedef struct motorDevConfig_s {

View file

@ -74,10 +74,6 @@ void pwmCompleteDshotMotorUpdate(uint8_t motorCount)
{ {
UNUSED(motorCount); UNUSED(motorCount);
if (!pwmMotorsEnabled) {
return;
}
for (int i = 0; i < dmaMotorTimerCount; i++) { for (int i = 0; i < dmaMotorTimerCount; i++) {
TIM_SetCounter(dmaMotorTimers[i].timer, 0); TIM_SetCounter(dmaMotorTimers[i].timer, 0);
TIM_DMACmd(dmaMotorTimers[i].timer, dmaMotorTimers[i].timerDmaSources, ENABLE); TIM_DMACmd(dmaMotorTimers[i].timer, dmaMotorTimers[i].timerDmaSources, ENABLE);

View file

@ -2231,7 +2231,7 @@ static void cliDshotProg(char *cmdline)
break; break;
default: default:
motorControlEnable = false; pwmDisableMotors();
int command = atoi(pch); int command = atoi(pch);
if (command >= 0 && command < DSHOT_MIN_THROTTLE) { if (command >= 0 && command < DSHOT_MIN_THROTTLE) {
@ -2259,7 +2259,7 @@ static void cliDshotProg(char *cmdline)
pch = strtok_r(NULL, " ", &saveptr); pch = strtok_r(NULL, " ", &saveptr);
} }
motorControlEnable = true; pwmEnableMotors();
} }
#endif #endif

View file

@ -108,7 +108,6 @@ int16_t magHold;
int16_t headFreeModeHold; int16_t headFreeModeHold;
uint8_t motorControlEnable = false;
static bool reverseMotors = false; static bool reverseMotors = false;
static uint32_t disarmAt; // Time of automatic disarm when "Don't spin the motors when armed" is enabled and auto_disarm_delay is nonzero static uint32_t disarmAt; // Time of automatic disarm when "Don't spin the motors when armed" is enabled and auto_disarm_delay is nonzero
@ -627,9 +626,8 @@ static void subTaskMotorUpdate(void)
} }
#endif #endif
if (motorControlEnable) { writeMotors();
writeMotors();
}
DEBUG_SET(DEBUG_PIDLOOP, 3, micros() - startTime); DEBUG_SET(DEBUG_PIDLOOP, 3, micros() - startTime);
} }

View file

@ -27,8 +27,6 @@ extern int16_t magHold;
extern bool isRXDataNew; extern bool isRXDataNew;
extern int16_t headFreeModeHold; extern int16_t headFreeModeHold;
extern uint8_t motorControlEnable;
typedef struct throttleCorrectionConfig_s { typedef struct throttleCorrectionConfig_s {
uint16_t throttle_correction_angle; // the angle when the throttle correction is maximal. in 0.1 degres, ex 225 = 22.5 ,30.0, 450 = 45.0 deg uint16_t throttle_correction_angle; // the angle when the throttle correction is maximal. in 0.1 degres, ex 225 = 22.5 ,30.0, 450 = 45.0 deg
uint8_t throttle_correction_value; // the correction that will be applied at throttle_correction_angle. uint8_t throttle_correction_value; // the correction that will be applied at throttle_correction_angle.

View file

@ -137,8 +137,6 @@
void targetPreInit(void); void targetPreInit(void);
#endif #endif
extern uint8_t motorControlEnable;
#ifdef SOFTSERIAL_LOOPBACK #ifdef SOFTSERIAL_LOOPBACK
serialPort_t *loopbackPort; serialPort_t *loopbackPort;
#endif #endif
@ -709,7 +707,7 @@ void init(void)
// Latch active features AGAIN since some may be modified by init(). // Latch active features AGAIN since some may be modified by init().
latchActiveFeatures(); latchActiveFeatures();
motorControlEnable = true; pwmEnableMotors();
#ifdef USE_OSD_SLAVE #ifdef USE_OSD_SLAVE
osdSlaveTasksInit(); osdSlaveTasksInit();

View file

@ -469,9 +469,8 @@ void writeMotors(void)
for (int i = 0; i < motorCount; i++) { for (int i = 0; i < motorCount; i++) {
pwmWriteMotor(i, motor[i]); pwmWriteMotor(i, motor[i]);
} }
pwmCompleteMotorUpdate(motorCount);
} }
pwmCompleteMotorUpdate(motorCount);
} }
static void writeAllMotors(int16_t mc) static void writeAllMotors(int16_t mc)

View file

@ -374,7 +374,7 @@ int timeval_sub(struct timespec *result, struct timespec *x, struct timespec *y)
// PWM part // PWM part
bool pwmMotorsEnabled = false; static bool pwmMotorsEnabled = false;
static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS]; static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS];
static pwmOutputPort_t servos[MAX_SUPPORTED_SERVOS]; static pwmOutputPort_t servos[MAX_SUPPORTED_SERVOS];
@ -406,6 +406,10 @@ pwmOutputPort_t *pwmGetMotors(void) {
return motors; return motors;
} }
void pwmEnableMotors(void) {
pwmMotorsEnabled = true;
}
bool pwmAreMotorsEnabled(void) { bool pwmAreMotorsEnabled(void) {
return pwmMotorsEnabled; return pwmMotorsEnabled;
} }