mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Improved gyro SPI detect function
This commit is contained in:
parent
0b9dd11cb5
commit
1ee5929b82
1 changed files with 19 additions and 0 deletions
|
@ -251,8 +251,11 @@ bool mpuCheckDataReady(gyroDev_t* gyro)
|
||||||
static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
||||||
{
|
{
|
||||||
UNUSED(gyro); // since there are FCs which have gyro on I2C but other devices on SPI
|
UNUSED(gyro); // since there are FCs which have gyro on I2C but other devices on SPI
|
||||||
|
|
||||||
#ifdef USE_GYRO_SPI_MPU6000
|
#ifdef USE_GYRO_SPI_MPU6000
|
||||||
|
#ifdef MPU6000_SPI_INSTANCE
|
||||||
spiBusSetInstance(&gyro->bus, MPU6000_SPI_INSTANCE);
|
spiBusSetInstance(&gyro->bus, MPU6000_SPI_INSTANCE);
|
||||||
|
#endif
|
||||||
#ifdef MPU6000_CS_PIN
|
#ifdef MPU6000_CS_PIN
|
||||||
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(MPU6000_CS_PIN)) : gyro->bus.spi.csnPin;
|
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(MPU6000_CS_PIN)) : gyro->bus.spi.csnPin;
|
||||||
#endif
|
#endif
|
||||||
|
@ -266,8 +269,12 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_GYRO_SPI_MPU6500
|
#ifdef USE_GYRO_SPI_MPU6500
|
||||||
|
#ifdef MPU6500_SPI_INSTANCE
|
||||||
spiBusSetInstance(&gyro->bus, MPU6500_SPI_INSTANCE);
|
spiBusSetInstance(&gyro->bus, MPU6500_SPI_INSTANCE);
|
||||||
|
#endif
|
||||||
|
#ifdef MPU6500_CS_PIN
|
||||||
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(MPU6500_CS_PIN)) : gyro->bus.spi.csnPin;
|
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(MPU6500_CS_PIN)) : gyro->bus.spi.csnPin;
|
||||||
|
#endif
|
||||||
const uint8_t mpu6500Sensor = mpu6500SpiDetect(&gyro->bus);
|
const uint8_t mpu6500Sensor = mpu6500SpiDetect(&gyro->bus);
|
||||||
// some targets using MPU_9250_SPI, ICM_20608_SPI or ICM_20602_SPI state sensor is MPU_65xx_SPI
|
// some targets using MPU_9250_SPI, ICM_20608_SPI or ICM_20602_SPI state sensor is MPU_65xx_SPI
|
||||||
if (mpu6500Sensor != MPU_NONE) {
|
if (mpu6500Sensor != MPU_NONE) {
|
||||||
|
@ -280,8 +287,12 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_GYRO_SPI_MPU9250
|
#ifdef USE_GYRO_SPI_MPU9250
|
||||||
|
#ifdef MPU9250_SPI_INSTANCE
|
||||||
spiBusSetInstance(&gyro->bus, MPU9250_SPI_INSTANCE);
|
spiBusSetInstance(&gyro->bus, MPU9250_SPI_INSTANCE);
|
||||||
|
#endif
|
||||||
|
#ifdef MPU9250_CS_PIN
|
||||||
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(MPU9250_CS_PIN)) : gyro->bus.spi.csnPin;
|
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(MPU9250_CS_PIN)) : gyro->bus.spi.csnPin;
|
||||||
|
#endif
|
||||||
if (mpu9250SpiDetect(&gyro->bus)) {
|
if (mpu9250SpiDetect(&gyro->bus)) {
|
||||||
gyro->mpuDetectionResult.sensor = MPU_9250_SPI;
|
gyro->mpuDetectionResult.sensor = MPU_9250_SPI;
|
||||||
gyro->mpuConfiguration.gyroReadXRegister = MPU_RA_GYRO_XOUT_H;
|
gyro->mpuConfiguration.gyroReadXRegister = MPU_RA_GYRO_XOUT_H;
|
||||||
|
@ -293,8 +304,12 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_GYRO_SPI_ICM20689
|
#ifdef USE_GYRO_SPI_ICM20689
|
||||||
|
#ifdef ICM20689_SPI_INSTANCE
|
||||||
spiBusSetInstance(&gyro->bus, ICM20689_SPI_INSTANCE);
|
spiBusSetInstance(&gyro->bus, ICM20689_SPI_INSTANCE);
|
||||||
|
#endif
|
||||||
|
#ifdef ICM20689_CS_PIN
|
||||||
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(ICM20689_CS_PIN)) : gyro->bus.spi.csnPin;
|
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(ICM20689_CS_PIN)) : gyro->bus.spi.csnPin;
|
||||||
|
#endif
|
||||||
if (icm20689SpiDetect(&gyro->bus)) {
|
if (icm20689SpiDetect(&gyro->bus)) {
|
||||||
gyro->mpuDetectionResult.sensor = ICM_20689_SPI;
|
gyro->mpuDetectionResult.sensor = ICM_20689_SPI;
|
||||||
gyro->mpuConfiguration.gyroReadXRegister = MPU_RA_GYRO_XOUT_H;
|
gyro->mpuConfiguration.gyroReadXRegister = MPU_RA_GYRO_XOUT_H;
|
||||||
|
@ -305,8 +320,12 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_ACCGYRO_BMI160
|
#ifdef USE_ACCGYRO_BMI160
|
||||||
|
#ifdef BMI160_SPI_INSTANCE
|
||||||
spiBusSetInstance(&gyro->bus, BMI160_SPI_INSTANCE);
|
spiBusSetInstance(&gyro->bus, BMI160_SPI_INSTANCE);
|
||||||
|
#endif
|
||||||
|
#ifdef BMI160_CS_PIN
|
||||||
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(BMI160_CS_PIN)) : gyro->bus.spi.csnPin;
|
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(BMI160_CS_PIN)) : gyro->bus.spi.csnPin;
|
||||||
|
#endif
|
||||||
if (bmi160Detect(&gyro->bus)) {
|
if (bmi160Detect(&gyro->bus)) {
|
||||||
gyro->mpuDetectionResult.sensor = BMI_160_SPI;
|
gyro->mpuDetectionResult.sensor = BMI_160_SPI;
|
||||||
gyro->mpuConfiguration.readFn = spiReadRegisterBuffer;
|
gyro->mpuConfiguration.readFn = spiReadRegisterBuffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue