@@ -72,7 +72,8 @@ static uint32_t pios_dshot_t0h_raw;
7272static uint32_t pios_dshot_t1h_raw ;
7373static uint32_t pios_dshot_t_raw ;
7474
75- static bool pios_servo_enabled = true;
75+ static bool pios_servo_enabled = true;
76+ static uint32_t pios_servo_active = 0 ; // No active outputs by default
7677
7778#define PIOS_SERVO_TIMER_CLOCK 1000000
7879#define PIOS_SERVO_SAFE_MARGIN 50
@@ -83,6 +84,20 @@ static bool pios_servo_enabled = true;
8384#define DSHOT_T1H_DIV 1333
8485#define DSHOT_NUM_BITS 16
8586
87+ extern void PIOS_Servo_SetActive (uint32_t active )
88+ {
89+ bool enabled = pios_servo_enabled ;
90+
91+ if (enabled ) {
92+ PIOS_Servo_Disable ();
93+ }
94+
95+ pios_servo_active = active ;
96+
97+ if (enabled ) {
98+ PIOS_Servo_Enable ();
99+ }
100+ }
86101
87102extern void PIOS_Servo_Disable ()
88103{
@@ -142,6 +157,10 @@ static void PIOS_Servo_SetupBank(uint8_t bank_nr)
142157 continue ;
143158 }
144159
160+ if (!(pios_servo_active & (1L << i ))) { // This output is not active
161+ continue ;
162+ }
163+
145164 GPIO_InitTypeDef init = chan -> pin .init ;
146165
147166 switch (bank -> mode ) {
@@ -345,6 +364,10 @@ static void PIOS_Servo_DShot_Update()
345364 continue ;
346365 }
347366
367+ if (!(pios_servo_active & (1L << i ))) { // This output is not active
368+ continue ;
369+ }
370+
348371 has_dshot = true;
349372
350373 uint16_t payload = pin -> value ;
@@ -451,7 +474,8 @@ void PIOS_Servo_Update()
451474 }
452475
453476 for (uint8_t i = 0 ; (i < servo_cfg -> num_channels ); i ++ ) {
454- if (pios_servo_pins [i ].bank -> mode == PIOS_SERVO_BANK_MODE_SINGLE_PULSE ) {
477+ if ((pios_servo_active & (1L << i ))
478+ && (pios_servo_pins [i ].bank -> mode == PIOS_SERVO_BANK_MODE_SINGLE_PULSE )) {
455479 /* Update the position */
456480 const struct pios_tim_channel * chan = & servo_cfg -> channels [i ];
457481
0 commit comments