Preparation for conversion to parameter groups 12

This commit is contained in:
Martin Budden 2017-02-17 17:24:13 +00:00
parent 14a7c805c1
commit 2c667376fa
8 changed files with 118 additions and 145 deletions

View File

@ -194,7 +194,7 @@ void pwmCompleteMotorUpdate(uint8_t motorCount)
pwmCompleteWritePtr(motorCount); pwmCompleteWritePtr(motorCount);
} }
void motorInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount) void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount)
{ {
memset(motors, 0, sizeof(motors)); memset(motors, 0, sizeof(motors));
@ -325,7 +325,7 @@ void pwmWriteServo(uint8_t index, uint16_t value)
} }
} }
void servoInit(const servoDevConfig_t *servoConfig) void servoDevInit(const servoDevConfig_t *servoConfig)
{ {
for (uint8_t servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) { for (uint8_t servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) {
const ioTag_t tag = servoConfig->ioTags[servoIndex]; const ioTag_t tag = servoConfig->ioTags[servoIndex];

View File

@ -126,7 +126,7 @@ typedef struct motorDevConfig_s {
ioTag_t ioTags[MAX_SUPPORTED_MOTORS]; ioTag_t ioTags[MAX_SUPPORTED_MOTORS];
} motorDevConfig_t; } motorDevConfig_t;
void motorInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount); void motorDevInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount);
typedef struct servoDevConfig_s { typedef struct servoDevConfig_s {
// PWM values, in milliseconds, common range is 1000-2000 (1ms to 2ms) // PWM values, in milliseconds, common range is 1000-2000 (1ms to 2ms)
@ -135,7 +135,7 @@ typedef struct servoDevConfig_s {
ioTag_t ioTags[MAX_SUPPORTED_SERVOS]; ioTag_t ioTags[MAX_SUPPORTED_SERVOS];
} servoDevConfig_t; } servoDevConfig_t;
void servoInit(const servoDevConfig_t *servoDevConfig); void servoDevInit(const servoDevConfig_t *servoDevConfig);
void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse); void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse);

View File

@ -52,13 +52,11 @@ uint8_t cliMode = 0;
#include "config/parameter_group.h" #include "config/parameter_group.h"
#include "config/parameter_group_ids.h" #include "config/parameter_group_ids.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "drivers/accgyro.h" #include "drivers/accgyro.h"
#include "drivers/buf_writer.h" #include "drivers/buf_writer.h"
#include "drivers/bus_i2c.h" #include "drivers/bus_i2c.h"
#include "drivers/compass.h" #include "drivers/compass.h"
#include "drivers/display.h"
#include "drivers/dma.h" #include "drivers/dma.h"
#include "drivers/flash.h" #include "drivers/flash.h"
#include "drivers/io.h" #include "drivers/io.h"
@ -72,12 +70,12 @@ uint8_t cliMode = 0;
#include "drivers/system.h" #include "drivers/system.h"
#include "drivers/timer.h" #include "drivers/timer.h"
#include "drivers/vcd.h" #include "drivers/vcd.h"
#include "drivers/display.h"
#include "fc/cli.h"
#include "fc/config.h" #include "fc/config.h"
#include "fc/rc_adjustments.h"
#include "fc/rc_controls.h" #include "fc/rc_controls.h"
#include "fc/runtime_config.h" #include "fc/runtime_config.h"
#include "fc/cli.h"
#include "flight/failsafe.h" #include "flight/failsafe.h"
#include "flight/imu.h" #include "flight/imu.h"
@ -92,10 +90,8 @@ uint8_t cliMode = 0;
#include "io/gimbal.h" #include "io/gimbal.h"
#include "io/gps.h" #include "io/gps.h"
#include "io/ledstrip.h" #include "io/ledstrip.h"
#include "io/motors.h"
#include "io/osd.h" #include "io/osd.h"
#include "io/serial.h" #include "io/serial.h"
#include "io/servos.h"
#include "io/vtx.h" #include "io/vtx.h"
#include "rx/rx.h" #include "rx/rx.h"
@ -397,6 +393,7 @@ typedef enum {
#ifdef OSD #ifdef OSD
TABLE_OSD, TABLE_OSD,
#endif #endif
LOOKUP_TABLE_COUNT
} lookupTableIndex_e; } lookupTableIndex_e;
static const lookupTableEntry_t lookupTables[] = { static const lookupTableEntry_t lookupTables[] = {
@ -887,7 +884,6 @@ static beeperDevConfig_t beeperDevConfigCopy;
#endif #endif
static controlRateConfig_t controlRateProfilesCopy[MAX_CONTROL_RATE_PROFILE_COUNT]; static controlRateConfig_t controlRateProfilesCopy[MAX_CONTROL_RATE_PROFILE_COUNT];
static pidProfile_t pidProfileCopy[MAX_PROFILE_COUNT]; static pidProfile_t pidProfileCopy[MAX_PROFILE_COUNT];
static modeActivationOperatorConfig_t modeActivationOperatorConfigCopy;
#endif // USE_PARAMETER_GROUPS #endif // USE_PARAMETER_GROUPS
static void cliPrint(const char *str) static void cliPrint(const char *str)
@ -968,52 +964,52 @@ static void cliPrintf(const char *format, ...)
bufWriterFlush(cliWriter); bufWriterFlush(cliWriter);
} }
static void printValuePointer(const clivalue_t *var, void *valuePointer, uint32_t full) static void printValuePointer(const clivalue_t *var, const void *valuePointer, uint32_t full)
{ {
int32_t value = 0; int32_t value = 0;
char buf[8]; char buf[8];
switch (var->type & VALUE_TYPE_MASK) { switch (var->type & VALUE_TYPE_MASK) {
case VAR_UINT8: case VAR_UINT8:
value = *(uint8_t *)valuePointer; value = *(uint8_t *)valuePointer;
break; break;
case VAR_INT8: case VAR_INT8:
value = *(int8_t *)valuePointer; value = *(int8_t *)valuePointer;
break; break;
case VAR_UINT16: case VAR_UINT16:
value = *(uint16_t *)valuePointer; value = *(uint16_t *)valuePointer;
break; break;
case VAR_INT16: case VAR_INT16:
value = *(int16_t *)valuePointer; value = *(int16_t *)valuePointer;
break; break;
/* not currently used /* not currently used
case VAR_UINT32: case VAR_UINT32:
value = *(uint32_t *)valuePointer; value = *(uint32_t *)valuePointer;
break; */ break; */
case VAR_FLOAT: case VAR_FLOAT:
cliPrintf("%s", ftoa(*(float *)valuePointer, buf)); cliPrintf("%s", ftoa(*(float *)valuePointer, buf));
if (full && (var->type & VALUE_MODE_MASK) == MODE_DIRECT) { if (full && (var->type & VALUE_MODE_MASK) == MODE_DIRECT) {
cliPrintf(" %s", ftoa((float)var->config.minmax.min, buf)); cliPrintf(" %s", ftoa((float)var->config.minmax.min, buf));
cliPrintf(" %s", ftoa((float)var->config.minmax.max, buf)); cliPrintf(" %s", ftoa((float)var->config.minmax.max, buf));
} }
return; // return from case for float only return; // return from case for float only
} }
switch(var->type & VALUE_MODE_MASK) { switch(var->type & VALUE_MODE_MASK) {
case MODE_DIRECT: case MODE_DIRECT:
cliPrintf("%d", value); cliPrintf("%d", value);
if (full) { if (full) {
cliPrintf(" %d %d", var->config.minmax.min, var->config.minmax.max); cliPrintf(" %d %d", var->config.minmax.min, var->config.minmax.max);
} }
break; break;
case MODE_LOOKUP: case MODE_LOOKUP:
cliPrintf(lookupTables[var->config.lookup.tableIndex].values[value]); cliPrintf(lookupTables[var->config.lookup.tableIndex].values[value]);
break; break;
} }
} }
@ -1189,10 +1185,6 @@ static const cliCurrentAndDefaultConfig_t *getCurrentAndDefaultConfigs(pgn_t pgn
ret.currentConfig = &systemConfigCopy; ret.currentConfig = &systemConfigCopy;
ret.defaultConfig = systemConfig(); ret.defaultConfig = systemConfig();
break; break;
case PG_MODE_ACTIVATION_OPERATOR_CONFIG:
ret.currentConfig = &modeActivationOperatorConfigCopy;
ret.defaultConfig = modeActivationOperatorConfig();
break;
case PG_CONTROL_RATE_PROFILES: case PG_CONTROL_RATE_PROFILES:
ret.currentConfig = &controlRateProfilesCopy[0]; ret.currentConfig = &controlRateProfilesCopy[0];
ret.defaultConfig = controlRateProfiles(0); ret.defaultConfig = controlRateProfiles(0);
@ -1336,37 +1328,37 @@ static bool valueEqualsDefault(const clivalue_t *value, const master_t *defaultC
bool result = false; bool result = false;
switch (value->type & VALUE_TYPE_MASK) { switch (value->type & VALUE_TYPE_MASK) {
case VAR_UINT8: case VAR_UINT8:
result = *(uint8_t *)ptr == *(uint8_t *)ptrDefault; result = *(uint8_t *)ptr == *(uint8_t *)ptrDefault;
break; break;
case VAR_INT8: case VAR_INT8:
result = *(int8_t *)ptr == *(int8_t *)ptrDefault; result = *(int8_t *)ptr == *(int8_t *)ptrDefault;
break; break;
case VAR_UINT16: case VAR_UINT16:
result = *(uint16_t *)ptr == *(uint16_t *)ptrDefault; result = *(uint16_t *)ptr == *(uint16_t *)ptrDefault;
break; break;
case VAR_INT16: case VAR_INT16:
result = *(int16_t *)ptr == *(int16_t *)ptrDefault; result = *(int16_t *)ptr == *(int16_t *)ptrDefault;
break; break;
/* not currently used /* not currently used
case VAR_UINT32: case VAR_UINT32:
result = *(uint32_t *)ptr == *(uint32_t *)ptrDefault; result = *(uint32_t *)ptr == *(uint32_t *)ptrDefault;
break; */ break; */
case VAR_FLOAT: case VAR_FLOAT:
result = *(float *)ptr == *(float *)ptrDefault; result = *(float *)ptr == *(float *)ptrDefault;
break; break;
} }
return result; return result;
} }
static void cliPrintVar(const clivalue_t *var, uint32_t full) static void cliPrintVar(const clivalue_t *var, uint32_t full)
{ {
void *ptr = getValuePointer(var); const void *ptr = getValuePointer(var);
printValuePointer(var, ptr, full); printValuePointer(var, ptr, full);
} }
@ -1405,21 +1397,21 @@ static void dumpValues(uint16_t valueSection, uint8_t dumpMask, const master_t *
static void cliPrintVarRange(const clivalue_t *var) static void cliPrintVarRange(const clivalue_t *var)
{ {
switch (var->type & VALUE_MODE_MASK) { switch (var->type & VALUE_MODE_MASK) {
case (MODE_DIRECT): { case (MODE_DIRECT): {
cliPrintf("Allowed range: %d - %d\r\n", var->config.minmax.min, var->config.minmax.max); cliPrintf("Allowed range: %d - %d\r\n", var->config.minmax.min, var->config.minmax.max);
}
break;
case (MODE_LOOKUP): {
const lookupTableEntry_t *tableEntry = &lookupTables[var->config.lookup.tableIndex];
cliPrint("Allowed values:");
for (uint32_t i = 0; i < tableEntry->valueCount ; i++) {
if (i > 0)
cliPrint(",");
cliPrintf(" %s", tableEntry->values[i]);
} }
break; cliPrint("\r\n");
case (MODE_LOOKUP): { }
const lookupTableEntry_t *tableEntry = &lookupTables[var->config.lookup.tableIndex]; break;
cliPrint("Allowed values:");
for (uint32_t i = 0; i < tableEntry->valueCount ; i++) {
if (i > 0)
cliPrint(",");
cliPrintf(" %s", tableEntry->values[i]);
}
cliPrint("\r\n");
}
break;
} }
} }
@ -1433,24 +1425,24 @@ static void cliSetVar(const clivalue_t *var, const int_float_value_t value)
void *ptr = getValuePointer(var); void *ptr = getValuePointer(var);
switch (var->type & VALUE_TYPE_MASK) { switch (var->type & VALUE_TYPE_MASK) {
case VAR_UINT8: case VAR_UINT8:
case VAR_INT8: case VAR_INT8:
*(int8_t *)ptr = value.int_value; *(int8_t *)ptr = value.int_value;
break; break;
case VAR_UINT16: case VAR_UINT16:
case VAR_INT16: case VAR_INT16:
*(int16_t *)ptr = value.int_value; *(int16_t *)ptr = value.int_value;
break; break;
/* not currently used /* not currently used
case VAR_UINT32: case VAR_UINT32:
*(uint32_t *)ptr = value.int_value; *(uint32_t *)ptr = value.int_value;
break; */ break; */
case VAR_FLOAT: case VAR_FLOAT:
*(float *)ptr = (float)value.float_value; *(float *)ptr = (float)value.float_value;
break; break;
} }
} }
@ -1574,9 +1566,9 @@ static void cliRxFailsafe(char *cmdline)
ptr = nextArg(ptr); ptr = nextArg(ptr);
if (ptr) { if (ptr) {
char *p = strchr(rxFailsafeModeCharacters, *(ptr)); const char *p = strchr(rxFailsafeModeCharacters, *(ptr));
if (p) { if (p) {
uint8_t requestedMode = p - rxFailsafeModeCharacters; const uint8_t requestedMode = p - rxFailsafeModeCharacters;
mode = rxFailsafeModesTable[type][requestedMode]; mode = rxFailsafeModesTable[type][requestedMode];
} else { } else {
mode = RX_FAILSAFE_MODE_INVALID; mode = RX_FAILSAFE_MODE_INVALID;
@ -1607,7 +1599,6 @@ static void cliRxFailsafe(char *cmdline)
return; return;
} }
channelFailsafeConfig->mode = mode; channelFailsafeConfig->mode = mode;
} }
char modeCharacter = rxFailsafeModeCharacters[channelFailsafeConfig->mode]; char modeCharacter = rxFailsafeModeCharacters[channelFailsafeConfig->mode];
@ -2226,14 +2217,11 @@ static void printColor(uint8_t dumpMask, const hsvColor_t *colors, const hsvColo
static void cliColor(char *cmdline) static void cliColor(char *cmdline)
{ {
int i;
const char *ptr;
if (isEmpty(cmdline)) { if (isEmpty(cmdline)) {
printColor(DUMP_MASTER, ledStripConfig()->colors, NULL); printColor(DUMP_MASTER, ledStripConfig()->colors, NULL);
} else { } else {
ptr = cmdline; const char *ptr = cmdline;
i = atoi(ptr); const int i = atoi(ptr);
if (i < LED_CONFIGURABLE_COLOR_COUNT) { if (i < LED_CONFIGURABLE_COLOR_COUNT) {
ptr = nextArg(cmdline); ptr = nextArg(cmdline);
if (!parseColor(i, ptr)) { if (!parseColor(i, ptr)) {
@ -2626,7 +2614,8 @@ static void cliWriteBytes(const uint8_t *buffer, int count)
} }
} }
static void cliSdInfo(char *cmdline) { static void cliSdInfo(char *cmdline)
{
UNUSED(cmdline); UNUSED(cmdline);
cliPrint("SD card: "); cliPrint("SD card: ");
@ -2704,7 +2693,7 @@ static void cliFlashErase(char *cmdline)
UNUSED(cmdline); UNUSED(cmdline);
#ifndef MINIMAL_CLI #ifndef MINIMAL_CLI
uint32_t i; uint32_t i = 0;
cliPrintf("Erasing, please wait ... \r\n"); cliPrintf("Erasing, please wait ... \r\n");
#else #else
cliPrintf("Erasing,\r\n"); cliPrintf("Erasing,\r\n");
@ -2733,8 +2722,8 @@ static void cliFlashErase(char *cmdline)
static void cliFlashWrite(char *cmdline) static void cliFlashWrite(char *cmdline)
{ {
uint32_t address = atoi(cmdline); const uint32_t address = atoi(cmdline);
char *text = strchr(cmdline, ' '); const char *text = strchr(cmdline, ' ');
if (!text) { if (!text) {
cliShowParseError(); cliShowParseError();
@ -2750,7 +2739,6 @@ static void cliFlashWrite(char *cmdline)
static void cliFlashRead(char *cmdline) static void cliFlashRead(char *cmdline)
{ {
uint32_t address = atoi(cmdline); uint32_t address = atoi(cmdline);
uint32_t length;
uint8_t buffer[32]; uint8_t buffer[32];
@ -2759,7 +2747,7 @@ static void cliFlashRead(char *cmdline)
if (!nextArg) { if (!nextArg) {
cliShowParseError(); cliShowParseError();
} else { } else {
length = atoi(nextArg); uint32_t length = atoi(nextArg);
cliPrintf("Reading %u bytes at %u:\r\n", length, address); cliPrintf("Reading %u bytes at %u:\r\n", length, address);
@ -2981,9 +2969,9 @@ static void cliFeature(char *cmdline)
#ifdef BEEPER #ifdef BEEPER
static void printBeeper(uint8_t dumpMask, const master_t *defaultConfig) static void printBeeper(uint8_t dumpMask, const master_t *defaultConfig)
{ {
uint8_t beeperCount = beeperTableEntryCount(); const uint8_t beeperCount = beeperTableEntryCount();
uint32_t mask = getBeeperOffMask(); const uint32_t mask = getBeeperOffMask();
uint32_t defaultMask = defaultConfig->beeper_off_flags; const uint32_t defaultMask = defaultConfig->beeper_off_flags;
for (int32_t i = 0; i < beeperCount - 2; i++) { for (int32_t i = 0; i < beeperCount - 2; i++) {
const char *formatOff = "beeper -%s\r\n"; const char *formatOff = "beeper -%s\r\n";
const char *formatOn = "beeper %s\r\n"; const char *formatOn = "beeper %s\r\n";
@ -3352,13 +3340,11 @@ static void cliPlaySound(char *cmdline)
static void cliProfile(char *cmdline) static void cliProfile(char *cmdline)
{ {
int i;
if (isEmpty(cmdline)) { if (isEmpty(cmdline)) {
cliPrintf("profile %d\r\n", getCurrentProfile()); cliPrintf("profile %d\r\n", getCurrentProfile());
return; return;
} else { } else {
i = atoi(cmdline); const int i = atoi(cmdline);
if (i >= 0 && i < MAX_PROFILE_COUNT) { if (i >= 0 && i < MAX_PROFILE_COUNT) {
masterConfig.current_profile_index = i; masterConfig.current_profile_index = i;
writeEEPROM(); writeEEPROM();
@ -3370,13 +3356,11 @@ static void cliProfile(char *cmdline)
static void cliRateProfile(char *cmdline) static void cliRateProfile(char *cmdline)
{ {
int i;
if (isEmpty(cmdline)) { if (isEmpty(cmdline)) {
cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile()); cliPrintf("rateprofile %d\r\n", getCurrentControlRateProfile());
return; return;
} else { } else {
i = atoi(cmdline); const int i = atoi(cmdline);
if (i >= 0 && i < MAX_RATEPROFILES) { if (i >= 0 && i < MAX_RATEPROFILES) {
changeControlRateProfile(i); changeControlRateProfile(i);
cliRateProfile(""); cliRateProfile("");
@ -4389,5 +4373,6 @@ void cliEnter(serialPort_t *serialPort)
void cliInit(const serialConfig_t *serialConfig) void cliInit(const serialConfig_t *serialConfig)
{ {
UNUSED(serialConfig); UNUSED(serialConfig);
BUILD_BUG_ON(LOOKUP_TABLE_COUNT != ARRAYLEN(lookupTables));
} }
#endif // USE_CLI #endif // USE_CLI

View File

@ -272,9 +272,9 @@ void init(void)
serialInit(feature(FEATURE_SOFTSERIAL), SERIAL_PORT_NONE); serialInit(feature(FEATURE_SOFTSERIAL), SERIAL_PORT_NONE);
#endif #endif
mixerInit(mixerConfig()->mixerMode, customMotorMixerMutable(0)); mixerInit(mixerConfig()->mixerMode);
#ifdef USE_SERVOS #ifdef USE_SERVOS
servoMixerInit(customServoMixers(0)); servosInit();
#endif #endif
uint16_t idlePulse = motorConfig()->mincommand; uint16_t idlePulse = motorConfig()->mincommand;
@ -288,13 +288,13 @@ void init(void)
} }
mixerConfigureOutput(); mixerConfigureOutput();
motorInit(&motorConfig()->dev, idlePulse, getMotorCount()); motorDevInit(&motorConfig()->dev, idlePulse, getMotorCount());
#ifdef USE_SERVOS #ifdef USE_SERVOS
servoConfigureOutput(); servoConfigureOutput();
if (isMixerUsingServos()) { if (isMixerUsingServos()) {
//pwm_params.useChannelForwarding = feature(FEATURE_CHANNEL_FORWARDING); //pwm_params.useChannelForwarding = feature(FEATURE_CHANNEL_FORWARDING);
servoInit(&servoConfig()->dev); servoDevInit(&servoConfig()->dev);
} }
#endif #endif

View File

@ -230,8 +230,6 @@ const mixer_t mixers[] = {
}; };
#endif #endif
static const motorMixer_t *customMixers;
static uint16_t disarmMotorOutput, deadbandMotor3dHigh, deadbandMotor3dLow; static uint16_t disarmMotorOutput, deadbandMotor3dHigh, deadbandMotor3dLow;
uint16_t motorOutputHigh, motorOutputLow; uint16_t motorOutputHigh, motorOutputLow;
static float rcCommandThrottleRange, rcCommandThrottleRange3dLow, rcCommandThrottleRange3dHigh; static float rcCommandThrottleRange, rcCommandThrottleRange3dLow, rcCommandThrottleRange3dHigh;
@ -289,12 +287,10 @@ void initEscEndpoints(void) {
rcCommandThrottleRange3dHigh = PWM_RANGE_MAX - rxConfig()->midrc - flight3DConfig()->deadband3d_throttle; rcCommandThrottleRange3dHigh = PWM_RANGE_MAX - rxConfig()->midrc - flight3DConfig()->deadband3d_throttle;
} }
void mixerInit(mixerMode_e mixerMode, const motorMixer_t *initialCustomMixers) void mixerInit(mixerMode_e mixerMode)
{ {
currentMixerMode = mixerMode; currentMixerMode = mixerMode;
customMixers = initialCustomMixers;
initEscEndpoints(); initEscEndpoints();
} }
@ -308,9 +304,9 @@ void mixerConfigureOutput(void)
// load custom mixer into currentMixer // load custom mixer into currentMixer
for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) { for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
// check if done // check if done
if (customMixers[i].throttle == 0.0f) if (customMotorMixer(i)->throttle == 0.0f)
break; break;
currentMixer[i] = customMixers[i]; currentMixer[i] = *customMotorMixer(i);
motorCount++; motorCount++;
} }
} else { } else {

View File

@ -124,7 +124,7 @@ uint8_t getMotorCount();
float getMotorMixRange(); float getMotorMixRange();
void mixerLoadMix(int index, motorMixer_t *customMixers); void mixerLoadMix(int index, motorMixer_t *customMixers);
void mixerInit(mixerMode_e mixerMode, const motorMixer_t *customMotorMixers); void mixerInit(mixerMode_e mixerMode);
void mixerConfigureOutput(void); void mixerConfigureOutput(void);

View File

@ -147,8 +147,6 @@ const mixerRules_t servoMixers[] = {
{ 0, NULL }, { 0, NULL },
}; };
static const servoMixer_t *customServoMixers;
void servoUseConfigs(servoParam_t *servoParamsToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse) void servoUseConfigs(servoParam_t *servoParamsToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse)
{ {
servoConf = servoParamsToUse; servoConf = servoParamsToUse;
@ -157,7 +155,7 @@ void servoUseConfigs(servoParam_t *servoParamsToUse, struct channelForwardingCon
int16_t determineServoMiddleOrForwardFromChannel(servoIndex_e servoIndex) int16_t determineServoMiddleOrForwardFromChannel(servoIndex_e servoIndex)
{ {
uint8_t channelToForwardFrom = servoConf[servoIndex].forwardFromChannel; const uint8_t channelToForwardFrom = servoConf[servoIndex].forwardFromChannel;
if (channelToForwardFrom != CHANNEL_FORWARDING_DISABLED && channelToForwardFrom < rxRuntimeConfig.channelCount) { if (channelToForwardFrom != CHANNEL_FORWARDING_DISABLED && channelToForwardFrom < rxRuntimeConfig.channelCount) {
return rcData[channelToForwardFrom]; return rcData[channelToForwardFrom];
@ -166,7 +164,6 @@ int16_t determineServoMiddleOrForwardFromChannel(servoIndex_e servoIndex)
return servoConf[servoIndex].middle; return servoConf[servoIndex].middle;
} }
int servoDirection(int servoIndex, int inputSource) int servoDirection(int servoIndex, int inputSource)
{ {
// determine the direction (reversed or not) from the direction bitfield of the servo // determine the direction (reversed or not) from the direction bitfield of the servo
@ -176,10 +173,8 @@ int servoDirection(int servoIndex, int inputSource)
return 1; return 1;
} }
void servoMixerInit(const servoMixer_t *initialCustomServoMixers) void servosInit(void)
{ {
customServoMixers = initialCustomServoMixers;
// 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[currentMixerMode].useServo; useServo = mixers[currentMixerMode].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
@ -201,10 +196,10 @@ void loadCustomServoMixer(void)
// load custom mixer into currentServoMixer // load custom mixer into currentServoMixer
for (uint8_t i = 0; i < MAX_SERVO_RULES; i++) { for (uint8_t i = 0; i < MAX_SERVO_RULES; i++) {
// check if done // check if done
if (customServoMixers[i].rate == 0) if (customServoMixers(i)->rate == 0)
break; break;
currentServoMixer[i] = customServoMixers[i]; currentServoMixer[i] = *customServoMixers(i);
servoRuleCount++; servoRuleCount++;
} }
} }

View File

@ -105,7 +105,6 @@ typedef struct servoParam_s {
PG_DECLARE_ARRAY(servoParam_t, MAX_SUPPORTED_SERVOS, servoParams); PG_DECLARE_ARRAY(servoParam_t, MAX_SUPPORTED_SERVOS, servoParams);
typedef struct servoConfig_s { typedef struct servoConfig_s {
// PWM values, in milliseconds, common range is 1000-2000 (1 to 2ms)
servoDevConfig_t dev; servoDevConfig_t dev;
uint16_t servo_lowpass_freq; // lowpass servo filter frequency selection; 1/1000ths of loop freq uint16_t servo_lowpass_freq; // lowpass servo filter frequency selection; 1/1000ths of loop freq
uint8_t tri_unarmed_servo; // send tail servo correction pulses even when unarmed uint8_t tri_unarmed_servo; // send tail servo correction pulses even when unarmed
@ -125,11 +124,9 @@ extern int16_t servo[MAX_SUPPORTED_SERVOS];
bool isMixerUsingServos(void); bool isMixerUsingServos(void);
void writeServos(void); void writeServos(void);
void servoMixerInit(const servoMixer_t *customServoMixers);
void servoUseConfigs(servoParam_t *servoParamsToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse);
void servoMixerLoadMix(int index, servoMixer_t *customServoMixers); void servoMixerLoadMix(int index, servoMixer_t *customServoMixers);
void loadCustomServoMixer(void); void loadCustomServoMixer(void);
void servoConfigureOutput(void); void servoUseConfigs(servoParam_t *servoParamsToUse, struct channelForwardingConfig_s *channelForwardingConfigToUse);
int servoDirection(int servoIndex, int fromChannel); int servoDirection(int servoIndex, int fromChannel);
void servoConfigureOutput(void);
void servosInit(void);