From 53a8da3e0e22e1fae9819119883a4687f9bc1fff Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Thu, 1 Jun 2023 12:54:32 -0500 Subject: [PATCH 01/14] initial ICM426xx support (#891) * 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 Co-authored-by: KarateBrot Co-authored-by: Steve Evans Co-authored-by: Dominic Clifton 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> --- src/main/common/utils.h | 2 + src/main/drivers/accgyro/accgyro.h | 12 +- src/main/drivers/accgyro/accgyro_mpu.c | 27 ++ src/main/drivers/accgyro/accgyro_mpu.h | 6 +- .../drivers/accgyro/accgyro_spi_icm426xx.c | 389 ++++++++++++++++++ .../drivers/accgyro/accgyro_spi_icm426xx.h | 36 ++ .../drivers/accgyro/accgyro_spi_mpu6500.c | 6 + src/main/drivers/bus_spi.c | 27 ++ src/main/drivers/bus_spi.h | 5 + src/main/flight/pid.c | 2 +- src/main/interface/settings.c | 12 +- src/main/pg/bus_spi.c | 6 + src/main/sensors/acceleration.c | 26 ++ src/main/sensors/acceleration.h | 2 + src/main/sensors/gyro.c | 30 +- src/main/sensors/gyro.h | 2 + src/main/target/common_fc_pre.h | 3 + 17 files changed, 586 insertions(+), 7 deletions(-) create mode 100644 src/main/drivers/accgyro/accgyro_spi_icm426xx.c create mode 100644 src/main/drivers/accgyro/accgyro_spi_icm426xx.h diff --git a/src/main/common/utils.h b/src/main/common/utils.h index 8cd021d1ff..95f2716244 100644 --- a/src/main/common/utils.h +++ b/src/main/common/utils.h @@ -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) diff --git a/src/main/drivers/accgyro/accgyro.h b/src/main/drivers/accgyro/accgyro.h index a29d931c25..2c17f4b2f5 100644 --- a/src/main/drivers/accgyro/accgyro.h +++ b/src/main/drivers/accgyro/accgyro.h @@ -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 @@ -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 { diff --git a/src/main/drivers/accgyro/accgyro_mpu.c b/src/main/drivers/accgyro/accgyro_mpu.c index 498536f8c2..5265e27342 100644 --- a/src/main/drivers/accgyro/accgyro_mpu.c +++ b/src/main/drivers/accgyro/accgyro_mpu.c @@ -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" @@ -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); diff --git a/src/main/drivers/accgyro/accgyro_mpu.h b/src/main/drivers/accgyro/accgyro_mpu.h index 550f05fe81..aa0f770e29 100644 --- a/src/main/drivers/accgyro/accgyro_mpu.h +++ b/src/main/drivers/accgyro/accgyro_mpu.h @@ -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 @@ -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 @@ -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; diff --git a/src/main/drivers/accgyro/accgyro_spi_icm426xx.c b/src/main/drivers/accgyro/accgyro_spi_icm426xx.c new file mode 100644 index 0000000000..24003f9017 --- /dev/null +++ b/src/main/drivers/accgyro/accgyro_spi_icm426xx.c @@ -0,0 +1,389 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#include +#include +#include + +#include "platform.h" + +#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) + +#include "common/axis.h" +#include "common/maths.h" + +#include "drivers/accgyro/accgyro.h" +#include "drivers/accgyro/accgyro_mpu.h" +#include "drivers/accgyro/accgyro_spi_icm426xx.h" +#include "drivers/bus_spi.h" +#include "drivers/exti.h" +#include "drivers/io.h" +#include "drivers/sensor.h" +#include "drivers/time.h" + +// 24 MHz max SPI frequency +#define ICM426XX_MAX_SPI_CLK_HZ 24000000 + +#define ICM426XX_RA_REG_BANK_SEL 0x76 +#define ICM426XX_BANK_SELECT0 0x00 +#define ICM426XX_BANK_SELECT1 0x01 +#define ICM426XX_BANK_SELECT2 0x02 +#define ICM426XX_BANK_SELECT3 0x03 +#define ICM426XX_BANK_SELECT4 0x04 + +#define ICM426XX_RA_PWR_MGMT0 0x4E // User Bank 0 +#define ICM426XX_PWR_MGMT0_ACCEL_MODE_LN (3 << 0) +#define ICM426XX_PWR_MGMT0_GYRO_MODE_LN (3 << 2) +#define ICM426XX_PWR_MGMT0_GYRO_ACCEL_MODE_OFF ((0 << 0) | (0 << 2)) +#define ICM426XX_PWR_MGMT0_TEMP_DISABLE_OFF (0 << 5) +#define ICM426XX_PWR_MGMT0_TEMP_DISABLE_ON (1 << 5) + +#define ICM426XX_RA_GYRO_CONFIG0 0x4F +#define ICM426XX_RA_ACCEL_CONFIG0 0x50 + +// --- Registers for gyro and acc Anti-Alias Filter --------- +#define ICM426XX_RA_GYRO_CONFIG_STATIC3 0x0C // User Bank 1 +#define ICM426XX_RA_GYRO_CONFIG_STATIC4 0x0D // User Bank 1 +#define ICM426XX_RA_GYRO_CONFIG_STATIC5 0x0E // User Bank 1 +#define ICM426XX_RA_ACCEL_CONFIG_STATIC2 0x03 // User Bank 2 +#define ICM426XX_RA_ACCEL_CONFIG_STATIC3 0x04 // User Bank 2 +#define ICM426XX_RA_ACCEL_CONFIG_STATIC4 0x05 // User Bank 2 +// --- Register & setting for gyro and acc UI Filter -------- +#define ICM426XX_RA_GYRO_ACCEL_CONFIG0 0x52 // User Bank 0 +#define ICM426XX_ACCEL_UI_FILT_BW_LOW_LATENCY (15 << 4) +#define ICM426XX_GYRO_UI_FILT_BW_LOW_LATENCY (15 << 0) +// ---------------------------------------------------------- + +#define ICM426XX_RA_GYRO_DATA_X1 0x25 // User Bank 0 +#define ICM426XX_RA_ACCEL_DATA_X1 0x1F // User Bank 0 + +#define ICM426XX_RA_INT_CONFIG 0x14 // User Bank 0 +#define ICM426XX_INT1_MODE_PULSED (0 << 2) +#define ICM426XX_INT1_MODE_LATCHED (1 << 2) +#define ICM426XX_INT1_DRIVE_CIRCUIT_OD (0 << 1) +#define ICM426XX_INT1_DRIVE_CIRCUIT_PP (1 << 1) +#define ICM426XX_INT1_POLARITY_ACTIVE_LOW (0 << 0) +#define ICM426XX_INT1_POLARITY_ACTIVE_HIGH (1 << 0) + +#define ICM426XX_RA_INT_CONFIG0 0x63 // User Bank 0 +#define ICM426XX_UI_DRDY_INT_CLEAR_ON_SBR ((0 << 5) || (0 << 4)) +#define ICM426XX_UI_DRDY_INT_CLEAR_ON_SBR_DUPLICATE ((0 << 5) || (0 << 4)) // duplicate settings in datasheet, Rev 1.2. +#define ICM426XX_UI_DRDY_INT_CLEAR_ON_F1BR ((1 << 5) || (0 << 4)) +#define ICM426XX_UI_DRDY_INT_CLEAR_ON_SBR_AND_F1BR ((1 << 5) || (1 << 4)) + +#define ICM426XX_RA_INT_CONFIG1 0x64 // User Bank 0 +#define ICM426XX_INT_ASYNC_RESET_BIT 4 +#define ICM426XX_INT_TDEASSERT_DISABLE_BIT 5 +#define ICM426XX_INT_TDEASSERT_ENABLED (0 << ICM426XX_INT_TDEASSERT_DISABLE_BIT) +#define ICM426XX_INT_TDEASSERT_DISABLED (1 << ICM426XX_INT_TDEASSERT_DISABLE_BIT) +#define ICM426XX_INT_TPULSE_DURATION_BIT 6 +#define ICM426XX_INT_TPULSE_DURATION_100 (0 << ICM426XX_INT_TPULSE_DURATION_BIT) +#define ICM426XX_INT_TPULSE_DURATION_8 (1 << ICM426XX_INT_TPULSE_DURATION_BIT) + +#define ICM426XX_RA_INT_SOURCE0 0x65 // User Bank 0 +#define ICM426XX_UI_DRDY_INT1_EN_DISABLED (0 << 3) +#define ICM426XX_UI_DRDY_INT1_EN_ENABLED (1 << 3) + +typedef enum { + ODR_CONFIG_8K = 0, + ODR_CONFIG_4K, + ODR_CONFIG_2K, + ODR_CONFIG_1K, + ODR_CONFIG_COUNT +} odrConfig_e; + +typedef enum { + AAF_CONFIG_258HZ = 0, + AAF_CONFIG_536HZ, + AAF_CONFIG_997HZ, + AAF_CONFIG_1962HZ, + AAF_CONFIG_COUNT +} aafConfig_e; + +typedef struct aafConfig_s { + uint8_t delt; + uint16_t deltSqr; + uint8_t bitshift; +} aafConfig_t; + +// Possible output data rates (ODRs) +static uint8_t odrLUT[ODR_CONFIG_COUNT] = { // see GYRO_ODR in section 5.6 + [ODR_CONFIG_8K] = 3, + [ODR_CONFIG_4K] = 4, + [ODR_CONFIG_2K] = 5, + [ODR_CONFIG_1K] = 6, +}; + +// Possible gyro Anti-Alias Filter (AAF) cutoffs for ICM-42688P +static aafConfig_t aafLUT42688[AAF_CONFIG_COUNT] = { // see table in section 5.3 + [AAF_CONFIG_258HZ] = { 6, 36, 10 }, + [AAF_CONFIG_536HZ] = { 12, 144, 8 }, + [AAF_CONFIG_997HZ] = { 21, 440, 6 }, + [AAF_CONFIG_1962HZ] = { 37, 1376, 4 }, +}; + +// Possible gyro Anti-Alias Filter (AAF) cutoffs for ICM-42688P +// actual cutoff differs slightly from those of the 42688P +static aafConfig_t aafLUT42605[AAF_CONFIG_COUNT] = { // see table in section 5.3 + [AAF_CONFIG_258HZ] = { 21, 440, 6 }, // actually 249 Hz + [AAF_CONFIG_536HZ] = { 39, 1536, 4 }, // actually 524 Hz + [AAF_CONFIG_997HZ] = { 63, 3968, 3 }, // actually 995 Hz + [AAF_CONFIG_1962HZ] = { 63, 3968, 3 }, // 995 Hz is the max cutoff on the 42605 +}; + +static void icm426xxSpiInit(const busDevice_t *bus) { + static bool hardwareInitialised = false; + if (hardwareInitialised) { + return; + } +#ifndef USE_DUAL_GYRO + IOInit(bus->busdev_u.spi.csnPin, OWNER_MPU_CS, 0); + IOConfigGPIO(bus->busdev_u.spi.csnPin, SPI_IO_CS_CFG); + IOHi(bus->busdev_u.spi.csnPin); +#endif + spiSetDivisor(bus->busdev_u.spi.instance, SPI_CLOCK_STANDARD); + hardwareInitialised = true; +} + +uint8_t icm426xxSpiDetect(const busDevice_t *bus) { + icm426xxSpiInit(bus); + spiSetDivisor(bus->busdev_u.spi.instance, SPI_CLOCK_INITIALIZATION); //low speed + spiBusWriteRegister(bus, MPU_RA_PWR_MGMT_1, ICM426xx_BIT_RESET); + uint8_t icmDetected = MPU_NONE; + uint8_t attemptsRemaining = 20; + do { + delay(150); + const uint8_t whoAmI = spiBusReadRegister(bus, MPU_RA_WHO_AM_I); + switch (whoAmI) { + case ICM42605_WHO_AM_I_CONST: + icmDetected = ICM_42605_SPI; + break; + case ICM42688P_WHO_AM_I_CONST: + icmDetected = ICM_42688P_SPI; + break; + default: + icmDetected = MPU_NONE; + break; + } + if (icmDetected != MPU_NONE) { + break; + } + if (!attemptsRemaining) { + return MPU_NONE; + } + } while (attemptsRemaining--); + spiSetDivisor(bus->busdev_u.spi.instance, SPI_CLOCK_STANDARD); + return icmDetected; +} + +void icm426xxAccInit(accDev_t *acc) { + acc->acc_1G = 512 * 4; +} + +bool icm426xxAccRead(accDev_t *acc) +{ + uint8_t data[6]; + + const bool ack = busReadRegisterBuffer(&acc->bus, ICM426XX_RA_ACCEL_DATA_X1, data, 6); + if (!ack) { + return false; + } + + acc->ADCRaw[X] = (int16_t)((data[0] << 8) | data[1]); + acc->ADCRaw[Y] = (int16_t)((data[2] << 8) | data[3]); + acc->ADCRaw[Z] = (int16_t)((data[4] << 8) | data[5]); + + return true; +} + +bool icm426xxSpiAccDetect(accDev_t *acc) { + switch (acc->mpuDetectionResult.sensor) { + case ICM_42605_SPI: + case ICM_42688P_SPI: + break; + default: + return false; + } + acc->initFn = icm426xxAccInit; + acc->readFn = icm426xxAccRead; + return true; +} + +static aafConfig_t getGyroAafConfig(const mpuSensor_e, const aafConfig_e); + +static void turnGyroAccOff(const gyroDev_t *gyro) +{ + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_PWR_MGMT0, ICM426XX_PWR_MGMT0_GYRO_ACCEL_MODE_OFF); +} + +// Turn on gyro and acc on in Low Noise mode +static void turnGyroAccOn(const gyroDev_t *gyro) +{ + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_PWR_MGMT0, ICM426XX_PWR_MGMT0_TEMP_DISABLE_OFF | ICM426XX_PWR_MGMT0_ACCEL_MODE_LN | ICM426XX_PWR_MGMT0_GYRO_MODE_LN); + delay(1); +} + +static void setUserBank(const gyroDev_t *gyro, const uint8_t user_bank) +{ + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_REG_BANK_SEL, user_bank & 7); +} + +void icm426xxGyroInit(gyroDev_t *gyro) +{ + mpuGyroInit(gyro); + + spiSetDivisor(gyro->bus.busdev_u.spi.instance, spiCalculateDivider(ICM426XX_MAX_SPI_CLK_HZ)); + + gyro->accDataReg = ICM426XX_RA_ACCEL_DATA_X1; + gyro->gyroDataReg = ICM426XX_RA_GYRO_DATA_X1; + + // Turn off ACC and GYRO so they can be configured + // See section 12.9 in ICM-42688-P datasheet v1.7 + setUserBank(gyro, ICM426XX_BANK_SELECT0); + turnGyroAccOff(gyro); + + // Configure gyro Anti-Alias Filter (see section 5.3 "ANTI-ALIAS FILTER") + const mpuSensor_e gyroModel = gyro->mpuDetectionResult.sensor; + aafConfig_t aafConfig = getGyroAafConfig(gyroModel, gyroConfig()->gyro_hardware_lpf); + setUserBank(gyro, ICM426XX_BANK_SELECT1); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_GYRO_CONFIG_STATIC3, aafConfig.delt); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_GYRO_CONFIG_STATIC4, aafConfig.deltSqr & 0xFF); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_GYRO_CONFIG_STATIC5, (aafConfig.deltSqr >> 8) | (aafConfig.bitshift << 4)); + + // Configure acc Anti-Alias Filter for 1kHz sample rate (see tasks.c) + aafConfig = getGyroAafConfig(gyroModel, AAF_CONFIG_258HZ); + setUserBank(gyro, ICM426XX_BANK_SELECT2); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_ACCEL_CONFIG_STATIC2, aafConfig.delt << 1); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_ACCEL_CONFIG_STATIC3, aafConfig.deltSqr & 0xFF); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_ACCEL_CONFIG_STATIC4, (aafConfig.deltSqr >> 8) | (aafConfig.bitshift << 4)); + + // Configure gyro and acc UI Filters + setUserBank(gyro, ICM426XX_BANK_SELECT0); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_GYRO_ACCEL_CONFIG0, ICM426XX_ACCEL_UI_FILT_BW_LOW_LATENCY | ICM426XX_GYRO_UI_FILT_BW_LOW_LATENCY); + + // Configure interrupt pin + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_INT_CONFIG, ICM426XX_INT1_MODE_PULSED | ICM426XX_INT1_DRIVE_CIRCUIT_PP | ICM426XX_INT1_POLARITY_ACTIVE_HIGH); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_INT_CONFIG0, ICM426XX_UI_DRDY_INT_CLEAR_ON_SBR); + + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_INT_SOURCE0, ICM426XX_UI_DRDY_INT1_EN_ENABLED); + + uint8_t intConfig1Value = spiReadRegMsk(&gyro->bus, ICM426XX_RA_INT_CONFIG1); + // Datasheet says: "User should change setting to 0 from default setting of 1, for proper INT1 and INT2 pin operation" + intConfig1Value &= ~(1 << ICM426XX_INT_ASYNC_RESET_BIT); + intConfig1Value |= (ICM426XX_INT_TPULSE_DURATION_8 | ICM426XX_INT_TDEASSERT_DISABLED); + + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_INT_CONFIG1, intConfig1Value); + + // Turn on gyro and acc on again so ODR and FSR can be configured + turnGyroAccOn(gyro); + + // Get desired output data rate + uint8_t odrConfig; + const unsigned decim = llog2(gyro->mpuDividerDrops + 1); + if (gyro->gyroRateKHz && decim < ODR_CONFIG_COUNT) { + odrConfig = odrLUT[decim]; + } else { + odrConfig = odrLUT[ODR_CONFIG_1K]; + gyro->gyroRateKHz = GYRO_RATE_1_kHz; + } + + STATIC_ASSERT(INV_FSR_2000DPS == 3, INV_FSR_2000DPS_must_be_3_to_generate_correct_value); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_GYRO_CONFIG0, (3 - INV_FSR_2000DPS) << 5 | (odrConfig & 0x0F)); + delay(15); + + STATIC_ASSERT(INV_FSR_16G == 3, INV_FSR_16G_must_be_3_to_generate_correct_value); + spiBusWriteRegister(&gyro->bus, ICM426XX_RA_ACCEL_CONFIG0, (3 - INV_FSR_16G) << 5 | (odrConfig & 0x0F)); + delay(15); +} + +// MIGHT NOT work on STM32F7 +#define STATIC_DMA_DATA_AUTO static +//FAST_CODE bool mpuGyroReadSPI(gyroDev_t *gyro) +bool icm426xxGyroReadSPI(gyroDev_t *gyro) +{ + //static const uint8_t dataToSend[7] = {MPU_RA_GYRO_XOUT_H | 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + STATIC_DMA_DATA_AUTO uint8_t dataToSend[7] = {ICM426XX_RA_GYRO_DATA_X1 | 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + //uint8_t data[7]; + STATIC_DMA_DATA_AUTO uint8_t data[7]; + + const bool ack = spiBusTransfer(&gyro->bus, dataToSend, data, 7); + if (!ack) { + return false; + } + + gyro->gyroADCRaw[X] = (int16_t)((data[1] << 8) | data[2]); + gyro->gyroADCRaw[Y] = (int16_t)((data[3] << 8) | data[4]); + gyro->gyroADCRaw[Z] = (int16_t)((data[5] << 8) | data[6]); + + return true; +} + +bool icm426xxSpiGyroDetect(gyroDev_t *gyro) { + switch (gyro->mpuDetectionResult.sensor) { + case ICM_42605_SPI: + case ICM_42688P_SPI: + break; + default: + return false; + } + + gyro->initFn = icm426xxGyroInit; + gyro->readFn = icm426xxGyroReadSPI; + + gyro->scale = (2000.0f / (1 << 15)); // 16.384 dps/lsb scalefactor for 2000dps sensors + + return true; +} + +static aafConfig_t getGyroAafConfig(const mpuSensor_e gyroModel, const aafConfig_e config) +{ + switch (gyroModel){ + case ICM_42605_SPI: + switch (config) { + case GYRO_HARDWARE_LPF_NORMAL: + return aafLUT42605[AAF_CONFIG_258HZ]; + case GYRO_HARDWARE_LPF_OPTION_1: + return aafLUT42605[AAF_CONFIG_536HZ]; + case GYRO_HARDWARE_LPF_OPTION_2: + return aafLUT42605[AAF_CONFIG_997HZ]; + default: + return aafLUT42605[AAF_CONFIG_258HZ]; + } + + case ICM_42688P_SPI: + default: + switch (config) { + case GYRO_HARDWARE_LPF_NORMAL: + return aafLUT42688[AAF_CONFIG_258HZ]; + case GYRO_HARDWARE_LPF_OPTION_1: + return aafLUT42688[AAF_CONFIG_536HZ]; + case GYRO_HARDWARE_LPF_OPTION_2: + return aafLUT42688[AAF_CONFIG_997HZ]; +#ifdef USE_GYRO_DLPF_EXPERIMENTAL + case GYRO_HARDWARE_LPF_EXPERIMENTAL: + return aafLUT42688[AAF_CONFIG_1962HZ]; +#endif + default: + return aafLUT42688[AAF_CONFIG_258HZ]; + } + } +} + +#endif // USE_GYRO_SPI_ICM42605 || USE_GYRO_SPI_ICM42688P diff --git a/src/main/drivers/accgyro/accgyro_spi_icm426xx.h b/src/main/drivers/accgyro/accgyro_spi_icm426xx.h new file mode 100644 index 0000000000..842fe6626e --- /dev/null +++ b/src/main/drivers/accgyro/accgyro_spi_icm426xx.h @@ -0,0 +1,36 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#pragma once + +#include "drivers/bus.h" + +#define ICM426xx_BIT_RESET (0x80) + +bool icm426xxAccDetect(accDev_t *acc); +bool icm426xxGyroDetect(gyroDev_t *gyro); + +void icm426xxAccInit(accDev_t *acc); +void icm426xxGyroInit(gyroDev_t *gyro); + +uint8_t icm426xxSpiDetect(const busDevice_t *dev); + +bool icm426xxSpiAccDetect(accDev_t *acc); +bool icm426xxSpiGyroDetect(gyroDev_t *gyro); \ No newline at end of file diff --git a/src/main/drivers/accgyro/accgyro_spi_mpu6500.c b/src/main/drivers/accgyro/accgyro_spi_mpu6500.c index a39d053d7a..86bca64388 100644 --- a/src/main/drivers/accgyro/accgyro_spi_mpu6500.c +++ b/src/main/drivers/accgyro/accgyro_spi_mpu6500.c @@ -69,6 +69,12 @@ uint8_t mpu6500SpiDetect(const busDevice_t *bus) { case ICM20608G_WHO_AM_I_CONST: mpuDetected = ICM_20608_SPI; break; + case ICM42605_WHO_AM_I_CONST: + mpuDetected = ICM_42605_SPI; + break; + case ICM42688P_WHO_AM_I_CONST: + mpuDetected = ICM_42688P_SPI; + break; default: mpuDetected = MPU_NONE; } diff --git a/src/main/drivers/bus_spi.c b/src/main/drivers/bus_spi.c index 93cec8510a..d42f0e6156 100644 --- a/src/main/drivers/bus_spi.c +++ b/src/main/drivers/bus_spi.c @@ -251,4 +251,31 @@ void spiBusSetInstance(busDevice_t *bus, SPI_TypeDef *instance) { bus->bustype = BUSTYPE_SPI; bus->busdev_u.spi.instance = instance; } + +uint16_t spiCalculateDivider(uint32_t freq) +{ +#if defined(STM32F4) || defined(STM32G4) || defined(STM32F7) + uint32_t spiClk = SystemCoreClock / 2; +#elif defined(STM32H7) + uint32_t spiClk = 100000000; +#elif defined(AT32F4) + if(freq > 36000000){ + freq = 36000000; + } + uint32_t spiClk = system_core_clock / 2; +#else +#error "Base SPI clock not defined for this architecture" +#endif + uint16_t divisor = 2; + spiClk >>= 1; + for (; (spiClk > freq) && (divisor < 256); divisor <<= 1, spiClk >>= 1); + return divisor; +} + +// Wait for bus to become free, then read a byte of data where the register is ORed with 0x80 +uint8_t spiReadRegMsk(const busDevice_t *bus, uint8_t reg) +{ + return spiBusReadRegister(bus, reg | 0x80); +} + #endif diff --git a/src/main/drivers/bus_spi.h b/src/main/drivers/bus_spi.h index 12d8d068a7..1fa4a0dab7 100644 --- a/src/main/drivers/bus_spi.h +++ b/src/main/drivers/bus_spi.h @@ -121,3 +121,8 @@ void spiBusSetInstance(busDevice_t *bus, SPI_TypeDef *instance); struct spiPinConfig_s; void spiPinConfigure(const struct spiPinConfig_s *pConfig); + +// Determine the divisor to use for a given bus frequency +uint16_t spiCalculateDivider(uint32_t freq); + +uint8_t spiReadRegMsk(const busDevice_t *bus, uint8_t reg); diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index bb6f1fbdbb..2344beb3d5 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -86,7 +86,7 @@ PG_REGISTER_WITH_RESET_TEMPLATE(pidConfig_t, pidConfig, PG_PID_CONFIG, 2); #ifdef STM32F10X #define PID_PROCESS_DENOM_DEFAULT 1 -#elif defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_ICM20689) +#elif defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) #define PID_PROCESS_DENOM_DEFAULT 1 #else #define PID_PROCESS_DENOM_DEFAULT 2 diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 0b6664170c..9634ec73c8 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -109,13 +109,13 @@ const char * const lookupTableAccHardware[] = { "AUTO", "NONE", "ADXL345", "MPU6050", "MMA8452", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "MPU9250", "ICM20601", "ICM20602", "ICM20608G", "ICM20649", "ICM20689", - "BMI160", "ACC_IMUF9001", "FAKE" + "ICM42605", "ICM42688P", "BMI160", "ACC_IMUF9001", "FAKE" }; // sync with gyroSensor_e const char * const lookupTableGyroHardware[] = { "AUTO", "NONE", "MPU6050", "L3G4200D", "MPU3050", "L3GD20", "MPU6000", "MPU6500", "MPU9250", "ICM20601", "ICM20602", "ICM20608G", "ICM20649", "ICM20689", - "BMI160", "GYRO_IMUF9001", "FAKE" + "ICM42605", "ICM42688P", "BMI160", "GYRO_IMUF9001", "FAKE" }; #if defined(USE_SENSOR_NAMES) || defined(USE_BARO) @@ -252,8 +252,16 @@ static const char * const lookupTableRxSpi[] = { static const char * const lookupTableGyroHardwareLpf[] = { "NORMAL", +#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) + "OPTION1", + "OPTION2", +#if defined(USE_GYRO_SPI_ICM42688P) && defined(USE_GYRO_DLPF_EXPERIMENTAL) // will need bmi270 logic as well + "EXPERIMENTAL", +#endif +#else "EXPERIMENTAL", "1KHZ_SAMPLING" +#endif }; #ifdef USE_32K_CAPABLE_GYRO diff --git a/src/main/pg/bus_spi.c b/src/main/pg/bus_spi.c index a51b0e9378..3b1fcfa7a8 100644 --- a/src/main/pg/bus_spi.c +++ b/src/main/pg/bus_spi.c @@ -91,6 +91,12 @@ ioTag_t preinitIPUList[SPI_PREINIT_IPU_COUNT] = { #ifdef ICM20689_CS_PIN IO_TAG(ICM20689_CS_PIN), #endif +#ifdef ICM42605_CS_PIN + IO_TAG(ICM42605_CS_PIN), +#endif +#ifdef ICM42688P_CS_PIN + IO_TAG(ICM42688P_CS_PIN), +#endif #ifdef BMI160_CS_PIN IO_TAG(BMI160_CS_PIN), #endif diff --git a/src/main/sensors/acceleration.c b/src/main/sensors/acceleration.c index 1d1f08b132..62460a182c 100644 --- a/src/main/sensors/acceleration.c +++ b/src/main/sensors/acceleration.c @@ -45,6 +45,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" @@ -298,6 +299,31 @@ bool accDetect(accDev_t *dev, accelerationSensor_e accHardwareToUse) { } FALLTHROUGH; #endif +#if defined(USE_ACC_SPI_ICM42605) || defined(USE_ACC_SPI_ICM42688P) + case ACC_ICM42605: + case ACC_ICM42688P: + if (icm426xxSpiAccDetect(dev)) { + switch (dev->mpuDetectionResult.sensor) { + case ICM_42605_SPI: + accHardware = ACC_ICM42605; +#ifdef ACC_ICM42605_ALIGN + dev->accAlign = ACC_ICM42605_ALIGN; +#endif + break; + case ICM_42688P_SPI: + accHardware = ACC_ICM42688P; +#ifdef ACC_ICM42688P_ALIGN + dev->accAlign = ACC_ICM42688P_ALIGN; +#endif + break; + default: + accHardware = ACC_NONE; + break; + } + break; + } + FALLTHROUGH; +#endif #ifdef USE_FAKE_ACC case ACC_FAKE: if (fakeAccDetect(dev)) { diff --git a/src/main/sensors/acceleration.h b/src/main/sensors/acceleration.h index 778263ee37..b448d2419b 100644 --- a/src/main/sensors/acceleration.h +++ b/src/main/sensors/acceleration.h @@ -47,6 +47,8 @@ typedef enum { ACC_ICM20608G, ACC_ICM20649, ACC_ICM20689, + ACC_ICM42605, + ACC_ICM42688P, ACC_BMI160, ACC_IMUF9001, ACC_FAKE diff --git a/src/main/sensors/gyro.c b/src/main/sensors/gyro.c index 60d6a62df3..b77528e9fd 100644 --- a/src/main/sensors/gyro.c +++ b/src/main/sensors/gyro.c @@ -46,6 +46,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" @@ -208,7 +209,7 @@ static void gyroInitLowpassFilterLpf(gyroSensor_t *gyroSensor, int slot, int typ #ifdef STM32F10X #define GYRO_SYNC_DENOM_DEFAULT 8 #elif defined(USE_GYRO_SPI_MPU6000) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_ICM20601) || 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_SYNC_DENOM_DEFAULT 1 #else #define GYRO_SYNC_DENOM_DEFAULT 3 @@ -496,6 +497,31 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev) { } FALLTHROUGH; #endif +#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) + case GYRO_ICM42605: + case GYRO_ICM42688P: + if (icm426xxSpiGyroDetect(dev)) { + switch (dev->mpuDetectionResult.sensor) { + case ICM_42605_SPI: + gyroHardware = GYRO_ICM42605; +#ifdef GYRO_ICM42605_ALIGN + dev->gyroAlign = GYRO_ICM42605_ALIGN; +#endif + break; + case ICM_42688P_SPI: + gyroHardware = GYRO_ICM42688P; +#ifdef GYRO_ICM42688P_ALIGN + dev->gyroAlign = GYRO_ICM42688P_ALIGN; +#endif + break; + default: + gyroHardware = GYRO_NONE; + break; + } + break; + } + FALLTHROUGH; +#endif #ifdef USE_ACCGYRO_BMI160 case GYRO_BMI160: if (bmi160SpiGyroDetect(dev)) { @@ -536,7 +562,7 @@ STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev) { static bool gyroInitSensor(gyroSensor_t *gyroSensor) { gyroSensor->gyroDev.gyro_high_fsr = gyroConfig()->gyro_high_fsr; #if defined(USE_GYRO_MPU6050) || defined(USE_GYRO_MPU3050) || defined(USE_GYRO_MPU6500) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU6000) \ - || defined(USE_ACC_MPU6050) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_SPI_ICM20601) || defined(USE_GYRO_SPI_ICM20649) || defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_IMUF9001) || defined(USE_ACCGYRO_BMI160) + || defined(USE_ACC_MPU6050) || defined(USE_GYRO_SPI_MPU9250) || defined(USE_GYRO_SPI_ICM20601) || defined(USE_GYRO_SPI_ICM20649) || defined(USE_GYRO_SPI_ICM20689) || defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) || defined(USE_GYRO_IMUF9001) || defined(USE_ACCGYRO_BMI160) mpuDetect(&gyroSensor->gyroDev); mpuResetFn = gyroSensor->gyroDev.mpuConfiguration.resetFn; // must be set after mpuDetect #endif diff --git a/src/main/sensors/gyro.h b/src/main/sensors/gyro.h index 1bbb627a89..4387c872e3 100644 --- a/src/main/sensors/gyro.h +++ b/src/main/sensors/gyro.h @@ -53,6 +53,8 @@ typedef enum { GYRO_ICM20608G, GYRO_ICM20649, GYRO_ICM20689, + GYRO_ICM42605, + GYRO_ICM42688P, GYRO_BMI160, GYRO_IMUF9001, GYRO_FAKE diff --git a/src/main/target/common_fc_pre.h b/src/main/target/common_fc_pre.h index 2345ab8aba..426ec9b767 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -228,3 +228,6 @@ #define USE_CMS_FAILSAFE_MENU #define USE_CMS_GPS_RESCUE_MENU #endif + +// ICM42688P define +#define USE_GYRO_DLPF_EXPERIMENTAL From c9cb676f1ed13222e80e7ee8dc00b65cb806b489 Mon Sep 17 00:00:00 2001 From: Roland <28628457+Peck07@users.noreply.github.com> Date: Fri, 2 Jun 2023 14:39:00 +0200 Subject: [PATCH 02/14] add ICM42688P support to FLYWOOF411_5IN1_AIO target (#907) add ICM426xx support to FLYWOOF411_5IN1_AIO target --- src/main/target/FLYWOOF411_5IN1_AIO/target.h | 8 ++++++++ src/main/target/FLYWOOF411_5IN1_AIO/target.mk | 1 + 2 files changed, 9 insertions(+) diff --git a/src/main/target/FLYWOOF411_5IN1_AIO/target.h b/src/main/target/FLYWOOF411_5IN1_AIO/target.h index c3cf698af1..fc3d6d1f90 100644 --- a/src/main/target/FLYWOOF411_5IN1_AIO/target.h +++ b/src/main/target/FLYWOOF411_5IN1_AIO/target.h @@ -61,6 +61,14 @@ //#define USE_ACC_SPI_ICM20689 //#define ACC_ICM20689_ALIGN CW180_DEG +#define USE_GYRO_SPI_ICM42688P +#define USE_ACC_SPI_ICM42688P + +#define ICM42688P_SPI_INSTANCE SPI1 +#define ICM42688P_CS_PIN PB2 +#define ACC_ICM426XX_ALIGN CW90_DEG +#define GYRO_ICM426XX_ALIGN CW90_DEG + // *************** Baro ************************** #define USE_I2C diff --git a/src/main/target/FLYWOOF411_5IN1_AIO/target.mk b/src/main/target/FLYWOOF411_5IN1_AIO/target.mk index d6dc58877c..19d3a639b7 100644 --- a/src/main/target/FLYWOOF411_5IN1_AIO/target.mk +++ b/src/main/target/FLYWOOF411_5IN1_AIO/target.mk @@ -6,6 +6,7 @@ TARGET_SRC = \ drivers/accgyro/accgyro_mpu.c \ drivers/accgyro/accgyro_spi_mpu6000.c \ drivers/accgyro/accgyro_spi_icm20689.c \ + drivers/accgyro/accgyro_spi_icm426xx.c \ drivers/barometer/barometer_bmp085.c \ drivers/barometer/barometer_bmp280.c \ drivers/barometer/barometer_ms5611.c \ From 9c0d7044e2c0bf614da0df859ade25676cb0bdd8 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 14 Jun 2023 10:36:17 -0500 Subject: [PATCH 03/14] bugfix gating USE_GYRO_DATA_ANALYSE (#917) bugfix gating USE_GYRO_DATA_ANALYSE when is used --- src/main/flight/pid.c | 4 +++- src/main/sensors/gyro.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index 2344beb3d5..19b51d18f7 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -315,12 +315,14 @@ void pidInitFilters(const pidProfile_t *pidProfile) { dtermABGapplyFn = (filterApplyFnPtr)alphaBetaGammaApply; ABGInit(&dtermABG[axis], pidProfile->dterm_ABG_alpha, pidProfile->dterm_ABG_boost, pidProfile->dterm_ABG_half_life, dT); } - +#ifdef USE_GYRO_DATA_ANALYSE if (isDynamicFilterActive()) { for (int axis2 = 0; axis2 < gyroConfig()->dyn_notch_count; axis2++) { biquadFilterInit(&dtermNotch[axis][axis2], 400, targetPidLooptime, gyroConfig()->dyn_notch_q / 100.0f, FILTER_NOTCH); } } +#endif + } #if defined(USE_THROTTLE_BOOST) diff --git a/src/main/sensors/gyro.h b/src/main/sensors/gyro.h index 4387c872e3..0f32c699e1 100644 --- a/src/main/sensors/gyro.h +++ b/src/main/sensors/gyro.h @@ -198,7 +198,9 @@ bool gyroYawSpinDetected(void); uint16_t gyroAbsRateDps(int axis); uint8_t gyroReadRegister(uint8_t whichSensor, uint8_t reg); float applySmithPredictor(smithPredictor_t *smithPredictor, float gyroFiltered); +#ifdef USE_GYRO_DATA_ANALYSE bool isDynamicFilterActive(void); +#endif #ifdef USE_YAW_SPIN_RECOVERY void initYawSpinRecovery(int maxYawRate); #endif From a0b59bba2b204e301b10d3aa8abcb95b48de27d4 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Fri, 30 Jun 2023 11:06:54 -0500 Subject: [PATCH 04/14] [Target] fix FLYWOOF411_5IN1_AIO ICM42688P alignment (#911) fix FLYWOOF411_5IN1_AIO ICM42688P align --- src/main/target/FLYWOOF411_5IN1_AIO/target.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/target/FLYWOOF411_5IN1_AIO/target.h b/src/main/target/FLYWOOF411_5IN1_AIO/target.h index fc3d6d1f90..5e93cd6460 100644 --- a/src/main/target/FLYWOOF411_5IN1_AIO/target.h +++ b/src/main/target/FLYWOOF411_5IN1_AIO/target.h @@ -66,8 +66,8 @@ #define ICM42688P_SPI_INSTANCE SPI1 #define ICM42688P_CS_PIN PB2 -#define ACC_ICM426XX_ALIGN CW90_DEG -#define GYRO_ICM426XX_ALIGN CW90_DEG +#define ACC_ICM42688P_ALIGN CW0_DEG_FLIP +#define GYRO_ICM42688P_ALIGN CW0_DEG_FLIP // *************** Baro ************************** #define USE_I2C From f25f0494a7fa07a8f028d642483e9053116e7926 Mon Sep 17 00:00:00 2001 From: BeauBrewski <85623381+BeauBrewski@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:03:18 -0500 Subject: [PATCH 05/14] [Target] IFLIGHT_F745_AIO_V2 (MPU6000 Only) (#895) * IFLIGHT_F745_AIO_V2 (MPU6000 ONLY) TARGET * IFLIGHT_F745_AIO_V2 - target.mk replace tabs w/ spaces --- src/main/target/IFLIGHT_F745_AIO_V2/target.c | 44 ++++ src/main/target/IFLIGHT_F745_AIO_V2/target.h | 188 ++++++++++++++++++ src/main/target/IFLIGHT_F745_AIO_V2/target.mk | 15 ++ 3 files changed, 247 insertions(+) create mode 100644 src/main/target/IFLIGHT_F745_AIO_V2/target.c create mode 100644 src/main/target/IFLIGHT_F745_AIO_V2/target.h create mode 100644 src/main/target/IFLIGHT_F745_AIO_V2/target.mk diff --git a/src/main/target/IFLIGHT_F745_AIO_V2/target.c b/src/main/target/IFLIGHT_F745_AIO_V2/target.c new file mode 100644 index 0000000000..c57c497050 --- /dev/null +++ b/src/main/target/IFLIGHT_F745_AIO_V2/target.c @@ -0,0 +1,44 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#include + +#include "platform.h" +#include "drivers/io.h" + +#include "drivers/dma.h" +#include "drivers/timer.h" +#include "drivers/timer_def.h" + +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0, 0 ), //LED + DEF_TIM(TIM2, CH2, PB3, TIM_USE_ANY, 0, 0 ), //CAM + + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 0, 0 ), // M1 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 0, 0 ), // M2 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MOTOR, 0, 0 ), // M3 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MOTOR, 0, 0 ), // M4 + DEF_TIM(TIM4, CH1, PD12, TIM_USE_MOTOR, 0, 0 ), // M5 + DEF_TIM(TIM4, CH2, PD13, TIM_USE_MOTOR, 0, 0 ), // M6 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MOTOR, 0, 1 ), // M7 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MOTOR, 0, 0 ), // M8 + + }; diff --git a/src/main/target/IFLIGHT_F745_AIO_V2/target.h b/src/main/target/IFLIGHT_F745_AIO_V2/target.h new file mode 100644 index 0000000000..6eec787ed9 --- /dev/null +++ b/src/main/target/IFLIGHT_F745_AIO_V2/target.h @@ -0,0 +1,188 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#pragma once + +#define TARGET_BOARD_IDENTIFIER "IFRC" + +#define USBD_PRODUCT_STRING "IFLIGHT_F745_AIO_V2" + +#define ENABLE_DSHOT_DMAR true + +#define LED0_PIN PC13 + +#define USE_BEEPER +#define BEEPER_PIN PD2 +#define BEEPER_INVERTED + +//**********Gyro Acc *************// + +#define USE_ACC +#define USE_GYRO +#define USE_DUAL_GYRO + +#define USE_SPI_GYRO +//#define USE_ACCGYRO_BMI270 +#define USE_GYRO_SPI_MPU6000 +#define USE_ACC_SPI_MPU6000 + +#define USE_EXTI +#define USE_GYRO_EXTI +#define GYRO_1_EXTI_PIN PD0 +#define GYRO_2_EXTI_PIN PD8 +#define MPU_INT_EXTI + +#define GYRO_1_CS_PIN PA4 +#define GYRO_1_SPI_INSTANCE SPI1 +#define GYRO_2_CS_PIN PB12 +#define GYRO_2_SPI_INSTANCE SPI2 + +#define GYRO_1_ALIGN CW0_DEG +#define ACC_1_ALIGN CW0_DEG +#define GYRO_2_ALIGN CW180_DEG +#define ACC_2_ALIGN CW180_DEG + +#define USE_MPU_DATA_READY_SIGNAL +#define ENSURE_MPU_DATA_READY_IS_LOW +#define GYRO_CONFIG_USE_GYRO_DEFAULT GYRO_CONFIG_USE_GYRO_1 + +//**********Mag and Baro**********// + +#define USE_MAG +#define USE_MAG_HMC5883 +#define USE_MAG_QMC5883 +#define MAG_HMC5883_ALIGN CW180_DEG +#define MAG_QMC5883_ALIGN CW180_DEG +#define MAG_I2C_INSTANCE (I2CDEV_1) + +#define USE_BARO +#define USE_BARO_MS5611 +#define USE_BARO_BMP280 +#define USE_BARO_DPS310 +#define BARO_I2C_INSTANCE (I2CDEV_1) + +//**********Serial****************// + +#define USE_VCP +//#define USE_USB_DETECT +//#define USB_DETECT_PIN PC4 + +#define USE_UART1 +#define UART1_RX_PIN PA10 +#define UART1_TX_PIN PA9 + +#define USE_UART2 +#define UART2_RX_PIN PA3 +#define UART2_TX_PIN PA2 + +#define USE_UART3 +#define UART3_RX_PIN PB11 +#define UART3_TX_PIN PB10 + +#define USE_UART4 +#define UART4_RX_PIN PA1 +#define UART4_TX_PIN PA0 + +#define USE_UART6 +#define UART6_RX_PIN PC7 +#define UART6_TX_PIN PC6 + +#define USE_UART7 +#define UART7_RX_PIN PE7 +#define UART7_TX_PIN PE8 + +#define USE_UART8 +#define UART8_RX_PIN PE0 +#define UART8_TX_PIN PE1 + +#define SERIAL_PORT_COUNT 8 //VCP, USART1, USART2, USART3, UART4, USART6, USART7, USART8 + +#define USE_ESCSERIAL +#define USE_CAMERA_CONTROL +#define CAMERA_CONTROL_PIN PB3 + +#define USE_SPI +#define USE_SPI_DEVICE_1 +#define USE_SPI_DEVICE_2 +#define USE_SPI_DEVICE_3 +#define USE_SPI_DEVICE_4 + +#define SPI1_SCK_PIN PA5 +#define SPI1_MISO_PIN PA6 +#define SPI1_MOSI_PIN PA7 + +#define SPI2_SCK_PIN PB13 +#define SPI2_MISO_PIN PB14 +#define SPI2_MOSI_PIN PB15 + +#define SPI3_SCK_PIN PC10 +#define SPI3_MISO_PIN PC11 +#define SPI3_MOSI_PIN PC12 + +#define SPI4_SCK_PIN PE2 +#define SPI4_MISO_PIN PE5 +#define SPI4_MOSI_PIN PE6 + +#define USE_MAX7456 +#define MAX7456_SPI_INSTANCE SPI4 +#define MAX7456_SPI_CS_PIN PE4 +#define MAX7456_SPI_CLK (SPI_CLOCK_STANDARD) // 10MHz +#define MAX7456_RESTORE_CLK (SPI_CLOCK_FAST) + +#define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT +#define USE_FLASHFS +#define USE_FLASH_M25P16 +#define FLASH_CS_PIN PA15 +#define FLASH_SPI_INSTANCE SPI3 + +#define USE_I2C +#define USE_I2C_DEVICE_1 +#define I2C_DEVICE_1 (I2CDEV_1) +#define I2C1_SCL PB8 +#define I2C1_SDA PB9 + +#define USE_I2C_DEVICE_2 +#define I2C_DEVICE_2 (I2CDEV_2) +#define I2C2_SCL PB10 +#define I2C2_SDA PB11 + +#define USE_ADC +#define VBAT_ADC_PIN PC3 +#define CURRENT_METER_ADC_PIN PC2 +#define RSSI_ADC_PIN PC5 +#define DEFAULT_VOLTAGE_METER_SOURCE VOLTAGE_METER_ADC +#define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC +#define CURRENT_METER_SCALE_DEFAULT 100 + +#define USE_LED_STRIP + +#define DEFAULT_FEATURES (FEATURE_OSD | FEATURE_TELEMETRY ) +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +#define SERIALRX_PROVIDER SERIALRX_SBUS + +#define TARGET_IO_PORTA 0xffff +#define TARGET_IO_PORTB 0xffff +#define TARGET_IO_PORTC 0xffff +#define TARGET_IO_PORTD 0xffff +#define TARGET_IO_PORTE 0xffff + +#define USABLE_TIMER_CHANNEL_COUNT 10 + +#define USED_TIMERS ( TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) ) diff --git a/src/main/target/IFLIGHT_F745_AIO_V2/target.mk b/src/main/target/IFLIGHT_F745_AIO_V2/target.mk new file mode 100644 index 0000000000..525f68127c --- /dev/null +++ b/src/main/target/IFLIGHT_F745_AIO_V2/target.mk @@ -0,0 +1,15 @@ +F7X5XG_TARGETS += $(TARGET) +FEATURES += VCP ONBOARDFLASH + +TARGET_SRC = \ + drivers/accgyro/accgyro_spi_mpu6000.c \ + drivers/accgyro/accgyro_mpu.c \ + drivers/barometer/barometer_ms5611.c \ + drivers/barometer/barometer_bmp280.c \ + drivers/barometer/barometer_bmp085.c \ + drivers/barometer/barometer_ms5611.c \ + drivers/compass/compass_hmc5883l.c \ + drivers/compass/compass_qmc5883l.c \ + drivers/light_ws2811strip.c \ + drivers/light_ws2811strip_hal.c \ + drivers/max7456.c From 75b47d1591249f40f1f9c0fa5aa2422f7a7d9997 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:34:21 -0500 Subject: [PATCH 06/14] [Target] JHEF7DUAL add ICM42688P (#902) add ICM42688P to JHEF7DUAL --- src/main/target/JHEF7DUAL/target.h | 7 ++++++- src/main/target/JHEF7DUAL/target.mk | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/target/JHEF7DUAL/target.h b/src/main/target/JHEF7DUAL/target.h index e7e4e5c221..1545a2a13c 100644 --- a/src/main/target/JHEF7DUAL/target.h +++ b/src/main/target/JHEF7DUAL/target.h @@ -53,10 +53,12 @@ #define USE_GYRO #define USE_GYRO_SPI_MPU6000 #define USE_GYRO_SPI_ICM20689 +#define USE_GYRO_SPI_ICM42688P #define USE_ACC #define USE_ACC_SPI_MPU6000 #define USE_ACC_SPI_ICM20689 +#define USE_ACC_SPI_ICM42688P #define ACC_ICM20689_1_ALIGN CW90_DEG #define GYRO_ICM20689_1_ALIGN CW90_DEG @@ -68,6 +70,9 @@ #define GYRO_2_ALIGN GYRO_MPU6000_2_ALIGN #define ACC_2_ALIGN ACC_MPU6000_2_ALIGN +#define ACC_ICM42688P_ALIGN CW90_DEG +#define GYRO_ICM42688P_ALIGN CW90_DEG + #define GYRO_CONFIG_USE_GYRO_DEFAULT GYRO_CONFIG_USE_GYRO_1 // *************** Baro ************************** @@ -140,7 +145,7 @@ #define USE_ADC #define ADC_INSTANCE ADC3 -#define ADC3_DMA_OPT 0 // DMA 2 Stream 0 Channel 2 +#define ADC3_DMA_OPT 0 // DMA 2 Stream 0 Channel 2 #define CURRENT_METER_ADC_PIN PC1 #define VBAT_ADC_PIN PC2 diff --git a/src/main/target/JHEF7DUAL/target.mk b/src/main/target/JHEF7DUAL/target.mk index 8b16c3f1b2..42e86d325d 100644 --- a/src/main/target/JHEF7DUAL/target.mk +++ b/src/main/target/JHEF7DUAL/target.mk @@ -5,6 +5,7 @@ TARGET_SRC = \ drivers/accgyro/accgyro_mpu.c \ drivers/accgyro/accgyro_spi_mpu6000.c \ drivers/accgyro/accgyro_spi_icm20689.c \ + drivers/accgyro/accgyro_spi_icm426xx.c \ drivers/barometer/barometer_bmp280.c \ drivers/compass/compass_fake.c \ drivers/light_ws2811strip.c \ From b54d768a99a0ab8a4b4474e3682445fc726a9379 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:44:33 -0500 Subject: [PATCH 07/14] [Target] GEPRC_F722_AIO ICM42688P (#903) * GEPRC_F722_AIO ICM42688P Co-authored-by: BeauBrewski <85623381+BeauBrewski@users.noreply.github.com> --- src/main/target/GEPRC_F722_AIO/target.c | 45 +++++++ src/main/target/GEPRC_F722_AIO/target.h | 158 +++++++++++++++++++++++ src/main/target/GEPRC_F722_AIO/target.mk | 15 +++ 3 files changed, 218 insertions(+) create mode 100644 src/main/target/GEPRC_F722_AIO/target.c create mode 100644 src/main/target/GEPRC_F722_AIO/target.h create mode 100644 src/main/target/GEPRC_F722_AIO/target.mk diff --git a/src/main/target/GEPRC_F722_AIO/target.c b/src/main/target/GEPRC_F722_AIO/target.c new file mode 100644 index 0000000000..5fdda10d02 --- /dev/null +++ b/src/main/target/GEPRC_F722_AIO/target.c @@ -0,0 +1,45 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#include + +#include "platform.h" +#include "drivers/io.h" + +#include "drivers/dma.h" +#include "drivers/timer.h" +#include "drivers/timer_def.h" + +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { +DEF_TIM(TIM5, CH1, PA0, TIM_USE_ANY, 0, 0), //CAMERA CONTROL +DEF_TIM(TIM9, CH2, PA3, TIM_USE_ANY, 0, 0), //PPM + +DEF_TIM(TIM8, CH4, PC9, TIM_USE_MOTOR, 0, 0), //MOTOR 1 +DEF_TIM(TIM8, CH3, PC8, TIM_USE_MOTOR, 0, 1), //MOTOR 2 +DEF_TIM(TIM8, CH2, PC7, TIM_USE_MOTOR, 0, 1), //MOTOR 3 +DEF_TIM(TIM8, CH1, PC6, TIM_USE_MOTOR, 0, 0), //MOTOR 4 + +//DEF_TIM(TIM4, CH1, PB6, TIM_USE_ANY, 0, 0), //in config but match no pins +//DEF_TIM(TIM4, CH2, PB7, TIM_USE_ANY, 0, 0), //pretty sure left over from +//DEF_TIM(TIM3, CH4, PB1, TIM_USE_ANY, 0, 0), //geprc_f722_bthd target/config +//DEF_TIM(TIM3, CH3, PB0, TIM_USE_ANY, 0, 0), //as match motors 5-8 + +DEF_TIM(TIM2, CH2, PA1, TIM_USE_LED, 0, 0) //LED +}; diff --git a/src/main/target/GEPRC_F722_AIO/target.h b/src/main/target/GEPRC_F722_AIO/target.h new file mode 100644 index 0000000000..2cb368bae7 --- /dev/null +++ b/src/main/target/GEPRC_F722_AIO/target.h @@ -0,0 +1,158 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + * + * Prepared by Kaio + */ +#pragma once + +#define TARGET_BOARD_IDENTIFIER "S7X2" +#define USBD_PRODUCT_STRING "GEPRC_F722_AIO" +#define TARGET_MANUFACTURER_IDENTIFIER "GEPR" + +#define LED0_PIN PC4 + +#define USE_BEEPER +#define BEEPER_PIN PC15 +#define BEEPER_INVERTED + +#define ENABLE_DSHOT_DMAR true + +#define USE_EXTI +#define MPU_INT_EXTI PA8 +#define USE_MPU_DATA_READY_SIGNAL + +#define USE_GYRO + +#define USE_GYRO_SPI_ICM42688P +#define ICM42688P_CS_PIN PA15 +#define ICM42688P_SPI_INSTANCE SPI1 +#define GYRO_ICM42688P_ALIGN CW90_DEG + +#define USE_GYRO_SPI_MPU6000 +#define MPU6000_CS_PIN PA15 +#define MPU6000_SPI_INSTANCE SPI1 +#define GYRO_MPU6000_ALIGN CW90_DEG + +#define USE_ACC + +#define USE_ACC_SPI_ICM42688P +#define ACC_ICM42688P_ALIGN CW90_DEG + +#define USE_ACC_SPI_MPU6000 +#define USE_ACC_SPI_MPU6500 +#define ACC_MPU6000_ALIGN CW90_DEG + +#define USE_BARO +#define USE_BARO_BMP280 +#define USE_BARO_BMP085 +#define USE_BARO_MS5611 +#define BARO_I2C_INSTANCE (I2CDEV_2) + +#define USE_MAG +#define USE_MAG_HMC5883 +#define USE_MAG_QMC5883 +#define MAG_I2C_INSTANCE (I2CDEV_2) + +#define USE_MAX7456 +#define MAX7456_SPI_INSTANCE SPI2 +#define MAX7456_SPI_CS_PIN PB12 + +#define USE_FLASHFS +#define USE_FLASH_M25P16 +#define FLASH_SPI_INSTANCE SPI3 +#define FLASH_CS_PIN PB9 +#define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT + +#define USE_VCP +#define USE_USB_DETECT + +#define USE_UART1 +#define UART1_RX_PIN PA10 +#define UART1_TX_PIN PA9 + +#define USE_UART2 +#define UART2_RX_PIN PA3 +#define UART2_TX_PIN PA2 + +#define USE_UART3 +#define UART3_RX_PIN PB11 +#define UART3_TX_PIN PB10 + +#define USE_UART4 +#define UART4_RX_PIN PC11 +#define UART4_TX_PIN PC10 + +#define USE_UART5 +#define UART5_RX_PIN PD2 +#define UART5_TX_PIN PC12 + +#define SERIAL_PORT_COUNT 6 //USB + 5 UARTS + +#define USE_ESCSERIAL //PPM +#define ESCSERIAL_TIMER_TX_PIN PA3 + +#define USE_SPI +#define USE_SPI_DEVICE_1 +#define SPI1_SCK_PIN PA5 +#define SPI1_MISO_PIN PA6 +#define SPI1_MOSI_PIN PA7 + +#define USE_SPI_DEVICE_2 +#define SPI2_SCK_PIN PB13 +#define SPI2_MISO_PIN PB14 +#define SPI2_MOSI_PIN PB15 + +#define USE_SPI_DEVICE_3 +#define SPI3_SCK_PIN PB3 +#define SPI3_MISO_PIN PB4 +#define SPI3_MOSI_PIN PB5 + +//#define USE_I2C +//#define USE_I2C_DEVICE_1 +//#define I2C1_SCL PB8 +//#define I2C1_SDA PB9 +//#define I2C_DEVICE (I2CDEV_1) + +#define USE_I2C_DEVICE_2 +#define I2C2_SCL PB10 +#define I2C2_SDA PB11 +#define I2C_DEVICE (I2CDEV_2) + +#define USE_ADC +#define ADC3_DMA_STREAM DMA2_Stream0 +#define VBAT_ADC_PIN PC2 +#define CURRENT_METER_ADC_PIN PC1 +//#define RSSI_ADC_PIN PC2 +#define DEFAULT_VOLTAGE_METER_SOURCE VOLTAGE_METER_ADC +#define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC +#define CURRENT_METER_SCALE_DEFAULT 100 + +#define SERIALRX_PROVIDER SERIALRX_SBUS +//#define SERIALRX_UART SERIAL_PORT_USART2 + +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +#define DEFAULT_FEATURES ( FEATURE_OSD | FEATURE_TELEMETRY ) + +#define TARGET_IO_PORTA ( 0xffff ) +#define TARGET_IO_PORTB ( 0xffff ) +#define TARGET_IO_PORTC ( 0xffff ) +#define TARGET_IO_PORTD ( 0xffff ) + +#define USABLE_TIMER_CHANNEL_COUNT 7 +#define USED_TIMERS ( TIM_N(2) | TIM_N(5) | TIM_N(8) | TIM_N(9) ) diff --git a/src/main/target/GEPRC_F722_AIO/target.mk b/src/main/target/GEPRC_F722_AIO/target.mk new file mode 100644 index 0000000000..ed078d59ff --- /dev/null +++ b/src/main/target/GEPRC_F722_AIO/target.mk @@ -0,0 +1,15 @@ +F7X2RE_TARGETS += $(TARGET) +FEATURES += VCP ONBOARDFLASH +TARGET_SRC = \ + drivers/accgyro/accgyro_spi_icm426xx.c \ + drivers/accgyro/accgyro_mpu.c \ + drivers/accgyro/accgyro_mpu6500.c \ + drivers/accgyro/accgyro_spi_mpu6000.c \ + drivers/accgyro/accgyro_spi_mpu6500.c \ + drivers/barometer/barometer_ms5611.c \ + drivers/barometer/barometer_bmp280.c \ + drivers/barometer/barometer_bmp085.c \ + drivers/compass/compass_hmc5883l.c \ + drivers/compass/compass_qmc5883l.c \ + drivers/max7456.c\ + drivers/light_ws2811strip.c From 11d38e5a06dee654f359d5681b4c4473b4e22b92 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:00:18 -0500 Subject: [PATCH 08/14] [Target] RUSHBLADEF7HD add ICM42688P (#904) * RUSHBLADEF7HD; ICM42688P, MPU6000 --- .../target.c | 0 src/main/target/RUSHBLADEF7HD/target.h | 156 ++++++++++++++++++ src/main/target/RUSHBLADEF7HD/target.mk | 12 ++ src/main/target/RUSH_BLADE_F7_HD/target.h | 151 ----------------- src/main/target/RUSH_BLADE_F7_HD/target.mk | 11 -- 5 files changed, 168 insertions(+), 162 deletions(-) rename src/main/target/{RUSH_BLADE_F7_HD => RUSHBLADEF7HD}/target.c (100%) create mode 100644 src/main/target/RUSHBLADEF7HD/target.h create mode 100644 src/main/target/RUSHBLADEF7HD/target.mk delete mode 100644 src/main/target/RUSH_BLADE_F7_HD/target.h delete mode 100644 src/main/target/RUSH_BLADE_F7_HD/target.mk diff --git a/src/main/target/RUSH_BLADE_F7_HD/target.c b/src/main/target/RUSHBLADEF7HD/target.c similarity index 100% rename from src/main/target/RUSH_BLADE_F7_HD/target.c rename to src/main/target/RUSHBLADEF7HD/target.c diff --git a/src/main/target/RUSHBLADEF7HD/target.h b/src/main/target/RUSHBLADEF7HD/target.h new file mode 100644 index 0000000000..3041655e66 --- /dev/null +++ b/src/main/target/RUSHBLADEF7HD/target.h @@ -0,0 +1,156 @@ +/* +* This file is part of Cleanflight and Betaflight. +* +* Cleanflight and Betaflight are free software. You can redistribute +* this software and/or modify this software under the terms of the +* GNU General Public License as published by the Free Software +* Foundation, either version 3 of the License, or (at your option) +* any later version. +* +* Cleanflight and Betaflight are distributed in the hope that they +* will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* See the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this software. +* +* If not, see . +*/ + +#pragma once +//#define USE_TARGET_CONFIG + +#define TARGET_BOARD_IDENTIFIER "RUSH" +#define USBD_PRODUCT_STRING "BLADE_F7_HD" + +#define ENABLE_DSHOT_DMAR true + +#define USE_LED_STRIP + +#define LED0_PIN PB10 + +#define USE_BEEPER +#define BEEPER_PIN PB2 +#define BEEPER_INVERTED + + +// *************** SPI1 Gyro & ACC ******************* + +#define USE_SPI +#define USE_SPI_DEVICE_1 +#define SPI1_SCK_PIN PA5 +#define SPI1_MISO_PIN PA6 +#define SPI1_MOSI_PIN PA7 + +#define USE_EXTI +#define USE_GYRO +#define USE_ACC + +#define USE_GYRO_SPI_MPU6000 +#define USE_ACC_SPI_MPU6000 +#define MPU6000_CS_PIN PC4 +#define MPU_INT_EXTI PA4 +#define MPU6000_SPI_INSTANCE SPI1 +#define GYRO_MPU6000_ALIGN CW270_DEG +#define ACC_MPU6000_ALIGN CW270_DEG + +#define USE_GYRO_SPI_ICM42688P +#define USE_ACC_SPI_ICM42688P +#define ICM42688P_EXTI_PIN PA4 +#define ICM42688P_CS_PIN PC4 +#define ICM42688P_SPI_INSTANCE SPI1 +#define GYRO_ICM42688P_ALIGN CW270_DEG +#define ACC_ICM42688P_ALIGN CW270_DEG + +#define USE_MPU_DATA_READY_SIGNAL +#define ENSURE_MPU_DATA_READY_IS_LOW + +// *************** I2C /Baro/Mag ********************* + +#define USE_I2C + +#define USE_I2C_DEVICE_1 +#define I2C_DEVICE_1 (I2CDEV_1) +#define I2C1_SCL PB8 +#define I2C1_SDA PB9 + +#define BARO_I2C_INSTANCE (I2CDEV_1) +#define USE_BARO +#define USE_BARO_BMP280 +#define USE_BARO_MS5611 +#define USE_BARO_BMP085 + +//#define MAG_I2C_INSTANCE (I2CDEV_1) +//#define USE_MAG +//#define USE_MAG_HMC5883 +//#define USE_MAG_QMC5883 + +// *************** SPI3 BLACKBOX**************** + +#define USE_SPI_DEVICE_2 +#define SPI2_SCK_PIN PB13 +#define SPI2_MISO_PIN PB14 +#define SPI2_MOSI_PIN PB15 + +#define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT +#define USE_FLASHFS +#define USE_FLASH_M25P16 +#define FLASH_CS_PIN PB12 +#define FLASH_SPI_INSTANCE SPI2 + +// *************** UART ***************************** + +#define USE_VCP +#define USE_USB_DETECT + +#define USE_UART1 +#define UART1_TX_PIN PA9 +#define UART1_RX_PIN PA10 + +#define USE_UART2 +#define UART2_TX_PIN PA2 +#define UART2_RX_PIN PA3 + +#define USE_UART3 +#define UART3_TX_PIN PC10 +#define UART3_RX_PIN PC11 + +#define USE_UART4 +#define UART4_TX_PIN PA0 +#define UART4_RX_PIN PA1 + +#define USE_UART5 +#define UART5_TX_PIN PC12 +#define UART5_RX_PIN PD2 + +#define SERIAL_PORT_COUNT 6 + +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +#define SERIALRX_PROVIDER SERIALRX_SBUS +#define SERIALRX_UART SERIAL_PORT_USART2 + +// *************** ADC ***************************** +#define USE_ADC +//#define ADC1_DMA_STREAM DMA2_Stream0 +#define VBAT_ADC_PIN PC0 +#define CURRENT_METER_ADC_PIN PC1 +//#define RSSI_ADC_PIN PC1 + +// *************** Others *************************** + + +#define DEFAULT_FEATURES ( FEATURE_TELEMETRY ) +#define DEFAULT_VOLTAGE_METER_SOURCE VOLTAGE_METER_ADC +#define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC +#define CURRENT_METER_SCALE_DEFAULT 179 + +#define USE_ESCSERIAL + +#define TARGET_IO_PORTA 0xffff +#define TARGET_IO_PORTB 0xffff +#define TARGET_IO_PORTC 0xffff +#define TARGET_IO_PORTD 0xffff + +#define USABLE_TIMER_CHANNEL_COUNT 10 +#define USED_TIMERS (TIM_N(1)|TIM_N(2)|TIM_N(3)|TIM_N(4)|TIM_N(8)) diff --git a/src/main/target/RUSHBLADEF7HD/target.mk b/src/main/target/RUSHBLADEF7HD/target.mk new file mode 100644 index 0000000000..4a0083c78c --- /dev/null +++ b/src/main/target/RUSHBLADEF7HD/target.mk @@ -0,0 +1,12 @@ +F7X2RE_TARGETS += $(TARGET) +FEATURES += VCP ONBOARDFLASH + +TARGET_SRC = \ +drivers/accgyro/accgyro_mpu.c \ +drivers/accgyro/accgyro_spi_mpu6000.c \ +drivers/accgyro/accgyro_spi_icm426xx.c \ +drivers/barometer/barometer_ms5611.c \ +drivers/barometer/barometer_bmp280.c \ +drivers/barometer/barometer_bmp085.c \ +drivers/light_ws2811strip.c \ +drivers/max7456.c diff --git a/src/main/target/RUSH_BLADE_F7_HD/target.h b/src/main/target/RUSH_BLADE_F7_HD/target.h deleted file mode 100644 index 1ad1a5f0c1..0000000000 --- a/src/main/target/RUSH_BLADE_F7_HD/target.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of Cleanflight and Betaflight. - * - * Cleanflight and Betaflight are free software. You can redistribute - * this software and/or modify this software under the terms of the - * GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) - * any later version. - * - * Cleanflight and Betaflight are distributed in the hope that they - * will be useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software. - * - * If not, see . - */ - - #pragma once - //#define USE_TARGET_CONFIG - - #define TARGET_BOARD_IDENTIFIER "RUSH" - #define USBD_PRODUCT_STRING "BLADE_F7_HD" - - #define ENABLE_DSHOT_DMAR true - - #define USE_LED_STRIP - - #define LED0_PIN PB10 - - #define USE_BEEPER - #define BEEPER_PIN PB2 - #define BEEPER_INVERTED - - - // *************** SPI1 Gyro & ACC ******************* - - #define USE_SPI - #define USE_SPI_DEVICE_1 - #define SPI1_SCK_PIN PA5 - #define SPI1_MISO_PIN PA6 - #define SPI1_MOSI_PIN PA7 - - #define USE_EXTI - #define MPU_INT_EXTI PA4 - - #define MPU6000_CS_PIN PC4 - #define MPU6000_SPI_INSTANCE SPI1 - - #define USE_GYRO - #define USE_GYRO_SPI_MPU6000 - - #define USE_ACC - #define USE_ACC_SPI_MPU6000 - - #define GYRO_MPU6000_ALIGN CW270_DEG - #define ACC_MPU6000_ALIGN CW270_DEG - - #define USE_MPU_DATA_READY_SIGNAL - #define ENSURE_MPU_DATA_READY_IS_LOW - - // *************** I2C /Baro/Mag ********************* - - #define USE_I2C - - #define USE_I2C_DEVICE_1 - #define I2C_DEVICE_1 (I2CDEV_1) - #define I2C1_SCL PB8 - #define I2C1_SDA PB9 - - #define BARO_I2C_INSTANCE (I2CDEV_1) - #define USE_BARO - #define USE_BARO_BMP280 - #define USE_BARO_MS5611 - #define USE_BARO_BMP085 - - //#define MAG_I2C_INSTANCE (I2CDEV_1) - //#define USE_MAG - //#define USE_MAG_HMC5883 - //#define USE_MAG_QMC5883 - - // *************** SPI3 BLACKBOX**************** - - #define USE_SPI_DEVICE_2 - #define SPI2_SCK_PIN PB13 - #define SPI2_MISO_PIN PB14 - #define SPI2_MOSI_PIN PB15 - - #define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT - #define USE_FLASHFS - #define USE_FLASH_M25P16 - #define FLASH_CS_PIN PB12 - #define FLASH_SPI_INSTANCE SPI2 - - // *************** UART ***************************** - - #define USE_VCP - #define USE_USB_DETECT - - #define USE_UART1 - #define UART1_TX_PIN PA9 - #define UART1_RX_PIN PA10 - - #define USE_UART2 - #define UART2_TX_PIN PA2 - #define UART2_RX_PIN PA3 - - #define USE_UART3 - #define UART3_TX_PIN PC10 - #define UART3_RX_PIN PC11 - - #define USE_UART4 - #define UART4_TX_PIN PA0 - #define UART4_RX_PIN PA1 - - #define USE_UART5 - #define UART5_TX_PIN PC12 - #define UART5_RX_PIN PD2 - - #define SERIAL_PORT_COUNT 6 - - #define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL - #define SERIALRX_PROVIDER SERIALRX_SBUS - #define SERIALRX_UART SERIAL_PORT_USART2 - - // *************** ADC ***************************** - #define USE_ADC - //#define ADC1_DMA_STREAM DMA2_Stream0 - #define VBAT_ADC_PIN PC0 - #define CURRENT_METER_ADC_PIN PC1 - //#define RSSI_ADC_PIN PC1 - - // *************** Others *************************** - - - #define DEFAULT_FEATURES ( FEATURE_TELEMETRY ) - #define DEFAULT_VOLTAGE_METER_SOURCE VOLTAGE_METER_ADC - #define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC - #define CURRENT_METER_SCALE_DEFAULT 179 - - #define USE_ESCSERIAL - - #define TARGET_IO_PORTA 0xffff - #define TARGET_IO_PORTB 0xffff - #define TARGET_IO_PORTC 0xffff - #define TARGET_IO_PORTD 0xffff - - #define USABLE_TIMER_CHANNEL_COUNT 10 - #define USED_TIMERS (TIM_N(1)|TIM_N(2)|TIM_N(3)|TIM_N(4)|TIM_N(8)) diff --git a/src/main/target/RUSH_BLADE_F7_HD/target.mk b/src/main/target/RUSH_BLADE_F7_HD/target.mk deleted file mode 100644 index 3b2730cf37..0000000000 --- a/src/main/target/RUSH_BLADE_F7_HD/target.mk +++ /dev/null @@ -1,11 +0,0 @@ -F7X2RE_TARGETS += $(TARGET) -FEATURES += VCP ONBOARDFLASH - -TARGET_SRC = \ - drivers/accgyro/accgyro_mpu.c \ - drivers/accgyro/accgyro_spi_mpu6000.c \ - drivers/barometer/barometer_ms5611.c \ - drivers/barometer/barometer_bmp280.c \ - drivers/barometer/barometer_bmp085.c \ - drivers/light_ws2811strip.c \ - drivers/max7456.c From 9d0485114d549d402e8e82535549902dc9029c9a Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:06:20 -0500 Subject: [PATCH 09/14] [Target] BETAFPVF722 add ICM42688P; fix Timers (#905) BETAFPVF722 add ICM42688P; fix Timers Co-authored-by: BeauBrewski <85623381+BeauBrewski@users.noreply.github.com> --- src/main/target/BETAFPVF722/target.c | 4 +--- src/main/target/BETAFPVF722/target.h | 17 ++++++++++++++--- src/main/target/BETAFPVF722/target.mk | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/target/BETAFPVF722/target.c b/src/main/target/BETAFPVF722/target.c index 1af98e92f5..b2aeb61ba6 100644 --- a/src/main/target/BETAFPVF722/target.c +++ b/src/main/target/BETAFPVF722/target.c @@ -28,8 +28,7 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { // FILO arrangement for motor assignments, Motor 1 starts at 2nd DECLARATION - DEF_TIM(TIM8, CH3, PC8, TIM_USE_ANY, 0, 0), // USE FOR CAMERA CONTROL - + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 0, 0), // D1-ST0 MOTOR1 DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 0, 0), // D1-ST3 MOTOR2 DEF_TIM(TIM2, CH2, PA1, TIM_USE_MOTOR, 0, 0), // D1-ST7 MOTOR3 @@ -38,5 +37,4 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { DEF_TIM(TIM4, CH2, PB7, TIM_USE_MOTOR, 0, 0), // NONE TIM4_UP_D1-ST6 MOTOR6 DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0, 0), // D1-ST2 LED/MOTOR5 - }; diff --git a/src/main/target/BETAFPVF722/target.h b/src/main/target/BETAFPVF722/target.h index 31821bc7b2..595a08c5f2 100644 --- a/src/main/target/BETAFPVF722/target.h +++ b/src/main/target/BETAFPVF722/target.h @@ -33,7 +33,7 @@ #define BEEPER_INVERTED //define camera control -#define CAMERA_CONTROL_PIN PC8 +// N/A //MPU-6000 #define USE_GYRO @@ -49,6 +49,16 @@ #define GYRO_MPU6000_ALIGN CW180_DEG #define ACC_MPU6000_ALIGN CW180_DEG + +// ICM42688P +#define USE_GYRO_SPI_ICM42688P +#define USE_ACC_SPI_ICM42688P +#define ICM42688P_CS_PIN PA4 +#define ICM42688P_SPI_INSTANCE SPI1 +#define GYRO_ICM42688P_ALIGN CW180_DEG +#define ACC_ICM42688P_ALIGN CW180_DEG + + // OSD #define USE_MAX7456 #define MAX7456_SPI_INSTANCE SPI3 @@ -120,6 +130,7 @@ #define VBAT_ADC_PIN PC0 #define RSSI_ADC_PIN PC2 #define CURRENT_METER_SCALE_DEFAULT 450 // 3.3/120A = 25mv/A +#define USE_SERIAL_4WAY_BLHELI_INTERFACE // SPI devices #define USE_SPI @@ -154,5 +165,5 @@ #define TARGET_IO_PORTD (BIT(2)) // timers -#define USABLE_TIMER_CHANNEL_COUNT 8 -#define USED_TIMERS ( TIM_N(1) |TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(8) ) +#define USABLE_TIMER_CHANNEL_COUNT 7 +#define USED_TIMERS ( TIM_N(1) |TIM_N(2) | TIM_N(3) | TIM_N(4) ) diff --git a/src/main/target/BETAFPVF722/target.mk b/src/main/target/BETAFPVF722/target.mk index 56beeaedad..0da79a44b5 100644 --- a/src/main/target/BETAFPVF722/target.mk +++ b/src/main/target/BETAFPVF722/target.mk @@ -4,6 +4,7 @@ FEATURES = VCP ONBOARDFLASH TARGET_SRC = \ drivers/accgyro/accgyro_spi_mpu6000.c \ drivers/accgyro/accgyro_mpu.c \ +drivers/accgyro/accgyro_spi_icm426xx.c \ drivers/barometer/barometer_bmp280.c \ drivers/barometer/barometer_ms5611.c \ drivers/compass/compass_hmc5883l.c \ From 43543b4de7d7e6e1f3b2d97d4f95bb5bf8583e7c Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:52:56 -0500 Subject: [PATCH 10/14] [Target] JHEF411 - add ICM42688P (#925) JHEF411 - add ICM42688P --- src/main/target/JHEF411/target.h | 7 +++++++ src/main/target/JHEF411/target.mk | 1 + 2 files changed, 8 insertions(+) diff --git a/src/main/target/JHEF411/target.h b/src/main/target/JHEF411/target.h index f4c720412c..7db7a91a6d 100644 --- a/src/main/target/JHEF411/target.h +++ b/src/main/target/JHEF411/target.h @@ -56,6 +56,13 @@ #define USE_ACC #define USE_ACC_SPI_MPU6000 #define ACC_MPU6000_ALIGN CW180_DEG + +#define USE_ACC_SPI_ICM42688P +#define USE_GYRO_SPI_ICM42688P +#define ICM42688P_CS_PIN PA4 +#define ICM42688P_SPI_INSTANCE SPI1 +#define ACC_ICM42688P_ALIGN CW180_DEG +#define GYRO_ICM42688P_ALIGN CW180_DEG // *************** Baro ************************** #define USE_I2C diff --git a/src/main/target/JHEF411/target.mk b/src/main/target/JHEF411/target.mk index a22931f0a8..04a1ea3283 100644 --- a/src/main/target/JHEF411/target.mk +++ b/src/main/target/JHEF411/target.mk @@ -4,6 +4,7 @@ FEATURES += VCP ONBOARDFLASH TARGET_SRC = \ drivers/accgyro/accgyro_mpu.c \ drivers/accgyro/accgyro_spi_mpu6000.c \ + drivers/accgyro/accgyro_spi_icm426xx.c \ drivers/barometer/barometer_bmp085.c \ drivers/barometer/barometer_bmp280.c \ drivers/barometer/barometer_ms5611.c \ From 548e054af08b7baa048ca8670d94db22cd2f9bb1 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:41:26 -0500 Subject: [PATCH 11/14] [Target Fix] MATEKF722SE - allow mpu6500 on gyro 1 and/or mpu6000 on gyro 2 (#928) [Target Fix] MATEKF722SE allow MPU6500 on gyro 1 and MPU6000 on gyro 2 --- src/main/target/MATEKF722SE/target.h | 14 +++++++++----- src/main/target/MATEKF722SE/target.mk | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/target/MATEKF722SE/target.h b/src/main/target/MATEKF722SE/target.h index df30407eda..dc89a9529d 100755 --- a/src/main/target/MATEKF722SE/target.h +++ b/src/main/target/MATEKF722SE/target.h @@ -46,7 +46,7 @@ #define USE_EXTI #define GYRO_1_EXTI_PIN PC4 #define GYRO_2_EXTI_PIN PC3 -#define MPU_INT_EXTI +#define MPU_INT_EXTI PC4 #define GYRO_1_CS_PIN PB2 #define GYRO_1_SPI_INSTANCE SPI1 @@ -61,15 +61,19 @@ #define USE_ACC_SPI_MPU6000 #define USE_ACC_SPI_MPU6500 +#define GYRO_1_ALIGN CW180_DEG_FLIP +#define ACC_1_ALIGN CW180_DEG_FLIP #define GYRO_MPU6000_1_ALIGN CW180_DEG_FLIP #define ACC_MPU6000_1_ALIGN CW180_DEG_FLIP -#define GYRO_1_ALIGN GYRO_MPU6000_1_ALIGN -#define ACC_1_ALIGN ACC_MPU6000_1_ALIGN +#define GYRO_MPU6500_1_ALIGN CW180_DEG_FLIP +#define ACC_MPU6500_1_ALIGN CW180_DEG_FLIP +#define GYRO_2_ALIGN CW90_DEG +#define ACC_2_ALIGN CW90_DEG #define GYRO_MPU6500_2_ALIGN CW90_DEG #define ACC_MPU6500_2_ALIGN CW90_DEG -#define GYRO_2_ALIGN GYRO_MPU6500_2_ALIGN -#define ACC_2_ALIGN ACC_MPU6500_2_ALIGN +#define GYRO_MPU6000_2_ALIGN CW90_DEG +#define ACC_MPU6000_2_ALIGN CW90_DEG #define USE_MPU_DATA_READY_SIGNAL #define ENSURE_MPU_DATA_READY_IS_LOW diff --git a/src/main/target/MATEKF722SE/target.mk b/src/main/target/MATEKF722SE/target.mk index db67145925..cd0322069a 100755 --- a/src/main/target/MATEKF722SE/target.mk +++ b/src/main/target/MATEKF722SE/target.mk @@ -3,6 +3,7 @@ FEATURES += VCP ONBOARDFLASH SDCARD TARGET_SRC = \ + drivers/accgyro/accgyro_mpu.c \ drivers/accgyro/accgyro_spi_mpu6500.c \ drivers/accgyro/accgyro_mpu6500.c \ drivers/accgyro/accgyro_spi_mpu6000.c \ From 9d64ef641d7713ec5e84c66552dd36db809133dc Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:49:49 -0500 Subject: [PATCH 12/14] [Target] DIAT_MAMBAF405_2022B - MPU6000, MPU6500, ICM42688P (#908) [Target] DIAT_MAMBAF405_2022B - MPU6000, MPU6500, ICM42688P --- src/main/target/DIAT_MAMBAF405_2022B/target.c | 41 +++++ src/main/target/DIAT_MAMBAF405_2022B/target.h | 164 ++++++++++++++++++ .../target/DIAT_MAMBAF405_2022B/target.mk | 16 ++ 3 files changed, 221 insertions(+) create mode 100644 src/main/target/DIAT_MAMBAF405_2022B/target.c create mode 100644 src/main/target/DIAT_MAMBAF405_2022B/target.h create mode 100644 src/main/target/DIAT_MAMBAF405_2022B/target.mk diff --git a/src/main/target/DIAT_MAMBAF405_2022B/target.c b/src/main/target/DIAT_MAMBAF405_2022B/target.c new file mode 100644 index 0000000000..37e46483ec --- /dev/null +++ b/src/main/target/DIAT_MAMBAF405_2022B/target.c @@ -0,0 +1,41 @@ +/* + * This file is part of EmuFlight. It is derived from Betaflight. + * + * This is free software. You can redistribute this software + * and/or modify this software under the terms of the GNU General + * Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later + * version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software. + * + * If not, see . + */ + +#include +#include "platform.h" +#include "drivers/io.h" +#include "drivers/dma.h" +#include "drivers/timer.h" +#include "drivers/timer_def.h" + +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + DEF_TIM(TIM2, CH2, PB3, TIM_USE_LED, 0, 0 ), // LED_STRIP, + DEF_TIM(TIM4, CH3, PB8, TIM_USE_ANY, 0, 0), // baro/mag // no dps310 in EmuFlight, + DEF_TIM(TIM11, CH1, PB9, TIM_USE_ANY, 0, 0), // baro/mag // no dps310 in EmuFlight, + DEF_TIM(TIM1, CH2, PA9, TIM_USE_MOTOR, 0, 0 ), // M1 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MOTOR, 0, 0 ), // M2 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MOTOR, 0, 0 ), // M3 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MOTOR, 0, 0 ), // M4 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 0, 0 ), // M5 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 0, 0 ), // M6 +}; + +// notice - this file was programmatically generated and may be incomplete. diff --git a/src/main/target/DIAT_MAMBAF405_2022B/target.h b/src/main/target/DIAT_MAMBAF405_2022B/target.h new file mode 100644 index 0000000000..2e8faaa864 --- /dev/null +++ b/src/main/target/DIAT_MAMBAF405_2022B/target.h @@ -0,0 +1,164 @@ +/* + * This file is part of EmuFlight. It is derived from Betaflight. + * + * This is free software. You can redistribute this software + * and/or modify this software under the terms of the GNU General + * Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later + * version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software. + * + * If not, see . + */ + +#pragma once + +#define TARGET_BOARD_IDENTIFIER "DIAT" +#define USBD_PRODUCT_STRING "MAMBAF405_2022B" + +#define USE_ACC +#define USE_ACC_SPI_MPU6000 +#define USE_GYRO +#define USE_GYRO_SPI_MPU6000 +#define USE_ACC_SPI_MPU6500 +#define USE_GYRO_SPI_MPU6500 +#define USE_GYRO_SPI_ICM42688P +#define USE_ACC_SPI_ICM42688P +#define USE_BARO_DPS310 +#define USE_FLASH +#define USE_FLASH_M25P16 +#define USE_MAX7456 +#define USE_BARO +#define USE_ADC +#define USE_SPI_GYRO + +#define USE_VCP +#define USE_FLASHFS +#define USE_FLASH_M25P16 //testing +#define USE_FLASH_W25M //testing +#define USE_FLASH_W25M512 //testing +#define USE_FLASH_W25Q //testing +#define USE_OSD + +#define USE_LED +#define LED0_PIN PC15 +#define LED1_PIN PC14 +#define LED_STRIP_PIN PB3 +#define USE_BEEPER +#define BEEPER_PIN PC13 +#define BEEPER_INVERTED + +#define USE_SPI +#define USE_SPI_DEVICE_1 +#define SPI1_SCK_PIN PA5 +#define SPI1_MISO_PIN PA6 +#define SPI1_MOSI_PIN PA7 +#define USE_SPI_DEVICE_2 +#define SPI2_SCK_PIN PB13 +#define SPI2_MISO_PIN PB14 +#define SPI2_MOSI_PIN PB15 +#define USE_SPI_DEVICE_3 +#define SPI3_SCK_PIN PC10 +#define SPI3_MISO_PIN PC11 +#define SPI3_MOSI_PIN PB5 + +#define USE_EXTI +#define USE_MPU_DATA_READY_SIGNAL + +#define MPU_INT_EXTI PC4 + +#define ACC_MPU6000_ALIGN CW270_DEG +#define GYRO_MPU6000_ALIGN CW270_DEG +#define MPU6000_CS_PIN PA4 +#define MPU6000_SPI_INSTANCE SPI1 + +#define ACC_MPU6500_ALIGN CW270_DEG +#define GYRO_MPU6500_ALIGN CW270_DEG +#define MPU6500_CS_PIN PA4 +#define MPU6500_SPI_INSTANCE SPI1 + +#define ACC_ICM42688P_ALIGN CW270_DEG +#define GYRO_ICM42688P_ALIGN CW270_DEG +#define ICM42688P_CS_PIN PA4 +#define ICM42688P_SPI_INSTANCE SPI1 + +#define MAG_I2C_INSTANCE (I2CDEV_1) +#define USE_I2C +#define USE_I2C_DEVICE_1 +#define I2C_DEVICE (I2CDEV_1) +#define MAG_I2C_INSTANCE (I2CDEV_1) +#define BARO_I2C_INSTANCE (I2CDEV_1) +#define I2C1_SCL PB8 +#define I2C1_SDA PB9 +// notice - this file was programmatically generated and likely needs MAG/BARO manually added and/or verified. + +#define FLASH_CS_PIN PA15 +#define FLASH_SPI_INSTANCE SPI3 +#define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT + +#define MAX7456_SPI_CS_PIN PB12 +#define MAX7456_SPI_INSTANCE SPI2 + +#define USE_UART1 +#define USE_UART2 +#define USE_UART3 +#define USE_UART4 +#define USE_UART5 +#define USE_UART6 +#define UART1_TX_PIN PB6 +#define UART2_TX_PIN PA2 +#define UART3_TX_PIN PB10 +#define UART4_TX_PIN PA0 +#define UART5_TX_PIN PC12 +#define UART6_TX_PIN PC6 +#define UART1_RX_PIN PB7 +#define UART2_RX_PIN PA3 +#define UART3_RX_PIN PB11 +#define UART4_RX_PIN PA1 +#define UART5_RX_PIN PD2 +#define UART6_RX_PIN PC7 +#define INVERTER_PIN_UART1 PC0 +#define SERIAL_PORT_COUNT 7 +// notice - UART/USART were programmatically generated + +#define VBAT_ADC_PIN PC1 +#define CURRENT_METER_ADC_PIN PC3 +#define ADC3_DMA_STREAM DMA2_Stream0 // # ADC 3: DMA2 Stream 0 Channel 2 +#define DEFAULT_VOLTAGE_METER_SOURCE VOLTAGE_METER_ADC +#define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC +#define DEFAULT_CURRENT_METER_SCALE 183 +#define ADC_INSTANCE ADC3 +// notice - DMA conversion were programmatically generated and may be incomplete. + +#define ENABLE_DSHOT_DMAR true + +#define PINIO1_PIN PC2 +#define PINIO2_PIN PC5 +#define PINIO1_CONFIG 129 +#define PINIO2_CONFIG 129 +#define PINIO1_BOX 0 +#define PINIO2_BOX 40 +// notice - this file was programmatically generated and may not have accounted for any config instance of "#define TLM_INVERTED ON", etc. + +#define TARGET_IO_PORTA 0xffff +#define TARGET_IO_PORTB 0xffff +#define TARGET_IO_PORTC 0xffff +#define TARGET_IO_PORTD 0xffff +// notice - masks were programmatically generated - please verify last port group for 0xffff or (BIT(2)) + +#define DEFAULT_FEATURES (FEATURE_OSD | FEATURE_TELEMETRY | FEATURE_AIRMODE | FEATURE_RX_SERIAL) +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +// notice - incomplete; may need additional DEFAULT_FEATURES; e.g. FEATURE_SOFTSERIAL | FEATURE_RX_SPI + +#define USABLE_TIMER_CHANNEL_COUNT 9 +#define USED_TIMERS ( TIM_N(1)|TIM_N(2)|TIM_N(3)|TIM_N(4)|TIM_N(8)|TIM_N(11) ) + +// notice - this file was programmatically generated and may be incomplete. diff --git a/src/main/target/DIAT_MAMBAF405_2022B/target.mk b/src/main/target/DIAT_MAMBAF405_2022B/target.mk new file mode 100644 index 0000000000..775a554519 --- /dev/null +++ b/src/main/target/DIAT_MAMBAF405_2022B/target.mk @@ -0,0 +1,16 @@ +F405_TARGETS += $(TARGET) +FEATURES += VCP ONBOARDFLASH + +TARGET_SRC = \ +drivers/accgyro/accgyro_mpu.c \ +drivers/accgyro/accgyro_spi_mpu6000.c \ +drivers/accgyro/accgyro_mpu6500.c \ +drivers/accgyro/accgyro_spi_mpu6500.c \ +drivers/accgyro/accgyro_spi_icm426xx.c \ +drivers/light_led.h \ +drivers/light_ws2811strip.c \ +drivers/pinio.c \ +drivers/max7456.c \ + +# notice - this file was programmatically generated and may be incomplete. +# eg: flash, compass, barometer, vtx6705, ledstrip, pinio, etc. From 41cfd39355b2dcc67f4a7883a3dccaf1ca5e044f Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:04:14 -0500 Subject: [PATCH 13/14] add rc rates_type to BBL header (#931) --- src/main/blackbox/blackbox.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index 8ee2428c8d..b17ed12485 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1138,6 +1138,7 @@ static bool blackboxWriteSysinfo(void) { BLACKBOX_PRINT_HEADER_LINE("spa_yaw_p", "%d", currentPidProfile->setPointPTransition[YAW]); BLACKBOX_PRINT_HEADER_LINE("spa_yaw_i", "%d", currentPidProfile->setPointITransition[YAW]); BLACKBOX_PRINT_HEADER_LINE("spa_yaw_d", "%d", currentPidProfile->setPointDTransition[YAW]); + BLACKBOX_PRINT_HEADER_LINE("rates_type", "%d", currentControlRateProfile->rates_type); BLACKBOX_PRINT_HEADER_LINE("rc_rates", "%d,%d,%d", currentControlRateProfile->rcRates[ROLL], currentControlRateProfile->rcRates[PITCH], currentControlRateProfile->rcRates[YAW]); From c55b0d708bcd9d4d127a8ae5523861bddbadf5c3 Mon Sep 17 00:00:00 2001 From: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:05:21 -0500 Subject: [PATCH 14/14] add motor_poles to BBL header (#932) * add motor_poles to BBL header --- src/main/blackbox/blackbox.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index b17ed12485..5797c373a8 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1267,6 +1267,7 @@ static bool blackboxWriteSysinfo(void) { BLACKBOX_PRINT_HEADER_LINE("motor_pwm_protocol", "%d", motorConfig()->dev.motorPwmProtocol); BLACKBOX_PRINT_HEADER_LINE("motor_pwm_rate", "%d", motorConfig()->dev.motorPwmRate); BLACKBOX_PRINT_HEADER_LINE("dshot_idle_value", "%d", motorConfig()->digitalIdleOffsetValue); + BLACKBOX_PRINT_HEADER_LINE("motor_poles", "%d", motorConfig()->motorPoleCount); BLACKBOX_PRINT_HEADER_LINE("debug_mode", "%d", systemConfig()->debug_mode); BLACKBOX_PRINT_HEADER_LINE("features", "%d", featureConfig()->enabledFeatures); #ifdef USE_RC_SMOOTHING_FILTER