mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Add IIM42653 IMU support (#14095)
* drivers: accgyro: iim42653 IMU support * reorder accgyro enums, update comment about IIM42653 * remove comma after VIRTUAL in enum
This commit is contained in:
parent
4a6e3bbe06
commit
7a44f1bdce
10 changed files with 51 additions and 19 deletions
|
@ -160,6 +160,7 @@ const char * const lookupTableAccHardware[] = {
|
||||||
"BMI270",
|
"BMI270",
|
||||||
"LSM6DSO",
|
"LSM6DSO",
|
||||||
"LSM6DSV16X",
|
"LSM6DSV16X",
|
||||||
|
"IIM42653",
|
||||||
"VIRTUAL"
|
"VIRTUAL"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -183,6 +184,7 @@ const char * const lookupTableGyroHardware[] = {
|
||||||
"BMI270",
|
"BMI270",
|
||||||
"LSM6DSO",
|
"LSM6DSO",
|
||||||
"LSM6DSV16X",
|
"LSM6DSV16X",
|
||||||
|
"IIM42653",
|
||||||
"VIRTUAL"
|
"VIRTUAL"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ typedef enum {
|
||||||
GYRO_BMI270,
|
GYRO_BMI270,
|
||||||
GYRO_LSM6DSO,
|
GYRO_LSM6DSO,
|
||||||
GYRO_LSM6DSV16X,
|
GYRO_LSM6DSV16X,
|
||||||
|
GYRO_IIM42653,
|
||||||
GYRO_VIRTUAL
|
GYRO_VIRTUAL
|
||||||
} gyroHardware_e;
|
} gyroHardware_e;
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,7 @@ static gyroSpiDetectFn_t gyroSpiDetectFnTable[] = {
|
||||||
#ifdef USE_ACCGYRO_BMI270
|
#ifdef USE_ACCGYRO_BMI270
|
||||||
bmi270Detect,
|
bmi270Detect,
|
||||||
#endif
|
#endif
|
||||||
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
|
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_IIM42653)
|
||||||
icm426xxSpiDetect,
|
icm426xxSpiDetect,
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_GYRO_SPI_ICM20649
|
#ifdef USE_GYRO_SPI_ICM20649
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#define ICM20689_WHO_AM_I_CONST (0x98)
|
#define ICM20689_WHO_AM_I_CONST (0x98)
|
||||||
#define ICM42605_WHO_AM_I_CONST (0x42)
|
#define ICM42605_WHO_AM_I_CONST (0x42)
|
||||||
#define ICM42688P_WHO_AM_I_CONST (0x47)
|
#define ICM42688P_WHO_AM_I_CONST (0x47)
|
||||||
|
#define IIM42653_WHO_AM_I_CONST (0x56)
|
||||||
#define LSM6DSV16X_WHO_AM_I_CONST (0x70)
|
#define LSM6DSV16X_WHO_AM_I_CONST (0x70)
|
||||||
|
|
||||||
// RA = Register Address
|
// RA = Register Address
|
||||||
|
@ -146,6 +147,7 @@ enum gyro_fsr_e {
|
||||||
INV_FSR_500DPS,
|
INV_FSR_500DPS,
|
||||||
INV_FSR_1000DPS,
|
INV_FSR_1000DPS,
|
||||||
INV_FSR_2000DPS,
|
INV_FSR_2000DPS,
|
||||||
|
INV_FSR_4000DPS,
|
||||||
NUM_GYRO_FSR
|
NUM_GYRO_FSR
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,6 +170,7 @@ enum accel_fsr_e {
|
||||||
INV_FSR_4G,
|
INV_FSR_4G,
|
||||||
INV_FSR_8G,
|
INV_FSR_8G,
|
||||||
INV_FSR_16G,
|
INV_FSR_16G,
|
||||||
|
INV_FSR_32G,
|
||||||
NUM_ACCEL_FSR
|
NUM_ACCEL_FSR
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -201,6 +204,7 @@ typedef enum {
|
||||||
ICM_20689_SPI,
|
ICM_20689_SPI,
|
||||||
ICM_42605_SPI,
|
ICM_42605_SPI,
|
||||||
ICM_42688P_SPI,
|
ICM_42688P_SPI,
|
||||||
|
IIM_42653_SPI,
|
||||||
BMI_160_SPI,
|
BMI_160_SPI,
|
||||||
BMI_270_SPI,
|
BMI_270_SPI,
|
||||||
LSM6DSO_SPI,
|
LSM6DSO_SPI,
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
|
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_IIM42653)
|
||||||
|
|
||||||
#include "common/axis.h"
|
#include "common/axis.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
@ -269,6 +269,9 @@ uint8_t icm426xxSpiDetect(const extDevice_t *dev)
|
||||||
case ICM42688P_WHO_AM_I_CONST:
|
case ICM42688P_WHO_AM_I_CONST:
|
||||||
icmDetected = ICM_42688P_SPI;
|
icmDetected = ICM_42688P_SPI;
|
||||||
break;
|
break;
|
||||||
|
case IIM42653_WHO_AM_I_CONST:
|
||||||
|
icmDetected = IIM_42653_SPI;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
icmDetected = MPU_NONE;
|
icmDetected = MPU_NONE;
|
||||||
break;
|
break;
|
||||||
|
@ -286,15 +289,22 @@ uint8_t icm426xxSpiDetect(const extDevice_t *dev)
|
||||||
|
|
||||||
void icm426xxAccInit(accDev_t *acc)
|
void icm426xxAccInit(accDev_t *acc)
|
||||||
{
|
{
|
||||||
acc->acc_1G = 512 * 4;
|
switch (acc->mpuDetectionResult.sensor) {
|
||||||
|
case IIM_42653_SPI:
|
||||||
|
acc->acc_1G = 512 * 2; // Accel scale 32g (1024 LSB/g)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
acc->acc_1G = 512 * 4; // Accel scale 16g (2048 LSB/g)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icm426xxSpiAccDetect(accDev_t *acc)
|
bool icm426xxSpiAccDetect(accDev_t *acc)
|
||||||
{
|
{
|
||||||
switch (acc->mpuDetectionResult.sensor) {
|
switch (acc->mpuDetectionResult.sensor) {
|
||||||
case ICM_42605_SPI:
|
case ICM_42605_SPI:
|
||||||
break;
|
|
||||||
case ICM_42688P_SPI:
|
case ICM_42688P_SPI:
|
||||||
|
case IIM_42653_SPI:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -386,12 +396,12 @@ void icm426xxGyroInit(gyroDev_t *gyro)
|
||||||
gyro->gyroRateKHz = GYRO_RATE_1_kHz;
|
gyro->gyroRateKHz = GYRO_RATE_1_kHz;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC_ASSERT(INV_FSR_2000DPS == 3, "INV_FSR_2000DPS must be 3 to generate correct value");
|
// This sets the gyro/accel to the maximum FSR, depending on the chip
|
||||||
spiWriteReg(dev, ICM426XX_RA_GYRO_CONFIG0, (3 - INV_FSR_2000DPS) << 5 | (odrConfig & 0x0F));
|
// ICM42605, ICM_42688P: 2000DPS and 16G.
|
||||||
|
// IIM42653: 4000DPS and 32G
|
||||||
|
spiWriteReg(dev, ICM426XX_RA_GYRO_CONFIG0, (0 << 5) | (odrConfig & 0x0F));
|
||||||
delay(15);
|
delay(15);
|
||||||
|
spiWriteReg(dev, ICM426XX_RA_ACCEL_CONFIG0, (0 << 5) | (odrConfig & 0x0F));
|
||||||
STATIC_ASSERT(INV_FSR_16G == 3, "INV_FSR_16G must be 3 to generate correct value");
|
|
||||||
spiWriteReg(dev, ICM426XX_RA_ACCEL_CONFIG0, (3 - INV_FSR_16G) << 5 | (odrConfig & 0x0F));
|
|
||||||
delay(15);
|
delay(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,8 +409,11 @@ bool icm426xxSpiGyroDetect(gyroDev_t *gyro)
|
||||||
{
|
{
|
||||||
switch (gyro->mpuDetectionResult.sensor) {
|
switch (gyro->mpuDetectionResult.sensor) {
|
||||||
case ICM_42605_SPI:
|
case ICM_42605_SPI:
|
||||||
break;
|
|
||||||
case ICM_42688P_SPI:
|
case ICM_42688P_SPI:
|
||||||
|
gyro->scale = GYRO_SCALE_2000DPS;
|
||||||
|
break;
|
||||||
|
case IIM_42653_SPI:
|
||||||
|
gyro->scale = GYRO_SCALE_4000DPS;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -409,8 +422,6 @@ bool icm426xxSpiGyroDetect(gyroDev_t *gyro)
|
||||||
gyro->initFn = icm426xxGyroInit;
|
gyro->initFn = icm426xxGyroInit;
|
||||||
gyro->readFn = mpuGyroReadSPI;
|
gyro->readFn = mpuGyroReadSPI;
|
||||||
|
|
||||||
gyro->scale = GYRO_SCALE_2000DPS;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,6 +441,7 @@ static aafConfig_t getGyroAafConfig(const mpuSensor_e gyroModel, const aafConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
case ICM_42688P_SPI:
|
case ICM_42688P_SPI:
|
||||||
|
case IIM_42653_SPI:
|
||||||
default:
|
default:
|
||||||
switch (config) {
|
switch (config) {
|
||||||
case GYRO_HARDWARE_LPF_NORMAL:
|
case GYRO_HARDWARE_LPF_NORMAL:
|
||||||
|
@ -448,4 +460,4 @@ static aafConfig_t getGyroAafConfig(const mpuSensor_e gyroModel, const aafConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_GYRO_SPI_ICM42605 || USE_GYRO_SPI_ICM42688P
|
#endif // USE_GYRO_SPI_ICM42605 || USE_GYRO_SPI_ICM42688P || USE_ACCGYRO_IIM42653
|
||||||
|
|
|
@ -50,6 +50,7 @@ typedef enum {
|
||||||
ACC_BMI270,
|
ACC_BMI270,
|
||||||
ACC_LSM6DSO,
|
ACC_LSM6DSO,
|
||||||
ACC_LSM6DSV16X,
|
ACC_LSM6DSV16X,
|
||||||
|
ACC_IIM42653,
|
||||||
ACC_VIRTUAL
|
ACC_VIRTUAL
|
||||||
} accelerationSensor_e;
|
} accelerationSensor_e;
|
||||||
|
|
||||||
|
|
|
@ -216,9 +216,10 @@ retry:
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_ACC_SPI_ICM42605) || defined(USE_ACC_SPI_ICM42688P)
|
#if defined(USE_ACC_SPI_ICM42605) || defined(USE_ACC_SPI_ICM42688P) || defined(USE_ACCGYRO_IIM42653)
|
||||||
case ACC_ICM42605:
|
case ACC_ICM42605:
|
||||||
case ACC_ICM42688P:
|
case ACC_ICM42688P:
|
||||||
|
case ACC_IIM42653:
|
||||||
if (icm426xxSpiAccDetect(dev)) {
|
if (icm426xxSpiAccDetect(dev)) {
|
||||||
switch (dev->mpuDetectionResult.sensor) {
|
switch (dev->mpuDetectionResult.sensor) {
|
||||||
case ICM_42605_SPI:
|
case ICM_42605_SPI:
|
||||||
|
@ -227,6 +228,9 @@ retry:
|
||||||
case ICM_42688P_SPI:
|
case ICM_42688P_SPI:
|
||||||
accHardware = ACC_ICM42688P;
|
accHardware = ACC_ICM42688P;
|
||||||
break;
|
break;
|
||||||
|
case IIM_42653_SPI:
|
||||||
|
accHardware = ACC_IIM42653;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
accHardware = ACC_NONE;
|
accHardware = ACC_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -314,6 +314,7 @@ void gyroInitSensor(gyroSensor_t *gyroSensor, const gyroDeviceConfig_t *config)
|
||||||
case GYRO_LSM6DSO:
|
case GYRO_LSM6DSO:
|
||||||
case GYRO_LSM6DSV16X:
|
case GYRO_LSM6DSV16X:
|
||||||
case GYRO_ICM42688P:
|
case GYRO_ICM42688P:
|
||||||
|
case GYRO_IIM42653:
|
||||||
case GYRO_ICM42605:
|
case GYRO_ICM42605:
|
||||||
gyroSensor->gyroDev.gyroHasOverflowProtection = true;
|
gyroSensor->gyroDev.gyroHasOverflowProtection = true;
|
||||||
break;
|
break;
|
||||||
|
@ -427,9 +428,10 @@ STATIC_UNIT_TESTED gyroHardware_e gyroDetect(gyroDev_t *dev)
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
|
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_IIM42653)
|
||||||
case GYRO_ICM42605:
|
case GYRO_ICM42605:
|
||||||
case GYRO_ICM42688P:
|
case GYRO_ICM42688P:
|
||||||
|
case GYRO_IIM42653:
|
||||||
if (icm426xxSpiGyroDetect(dev)) {
|
if (icm426xxSpiGyroDetect(dev)) {
|
||||||
switch (dev->mpuDetectionResult.sensor) {
|
switch (dev->mpuDetectionResult.sensor) {
|
||||||
case ICM_42605_SPI:
|
case ICM_42605_SPI:
|
||||||
|
@ -438,6 +440,9 @@ STATIC_UNIT_TESTED gyroHardware_e gyroDetect(gyroDev_t *dev)
|
||||||
case ICM_42688P_SPI:
|
case ICM_42688P_SPI:
|
||||||
gyroHardware = GYRO_ICM42688P;
|
gyroHardware = GYRO_ICM42688P;
|
||||||
break;
|
break;
|
||||||
|
case IIM_42653_SPI:
|
||||||
|
gyroHardware = GYRO_IIM42653;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
gyroHardware = GYRO_NONE;
|
gyroHardware = GYRO_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -107,7 +107,8 @@
|
||||||
&& !defined(USE_ACC_SPI_MPU6000) \
|
&& !defined(USE_ACC_SPI_MPU6000) \
|
||||||
&& !defined(USE_ACC_SPI_MPU6500) \
|
&& !defined(USE_ACC_SPI_MPU6500) \
|
||||||
&& !defined(USE_ACC_SPI_MPU9250) \
|
&& !defined(USE_ACC_SPI_MPU9250) \
|
||||||
&& !defined(USE_VIRTUAL_ACC)
|
&& !defined(USE_VIRTUAL_ACC) \
|
||||||
|
&& !defined(USE_ACCGYRO_IIM42653)
|
||||||
#error At least one USE_ACC device definition required
|
#error At least one USE_ACC device definition required
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -126,7 +127,8 @@
|
||||||
&& !defined(USE_GYRO_SPI_MPU6000) \
|
&& !defined(USE_GYRO_SPI_MPU6000) \
|
||||||
&& !defined(USE_GYRO_SPI_MPU6500) \
|
&& !defined(USE_GYRO_SPI_MPU6500) \
|
||||||
&& !defined(USE_GYRO_SPI_MPU9250) \
|
&& !defined(USE_GYRO_SPI_MPU9250) \
|
||||||
&& !defined(USE_VIRTUAL_GYRO)
|
&& !defined(USE_VIRTUAL_GYRO) \
|
||||||
|
&& !defined(USE_ACCGYRO_IIM42653)
|
||||||
#error At least one USE_GYRO device definition required
|
#error At least one USE_GYRO device definition required
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -466,8 +468,8 @@
|
||||||
|
|
||||||
// Generate USE_SPI_GYRO or USE_I2C_GYRO
|
// Generate USE_SPI_GYRO or USE_I2C_GYRO
|
||||||
#if defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU9250) \
|
#if defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU9250) \
|
||||||
|| defined(USE_GYRO_L3GD20) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_BMI160) \
|
|| defined(USE_GYRO_L3GD20) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_ACCGYRO_IIM42653) \
|
||||||
|| defined(USE_ACCGYRO_BMI270) || defined(USE_ACCGYRO_LSM6DSV16X) || defined(USE_ACCGYRO_LSM6DSO)
|
|| defined(USE_ACCGYRO_BMI160) || defined(USE_ACCGYRO_BMI270) || defined(USE_ACCGYRO_LSM6DSV16X) || defined(USE_ACCGYRO_LSM6DSO)
|
||||||
#ifndef USE_SPI_GYRO
|
#ifndef USE_SPI_GYRO
|
||||||
#define USE_SPI_GYRO
|
#define USE_SPI_GYRO
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -114,6 +114,7 @@
|
||||||
#define USE_ACCGYRO_BMI270
|
#define USE_ACCGYRO_BMI270
|
||||||
#define USE_GYRO_SPI_ICM42605
|
#define USE_GYRO_SPI_ICM42605
|
||||||
#define USE_GYRO_SPI_ICM42688P
|
#define USE_GYRO_SPI_ICM42688P
|
||||||
|
#define USE_ACCGYRO_IIM42653
|
||||||
#define USE_ACC_SPI_ICM42605
|
#define USE_ACC_SPI_ICM42605
|
||||||
#define USE_ACC_SPI_ICM42688P
|
#define USE_ACC_SPI_ICM42688P
|
||||||
#define USE_ACCGYRO_LSM6DSV16X
|
#define USE_ACCGYRO_LSM6DSV16X
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue