Skip to content

Commit

Permalink
initial ICM426xx support (#891)
Browse files Browse the repository at this point in the history
* ICM426xx - very dont know
* ICM426xx - FOXEERF722V4
* ICM426xx -  ICM_42688P & ICM_42605 ; CAUTION / really no idea if this is anything good
* ICM426xx - more ICM_42688P & ICM_42605 ; CAUTION / really no idea if this is anything good
* ICM426xx - FOXEERF745V3_AIO
* ICM426xx - very dont know, part deaux
* ICM426xx - very dont know, RUSHBLADEF7HD
* ICM426xx - same; add accgyro_mpu.c; add icm 42688p to BETAFPVF722
* ICM426xx - still finding missing elements
* ICM426xx - acc/gyro read change for icm426xx (@Peck07 fix to make it functional)
* ICM426xx - DIAT_MAMBAF405_2022B; WIP; untested
* ICM426xx - Adding ICM4xxxx to GEPRCF722_AIO
* ICM426xx - JHEF_JHEF7DUAL; WIP; untested
* ICM426xx - JHEF_JHEF7DUAL; WIP; not working; no USB connect
* ICM426xx - add CRAZYFLIE2 to unsupported targets due to build failure and obsolescence
* ICM426xx - fix out of band #endif
* ICM426xx - JHEF_JHEF7DUAL; WIP; untested
* ICM426xx - modded existing JHEF7DUAL; new JHEF_JHEF7DUAL is not working
* ICM426xx - fix BETAFPVF722 target
* ICM426xx - fix JHEF_JHEF7DUAL target
* ICM426xx - gyro_hardware_lpf modes
* ICM426xx - define USE_GYRO_DLPF_EXPERIMENTAL
* ICM426xx - add ICM42605_CS_PIN
* ICM426xx - remove comma in lookupTableGyroHardwareLpf
* ICM426xx - target resets and removal
* ICM426xx - extra line removal
---------
Co-authored-by: tbolin <tobias_bolin@hotmail.com>
Co-authored-by: KarateBrot <Rm2k-Freak@web.de>
Co-authored-by: Steve Evans <Steve@SCEvans.com>
Co-authored-by: Dominic Clifton <dominic.clifton@cleanflight.com>
Co-authored-by: Peck07 <28628457+Peck07@users.noreply.github.com>
Co-authored-by: BeauBrewski <85623381+BeauBrewski@users.noreply.github.com>
Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com>
  • Loading branch information
nerdCopter committed Jun 1, 2023
1 parent 4d731cd commit 53a8da3
Show file tree
Hide file tree
Showing 17 changed files with 586 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ static inline int32_t cmp32(uint32_t a, uint32_t b) {
return (int32_t)(a - b);
}

static inline uint32_t llog2(uint32_t n) { return 31 - __builtin_clz(n | 1); }

// using memcpy_fn will force memcpy function call, instead of inlining it. In most cases function call takes fewer instructions
// than inlined version (inlining is cheaper for very small moves < 8 bytes / 2 store instructions)
#if defined(UNIT_TEST) || defined(SIMULATOR_BUILD)
Expand Down
12 changes: 11 additions & 1 deletion src/main/drivers/accgyro/accgyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@
#endif

#define GYRO_HARDWARE_LPF_NORMAL 0
#define GYRO_HARDWARE_LPF_EXPERIMENTAL 1
#define GYRO_HARDWARE_LPF_1KHZ_SAMPLE 2

#if defined(USE_GYRO_SPI_ICM42688P)
#define GYRO_HARDWARE_LPF_EXPERIMENTAL 3
#else
#define GYRO_HARDWARE_LPF_EXPERIMENTAL 1
#endif

#define GYRO_32KHZ_HARDWARE_LPF_NORMAL 0
#define GYRO_32KHZ_HARDWARE_LPF_EXPERIMENTAL 1

#define GYRO_HARDWARE_LPF_OPTION_1 1
#define GYRO_HARDWARE_LPF_OPTION_2 2

#define GYRO_LPF_256HZ 0
#define GYRO_LPF_188HZ 1
#define GYRO_LPF_98HZ 2
Expand Down Expand Up @@ -91,6 +99,8 @@ typedef struct gyroDev_s {
ioTag_t mpuIntExtiTag;
uint8_t gyroHasOverflowProtection;
gyroSensor_e gyroHardware;
uint8_t accDataReg;
uint8_t gyroDataReg;
} gyroDev_t;

typedef struct accDev_s {
Expand Down
27 changes: 27 additions & 0 deletions src/main/drivers/accgyro/accgyro_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "drivers/accgyro/accgyro_spi_bmi160.h"
#include "drivers/accgyro/accgyro_spi_icm20649.h"
#include "drivers/accgyro/accgyro_spi_icm20689.h"
#include "drivers/accgyro/accgyro_spi_icm426xx.h"
#include "drivers/accgyro/accgyro_spi_mpu6000.h"
#include "drivers/accgyro/accgyro_spi_mpu6500.h"
#include "drivers/accgyro/accgyro_spi_mpu9250.h"
Expand Down Expand Up @@ -365,6 +366,32 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro) {
return true;
}
#endif
#ifdef USE_GYRO_SPI_ICM42605
#ifdef ICM42605_SPI_INSTANCE
spiBusSetInstance(&gyro->bus, ICM42605_SPI_INSTANCE);
#endif
#ifdef ICM42605_CS_PIN
gyro->bus.busdev_u.spi.csnPin = gyro->bus.busdev_u.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(ICM42605_CS_PIN)) : gyro->bus.busdev_u.spi.csnPin;
#endif
sensor = icm426xxSpiDetect(&gyro->bus);
if (sensor != MPU_NONE) {
gyro->mpuDetectionResult.sensor = sensor;
return true;
}
#endif
#ifdef USE_GYRO_SPI_ICM42688P
#ifdef ICM42688P_SPI_INSTANCE
spiBusSetInstance(&gyro->bus, ICM42688P_SPI_INSTANCE);
#endif
#ifdef ICM42688P_CS_PIN
gyro->bus.busdev_u.spi.csnPin = gyro->bus.busdev_u.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(ICM42688P_CS_PIN)) : gyro->bus.busdev_u.spi.csnPin;
#endif
sensor = icm426xxSpiDetect(&gyro->bus);
if (sensor != MPU_NONE) {
gyro->mpuDetectionResult.sensor = sensor;
return true;
}
#endif
#ifdef USE_ACCGYRO_BMI160
#ifndef USE_DUAL_GYRO
spiBusSetInstance(&gyro->bus, BMI160_SPI_INSTANCE);
Expand Down
6 changes: 5 additions & 1 deletion src/main/drivers/accgyro/accgyro_mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//#define DEBUG_MPU_DATA_READY_INTERRUPT

#if defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_SPI_ICM20649) \
|| defined(USE_GYRO_SPI_ICM20689)
|| defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
#define GYRO_USES_SPI
#endif

Expand All @@ -47,6 +47,8 @@
#define ICM20608G_WHO_AM_I_CONST (0xAF)
#define ICM20649_WHO_AM_I_CONST (0xE1)
#define ICM20689_WHO_AM_I_CONST (0x98)
#define ICM42605_WHO_AM_I_CONST (0x42)
#define ICM42688P_WHO_AM_I_CONST (0x47)

// RA = Register Address

Expand Down Expand Up @@ -214,6 +216,8 @@ typedef enum {
ICM_20608_SPI,
ICM_20649_SPI,
ICM_20689_SPI,
ICM_42605_SPI,
ICM_42688P_SPI,
BMI_160_SPI,
IMUF_9001_SPI,
} mpuSensor_e;
Expand Down
Loading

0 comments on commit 53a8da3

Please sign in to comment.