From de21b5ae3e422e31bbe075cec21087e3671ac72e Mon Sep 17 00:00:00 2001 From: IVData Date: Thu, 3 Sep 2020 18:38:10 +1200 Subject: [PATCH 1/2] Added option to output servos on PWM and SBUS --- src/main/drivers/pwm_mapping.c | 3 ++- src/main/drivers/pwm_mapping.h | 3 ++- src/main/drivers/pwm_output.c | 11 +++++++++++ src/main/fc/config.c | 2 +- src/main/fc/fc_tasks.c | 2 +- src/main/fc/settings.yaml | 2 +- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/drivers/pwm_mapping.c b/src/main/drivers/pwm_mapping.c index 8c6eaea463..a7a27b4ede 100644 --- a/src/main/drivers/pwm_mapping.c +++ b/src/main/drivers/pwm_mapping.c @@ -268,7 +268,8 @@ static bool motorsUseHardwareTimers(void) static bool servosUseHardwareTimers(void) { - return servoConfig()->servo_protocol == SERVO_TYPE_PWM; + return servoConfig()->servo_protocol == SERVO_TYPE_PWM || + servoConfig()->servo_protocol == SERVO_TYPE_SBUS_PWM; } static void pwmInitMotors(timMotorServoHardware_t * timOutputs) diff --git a/src/main/drivers/pwm_mapping.h b/src/main/drivers/pwm_mapping.h index 2c8b8f83a5..7efbf39431 100644 --- a/src/main/drivers/pwm_mapping.h +++ b/src/main/drivers/pwm_mapping.h @@ -52,7 +52,8 @@ typedef enum { typedef enum { SERVO_TYPE_PWM = 0, SERVO_TYPE_SERVO_DRIVER, - SERVO_TYPE_SBUS + SERVO_TYPE_SBUS, + SERVO_TYPE_SBUS_PWM } servoProtocolType_e; typedef enum { diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 6472741a78..0f4e0caf18 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -501,6 +501,12 @@ static void pwmServoWriteStandard(uint8_t index, uint16_t value) } } +static void sbusPwmWriteStandard(uint8_t index, uint16_t value) +{ + pwmServoWriteStandard(index, value); + sbusServoUpdate(index, value); +} + #ifdef USE_PWM_SERVO_DRIVER static void pwmServoWriteExternalDriver(uint8_t index, uint16_t value) { @@ -532,6 +538,11 @@ void pwmServoPreconfigure(void) sbusServoInitialize(); servoWritePtr = sbusServoUpdate; break; + + case SERVO_TYPE_SBUS_PWM: + sbusServoInitialize(); + servoWritePtr = sbusPwmWriteStandard; + break; #endif } } diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 627fd350b5..5fcf8a6d11 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -217,7 +217,7 @@ void validateAndFixConfig(void) #endif #ifndef USE_SERVO_SBUS - if (servoConfig()->servo_protocol == SERVO_TYPE_SBUS) { + if (servoConfig()->servo_protocol == SERVO_TYPE_SBUS || servoConfig()->servo_protocol == SERVO_TYPE_SBUS_PWM) { servoConfigMutable()->servo_protocol = SERVO_TYPE_PWM; } #endif diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 190a299d9d..4ff3e6b9b0 100755 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -346,7 +346,7 @@ void fcTasksInit(void) setTaskEnabled(TASK_STACK_CHECK, true); #endif #if defined(USE_PWM_SERVO_DRIVER) || defined(USE_SERVO_SBUS) - setTaskEnabled(TASK_PWMDRIVER, (servoConfig()->servo_protocol == SERVO_TYPE_SERVO_DRIVER) || (servoConfig()->servo_protocol == SERVO_TYPE_SBUS)); + setTaskEnabled(TASK_PWMDRIVER, (servoConfig()->servo_protocol == SERVO_TYPE_SERVO_DRIVER) || (servoConfig()->servo_protocol == SERVO_TYPE_SBUS) || (servoConfig()->servo_protocol == SERVO_TYPE_SBUS_PWM)); #endif #ifdef USE_CMS #ifdef USE_MSP_DISPLAYPORT diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 65ac689cdd..d4246fc471 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -34,7 +34,7 @@ tables: - name: motor_pwm_protocol values: ["STANDARD", "ONESHOT125", "ONESHOT42", "MULTISHOT", "BRUSHED", "DSHOT150", "DSHOT300", "DSHOT600", "DSHOT1200", "SERIALSHOT"] - name: servo_protocol - values: ["PWM", "SERVO_DRIVER", "SBUS"] + values: ["PWM", "SERVO_DRIVER", "SBUS", "SBUS_PWM"] - name: failsafe_procedure values: ["SET-THR", "DROP", "RTH", "NONE"] - name: current_sensor From 64f3d70002e2890e0f8d8f3c066ff342bb6e3b90 Mon Sep 17 00:00:00 2001 From: IVData Date: Wed, 16 Sep 2020 12:30:17 +1200 Subject: [PATCH 2/2] Fix builds for targets without USE_SERVO_SBUS --- src/main/drivers/pwm_output.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 0f4e0caf18..ba147cc562 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -501,11 +501,13 @@ static void pwmServoWriteStandard(uint8_t index, uint16_t value) } } +#ifdef USE_SERVO_SBUS static void sbusPwmWriteStandard(uint8_t index, uint16_t value) { pwmServoWriteStandard(index, value); sbusServoUpdate(index, value); } +#endif #ifdef USE_PWM_SERVO_DRIVER static void pwmServoWriteExternalDriver(uint8_t index, uint16_t value)