From 9ef9f98310426aee573ab283b0e8a389c79bedf3 Mon Sep 17 00:00:00 2001 From: jflyper Date: Fri, 31 Aug 2018 10:54:52 +0900 Subject: [PATCH] Various fixes based on mikeller's comment. --- src/main/interface/cli.c | 1 - src/main/interface/settings.c | 21 +++++++++------------ src/main/pg/gyrodev.c | 10 ++++++---- src/main/pg/gyrodev.h | 11 +---------- src/main/pg/pg.h | 2 ++ src/main/target/ANYFCF7/target.h | 2 +- src/main/target/ANYFCM7/target.h | 2 +- src/main/target/CRAZYBEEF3FR/target.h | 2 +- src/main/target/FRSKYF3/target.h | 2 +- src/main/target/NUCLEOF722/target.h | 2 +- src/main/target/RCEXPLORERF3/target.h | 2 +- src/main/target/RG_SSD_F3/target.h | 2 +- src/main/target/SPEKTRUMF400/target.h | 2 +- src/main/target/STM32F7X2/target.h | 2 +- src/main/target/TINYFISH/target.h | 2 +- src/main/target/VRRACE/target.h | 2 +- src/main/target/common_defaults_post.h | 6 ++++++ 17 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/main/interface/cli.c b/src/main/interface/cli.c index b4cf79cc0..c380f5e98 100644 --- a/src/main/interface/cli.c +++ b/src/main/interface/cli.c @@ -3824,7 +3824,6 @@ const cliResourceValue_t resourceTable[] = { #ifdef USE_RX_SPI DEFS( OWNER_RX_SPI_CS, PG_RX_SPI_CONFIG, rxSpiConfig_t, csnTag ), #endif -#define PG_ARRAY_OFFSET(type, index, member) (index * sizeof(type) + offsetof(type, member)) DEFW( OWNER_GYRO_CS, PG_GYRO_DEVICE_CONFIG, gyroDeviceConfig_t, csnTag, 2 ), }; diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index b2a8f9ff5..e3866a196 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -531,7 +531,6 @@ const clivalue_t valueTable[] = { #if defined(GYRO_USES_SPI) && defined(USE_32K_CAPABLE_GYRO) { "gyro_use_32khz", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_use_32khz) }, #endif -#endif #ifdef USE_MULTI_GYRO { "gyro_to_use", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_GYRO }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_to_use) }, #endif @@ -1157,21 +1156,19 @@ const clivalue_t valueTable[] = { // RCDEVICE #ifdef USE_RCDEVICE { "rcdevice_init_dev_attempts", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 10 }, PG_RCDEVICE_CONFIG, offsetof(rcdeviceConfig_t, initDeviceAttempts) }, - { "rcdevice_init_dev_attempt_interval", VAR_UINT32 | MASTER_VALUE, .config.minmax = { 500, 5000 }, PG_RCDEVICE_CONFIG, offsetof(rcdeviceConfig_t, initDeviceAttemptInterval) } + { "rcdevice_init_dev_attempt_interval", VAR_UINT32 | MASTER_VALUE, .config.minmax = { 500, 5000 }, PG_RCDEVICE_CONFIG, offsetof(rcdeviceConfig_t, initDeviceAttemptInterval) }, #endif -#define PG_ARRAY_OFFSET(type, index, member) (index * sizeof(type) + offsetof(type, member)) - // PG_GYRO_DEVICE_CONFIG - { "gyro_1_bustype", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BUS_TYPE }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 0, bustype) }, - { "gyro_1_spibus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, SPIDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 0, spiBus) }, - { "gyro_1_i2cBus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 0, i2cBus) }, - { "gyro_1_i2c_address", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2C_ADDR7_MAX }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 0, i2cAddress) }, + { "gyro_1_bustype", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BUS_TYPE }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 0, bustype) }, + { "gyro_1_spibus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, SPIDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 0, spiBus) }, + { "gyro_1_i2cBus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 0, i2cBus) }, + { "gyro_1_i2c_address", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2C_ADDR7_MAX }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 0, i2cAddress) }, #ifdef USE_MULTI_GYRO - { "gyro_2_bustype", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BUS_TYPE }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 1, bustype) }, - { "gyro_2_spibus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, SPIDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 1, spiBus) }, - { "gyro_2_i2cBus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 1, i2cBus) }, - { "gyro_2_i2c_address", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2C_ADDR7_MAX }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_OFFSET(gyroDeviceConfig_t, 1, i2cAddress) }, + { "gyro_2_bustype", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BUS_TYPE }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 1, bustype) }, + { "gyro_2_spibus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, SPIDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 1, spiBus) }, + { "gyro_2_i2cBus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 1, i2cBus) }, + { "gyro_2_i2c_address", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2C_ADDR7_MAX }, PG_GYRO_DEVICE_CONFIG, PG_ARRAY_ELEMENT_OFFSET(gyroDeviceConfig_t, 1, i2cAddress) }, #endif }; diff --git a/src/main/pg/gyrodev.c b/src/main/pg/gyrodev.c index ad82c17a0..d9a346f15 100644 --- a/src/main/pg/gyrodev.c +++ b/src/main/pg/gyrodev.c @@ -25,16 +25,18 @@ #include "pg/pg.h" #include "pg/pg_ids.h" +#include "pg/gyrodev.h" #include "drivers/io.h" #include "drivers/bus_spi.h" +#include "drivers/sensor.h" +#include "sensors/gyro.h" -#include "pg/gyrodev.h" ioTag_t selectMPUIntExtiConfigByHardwareRevision(void); // XXX Should be gone #if defined(USE_SPI_GYRO) || defined(USE_I2C_GYRO) -static void gyroResetCommonDeviceConfig(gyroDeviceConfig_t *devconf, ioTag_t extiTag, sensor_align_e align) +static void gyroResetCommonDeviceConfig(gyroDeviceConfig_t *devconf, ioTag_t extiTag, uint8_t align) { devconf->extiTag = extiTag; devconf->align = align; @@ -42,7 +44,7 @@ static void gyroResetCommonDeviceConfig(gyroDeviceConfig_t *devconf, ioTag_t ext #endif #ifdef USE_SPI_GYRO -static void gyroResetSpiDeviceConfig(gyroDeviceConfig_t *devconf, SPI_TypeDef *instance, ioTag_t csnTag, ioTag_t extiTag, sensor_align_e align) +static void gyroResetSpiDeviceConfig(gyroDeviceConfig_t *devconf, SPI_TypeDef *instance, ioTag_t csnTag, ioTag_t extiTag, uint8_t align) { devconf->bustype = BUSTYPE_SPI; devconf->spiBus = SPI_DEV_TO_CFG(spiDeviceByInstance(instance)); @@ -52,7 +54,7 @@ static void gyroResetSpiDeviceConfig(gyroDeviceConfig_t *devconf, SPI_TypeDef *i #endif #ifdef USE_I2C_GYRO -static void gyroResetI2cDeviceConfig(gyroDeviceConfig_t *devconf, I2CDevice i2cbus, ioTag_t extiTag, sensor_align_e align) +static void gyroResetI2cDeviceConfig(gyroDeviceConfig_t *devconf, I2CDevice i2cbus, ioTag_t extiTag, uint8_t align) { devconf->bustype = BUSTYPE_I2C; devconf->i2cBus = I2C_DEV_TO_CFG(i2cbus); diff --git a/src/main/pg/gyrodev.h b/src/main/pg/gyrodev.h index 22fd36da5..fe3d2dbf1 100644 --- a/src/main/pg/gyrodev.h +++ b/src/main/pg/gyrodev.h @@ -22,12 +22,9 @@ #include -//#include #include "pg/pg.h" #include "drivers/io_types.h" -#include "drivers/sensor.h" -#include "sensors/gyro.h" typedef struct gyroDeviceConfig_s { int8_t index; @@ -37,13 +34,7 @@ typedef struct gyroDeviceConfig_s { uint8_t i2cBus; uint8_t i2cAddress; ioTag_t extiTag; - sensor_align_e align; + uint8_t align; // sensor_align_e } gyroDeviceConfig_t; -#ifdef USE_MULTI_GYRO -#define MAX_GYRODEV_COUNT 2 -#else -#define MAX_GYRODEV_COUNT 1 -#endif - PG_DECLARE_ARRAY(gyroDeviceConfig_t, MAX_GYRODEV_COUNT, gyroDeviceConfig); diff --git a/src/main/pg/pg.h b/src/main/pg/pg.h index a0eb315c1..cab5724bd 100644 --- a/src/main/pg/pg.h +++ b/src/main/pg/pg.h @@ -174,6 +174,8 @@ extern const uint8_t __pg_resetdata_end[]; /**/ #endif +#define PG_ARRAY_ELEMENT_OFFSET(type, index, member) (index * sizeof(type) + offsetof(type, member)) + // Emit reset defaults for config. // Config must be registered with PG_REGISTER__WITH_RESET_TEMPLATE macro #define PG_RESET_TEMPLATE(_type, _name, ...) \ diff --git a/src/main/target/ANYFCF7/target.h b/src/main/target/ANYFCF7/target.h index fac0ebf5b..f90a67d4c 100644 --- a/src/main/target/ANYFCF7/target.h +++ b/src/main/target/ANYFCF7/target.h @@ -46,7 +46,7 @@ #define USE_MPU_DATA_READY_SIGNAL #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC4 +#define GYRO_1_EXTI_PIN PC4 #define USE_EXTI #define USE_MAG diff --git a/src/main/target/ANYFCM7/target.h b/src/main/target/ANYFCM7/target.h index b8ac7a991..7e2532136 100644 --- a/src/main/target/ANYFCM7/target.h +++ b/src/main/target/ANYFCM7/target.h @@ -46,7 +46,7 @@ #define USE_MPU_DATA_READY_SIGNAL #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC4 +#define GYRO_1_EXTI_PIN PC4 #define USE_EXTI #define USE_MAG diff --git a/src/main/target/CRAZYBEEF3FR/target.h b/src/main/target/CRAZYBEEF3FR/target.h index e3a95f054..f37b78e0f 100644 --- a/src/main/target/CRAZYBEEF3FR/target.h +++ b/src/main/target/CRAZYBEEF3FR/target.h @@ -64,7 +64,7 @@ #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC13 +#define GYRO_1_EXTI_PIN PC13 #define USE_MPU_DATA_READY_SIGNAL #define GYRO_1_SPI_INSTANCE SPI1 #define GYRO_1_CS_PIN PA4 diff --git a/src/main/target/FRSKYF3/target.h b/src/main/target/FRSKYF3/target.h index 7399db6ec..8d4f0606e 100644 --- a/src/main/target/FRSKYF3/target.h +++ b/src/main/target/FRSKYF3/target.h @@ -54,7 +54,7 @@ #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC13 +#define GYRO_1_EXTI_PIN PC13 #define USE_MPU_DATA_READY_SIGNAL #define EXTI15_10_CALLBACK_HANDLER_COUNT 1 // MPU_INT, SDCardDetect #define MPU_ADDRESS 0x69 diff --git a/src/main/target/NUCLEOF722/target.h b/src/main/target/NUCLEOF722/target.h index 2c1285517..77802a5ac 100644 --- a/src/main/target/NUCLEOF722/target.h +++ b/src/main/target/NUCLEOF722/target.h @@ -49,7 +49,7 @@ #define USE_MPU_DATA_READY_SIGNAL #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPB15 +#define GYRO_1_EXTI_PIN PB15 #define USE_EXTI #define USE_MAG diff --git a/src/main/target/RCEXPLORERF3/target.h b/src/main/target/RCEXPLORERF3/target.h index 539d9aceb..927ec446c 100644 --- a/src/main/target/RCEXPLORERF3/target.h +++ b/src/main/target/RCEXPLORERF3/target.h @@ -47,7 +47,7 @@ #define USE_EXTI #define USE_MPU_DATA_READY_SIGNAL #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPA15 +#define GYRO_1_EXTI_PIN PA15 #define USE_GYRO #define USE_GYRO_SPI_MPU6000 diff --git a/src/main/target/RG_SSD_F3/target.h b/src/main/target/RG_SSD_F3/target.h index 3163e2187..4a9bb9caa 100644 --- a/src/main/target/RG_SSD_F3/target.h +++ b/src/main/target/RG_SSD_F3/target.h @@ -64,7 +64,7 @@ #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC13 +#define GYRO_1_EXTI_PIN PC13 #define USE_MPU_DATA_READY_SIGNAL #define ENSURE_MPU_DATA_READY_IS_LOW diff --git a/src/main/target/SPEKTRUMF400/target.h b/src/main/target/SPEKTRUMF400/target.h index f1c4af6c1..87b44a91a 100644 --- a/src/main/target/SPEKTRUMF400/target.h +++ b/src/main/target/SPEKTRUMF400/target.h @@ -66,7 +66,7 @@ #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC13 +#define GYRO_1_EXTI_PIN PC13 #define USE_MPU_DATA_READY_SIGNAL #define ENSURE_MPU_DATA_READY_IS_LOW diff --git a/src/main/target/STM32F7X2/target.h b/src/main/target/STM32F7X2/target.h index 9958bf942..08995555e 100644 --- a/src/main/target/STM32F7X2/target.h +++ b/src/main/target/STM32F7X2/target.h @@ -37,7 +37,7 @@ #define USE_MPU_DATA_READY_SIGNAL //#define DEBUG_MPU_DATA_READY_INTERRUPT #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPB15 // XXX Should be gone +#define GYRO_1_EXTI_PIN PB15 // XXX Should be gone #define USE_ACC #define USE_GYRO diff --git a/src/main/target/TINYFISH/target.h b/src/main/target/TINYFISH/target.h index 9655d131d..4ac486e69 100644 --- a/src/main/target/TINYFISH/target.h +++ b/src/main/target/TINYFISH/target.h @@ -35,7 +35,7 @@ #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPC13 +#define GYRO_1_EXTI_PIN PC13 #define USE_MPU_DATA_READY_SIGNAL #define GYRO_1_SPI_INSTANCE SPI1 diff --git a/src/main/target/VRRACE/target.h b/src/main/target/VRRACE/target.h index 13643d4cb..9a050f627 100644 --- a/src/main/target/VRRACE/target.h +++ b/src/main/target/VRRACE/target.h @@ -46,7 +46,7 @@ // MPU6500 interrupts #define USE_EXTI #define USE_GYRO_EXTI -#define GYRO_1_EXTI_PINPD10 +#define GYRO_1_EXTI_PIN PD10 #define USE_MPU_DATA_READY_SIGNAL /* diff --git a/src/main/target/common_defaults_post.h b/src/main/target/common_defaults_post.h index c9328ade9..9ffd9ad5a 100644 --- a/src/main/target/common_defaults_post.h +++ b/src/main/target/common_defaults_post.h @@ -251,3 +251,9 @@ #else #define GYRO_I2C_ADDRESS 0 // AUTO #endif + +#ifdef USE_MULTI_GYRO +#define MAX_GYRODEV_COUNT 2 +#else +#define MAX_GYRODEV_COUNT 1 +#endif