From 5b40bb4b247e3b884d7ba04844e41a5e9b840f57 Mon Sep 17 00:00:00 2001 From: jflyper Date: Fri, 25 Jan 2019 23:40:47 +0900 Subject: [PATCH] Set acc alignment to that of active gyro --- src/main/cli/settings.c | 2 -- src/main/sensors/acceleration.c | 13 +++++++------ src/main/sensors/gyro.c | 3 --- src/main/target/common_defaults_post.h | 7 ++----- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index 5096a32d7..e83107806 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -578,7 +578,6 @@ const lookupTableEntry_t lookupTables[] = { const clivalue_t valueTable[] = { // PG_GYRO_CONFIG - { "align_gyro", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_ALIGNMENT }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_align) }, { "gyro_hardware_lpf", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_GYRO_HARDWARE_LPF }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_hardware_lpf) }, #if defined(USE_32K_CAPABLE_GYRO) && defined(USE_GYRO_DLPF_EXPERIMENTAL) { "gyro_32khz_hardware_lpf", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_GYRO_32KHZ_HARDWARE_LPF }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_32khz_hardware_lpf) }, @@ -631,7 +630,6 @@ const clivalue_t valueTable[] = { { "gyro_filter_debug_axis", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_GYRO_FILTER_DEBUG }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_filter_debug_axis) }, // PG_ACCELEROMETER_CONFIG - { "align_acc", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_ALIGNMENT }, PG_ACCELEROMETER_CONFIG, offsetof(accelerometerConfig_t, acc_align) }, { "acc_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_ACC_HARDWARE }, PG_ACCELEROMETER_CONFIG, offsetof(accelerometerConfig_t, acc_hardware) }, #if defined(USE_GYRO_SPI_ICM20649) { "acc_high_range", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_ACCELEROMETER_CONFIG, offsetof(accelerometerConfig_t, acc_high_fsr) }, diff --git a/src/main/sensors/acceleration.c b/src/main/sensors/acceleration.c index 8970d66ce..fb8349340 100644 --- a/src/main/sensors/acceleration.c +++ b/src/main/sensors/acceleration.c @@ -35,6 +35,7 @@ #include "config/feature.h" #include "pg/pg.h" #include "pg/pg_ids.h" +#include "pg/gyrodev.h" #include "drivers/accgyro/accgyro.h" #include "drivers/accgyro/accgyro_fake.h" @@ -314,10 +315,13 @@ bool accInit(uint32_t gyroSamplingInverval) acc.dev.mpuDetectionResult = *gyroMpuDetectionResult(); acc.dev.acc_high_fsr = accelerometerConfig()->acc_high_fsr; - acc.dev.accAlign = ACC_1_ALIGN; -#ifdef ACC_2_ALIGN + // Copy alignment from active gyro, as all production boards use acc-gyro-combi chip. + // Exceptions are STM32F3DISCOVERY and STM32F411DISCOVERY, and (may be) handled in future enhancement. + + acc.dev.accAlign = gyroDeviceConfig(0)->align; +#ifdef USE_MULTI_GYRO if (gyroConfig()->gyro_to_use == GYRO_CONFIG_USE_GYRO_2) { - acc.dev.accAlign = ACC_2_ALIGN; + acc.dev.accAlign = gyroDeviceConfig(1)->align; } #endif @@ -348,9 +352,6 @@ bool accInit(uint32_t gyroSamplingInverval) biquadFilterInitLPF(&accFilter[axis], accLpfCutHz, acc.accSamplingInterval); } } - if (accelerometerConfig()->acc_align != ALIGN_DEFAULT) { - acc.dev.accAlign = accelerometerConfig()->acc_align; - } return true; } diff --git a/src/main/sensors/gyro.c b/src/main/sensors/gyro.c index 7a9e1798d..e6114309e 100644 --- a/src/main/sensors/gyro.c +++ b/src/main/sensors/gyro.c @@ -453,9 +453,6 @@ static bool gyroInitSensor(gyroSensor_t *gyroSensor, const gyroDeviceConfig_t *c gyroSensor->gyroDev.hardware_lpf = gyroConfig()->gyro_hardware_lpf; gyroSensor->gyroDev.hardware_32khz_lpf = gyroConfig()->gyro_32khz_hardware_lpf; gyroSensor->gyroDev.initFn(&gyroSensor->gyroDev); - if (gyroConfig()->gyro_align != ALIGN_DEFAULT) { - gyroSensor->gyroDev.gyroAlign = gyroConfig()->gyro_align; - } // As new gyros are supported, be sure to add them below based on whether they are subject to the overflow/inversion bug // Any gyro not explicitly defined will default to not having built-in overflow protection as a safe alternative. diff --git a/src/main/target/common_defaults_post.h b/src/main/target/common_defaults_post.h index c96246da7..94b9ec13f 100644 --- a/src/main/target/common_defaults_post.h +++ b/src/main/target/common_defaults_post.h @@ -273,7 +273,6 @@ #define GYRO_2_CS_PIN NONE #define GYRO_2_ALIGN ALIGN_DEFAULT #define GYRO_2_EXTI_PIN NONE -#define ACC_2_ALIGN ALIGN_DEFAULT #endif #if !defined(GYRO_1_SPI_INSTANCE) @@ -292,10 +291,6 @@ #define GYRO_1_ALIGN ALIGN_DEFAULT #endif -#if !defined(ACC_1_ALIGN) -#define ACC_1_ALIGN ALIGN_DEFAULT -#endif - #if defined(MPU_ADDRESS) #define GYRO_I2C_ADDRESS MPU_ADDRESS #else @@ -304,8 +299,10 @@ #ifdef USE_MULTI_GYRO #define MAX_GYRODEV_COUNT 2 +#define MAX_ACCDEV_COUNT 2 #else #define MAX_GYRODEV_COUNT 1 +#define MAX_ACCDEV_COUNT 1 #endif #ifdef USE_VCP