mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Update mixer to use servo count from results of pwm mapping.
Also ensure that only aux channels for which there are available servos are used when forwarding channels. Removed magic number usage.
This commit is contained in:
parent
51366ed629
commit
fd59a4cd52
5 changed files with 43 additions and 22 deletions
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
@ -143,14 +143,16 @@ static const uint16_t * const hardwareMaps[] = {
|
||||||
airPPM,
|
airPPM,
|
||||||
};
|
};
|
||||||
|
|
||||||
void pwmInit(drv_pwm_config_t *init)
|
pwmOutputConfiguration_t *pwmInit(drv_pwm_config_t *init)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
const uint16_t *setup;
|
const uint16_t *setup;
|
||||||
|
|
||||||
int channelIndex = 0;
|
int channelIndex = 0;
|
||||||
int servoIndex = 0;
|
|
||||||
int motorIndex = 0;
|
static pwmOutputConfiguration_t pwmOutputConfiguration;
|
||||||
|
|
||||||
|
memset(&pwmOutputConfiguration, 0, sizeof(pwmOutputConfiguration));
|
||||||
|
|
||||||
// this is pretty hacky shit, but it will do for now. array of 4 config maps, [ multiPWM multiPPM airPWM airPPM ]
|
// this is pretty hacky shit, but it will do for now. array of 4 config maps, [ multiPWM multiPPM airPWM airPPM ]
|
||||||
if (init->airplane)
|
if (init->airplane)
|
||||||
|
@ -265,14 +267,16 @@ void pwmInit(drv_pwm_config_t *init)
|
||||||
channelIndex++;
|
channelIndex++;
|
||||||
} else if (type == TYPE_M) {
|
} else if (type == TYPE_M) {
|
||||||
if (init->motorPwmRate > 500) {
|
if (init->motorPwmRate > 500) {
|
||||||
pwmBrushedMotorConfig(&timerHardware[timerIndex], motorIndex, init->motorPwmRate, init->idlePulse);
|
pwmBrushedMotorConfig(&timerHardware[timerIndex], pwmOutputConfiguration.motorCount, init->motorPwmRate, init->idlePulse);
|
||||||
} else {
|
} else {
|
||||||
pwmBrushlessMotorConfig(&timerHardware[timerIndex], motorIndex, init->motorPwmRate, init->idlePulse);
|
pwmBrushlessMotorConfig(&timerHardware[timerIndex], pwmOutputConfiguration.motorCount, init->motorPwmRate, init->idlePulse);
|
||||||
}
|
}
|
||||||
motorIndex++;
|
pwmOutputConfiguration.motorCount++;
|
||||||
} else if (type == TYPE_S) {
|
} else if (type == TYPE_S) {
|
||||||
pwmServoConfig(&timerHardware[timerIndex], servoIndex, init->servoPwmRate, init->servoCenterPulse);
|
pwmServoConfig(&timerHardware[timerIndex], pwmOutputConfiguration.servoCount, init->servoPwmRate, init->servoCenterPulse);
|
||||||
servoIndex++;
|
pwmOutputConfiguration.servoCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &pwmOutputConfiguration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,12 @@ typedef struct drv_pwm_config_t {
|
||||||
uint16_t servoCenterPulse;
|
uint16_t servoCenterPulse;
|
||||||
} drv_pwm_config_t;
|
} drv_pwm_config_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct pwmOutputConfiguration_s {
|
||||||
|
uint8_t servoCount;
|
||||||
|
uint8_t motorCount;
|
||||||
|
} pwmOutputConfiguration_t;
|
||||||
|
|
||||||
// This indexes into the read-only hardware definition structure, timerHardware_t, as well as into pwmPorts structure with dynamic data.
|
// This indexes into the read-only hardware definition structure, timerHardware_t, as well as into pwmPorts structure with dynamic data.
|
||||||
enum {
|
enum {
|
||||||
PWM1 = 0,
|
PWM1 = 0,
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "drivers/gpio.h"
|
#include "drivers/gpio.h"
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
#include "drivers/pwm_output.h"
|
#include "drivers/pwm_output.h"
|
||||||
|
#include "drivers/pwm_mapping.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
#include "io/gimbal.h"
|
#include "io/gimbal.h"
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
#include "config/runtime_config.h"
|
#include "config/runtime_config.h"
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
|
|
||||||
|
#define AUX_FORWARD_CHANNEL_TO_SERVO_COUNT 4
|
||||||
|
|
||||||
static uint8_t numberMotor = 0;
|
static uint8_t numberMotor = 0;
|
||||||
int16_t motor[MAX_SUPPORTED_MOTORS];
|
int16_t motor[MAX_SUPPORTED_MOTORS];
|
||||||
|
@ -47,6 +49,8 @@ int16_t servo[MAX_SUPPORTED_SERVOS] = { 1500, 1500, 1500, 1500, 1500, 1500, 1500
|
||||||
|
|
||||||
static int useServo;
|
static int useServo;
|
||||||
|
|
||||||
|
static uint8_t servoCount;
|
||||||
|
|
||||||
static servoParam_t *servoConf;
|
static servoParam_t *servoConf;
|
||||||
static mixerConfig_t *mixerConfig;
|
static mixerConfig_t *mixerConfig;
|
||||||
static flight3DConfig_t *flight3DConfig;
|
static flight3DConfig_t *flight3DConfig;
|
||||||
|
@ -239,12 +243,14 @@ int servoDirection(int nr, int lr)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mixerInit(MultiType mixerConfiguration, motorMixer_t *customMixers)
|
void mixerInit(MultiType mixerConfiguration, motorMixer_t *customMixers, pwmOutputConfiguration_t *pwmOutputConfiguration)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
currentMixerConfiguration = mixerConfiguration;
|
currentMixerConfiguration = mixerConfiguration;
|
||||||
|
|
||||||
|
servoCount = pwmOutputConfiguration->servoCount;
|
||||||
|
|
||||||
// enable servos for mixes that require them. note, this shifts motor counts.
|
// enable servos for mixes that require them. note, this shifts motor counts.
|
||||||
useServo = mixers[mixerConfiguration].useServo;
|
useServo = mixers[mixerConfiguration].useServo;
|
||||||
// if we want camstab/trig, that also enables servos, even if mixer doesn't
|
// if we want camstab/trig, that also enables servos, even if mixer doesn't
|
||||||
|
@ -536,15 +542,20 @@ void mixTable(void)
|
||||||
|
|
||||||
// forward AUX1-4 to servo outputs (not constrained)
|
// forward AUX1-4 to servo outputs (not constrained)
|
||||||
if (gimbalConfig->gimbal_flags & GIMBAL_FORWARDAUX) {
|
if (gimbalConfig->gimbal_flags & GIMBAL_FORWARDAUX) {
|
||||||
int offset = 0;
|
|
||||||
// offset servos based off number already used in mixer types
|
// offset servos based off number already used in mixer types
|
||||||
// airplane and servo_tilt together can't be used
|
// airplane and servo_tilt together can't be used
|
||||||
if (currentMixerConfiguration == MULTITYPE_AIRPLANE || currentMixerConfiguration == MULTITYPE_FLYING_WING)
|
int8_t firstServo = servoCount - AUX_FORWARD_CHANNEL_TO_SERVO_COUNT;
|
||||||
offset = 4;
|
|
||||||
else if (mixers[currentMixerConfiguration].useServo)
|
// start forwarding from this channel
|
||||||
offset = 2;
|
uint8_t channelOffset = AUX1;
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
pwmWriteServo(i + offset, rcData[AUX1 + i]);
|
int8_t servoOffset;
|
||||||
|
for (servoOffset = 0; servoOffset < AUX_FORWARD_CHANNEL_TO_SERVO_COUNT; servoOffset++) {
|
||||||
|
if (firstServo + servoOffset < 0) {
|
||||||
|
continue; // there are not enough servos to forward all the AUX channels.
|
||||||
|
}
|
||||||
|
pwmWriteServo(firstServo + servoOffset, rcData[channelOffset++]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maxMotor = motor[0];
|
maxMotor = motor[0];
|
||||||
|
|
|
@ -94,7 +94,6 @@ extern int16_t motor_disarmed[MAX_SUPPORTED_MOTORS];
|
||||||
extern int16_t servo[MAX_SUPPORTED_SERVOS];
|
extern int16_t servo[MAX_SUPPORTED_SERVOS];
|
||||||
|
|
||||||
bool isMixerUsingServos(void);
|
bool isMixerUsingServos(void);
|
||||||
void mixerInit(MultiType mixerConfiguration, motorMixer_t *customMixers);
|
|
||||||
void writeAllMotors(int16_t mc);
|
void writeAllMotors(int16_t mc);
|
||||||
void mixerLoadMix(int index, motorMixer_t *customMixers);
|
void mixerLoadMix(int index, motorMixer_t *customMixers);
|
||||||
void mixerResetMotors(void);
|
void mixerResetMotors(void);
|
||||||
|
|
|
@ -78,7 +78,8 @@ void timerInit(void);
|
||||||
void initTelemetry(void);
|
void initTelemetry(void);
|
||||||
void serialInit(serialConfig_t *initialSerialConfig);
|
void serialInit(serialConfig_t *initialSerialConfig);
|
||||||
failsafe_t* failsafeInit(rxConfig_t *intialRxConfig);
|
failsafe_t* failsafeInit(rxConfig_t *intialRxConfig);
|
||||||
void pwmInit(drv_pwm_config_t *init);
|
pwmOutputConfiguration_t *pwmInit(drv_pwm_config_t *init);
|
||||||
|
void mixerInit(MultiType mixerConfiguration, motorMixer_t *customMixers, pwmOutputConfiguration_t *pwmOutputConfiguration);
|
||||||
void rxInit(rxConfig_t *rxConfig, failsafe_t *failsafe);
|
void rxInit(rxConfig_t *rxConfig, failsafe_t *failsafe);
|
||||||
void buzzerInit(failsafe_t *initialFailsafe);
|
void buzzerInit(failsafe_t *initialFailsafe);
|
||||||
void gpsInit(serialConfig_t *serialConfig, gpsConfig_t *initialGpsConfig, gpsProfile_t *initialGpsProfile, pidProfile_t *pidProfile);
|
void gpsInit(serialConfig_t *serialConfig, gpsConfig_t *initialGpsConfig, gpsProfile_t *initialGpsProfile, pidProfile_t *pidProfile);
|
||||||
|
@ -163,8 +164,6 @@ void init(void)
|
||||||
compassInit();
|
compassInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mixerInit(masterConfig.mixerConfiguration, masterConfig.customMixer);
|
|
||||||
|
|
||||||
timerInit();
|
timerInit();
|
||||||
|
|
||||||
serialInit(&masterConfig.serialConfig);
|
serialInit(&masterConfig.serialConfig);
|
||||||
|
@ -195,7 +194,9 @@ void init(void)
|
||||||
pwm_params.idlePulse = 0; // brushed motors
|
pwm_params.idlePulse = 0; // brushed motors
|
||||||
pwm_params.servoCenterPulse = masterConfig.rxConfig.midrc;
|
pwm_params.servoCenterPulse = masterConfig.rxConfig.midrc;
|
||||||
|
|
||||||
pwmInit(&pwm_params);
|
pwmOutputConfiguration_t *pwmOutputConfiguration = pwmInit(&pwm_params);
|
||||||
|
|
||||||
|
mixerInit(masterConfig.mixerConfiguration, masterConfig.customMixer, pwmOutputConfiguration);
|
||||||
|
|
||||||
failsafe = failsafeInit(&masterConfig.rxConfig);
|
failsafe = failsafeInit(&masterConfig.rxConfig);
|
||||||
buzzerInit(failsafe);
|
buzzerInit(failsafe);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue