Skip to content

Commit 7b9b5d5

Browse files
Merge pull request #11418 from csky-space/icm45686-driver
added support of icm45686 sensor
2 parents 47e98d3 + 96a0ec3 commit 7b9b5d5

File tree

12 files changed

+564
-10
lines changed

12 files changed

+564
-10
lines changed

src/main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ main_sources(COMMON_SRC
8787
drivers/accgyro/accgyro_icm20689.h
8888
drivers/accgyro/accgyro_icm42605.c
8989
drivers/accgyro/accgyro_icm42605.h
90+
drivers/accgyro/accgyro_icm45686.c
91+
drivers/accgyro/accgyro_icm45686.h
9092
drivers/accgyro/accgyro_mpu.c
9193
drivers/accgyro/accgyro_mpu.h
9294
drivers/accgyro/accgyro_mpu6000.c

src/main/drivers/accgyro/accgyro_icm45686.c

Lines changed: 500 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* This file is part of INAV.
3+
*
4+
* INAV is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* INAV is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with INAV. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once
19+
20+
21+
bool icm45686AccDetect(accDev_t *acc);
22+
bool icm45686GyroDetect(gyroDev_t *gyro);

src/main/drivers/accgyro/accgyro_mpu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define ICM20689_WHO_AM_I_CONST (0x98)
3131
#define ICM42605_WHO_AM_I_CONST (0x42)
3232
#define ICM42688P_WHO_AM_I_CONST (0x47)
33+
#define ICM45686_WHO_AM_I_CONST (0xE9)
3334

3435

3536
// RA = Register Address
@@ -181,4 +182,4 @@ const gyroFilterAndRateConfig_t * mpuChooseGyroConfig(uint8_t desiredLpf, uint16
181182
bool mpuGyroRead(struct gyroDev_s *gyro);
182183
bool mpuGyroReadScratchpad(struct gyroDev_s *gyro);
183184
bool mpuAccReadScratchpad(struct accDev_s *acc);
184-
bool mpuTemperatureReadScratchpad(struct gyroDev_s *gyro, int16_t * data);
185+
bool mpuTemperatureReadScratchpad(struct gyroDev_s *gyro, int16_t * data);

src/main/drivers/bus.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ typedef enum {
8585
DEVHW_ICM42605,
8686
DEVHW_BMI270,
8787
DEVHW_LSM6D,
88+
DEVHW_ICM45686,
8889
/* Combined ACC/GYRO/MAG chips */
8990
DEVHW_MPU9250,
9091

@@ -330,4 +331,4 @@ bool busWrite(const busDevice_t * busdev, uint8_t reg, uint8_t data);
330331
bool busTransfer(const busDevice_t * dev, uint8_t * rxBuf, const uint8_t * txBuf, int length);
331332
bool busTransferMultiple(const busDevice_t * dev, busTransferDescriptor_t * buffers, int count);
332333

333-
bool busIsBusy(const busDevice_t * dev);
334+
bool busIsBusy(const busDevice_t * dev);

src/main/fc/cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static const char *debugModeNames[DEBUG_COUNT] = {
230230
// sync with gyroSensor_e
231231
static const char *const gyroNames[] = {
232232
"NONE", "AUTO", "MPU6000", "MPU6500", "MPU9250", "BMI160",
233-
"ICM20689", "BMI088", "ICM42605", "BMI270", "LSM6DXX", "FAKE"};
233+
"ICM20689", "BMI088", "ICM42605", "BMI270", "LSM6DXX", "ICM45686", "FAKE"};
234234

235235
// sync this with sensors_e
236236
static const char * const sensorTypeNames[] = {

src/main/fc/settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tables:
22
- name: alignment
33
values: ["DEFAULT", "CW0", "CW90", "CW180", "CW270", "CW0FLIP", "CW90FLIP", "CW180FLIP", "CW270FLIP"]
44
- name: acc_hardware
5-
values: ["NONE", "AUTO", "MPU6000", "MPU6500", "MPU9250", "BMI160", "ICM20689", "BMI088", "ICM42605", "BMI270","LSM6DXX", "FAKE"]
5+
values: ["NONE", "AUTO", "MPU6000", "MPU6500", "MPU9250", "BMI160", "ICM20689", "BMI088", "ICM42605", "BMI270","LSM6DXX", ICM45686, "FAKE"]
66
enum: accelerationSensor_e
77
- name: rangefinder_hardware
88
values: ["NONE", "SRF10", "VL53L0X", "MSP", "BENEWAKE", "VL53L1X", "US42", "TOF10120_I2C", "FAKE", "TERARANGER_EVO", "USD1_V0", "NRA"]

src/main/sensors/acceleration.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "drivers/accgyro/accgyro_bmi270.h"
4646
#include "drivers/accgyro/accgyro_icm20689.h"
4747
#include "drivers/accgyro/accgyro_icm42605.h"
48+
#include "drivers/accgyro/accgyro_icm45686.h"
4849
#include "drivers/accgyro/accgyro_lsm6dxx.h"
4950
#include "drivers/accgyro/accgyro_fake.h"
5051
#include "drivers/sensor.h"
@@ -247,6 +248,18 @@ static bool accDetect(accDev_t *dev, accelerationSensor_e accHardwareToUse)
247248
}
248249
FALLTHROUGH;
249250
#endif
251+
#ifdef USE_IMU_ICM45686
252+
case ACC_ICM45686:
253+
if (icm45686AccDetect(dev)) {
254+
accHardware = ACC_ICM45686;
255+
break;
256+
}
257+
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
258+
if (accHardwareToUse != ACC_AUTODETECT) {
259+
break;
260+
}
261+
FALLTHROUGH;
262+
#endif
250263
#ifdef USE_IMU_FAKE
251264
case ACC_FAKE:
252265
if (fakeAccDetect(dev)) {
@@ -696,4 +709,4 @@ void accInitFilters(void)
696709
bool accIsHealthy(void)
697710
{
698711
return true;
699-
}
712+
}

src/main/sensors/acceleration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef enum {
4444
ACC_ICM42605,
4545
ACC_BMI270,
4646
ACC_LSM6DXX,
47+
ACC_ICM45686,
4748
ACC_FAKE,
4849
ACC_MAX = ACC_FAKE
4950
} accelerationSensor_e;
@@ -97,4 +98,4 @@ void accSetCalibrationValues(void);
9798
void accInitFilters(void);
9899
bool accIsHealthy(void);
99100
bool accGetCalibrationAxisStatus(int axis);
100-
uint8_t accGetCalibrationAxisFlags(void);
101+
uint8_t accGetCalibrationAxisFlags(void);

src/main/sensors/gyro.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "drivers/accgyro/accgyro_bmi270.h"
4848
#include "drivers/accgyro/accgyro_icm20689.h"
4949
#include "drivers/accgyro/accgyro_icm42605.h"
50+
#include "drivers/accgyro/accgyro_icm45686.h"
5051
#include "drivers/accgyro/accgyro_lsm6dxx.h"
5152
#include "drivers/accgyro/accgyro_fake.h"
5253
#include "drivers/io.h"
@@ -228,6 +229,15 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev, gyroSensor_e gyroHard
228229
FALLTHROUGH;
229230
#endif
230231

232+
#ifdef USE_IMU_ICM45686
233+
case GYRO_ICM45686:
234+
if (icm45686GyroDetect(dev)) {
235+
gyroHardware = GYRO_ICM45686;
236+
break;
237+
}
238+
FALLTHROUGH;
239+
#endif
240+
231241
#ifdef USE_IMU_FAKE
232242
case GYRO_FAKE:
233243
if (fakeGyroDetect(dev)) {
@@ -609,4 +619,4 @@ void gyroUpdateDynamicLpf(float cutoffFreq) {
609619
float averageAbsGyroRates(void)
610620
{
611621
return (fabsf(gyro.gyroADCf[ROLL]) + fabsf(gyro.gyroADCf[PITCH]) + fabsf(gyro.gyroADCf[YAW])) / 3.0f;
612-
}
622+
}

0 commit comments

Comments
 (0)