Skip to content

Commit 8935906

Browse files
mindneverf5soh
authored andcommitted
Merged in mindnever/librepilot/LP-544_fix_ws2811_servo_conflict (pull request #473)
LP-544 Fix for ws2811 & servo driver conflict. Approved-by: Vladimir Zidar <mr_w@mindnever.org> Approved-by: Philippe Renon <philippe_renon@yahoo.fr> Approved-by: Jan NIJS <dr.oblivium@gmail.com> Approved-by: Lalanne Laurent <f5soh@free.fr>
2 parents 1837cf1 + cc29d52 commit 8935906

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
@@ -1057,6 +1057,25 @@ static void actuator_update_rate_if_changed(bool force_update)
10571057
}
10581058
}
10591059

1060+
static void update_servo_active()
1061+
{
1062+
/* For each mixer output that is not disabled,
1063+
* figure out servo address and send allocation map to pios_servo driver.
1064+
* We need to execute this when either ActuatorSettings or MixerSettings change.
1065+
*/
1066+
uint32_t servo_active = 0;
1067+
1068+
Mixer_t *mixers = (Mixer_t *)&mixerSettings.Mixer1Type;
1069+
1070+
for (int ct = 0; ct < MAX_MIX_ACTUATORS; ct++) {
1071+
if (mixers[ct].type != MIXERSETTINGS_MIXER1TYPE_DISABLED) {
1072+
servo_active |= 1 << actuatorSettings.ChannelAddr[ct];
1073+
}
1074+
}
1075+
1076+
PIOS_Servo_SetActive(servo_active);
1077+
}
1078+
10601079
static void ActuatorSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10611080
{
10621081
ActuatorSettingsGet(&actuatorSettings);
@@ -1065,6 +1084,8 @@ static void ActuatorSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10651084
spinWhileArmed = false;
10661085
}
10671086
actuator_update_rate_if_changed(false);
1087+
1088+
update_servo_active();
10681089
}
10691090

10701091
static void MixerSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
@@ -1077,6 +1098,8 @@ static void MixerSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10771098
mixer_settings_count++;
10781099
}
10791100
}
1101+
1102+
update_servo_active();
10801103
}
10811104
static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
10821105
{

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)