Skip to content

Commit

Permalink
Merge pull request cleanflight#1752 from martinbudden/issue1751
Browse files Browse the repository at this point in the history
Fixes Issue1751 - decreases ROM size of CJMCU target by about 1500 bytes
  • Loading branch information
hydra committed Feb 5, 2016
2 parents e285a74 + 4743b55 commit 688931d
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ void resetGpsProfile(gpsProfile_t *gpsProfile)
}
#endif

#ifdef BARO
void resetBarometerConfig(barometerConfig_t *barometerConfig)
{
barometerConfig->baro_sample_count = 21;
barometerConfig->baro_noise_lpf = 0.6f;
barometerConfig->baro_cf_vel = 0.985f;
barometerConfig->baro_cf_alt = 0.965f;
}
#endif

void resetSensorAlignment(sensorAlignmentConfig_t *sensorAlignmentConfig)
{
Expand All @@ -251,6 +253,7 @@ void resetFlight3DConfig(flight3DConfig_t *flight3DConfig)
flight3DConfig->deadband3d_throttle = 50;
}

#ifdef TELEMETRY
void resetTelemetryConfig(telemetryConfig_t *telemetryConfig)
{
telemetryConfig->telemetry_inversion = 0;
Expand All @@ -262,6 +265,7 @@ void resetTelemetryConfig(telemetryConfig_t *telemetryConfig)
telemetryConfig->frsky_vfas_precision = 0;
telemetryConfig->hottAlarmSoundInterval = 5;
}
#endif

void resetBatteryConfig(batteryConfig_t *batteryConfig)
{
Expand Down Expand Up @@ -424,7 +428,9 @@ static void resetConf(void)

resetBatteryConfig(&masterConfig.batteryConfig);

#ifdef TELEMETRY
resetTelemetryConfig(&masterConfig.telemetryConfig);
#endif

masterConfig.rxConfig.serialrx_provider = 0;
masterConfig.rxConfig.sbus_inversion = 1;
Expand Down Expand Up @@ -502,7 +508,9 @@ static void resetConf(void)
currentProfile->accDeadband.z = 40;
currentProfile->acc_unarmedcal = 1;

#ifdef BARO
resetBarometerConfig(&currentProfile->barometerConfig);
#endif

// Radio
parseRcChannels("AETR1234", &masterConfig.rxConfig);
Expand Down Expand Up @@ -778,12 +786,14 @@ void activateConfig(void)
currentProfile->throttle_correction_angle
);

#if defined(BARO) || defined(SONAR)
configureAltitudeHold(
&currentProfile->pidProfile,
&currentProfile->barometerConfig,
&currentProfile->rcControlsConfig,
&masterConfig.escAndServoConfig
);
#endif

#ifdef BARO
useBarometerConfig(&currentProfile->barometerConfig);
Expand Down Expand Up @@ -834,7 +844,9 @@ void validateAndFixConfig(void)

#ifdef STM32F303xC
// hardware supports serial port inversion, make users life easier for those that want to connect SBus RX's
#ifdef TELEMETRY
masterConfig.telemetryConfig.telemetry_inversion = 1;
#endif
#endif

/*
Expand Down
2 changes: 2 additions & 0 deletions src/main/config/config_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ typedef struct master_t {

serialConfig_t serialConfig;

#ifdef TELEMETRY
telemetryConfig_t telemetryConfig;
#endif

#ifdef LED_STRIP
ledConfig_t ledConfigs[MAX_LED_STRIP_LENGTH];
Expand Down
2 changes: 2 additions & 0 deletions src/main/config/config_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ typedef struct profile_s {
float accz_lpf_cutoff; // cutoff frequency for the low pass filter used on the acc z-axis for althold in Hz
accDeadband_t accDeadband;

#ifdef BARO
barometerConfig_t barometerConfig;
#endif

uint8_t acc_unarmedcal; // turn automatic acc compensation on/off

Expand Down
8 changes: 7 additions & 1 deletion src/main/drivers/pwm_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
#include "gpio.h"
#include "timer.h"

#ifdef USE_QUAD_MIXER_ONLY
#define MAX_PWM_MOTORS 4
#define MAX_PWM_SERVOS 1
#define MAX_MOTORS 4
#define MAX_SERVOS 1
#else
#define MAX_PWM_MOTORS 12
#define MAX_PWM_SERVOS 8

#define MAX_MOTORS 12
#define MAX_SERVOS 8
#endif
#define MAX_PWM_OUTPUT_PORTS MAX_PWM_MOTORS // must be set to the largest of either MAX_MOTORS or MAX_SERVOS

#if MAX_PWM_OUTPUT_PORTS < MAX_MOTORS || MAX_PWM_OUTPUT_PORTS < MAX_SERVOS
Expand Down
6 changes: 5 additions & 1 deletion src/main/flight/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ static bool imuIsAccelerometerHealthy(void)
return (81 < accMagnitude) && (accMagnitude < 121);
}

#ifdef MAG
static bool isMagnetometerHealthy(void)
{
return (magADC[X] != 0) && (magADC[Y] != 0) && (magADC[Z] != 0);
}
#endif

static void imuCalculateEstimatedAttitude(void)
{
Expand Down Expand Up @@ -402,9 +404,11 @@ static void imuCalculateEstimatedAttitude(void)
useAcc = true;
}

#ifdef MAG
if (sensors(SENSOR_MAG) && isMagnetometerHealthy()) {
useMag = true;
}
#endif
#if defined(GPS)
else if (STATE(FIXED_WING) && sensors(SENSOR_GPS) && STATE(GPS_FIX) && GPS_numSat >= 5 && GPS_speed >= 300) {
// In case of a fixed-wing aircraft we can use GPS course over ground to correct heading
Expand Down Expand Up @@ -464,4 +468,4 @@ int16_t calculateThrottleAngleCorrection(uint8_t throttle_correction_value)
if (angle > 900)
angle = 900;
return lrintf(throttle_correction_value * sin_approx(angle / (900.0f * M_PIf / 2.0f)));
}
}
5 changes: 5 additions & 0 deletions src/main/flight/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

#pragma once

#ifdef USE_QUAD_MIXER_ONLY
#define MAX_SUPPORTED_MOTORS 4
#define MAX_SUPPORTED_SERVOS 1
#else
#define MAX_SUPPORTED_MOTORS 12
#define MAX_SUPPORTED_SERVOS 8
#endif
#define YAW_JUMP_PREVENTION_LIMIT_LOW 80
#define YAW_JUMP_PREVENTION_LIMIT_HIGH 500

Expand Down
15 changes: 15 additions & 0 deletions src/main/io/beeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define BEEPER_COMMAND_REPEAT 0xFE
#define BEEPER_COMMAND_STOP 0xFF

#ifdef BEEPER
/* Beeper Sound Sequences: (Square wave generation)
* Sequence must end with 0xFF or 0xFE. 0xFE repeats the sequence from
* start when 0xFF stops the sound when it's completed.
Expand Down Expand Up @@ -379,3 +380,17 @@ int beeperTableEntryCount(void)
{
return (int)BEEPER_TABLE_ENTRY_COUNT;
}

#else

// Stub out beeper functions if #BEEPER not defined
void beeper(beeperMode_e mode) {UNUSED(mode);}
void beeperSilence(void) {}
void beeperConfirmationBeeps(uint8_t beepCount) {UNUSED(beepCount);}
void beeperUpdate(void) {}
uint32_t getArmingBeepTimeMicros(void) {return 0;}
beeperMode_e beeperModeForTableIndex(int idx) {UNUSED(idx); return BEEPER_SILENCE;}
const char *beeperNameForTableIndex(int idx) {UNUSED(idx); return NULL;}
int beeperTableEntryCount(void) {return 0;}

#endif
6 changes: 6 additions & 0 deletions src/main/io/serial_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ const clivalue_t valueTable[] = {
{ "sbus_inversion", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.sbus_inversion, .config.lookup = { TABLE_OFF_ON } },
{ "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.spektrum_sat_bind, .config.minmax = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX} },

#ifdef TELEMETRY
{ "telemetry_switch", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.telemetry_switch, .config.lookup = { TABLE_OFF_ON } },
{ "telemetry_inversion", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.telemetry_inversion, .config.lookup = { TABLE_OFF_ON } },
{ "frsky_default_lattitude", VAR_FLOAT | MASTER_VALUE, &masterConfig.telemetryConfig.gpsNoFixLatitude, .config.minmax = { -90.0, 90.0 } },
Expand All @@ -549,6 +550,7 @@ const clivalue_t valueTable[] = {
{ "frsky_unit", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.telemetryConfig.frsky_unit, .config.lookup = { TABLE_UNIT } },
{ "frsky_vfas_precision", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.frsky_vfas_precision, .config.minmax = { FRSKY_VFAS_PRECISION_LOW, FRSKY_VFAS_PRECISION_HIGH } },
{ "hott_alarm_sound_interval", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.hottAlarmSoundInterval, .config.minmax = { 0, 120 } },
#endif

{ "battery_capacity", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.batteryCapacity, .config.minmax = { 0, 20000 } },
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatscale, .config.minmax = { VBAT_SCALE_MIN, VBAT_SCALE_MAX } },
Expand Down Expand Up @@ -631,14 +633,18 @@ const clivalue_t valueTable[] = {
{ "acc_trim_pitch", VAR_INT16 | PROFILE_VALUE, &masterConfig.profile[0].accelerometerTrims.values.pitch, .config.minmax = { -300, 300 } },
{ "acc_trim_roll", VAR_INT16 | PROFILE_VALUE, &masterConfig.profile[0].accelerometerTrims.values.roll, .config.minmax = { -300, 300 } },

#ifdef BARO
{ "baro_tab_size", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].barometerConfig.baro_sample_count, .config.minmax = { 0, BARO_SAMPLE_COUNT_MAX } },
{ "baro_noise_lpf", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].barometerConfig.baro_noise_lpf, .config.minmax = { 0 , 1 } },
{ "baro_cf_vel", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].barometerConfig.baro_cf_vel, .config.minmax = { 0 , 1 } },
{ "baro_cf_alt", VAR_FLOAT | PROFILE_VALUE, &masterConfig.profile[0].barometerConfig.baro_cf_alt, .config.minmax = { 0 , 1 } },
{ "baro_hardware", VAR_UINT8 | MASTER_VALUE, &masterConfig.baro_hardware, .config.minmax = { 0, BARO_MAX } },
#endif

#ifdef MAG
{ "mag_hardware", VAR_UINT8 | MASTER_VALUE, &masterConfig.mag_hardware, .config.minmax = { 0, MAG_MAX } },
{ "mag_declination", VAR_INT16 | PROFILE_VALUE, &masterConfig.profile[0].mag_declination, .config.minmax = { -18000, 18000 } },
#endif

{ "pid_delta_method", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, &masterConfig.profile[0].pidProfile.deltaMethod, .config.lookup = { TABLE_DELTA_METHOD } },

Expand Down
19 changes: 16 additions & 3 deletions src/main/io/serial_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ static void tailSerialReply(void)
serialEndWrite(mspSerialPort);
}

#ifdef USE_SERVOS
static void s_struct(uint8_t *cb, uint8_t siz)
{
headSerialReply(siz);
while (siz--)
serialize8(*cb++);
}
#endif

static void serializeNames(const char *s)
{
Expand Down Expand Up @@ -464,9 +466,11 @@ void mspInit(serialConfig_t *serialConfig)
activeBoxIds[activeBoxIdCount++] = BOXHORIZON;
}

#ifdef BARO
if (sensors(SENSOR_BARO)) {
activeBoxIds[activeBoxIdCount++] = BOXBARO;
}
#endif

if (sensors(SENSOR_ACC) || sensors(SENSOR_MAG)) {
activeBoxIds[activeBoxIdCount++] = BOXMAG;
Expand Down Expand Up @@ -500,8 +504,10 @@ void mspInit(serialConfig_t *serialConfig)

activeBoxIds[activeBoxIdCount++] = BOXOSD;

#ifdef TELEMETRY
if (feature(FEATURE_TELEMETRY) && masterConfig.telemetryConfig.telemetry_switch)
activeBoxIds[activeBoxIdCount++] = BOXTELEMETRY;
#endif

if (feature(FEATURE_SONAR)){
activeBoxIds[activeBoxIdCount++] = BOXSONAR;
Expand Down Expand Up @@ -727,7 +733,10 @@ static bool processOutCommand(uint8_t cmdMSP)
break;
#endif
case MSP_MOTOR:
s_struct((uint8_t *)motor, 16);
headSerialReply(16);
for (i = 0; i < 8; i++) {
serialize16(i < MAX_SUPPORTED_MOTORS ? motor[i] : 0);
}
break;
case MSP_RC:
headSerialReply(2 * rxRuntimeConfig.channelCount);
Expand Down Expand Up @@ -1361,8 +1370,12 @@ static bool processInCommand(void)
masterConfig.batteryConfig.vbatwarningcellvoltage = read8(); // vbatlevel when buzzer starts to alert
break;
case MSP_SET_MOTOR:
for (i = 0; i < 8; i++) // FIXME should this use MAX_MOTORS or MAX_SUPPORTED_MOTORS instead of 8
motor_disarmed[i] = read16();
for (i = 0; i < 8; i++) {
const int16_t disarmed = read16();
if (i < MAX_SUPPORTED_MOTORS) {
motor_disarmed[i] = disarmed;
}
}
break;
case MSP_SET_SERVO_CONFIGURATION:
#ifdef USE_SERVOS
Expand Down
2 changes: 2 additions & 0 deletions src/main/mw.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,12 @@ void taskHandleSerial(void)
handleSerial();
}

#ifdef BEEPER
void taskUpdateBeeper(void)
{
beeperUpdate(); //call periodic beeper handler
}
#endif

void taskUpdateBattery(void)
{
Expand Down
2 changes: 2 additions & 0 deletions src/main/scheduler_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ cfTask_t cfTasks[TASK_COUNT] = {
.staticPriority = TASK_PRIORITY_LOW,
},

#ifdef BEEPER
[TASK_BEEPER] = {
.taskName = "BEEPER",
.taskFunc = taskUpdateBeeper,
.desiredPeriod = 1000000 / 100, // 100 Hz
.staticPriority = TASK_PRIORITY_MEDIUM,
},
#endif

[TASK_BATTERY] = {
.taskName = "BATTERY",
Expand Down
9 changes: 9 additions & 0 deletions src/main/sensors/initialisation.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ static void detectBaro(baroSensor_e baroHardwareToUse)
#endif
}

#ifdef MAG
static void detectMag(magSensor_e magHardwareToUse)
{
magSensor_e magHardware;
Expand Down Expand Up @@ -637,6 +638,7 @@ static void detectMag(magSensor_e magHardwareToUse)
detectedSensors[SENSOR_INDEX_MAG] = magHardware;
sensorsSet(SENSOR_MAG);
}
#endif

void reconfigureAlignment(sensorAlignmentConfig_t *sensorAlignmentConfig)
{
Expand All @@ -646,9 +648,11 @@ void reconfigureAlignment(sensorAlignmentConfig_t *sensorAlignmentConfig)
if (sensorAlignmentConfig->acc_align != ALIGN_DEFAULT) {
accAlign = sensorAlignmentConfig->acc_align;
}
#ifdef MAG
if (sensorAlignmentConfig->mag_align != ALIGN_DEFAULT) {
magAlign = sensorAlignmentConfig->mag_align;
}
#endif
}

bool sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint8_t gyroLpf, uint8_t accHardwareToUse, uint8_t magHardwareToUse, uint8_t baroHardwareToUse,
Expand All @@ -657,6 +661,9 @@ bool sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint8_t g

int16_t deg, min;

#ifndef MAG
UNUSED(magHardwareToUse);
#endif
memset(&acc, 0, sizeof(acc));
memset(&gyro, 0, sizeof(gyro));

Expand All @@ -682,7 +689,9 @@ bool sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint8_t g
gyroUpdateSampleRate(looptime, gyroLpf, gyroSync, gyroSyncDenominator); // Set gyro sampling rate divider before initialization
gyro.init(gyroLpf);

#ifdef MAG
detectMag(magHardwareToUse);
#endif

reconfigureAlignment(sensorAlignmentConfig);

Expand Down

0 comments on commit 688931d

Please sign in to comment.