Skip to content

Commit cc29d52

Browse files
committed
LP-544 Add PIOS_Servo_SetActive() API to communicate active servo channels from Actuator module to pios_servo driver. pios_servo is not allowed to touch inactive outputs.
1 parent 2f1e7cd commit cc29d52

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

flight/modules/Actuator/actuator.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,25 @@ static void actuator_update_rate_if_changed(bool force_update)
10621062
}
10631063
}
10641064

1065+
static void update_servo_active()
1066+
{
1067+
/* For each mixer output that is not disabled,
1068+
* figure out servo address and send allocation map to pios_servo driver.
1069+
* We need to execute this when either ActuatorSettings or MixerSettings change.
1070+
*/
1071+
uint32_t servo_active = 0;
1072+
1073+
Mixer_t *mixers = (Mixer_t *)&mixerSettings.Mixer1Type;
1074+
1075+
for (int ct = 0; ct < MAX_MIX_ACTUATORS; ct++) {
1076+
if (mixers[ct].type != MIXERSETTINGS_MIXER1TYPE_DISABLED) {
1077+
servo_active |= 1 << actuatorSettings.ChannelAddr[ct];
1078+
}
1079+
}
1080+
1081+
PIOS_Servo_SetActive(servo_active);
1082+
}
1083+
10651084
static void ActuatorSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10661085
{
10671086
ActuatorSettingsGet(&actuatorSettings);
@@ -1070,6 +1089,8 @@ static void ActuatorSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10701089
spinWhileArmed = false;
10711090
}
10721091
actuator_update_rate_if_changed(false);
1092+
1093+
update_servo_active();
10731094
}
10741095

10751096
static void MixerSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
@@ -1082,6 +1103,8 @@ static void MixerSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10821103
mixer_settings_count++;
10831104
}
10841105
}
1106+
1107+
update_servo_active();
10851108
}
10861109
static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10871110
{

flight/pios/common/pios_servo.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static uint32_t pios_dshot_t0h_raw;
7272
static uint32_t pios_dshot_t1h_raw;
7373
static 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

87102
extern 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

flight/pios/inc/pios_servo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum pios_servo_bank_mode {
4141
/* Public Functions */
4242
extern void PIOS_Servo_SetHz(const uint16_t *speeds, const uint32_t *clock, uint8_t banks);
4343
extern void PIOS_Servo_Set(uint8_t Servo, uint16_t Position);
44+
extern void PIOS_Servo_SetActive(uint32_t Active);
4445
extern void PIOS_Servo_Update();
4546
extern void PIOS_Servo_SetBankMode(uint8_t bank, uint8_t mode);
4647
extern void PIOS_Servo_DSHot_Rate(uint32_t rate_in_khz);

flight/targets/boards/oplinkmini/firmware/pios_board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ void PIOS_Board_Init(void)
336336
PIOS_Servo_Init(&pios_servo_flexi_cfg);
337337
}
338338

339-
// Set bank modes
339+
// Set bank modes and activate output. We need to do this here because oplm does not run Actuator module.
340340
PIOS_Servo_SetBankMode(0, PIOS_SERVO_BANK_MODE_PWM);
341341
PIOS_Servo_SetBankMode(1, PIOS_SERVO_BANK_MODE_PWM);
342+
PIOS_Servo_SetActive(0b11);
342343
#endif
343344

344345
PIOS_BOARD_IO_Configure_RFM22B();

0 commit comments

Comments
 (0)