From c68454798485b3167eb6c002adc5186ef4ef6f6a Mon Sep 17 00:00:00 2001 From: mikeller Date: Tue, 25 Dec 2018 00:55:26 +1300 Subject: [PATCH] Cleaned up Dshot defines. --- src/main/drivers/pwm_output.h | 2 ++ src/main/flight/mixer.c | 8 ++++---- src/main/flight/mixer.h | 3 --- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index a1dbe30ee..7b42bdb9a 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -69,6 +69,8 @@ typedef enum { DSHOT_CMD_MAX = 47 } dshotCommands_e; +#define DSHOT_MIN_THROTTLE 48 +#define DSHOT_MAX_THROTTLE 2047 typedef enum { PWM_TYPE_STANDARD = 0, diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index dc69a46ca..d7841d40e 100644 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -375,7 +375,7 @@ void initEscEndpoints(void) case PWM_TYPE_DSHOT600: case PWM_TYPE_DSHOT300: case PWM_TYPE_DSHOT150: - disarmMotorOutput = DSHOT_DISARM_COMMAND; + disarmMotorOutput = DSHOT_CMD_MOTOR_STOP; if (featureIsEnabled(FEATURE_3D)) { motorOutputLow = DSHOT_MIN_THROTTLE + ((DSHOT_3D_FORWARD_MIN_THROTTLE - 1 - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue); } else { @@ -941,14 +941,14 @@ float convertExternalToMotor(uint16_t externalValue) if (featureIsEnabled(FEATURE_3D)) { if (externalValue == PWM_RANGE_MID) { - motorValue = DSHOT_DISARM_COMMAND; + motorValue = DSHOT_CMD_MOTOR_STOP; } else if (externalValue < PWM_RANGE_MID) { motorValue = scaleRange(externalValue, PWM_RANGE_MIN, PWM_RANGE_MID - 1, DSHOT_3D_FORWARD_MIN_THROTTLE - 1, DSHOT_MIN_THROTTLE); } else { motorValue = scaleRange(externalValue, PWM_RANGE_MID + 1, PWM_RANGE_MAX, DSHOT_3D_FORWARD_MIN_THROTTLE, DSHOT_MAX_THROTTLE); } } else { - motorValue = (externalValue == PWM_RANGE_MIN) ? DSHOT_DISARM_COMMAND : scaleRange(externalValue, PWM_RANGE_MIN + 1, PWM_RANGE_MAX, DSHOT_MIN_THROTTLE, DSHOT_MAX_THROTTLE); + motorValue = (externalValue == PWM_RANGE_MIN) ? DSHOT_CMD_MOTOR_STOP : scaleRange(externalValue, PWM_RANGE_MIN + 1, PWM_RANGE_MAX, DSHOT_MIN_THROTTLE, DSHOT_MAX_THROTTLE); } break; @@ -969,7 +969,7 @@ uint16_t convertMotorToExternal(float motorValue) #ifdef USE_DSHOT case true: if (featureIsEnabled(FEATURE_3D)) { - if (motorValue == DSHOT_DISARM_COMMAND || motorValue < DSHOT_MIN_THROTTLE) { + if (motorValue == DSHOT_CMD_MOTOR_STOP || motorValue < DSHOT_MIN_THROTTLE) { externalValue = PWM_RANGE_MID; } else if (motorValue <= DSHOT_3D_FORWARD_MIN_THROTTLE - 1) { externalValue = scaleRange(motorValue, DSHOT_MIN_THROTTLE, DSHOT_3D_FORWARD_MIN_THROTTLE - 1, PWM_RANGE_MID - 1, PWM_RANGE_MIN); diff --git a/src/main/flight/mixer.h b/src/main/flight/mixer.h index 566fd2c51..d0acff715 100644 --- a/src/main/flight/mixer.h +++ b/src/main/flight/mixer.h @@ -33,9 +33,6 @@ #define BRUSHLESS_MOTORS_PWM_RATE 480 // Digital protocol has fixed values -#define DSHOT_DISARM_COMMAND 0 -#define DSHOT_MIN_THROTTLE 48 -#define DSHOT_MAX_THROTTLE 2047 #define DSHOT_3D_FORWARD_MIN_THROTTLE 1048 // Note: this is called MultiType/MULTITYPE_* in baseflight.