Skip to content

Commit

Permalink
Merge pull request #6928 from iNavFlight/dzikuvx-rework-default-mag-a…
Browse files Browse the repository at this point in the history
…lignment

Make CW270FLIP default MAG alignment
  • Loading branch information
DzikuVx authored May 7, 2021
2 parents 21fc620 + 3cd2578 commit e1b4a0f
Show file tree
Hide file tree
Showing 44 changed files with 205 additions and 89 deletions.
6 changes: 6 additions & 0 deletions src/main/fc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ void validateAndFixConfig(void)
// Call target-specific validation function
validateAndFixTargetConfig();

#ifdef USE_MAG
if (compassConfig()->mag_align == ALIGN_DEFAULT) {
compassConfigMutable()->mag_align = CW270_DEG_FLIP;
}
#endif

if (settingsValidate(NULL)) {
DISABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
} else {
Expand Down
35 changes: 2 additions & 33 deletions src/main/sensors/compass.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_QMC5883:
#ifdef USE_MAG_QMC5883
if (qmc5883Detect(dev)) {
#ifdef MAG_QMC5883_ALIGN
dev->magAlign.onBoard = MAG_QMC5883_ALIGN;
#endif
magHardware = MAG_QMC5883;
break;
}
Expand All @@ -111,9 +108,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_HMC5883:
#ifdef USE_MAG_HMC5883
if (hmc5883lDetect(dev)) {
#ifdef MAG_HMC5883_ALIGN
dev->magAlign.onBoard = MAG_HMC5883_ALIGN;
#endif
magHardware = MAG_HMC5883;
break;
}
Expand All @@ -127,9 +121,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_AK8975:
#ifdef USE_MAG_AK8975
if (ak8975Detect(dev)) {
#ifdef MAG_AK8975_ALIGN
dev->magAlign.onBoard = MAG_AK8975_ALIGN;
#endif
magHardware = MAG_AK8975;
break;
}
Expand All @@ -143,9 +134,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_AK8963:
#ifdef USE_MAG_AK8963
if (ak8963Detect(dev)) {
#ifdef MAG_AK8963_ALIGN
dev->magAlign.onBoard = MAG_AK8963_ALIGN;
#endif
magHardware = MAG_AK8963;
break;
}
Expand All @@ -159,9 +147,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_GPS:
#ifdef USE_GPS
if (gpsMagDetect(dev)) {
#ifdef MAG_GPS_ALIGN
dev->magAlign.onBoard = MAG_GPS_ALIGN;
#endif
magHardware = MAG_GPS;
break;
}
Expand All @@ -175,9 +160,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_MAG3110:
#ifdef USE_MAG_MAG3110
if (mag3110detect(dev)) {
#ifdef MAG_MAG3110_ALIGN
dev->magAlign.onBoard = MAG_MAG3110_ALIGN;
#endif
magHardware = MAG_MAG3110;
break;
}
Expand All @@ -191,9 +173,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_IST8310:
#ifdef USE_MAG_IST8310
if (ist8310Detect(dev)) {
#ifdef MAG_IST8310_ALIGN
dev->magAlign.onBoard = MAG_IST8310_ALIGN;
#endif
magHardware = MAG_IST8310;
break;
}
Expand All @@ -207,9 +186,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_IST8308:
#ifdef USE_MAG_IST8308
if (ist8308Detect(dev)) {
#ifdef MAG_IST8308_ALIGN
dev->magAlign.onBoard = MAG_IST8308_ALIGN;
#endif
magHardware = MAG_IST8308;
break;
}
Expand All @@ -223,9 +199,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_MPU9250:
#ifdef USE_MAG_MPU9250
if (mpu9250CompassDetect(dev)) {
#ifdef MAG_MPU9250_ALIGN
dev->magAlign.onBoard = MAG_MPU9250_ALIGN;
#endif
magHardware = MAG_MPU9250;
break;
}
Expand All @@ -235,9 +208,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_LIS3MDL:
#ifdef USE_MAG_LIS3MDL
if (lis3mdlDetect(dev)) {
#ifdef MAG_LIS3MDL_ALIGN
dev->magAlign = MAG_LIS3MDL_ALIGN;
#endif
magHardware = MAG_LIS3MDL;
break;
}
Expand Down Expand Up @@ -266,9 +236,6 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
case MAG_RM3100:
#ifdef USE_MAG_RM3100
if (rm3100MagDetect(dev)) {
#ifdef MAG_RM3100_ALIGN
dev->magAlign.onBoard = MAG_RM3100_ALIGN;
#endif
magHardware = MAG_RM3100;
break;
}
Expand Down Expand Up @@ -344,6 +311,8 @@ bool compassInit(void)
mag.dev.magAlign.useExternal = false;
if (compassConfig()->mag_align != ALIGN_DEFAULT) {
mag.dev.magAlign.onBoard = compassConfig()->mag_align;
} else {
mag.dev.magAlign.onBoard = CW270_DEG_FLIP; // The most popular default is 270FLIP for external mags
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/target/AIRBOTF4/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C2
#define MAG_HMC5883_ALIGN CW90_DEG
#define USE_MAG_HMC5883
#define USE_MAG_AK8963
#define USE_MAG_AK8975
Expand Down Expand Up @@ -128,8 +127,6 @@

#define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT

#define MAG_GPS_ALIGN CW180_DEG_FLIP

#define DEFAULT_RX_TYPE RX_TYPE_PPM
#define DISABLE_RX_PWM_FEATURE
#define DEFAULT_FEATURES (FEATURE_TX_PROF_SEL | FEATURE_BLACKBOX | FEATURE_VBAT)
Expand Down
1 change: 0 additions & 1 deletion src/main/target/ALIENFLIGHTF3/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#define USE_MAG
#define MAG_I2C_BUS BUS_I2C2
#define USE_MAG_MPU9250
#define MAG_MPU9250_ALIGN CW0_DEG
#define USE_MAG_AK8963
#define USE_MAG_AK8975
#define USE_MAG_HMC5883
Expand Down
3 changes: 3 additions & 0 deletions src/main/target/ALIENFLIGHTF4/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include "sensors/battery.h"
#include "sensors/sensors.h"
#include "sensors/compass.h"

#include "telemetry/telemetry.h"

Expand All @@ -56,6 +57,8 @@
// alternative defaults settings for AlienFlight targets
void targetConfiguration(void)
{
compassConfigMutable()->mag_align = CW90_DEG;

serialConfigMutable()->portConfigs[2].functionMask = FUNCTION_RX_SERIAL;
batteryMetersConfigMutable()->current.offset = CURRENTOFFSET;
batteryMetersConfigMutable()->current.scale = CURRENTSCALE;
Expand Down
2 changes: 0 additions & 2 deletions src/main/target/ALIENFLIGHTF4/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
#define USE_MAG_IST8308
#define USE_MAG_LIS3MDL

#define MAG_MPU9250_ALIGN CW0_DEG

#define TEMPERATURE_I2C_BUS BUS_I2C1
#define BNO055_I2C_BUS BUS_I2C1

Expand Down
3 changes: 3 additions & 0 deletions src/main/target/ALIENFLIGHTNGF7/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "config/feature.h"

#include "sensors/battery.h"
#include "sensors/compass.h"

#include "hardware_revision.h"

Expand All @@ -58,6 +59,8 @@
// alternative defaults settings for AlienFlight targets
void targetConfiguration(void)
{
compassConfigMutable()->mag_align = CW90_DEG;

serialConfigMutable()->portConfigs[2].functionMask = FUNCTION_RX_SERIAL;
batteryMetersConfigMutable()->current.offset = CURRENTOFFSET;
batteryMetersConfigMutable()->current.scale = CURRENTSCALE;
Expand Down
3 changes: 0 additions & 3 deletions src/main/target/ALIENFLIGHTNGF7/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
#define USE_MAG_IST8308
#define USE_MAG_LIS3MDL

#define MAG_AK9863_ALIGN CW0_DEG
#define MAG_MPU9250_ALIGN CW0_DEG

#define AK8963_CS_PIN PC15
#define AK8963_SPI_BUS BUS_SPI3

Expand Down
3 changes: 0 additions & 3 deletions src/main/target/ANYFC/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#define USE_MAG_IST8310
#define USE_MAG_IST8308
#define USE_MAG_LIS3MDL
#define MAG_HMC5883_ALIGN CW270_DEG_FLIP

#define TEMPERATURE_I2C_BUS BUS_I2C2

Expand Down Expand Up @@ -104,8 +103,6 @@

//#define HIL

#define MAG_GPS_ALIGN CW180_DEG_FLIP

#define USE_ADC
#define ADC_CHANNEL_1_PIN PC0
#define ADC_CHANNEL_2_PIN PC1
Expand Down
3 changes: 0 additions & 3 deletions src/main/target/ANYFCF7/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C2
#define MAG_HMC5883_ALIGN CW270_DEG_FLIP
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
#define USE_MAG_IST8310
Expand Down Expand Up @@ -142,8 +141,6 @@
#define USE_I2C_DEVICE_4
#define USE_I2C_DEVICE_2

#define MAG_GPS_ALIGN CW180_DEG_FLIP

#define SENSORS_SET (SENSOR_ACC|SENSOR_MAG|SENSOR_BARO)

#define USE_NAV
Expand Down
1 change: 0 additions & 1 deletion src/main/target/ANYFCM7/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C2
#define MAG_HMC5883_ALIGN CW270_DEG_FLIP
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
#define USE_MAG_IST8310
Expand Down
1 change: 0 additions & 1 deletion src/main/target/BEEROTORF4/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C1
#define MAG_HMC5883_ALIGN CW90_DEG
#define USE_MAG_HMC5883
#define USE_MAG_AK8963
#define USE_MAG_AK8975
Expand Down
1 change: 0 additions & 1 deletion src/main/target/BETAFLIGHTF4/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C2
//#define MAG_HMC5883_ALIGN CW90_DEG
#define USE_MAG_AK8963
#define USE_MAG_AK8975
#define USE_MAG_HMC5883
Expand Down
1 change: 0 additions & 1 deletion src/main/target/CHEBUZZF3/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

#define USE_MAG
#define MAG_I2C_BUS BUS_I2C1
#define MAG_AK8975_ALIGN CW90_DEG_FLIP
#define USE_MAG_AK8975
#define USE_MAG_HMC5883
#define USE_MAG_QMC5883
Expand Down
55 changes: 55 additions & 0 deletions src/main/target/CLRACINGF4AIR/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdbool.h>
#include <stdint.h>

#include <platform.h>

#include "common/axis.h"

#include "drivers/sensor.h"
#include "drivers/pwm_esc_detect.h"
#include "drivers/pwm_mapping.h"
#include "drivers/pwm_output.h"
#include "drivers/serial.h"

#include "fc/rc_controls.h"

#include "flight/failsafe.h"
#include "flight/mixer.h"
#include "flight/pid.h"

#include "rx/rx.h"

#include "io/serial.h"

#include "telemetry/telemetry.h"

#include "sensors/battery.h"
#include "sensors/sensors.h"

#include "config/config_master.h"
#include "config/feature.h"

#include "sensors/battery.h"
#include "sensors/compass.h"

void targetConfiguration(void)
{
compassConfigMutable()->mag_align = CW90_DEG;
}
1 change: 0 additions & 1 deletion src/main/target/CLRACINGF4AIR/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

#define USE_MAG
#define USE_MAG_MPU9250
#define MAG_MPU9250_ALIGN CW90_DEG

// MPU6 interrupts
#define USE_EXTI
Expand Down
8 changes: 4 additions & 4 deletions src/main/target/COLIBRI/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
#include "platform.h"

#include "config/feature.h"

#include "fc/config.h"

#include "flight/mixer.h"

#include "io/serial.h"

#include "rx/rx.h"
#include "sensors/compass.h"

void targetConfiguration(void)
{
rxConfigMutable()->serialrx_provider = SERIALRX_SBUS;
rxConfigMutable()->receiverType = RX_TYPE_SERIAL;
serialConfigMutable()->portConfigs[2].functionMask = FUNCTION_RX_SERIAL;
#ifdef QUANTON
compassConfigMutable()->mag_align = CW90_DEG;
#endif
}
2 changes: 0 additions & 2 deletions src/main/target/COLIBRI/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@

#ifdef QUANTON
#define IMU_MPU6000_ALIGN CW90_DEG
#define MAG_HMC5883_ALIGN CW90_DEG
#else
#define IMU_MPU6000_ALIGN CW270_DEG_FLIP
#define MAG_HMC5883_ALIGN CW270_DEG_FLIP
#endif

#define USE_BARO
Expand Down
Loading

0 comments on commit e1b4a0f

Please sign in to comment.