Skip to content

Commit 4c0db7f

Browse files
authored
Merge pull request #10276 from iNavFlight/mmosca-sbus-output-improvements
Allow number of servos exceed pwm outputs, if servo protocol is sbus_pwm
2 parents ee5d217 + a863afa commit 4c0db7f

File tree

9 files changed

+37
-9
lines changed

9 files changed

+37
-9
lines changed

src/main/drivers/pwm_mapping.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "sensors/rangefinder.h"
4343

4444
#include "io/serial.h"
45+
#include "io/servo_sbus.h"
4546

4647
enum {
4748
MAP_TO_NONE,
@@ -442,15 +443,21 @@ static void pwmInitServos(timMotorServoHardware_t * timOutputs)
442443
return;
443444
}
444445

446+
445447
// If mixer requests more servos than we have timer outputs - throw an error
446-
if (servoCount > timOutputs->maxTimServoCount) {
448+
uint16_t maxServos = timOutputs->maxTimServoCount;
449+
if (servoConfig()->servo_protocol == SERVO_TYPE_SBUS_PWM) {
450+
maxServos = MAX(SERVO_SBUS_MAX_SERVOS, timOutputs->maxTimServoCount);
451+
}
452+
453+
if (servoCount > maxServos) {
447454
pwmInitError = PWM_INIT_ERROR_NOT_ENOUGH_SERVO_OUTPUTS;
448455
LOG_ERROR(PWM, "Too many servos. Mixer requested %d, timer outputs %d", servoCount, timOutputs->maxTimServoCount);
449456
return;
450457
}
451458

452459
// Configure individual servo outputs
453-
for (int idx = 0; idx < servoCount; idx++) {
460+
for (int idx = 0; idx < MIN(servoCount, timOutputs->maxTimServoCount); idx++) {
454461
const timerHardware_t *timHw = timOutputs->timServos[idx];
455462

456463
if (!pwmServoConfig(timHw, idx, servoConfig()->servoPwmRate, servoConfig()->servoCenterPulse, feature(FEATURE_PWM_OUTPUT_ENABLE))) {

src/main/drivers/pwm_mapping.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "flight/mixer.h"
2222
#include "flight/mixer_profile.h"
2323
#include "flight/servos.h"
24+
#include "common/maths.h"
2425

2526
#if defined(TARGET_MOTOR_COUNT)
2627
#define MAX_MOTORS TARGET_MOTOR_COUNT

src/main/drivers/pwm_output.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ ioTag_t pwmGetMotorPinTag(int motorIndex)
638638

639639
static void pwmServoWriteStandard(uint8_t index, uint16_t value)
640640
{
641-
if (servos[index]) {
641+
if (index < MAX_SERVOS && servos[index]) {
642642
*servos[index]->ccr = value;
643643
}
644644
}

src/main/fc/rc_controls.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ typedef enum rc_alias {
4040
AUX12, // 16
4141
AUX13, // 17
4242
AUX14, // 18
43-
#ifdef USE_24CHANNELS
43+
#ifdef USE_34CHANNELS
4444
AUX15, // 19
4545
AUX16, // 20
4646
AUX17, // 21
4747
AUX18, // 22
4848
AUX19, // 23
4949
AUX20, // 24
50+
AUX21, // 25
51+
AUX22, // 26
52+
AUX23, // 27
53+
AUX24, // 28
54+
AUX25, // 29
55+
AUX26, // 30
56+
AUX27, // 31
57+
AUX28, // 32
58+
AUX29, // 33
59+
AUX30, // 34
5060
#endif
5161
} rc_alias_e;
5262

src/main/flight/servos.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,23 @@ void servoMixer(float dT)
349349
input[INPUT_RC_CH16] = GET_RX_CHANNEL_INPUT(AUX12);
350350
input[INPUT_RC_CH17] = GET_RX_CHANNEL_INPUT(AUX13);
351351
input[INPUT_RC_CH18] = GET_RX_CHANNEL_INPUT(AUX14);
352-
#ifdef USE_24CHANNELS
352+
#ifdef USE_34CHANNELS
353353
input[INPUT_RC_CH19] = GET_RX_CHANNEL_INPUT(AUX15);
354354
input[INPUT_RC_CH20] = GET_RX_CHANNEL_INPUT(AUX16);
355355
input[INPUT_RC_CH21] = GET_RX_CHANNEL_INPUT(AUX17);
356356
input[INPUT_RC_CH22] = GET_RX_CHANNEL_INPUT(AUX18);
357357
input[INPUT_RC_CH23] = GET_RX_CHANNEL_INPUT(AUX19);
358358
input[INPUT_RC_CH24] = GET_RX_CHANNEL_INPUT(AUX20);
359+
input[INPUT_RC_CH25] = GET_RX_CHANNEL_INPUT(AUX21);
360+
input[INPUT_RC_CH26] = GET_RX_CHANNEL_INPUT(AUX22);
361+
input[INPUT_RC_CH27] = GET_RX_CHANNEL_INPUT(AUX23);
362+
input[INPUT_RC_CH28] = GET_RX_CHANNEL_INPUT(AUX24);
363+
input[INPUT_RC_CH29] = GET_RX_CHANNEL_INPUT(AUX25);
364+
input[INPUT_RC_CH30] = GET_RX_CHANNEL_INPUT(AUX26);
365+
input[INPUT_RC_CH31] = GET_RX_CHANNEL_INPUT(AUX27);
366+
input[INPUT_RC_CH32] = GET_RX_CHANNEL_INPUT(AUX28);
367+
input[INPUT_RC_CH33] = GET_RX_CHANNEL_INPUT(AUX29);
368+
input[INPUT_RC_CH34] = GET_RX_CHANNEL_INPUT(AUX30);
359369
#endif
360370
#undef GET_RX_CHANNEL_INPUT
361371

src/main/flight/servos.h

-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ typedef enum {
6868
INPUT_HEADTRACKER_ROLL = 41,
6969
INPUT_RC_CH17 = 42,
7070
INPUT_RC_CH18 = 43,
71-
#ifdef USE_24CHANNELS
7271
INPUT_RC_CH19 = 44,
7372
INPUT_RC_CH20 = 45,
7473
INPUT_RC_CH21 = 46,
@@ -85,7 +84,6 @@ typedef enum {
8584
INPUT_RC_CH32 = 57,
8685
INPUT_RC_CH33 = 58,
8786
INPUT_RC_CH34 = 59,
88-
#endif
8987
INPUT_SOURCE_COUNT
9088
} inputSource_e;
9189

src/main/io/servo_sbus.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#pragma once
2626

27+
#define SERVO_SBUS_MAX_SERVOS 18
28+
2729
bool sbusServoInitialize(void);
2830
void sbusServoUpdate(uint8_t index, uint16_t value);
2931
void sbusServoSendUpdate(void);

src/main/rx/jetiexbus.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#define JETIEXBUS_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO)
6565
#define JETIEXBUS_MIN_FRAME_GAP 1000
6666

67-
#ifdef USE_24CHANNELS
67+
#ifdef USE_34CHANNELS
6868
#define JETIEXBUS_CHANNEL_COUNT 24
6969
#else
7070
#define JETIEXBUS_CHANNEL_COUNT 16

src/main/target/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
#define USE_SERIALRX_SUMD
207207
#define USE_TELEMETRY_HOTT
208208
#define USE_HOTT_TEXTMODE
209-
#define USE_24CHANNELS
209+
#define USE_34CHANNELS
210210
#define MAX_MIXER_PROFILE_COUNT 2
211211
#define USE_SMARTPORT_MASTER
212212
#elif !defined(STM32F7)

0 commit comments

Comments
 (0)