Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method for adding defaults using defines for resources. #12342

Merged
merged 5 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/drivers/camera_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ void pgResetFn_cameraControlConfig(cameraControlConfig_t *cameraControlConfig)
cameraControlConfig->refVoltage = 330;
cameraControlConfig->keyDelayMs = 180;
cameraControlConfig->internalResistance = 470;
cameraControlConfig->ioTag = timerioTagGetByUsage(TIM_USE_CAMERA_CONTROL, 0);
#ifdef CAMERA_CONTROL_PIN
cameraControlConfig->ioTag = IO_TAG(CAMERA_CONTROL_PIN);
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use (black) macro magic so that CAMERA_CONTROL_PIN will expand to tag if defined (including NONE), and to NONE when undefined. It may also check that TAG definition is valid.
It may make this code more readable ..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping me if you think it is good idea ..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @blckmn ☝️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ledvinap absolutely! You are the king of macros, so happy for you to show how it'd work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cameraControlConfig->ioTag = IO_TAG_NONE;
#endif
cameraControlConfig->inverted = 0; // Output is inverted externally
cameraControlConfig->buttonResistanceValues[CAMERA_CONTROL_KEY_ENTER] = 450;
cameraControlConfig->buttonResistanceValues[CAMERA_CONTROL_KEY_LEFT] = 270;
Expand Down
6 changes: 3 additions & 3 deletions src/main/fc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ void init(void)
targetConfiguration();
#endif

#ifdef USE_BRUSHED_ESC_AUTODETECT
#if defined(USE_BRUSHED_ESC_AUTODETECT) && defined(MOTOR1_PIN)
// Opportunistically use the first motor pin of the default configuration for detection.
// We are doing this as with some boards, timing seems to be important, and the later detection will fail.
ioTag_t motorIoTag = timerioTagGetByUsage(TIM_USE_MOTOR, 0);
ioTag_t motorIoTag = IO_TAG(MOTOR1_PIN);

if (motorIoTag) {
detectBrushedESC(motorIoTag);
Expand Down Expand Up @@ -427,7 +427,7 @@ void init(void)
dbgPinInit();
#endif

#ifdef USE_BRUSHED_ESC_AUTODETECT
#if defined(USE_BRUSHED_ESC_AUTODETECT) && defined(MOTOR1_PIN)
// Now detect again with the actually configured pin for motor 1, if it is not the default pin.
ioTag_t configuredMotorIoTag = motorConfig()->dev.ioTags[0];

Expand Down
15 changes: 12 additions & 3 deletions src/main/flight/servos.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@ void pgResetFn_servoConfig(servoConfig_t *servoConfig)
servoConfig->servo_lowpass_freq = 0;
servoConfig->channelForwardingStartChannel = AUX1;

for (unsigned servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) {
servoConfig->dev.ioTags[servoIndex] = timerioTagGetByUsage(TIM_USE_SERVO, servoIndex);
}
#ifdef SERVO1_PIN
servoConfig->dev.ioTags[0] = IO_TAG(SERVO1_PIN);
#endif
#ifdef SERVO2_PIN
servoConfig->dev.ioTags[1] = IO_TAG(SERVO2_PIN);
#endif
#ifdef SERVO3_PIN
servoConfig->dev.ioTags[2] = IO_TAG(SERVO3_PIN);
#endif
#ifdef SERVO4_PIN
servoConfig->dev.ioTags[3] = IO_TAG(SERVO4_PIN);
#endif
}

PG_REGISTER_ARRAY(servoMixer_t, MAX_SERVO_RULES, customServoMixers, PG_SERVO_MIXER, 0);
Expand Down
6 changes: 5 additions & 1 deletion src/main/io/ledstrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ void pgResetFn_ledStripConfig(ledStripConfig_t *ledStripConfig)
ledStripConfig->ledstrip_visual_beeper_color = VISUAL_BEEPER_COLOR;
ledStripConfig->ledstrip_brightness = 100;
#ifndef UNIT_TEST
ledStripConfig->ioTag = timerioTagGetByUsage(TIM_USE_LED, 0);
#ifdef LED_STRIP_PIN
ledStripConfig->ioTag = IO_TAG(LED_STRIP_PIN);
#else
ledStripConfig->ioTag = IO_TAG_NONE;
#endif
#endif
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/io/transponder_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ void pgResetFn_transponderConfig(transponderConfig_t *transponderConfig)
.data = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0x0, 0x0, 0x0 }, // Note, this is NOT a valid transponder code, it's just for testing production hardware
.ioTag = IO_TAG_NONE
);
transponderConfig->ioTag = timerioTagGetByUsage(TIM_USE_TRANSPONDER, 0);
#ifdef TRANSPONDER_PIN
transponderConfig->ioTag = IO_TAG(TRANSPONDER_PIN);
#else
transponderConfig->ioTag = IO_TAG_NONE;
#endif
}

static bool transponderInitialised = false;
Expand Down
19 changes: 16 additions & 3 deletions src/main/pg/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,22 @@ void pgResetFn_motorConfig(motorConfig_t *motorConfig)
#endif

#ifdef USE_TIMER
for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS; motorIndex++) {
motorConfig->dev.ioTags[motorIndex] = timerioTagGetByUsage(TIM_USE_MOTOR, motorIndex);
}
#ifdef MOTOR1_PIN
motorConfig->dev.ioTags[0] = IO_TAG(MOTOR1_PIN);
#endif
#ifdef MOTOR2_PIN
motorConfig->dev.ioTags[1] = IO_TAG(MOTOR2_PIN);
#endif
#ifdef MOTOR3_PIN
motorConfig->dev.ioTags[2] = IO_TAG(MOTOR3_PIN);
#endif
#ifdef MOTOR4_PIN
motorConfig->dev.ioTags[3] = IO_TAG(MOTOR4_PIN);
#endif
blckmn marked this conversation as resolved.
Show resolved Hide resolved
/*
NOTE as we predominantly build for quads, the default motor pin defines is 4,
add more if a specific configuration ever requires it.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAX_SUPPORTED_MOTORS is 8. This should support the same amount of motor pins.

Also, all SPRacing FC's always have 8 motor outputs.

#endif

motorConfig->motorPoleCount = 14; // Most brushes motors that we use are 14 poles
Expand Down
21 changes: 17 additions & 4 deletions src/main/pg/rx_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ PG_REGISTER_WITH_RESET_FN(pwmConfig_t, pwmConfig, PG_PWM_CONFIG, 0);
void pgResetFn_pwmConfig(pwmConfig_t *pwmConfig)
{
pwmConfig->inputFilteringMode = INPUT_FILTERING_DISABLED;
for (unsigned inputIndex = 0; inputIndex < PWM_INPUT_PORT_COUNT; inputIndex++) {
pwmConfig->ioTags[inputIndex] = timerioTagGetByUsage(TIM_USE_PWM, inputIndex);
}
#ifdef RX_PWM1_PIN
pwmConfig->ioTags[0] = IO_TAG(RX_PWM1_PIN);
#endif
#ifdef RX_PWM2_PIN
pwmConfig->ioTags[1] = IO_TAG(RX_PWM2_PIN);
#endif
#ifdef RX_PWM3_PIN
pwmConfig->ioTags[2] = IO_TAG(RX_PWM3_PIN);
#endif
#ifdef RX_PWM4_PIN
pwmConfig->ioTags[3] = IO_TAG(RX_PWM4_PIN);
#endif
blckmn marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

Expand All @@ -49,7 +58,11 @@ PG_REGISTER_WITH_RESET_FN(ppmConfig_t, ppmConfig, PG_PPM_CONFIG, 0);

void pgResetFn_ppmConfig(ppmConfig_t *ppmConfig)
{
ppmConfig->ioTag = timerioTagGetByUsage(TIM_USE_PPM, 0);
#ifdef RX_PPM_PIN
ppmConfig->ioTag = IO_TAG(RX_PPM_PIN);
#else
ppmConfig->ioTag = IO_TAG_NONE;
#endif
}
#endif

Expand Down
28 changes: 5 additions & 23 deletions src/main/pg/timerio.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,15 @@

#include "timerio.h"

#define TIMER_PIN_MAP(idx, pin, pos, dmaOpt) \
{ config[idx].ioTag = IO_TAG(pin); config[idx].index = pos; config[idx].dmaopt = dmaOpt; }

PG_REGISTER_ARRAY_WITH_RESET_FN(timerIOConfig_t, MAX_TIMER_PINMAP_COUNT, timerIOConfig, PG_TIMER_IO_CONFIG, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to raise version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean?


void pgResetFn_timerIOConfig(timerIOConfig_t *config)
{
#if defined(USE_TIMER_MGMT) && USABLE_TIMER_CHANNEL_COUNT > 0
unsigned configIndex = 0;
for (unsigned timerIndex = 0; timerIndex < USABLE_TIMER_CHANNEL_COUNT; timerIndex++) {
const timerHardware_t *configuredTimer = &timerHardware[timerIndex];
unsigned positionIndex = 1;
for (unsigned fullTimerIndex = 0; fullTimerIndex < FULL_TIMER_CHANNEL_COUNT; fullTimerIndex++) {
const timerHardware_t *timer = &fullTimerHardware[fullTimerIndex];
if (timer->tag == configuredTimer->tag) {
if (timer->tim == configuredTimer->tim && timer->channel == configuredTimer->channel) {
config[configIndex].ioTag = timer->tag;
config[configIndex].index = positionIndex;

config[configIndex].dmaopt = dmaGetOptionByTimer(configuredTimer);

configIndex++;

break;
} else {
positionIndex++;
}
}
}
}
#ifdef TIMER_PIN_MAPPING
TIMER_PIN_MAPPING
blckmn marked this conversation as resolved.
Show resolved Hide resolved
#else
UNUSED(config);
#endif
Expand Down