1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

FIX: Multi gyro and SDIO hard fault (#12446)

This commit is contained in:
J Blackman 2023-03-04 12:43:25 +11:00 committed by GitHub
parent 3470fd5584
commit 799e0c1e50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 69 deletions

View file

@ -34,10 +34,6 @@
#include "drivers/sensor.h"
#include "sensors/gyro.h"
#ifndef GYRO_1_SPI_INSTANCE
#define GYRO_1_SPI_INSTANCE NULL
#endif
#ifndef GYRO_1_CS_PIN
#define GYRO_1_CS_PIN NONE
#endif
@ -46,10 +42,6 @@
#define GYRO_1_EXTI_PIN NONE
#endif
#ifndef GYRO_2_SPI_INSTANCE
#define GYRO_2_SPI_INSTANCE NULL
#endif
#ifndef GYRO_2_CS_PIN
#define GYRO_2_CS_PIN NONE
#endif
@ -75,24 +67,15 @@
#define GYRO_2_ALIGN CW0_DEG
#endif
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, uint8_t alignment, sensorAlignment_t customAlignment)
{
devconf->extiTag = extiTag;
devconf->alignment = alignment;
devconf->customAlignment = customAlignment;
}
#endif
#ifdef USE_SPI_GYRO
#if defined(USE_SPI_GYRO) && (defined(GYRO_1_SPI_INSTANCE) || defined(GYRO_2_SPI_INSTANCE))
static void gyroResetSpiDeviceConfig(gyroDeviceConfig_t *devconf, SPI_TypeDef *instance, ioTag_t csnTag, ioTag_t extiTag, uint8_t alignment, sensorAlignment_t customAlignment)
{
devconf->busType = BUS_TYPE_SPI;
devconf->spiBus = SPI_DEV_TO_CFG(spiDeviceByInstance(instance));
devconf->csnTag = csnTag;
gyroResetCommonDeviceConfig(devconf, extiTag, alignment, customAlignment);
devconf->extiTag = extiTag;
devconf->alignment = alignment;
devconf->customAlignment = customAlignment;
}
#endif
@ -102,7 +85,9 @@ static void gyroResetI2cDeviceConfig(gyroDeviceConfig_t *devconf, I2CDevice i2cb
devconf->busType = BUS_TYPE_I2C;
devconf->i2cBus = I2C_DEV_TO_CFG(i2cbus);
devconf->i2cAddress = GYRO_I2C_ADDRESS;
gyroResetCommonDeviceConfig(devconf, extiTag, alignment, customAlignment);
devconf->extiTag = extiTag;
devconf->alignment = alignment;
devconf->customAlignment = customAlignment;
}
#endif
@ -120,7 +105,11 @@ void pgResetFn_gyroDeviceConfig(gyroDeviceConfig_t *devconf)
// All multi-gyro boards use SPI based gyros.
#ifdef USE_SPI_GYRO
#ifdef GYRO_1_SPI_INSTANCE
gyroResetSpiDeviceConfig(&devconf[0], GYRO_1_SPI_INSTANCE, IO_TAG(GYRO_1_CS_PIN), IO_TAG(GYRO_1_EXTI_PIN), GYRO_1_ALIGN, customAlignment1);
#else
devconf[0].busType = BUS_TYPE_NONE;
#endif
#ifdef USE_MULTI_GYRO
devconf[1].index = 1;
sensorAlignment_t customAlignment2 = CUSTOM_ALIGN_CW0_DEG;
@ -129,7 +118,13 @@ void pgResetFn_gyroDeviceConfig(gyroDeviceConfig_t *devconf)
#else
buildAlignmentFromStandardAlignment(&customAlignment2, GYRO_2_ALIGN);
#endif // GYRO_2_CUSTOM_ALIGN
#ifdef GYRO_2_SPI_INSTANCE
gyroResetSpiDeviceConfig(&devconf[1], GYRO_2_SPI_INSTANCE, IO_TAG(GYRO_2_CS_PIN), IO_TAG(GYRO_2_EXTI_PIN), GYRO_2_ALIGN, customAlignment2);
#else
devconf[1].busType = BUS_TYPE_NONE;
#endif
#endif // USE_MULTI_GYRO
#endif // USE_SPI_GYRO
@ -138,9 +133,4 @@ void pgResetFn_gyroDeviceConfig(gyroDeviceConfig_t *devconf)
devconf[0].i2cBus = I2C_DEV_TO_CFG(I2CINVALID); // XXX Not required?
gyroResetI2cDeviceConfig(&devconf[0], I2C_DEVICE, IO_TAG(GYRO_1_EXTI_PIN), GYRO_1_ALIGN, customAlignment1);
#endif
// Special treatment for very rare F3 targets with variants having either I2C or SPI acc/gyro chip; mark it for run time detection.
#if defined(USE_SPI_GYRO) && defined(USE_I2C_GYRO)
devconf[0].busType = BUS_TYPE_GYRO_AUTO;
#endif
}