-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3868 from shellixyz/KAKUTEF7_target
Add KAKUTEF7 target
- Loading branch information
Showing
13 changed files
with
441 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* This file is part of iNavFlight. | ||
* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#include "platform.h" | ||
#include "build/debug.h" | ||
|
||
#include "common/axis.h" | ||
#include "common/maths.h" | ||
|
||
#include "drivers/system.h" | ||
#include "drivers/time.h" | ||
#include "drivers/io.h" | ||
#include "drivers/exti.h" | ||
#include "drivers/bus.h" | ||
|
||
#include "drivers/accgyro/accgyro.h" | ||
#include "drivers/accgyro/accgyro_mpu.h" | ||
#include "drivers/accgyro/accgyro_icm20689.h" | ||
|
||
#if (defined(USE_GYRO_ICM20689) || defined(USE_ACC_ICM20689)) | ||
|
||
static uint8_t icm20689DeviceDetect(const busDevice_t *busDev) | ||
{ | ||
busSetSpeed(busDev, BUS_SPEED_INITIALIZATION); | ||
|
||
busWrite(busDev, MPU_RA_PWR_MGMT_1, ICM20689_BIT_RESET); | ||
|
||
uint8_t attemptsRemaining = 20; | ||
uint8_t in; | ||
do { | ||
delay(150); | ||
busRead(busDev, MPU_RA_WHO_AM_I, &in); | ||
switch (in) { | ||
case ICM20601_WHO_AM_I_CONST: | ||
case ICM20602_WHO_AM_I_CONST: | ||
case ICM20608G_WHO_AM_I_CONST: | ||
case ICM20689_WHO_AM_I_CONST: | ||
return true; | ||
} | ||
} while (attemptsRemaining--); | ||
|
||
return false; | ||
} | ||
|
||
static void icm20689AccInit(accDev_t *acc) | ||
{ | ||
acc->acc_1G = 512 * 4; | ||
} | ||
|
||
bool icm20689AccDetect(accDev_t *acc) | ||
{ | ||
acc->busDev = busDeviceOpen(BUSTYPE_ANY, DEVHW_ICM20689, acc->imuSensorToUse); | ||
if (acc->busDev == NULL) { | ||
return false; | ||
} | ||
|
||
mpuContextData_t * ctx = busDeviceGetScratchpadMemory(acc->busDev); | ||
if (ctx->chipMagicNumber != 0x50D1) { | ||
return false; | ||
} | ||
|
||
acc->initFn = icm20689AccInit; | ||
acc->readFn = mpuAccReadScratchpad; | ||
|
||
return true; | ||
} | ||
|
||
static void icm20689AccAndGyroInit(gyroDev_t *gyro) | ||
{ | ||
busDevice_t * busDev = gyro->busDev; | ||
const gyroFilterAndRateConfig_t * config = mpuChooseGyroConfig(gyro->lpf, 1000000 / gyro->requestedSampleIntervalUs); | ||
gyro->sampleRateIntervalUs = 1000000 / config->gyroRateHz; | ||
|
||
gyroIntExtiInit(gyro); | ||
|
||
busSetSpeed(busDev, BUS_SPEED_INITIALIZATION); | ||
|
||
busWrite(busDev, MPU_RA_PWR_MGMT_1, ICM20689_BIT_RESET); | ||
delay(100); | ||
busWrite(busDev, MPU_RA_SIGNAL_PATH_RESET, 0x03); | ||
delay(100); | ||
busWrite(busDev, MPU_RA_PWR_MGMT_1, INV_CLK_PLL); | ||
delay(15); | ||
busWrite(busDev, MPU_RA_GYRO_CONFIG, INV_FSR_2000DPS << 3); // XXX | ||
delay(15); | ||
busWrite(busDev, MPU_RA_ACCEL_CONFIG, INV_FSR_16G << 3); | ||
delay(15); | ||
busWrite(busDev, MPU_RA_CONFIG, config->gyroConfigValues[0]); | ||
delay(15); | ||
busWrite(busDev, MPU_RA_SMPLRT_DIV, config->gyroConfigValues[1]); // Get Divider Drops | ||
delay(100); | ||
|
||
// Data ready interrupt configuration | ||
busWrite(busDev, MPU_RA_INT_PIN_CFG, 0x10); // INT_ANYRD_2CLEAR, BYPASS_EN | ||
|
||
delay(15); | ||
|
||
#ifdef USE_MPU_DATA_READY_SIGNAL | ||
busWrite(busDev, MPU_RA_INT_ENABLE, 0x01); // RAW_RDY_EN interrupt enable | ||
#endif | ||
} | ||
|
||
bool icm20689GyroDetect(gyroDev_t *gyro) | ||
{ | ||
gyro->busDev = busDeviceInit(BUSTYPE_ANY, DEVHW_ICM20689, gyro->imuSensorToUse, OWNER_MPU); | ||
if (gyro->busDev == NULL) { | ||
return false; | ||
} | ||
|
||
if (!icm20689DeviceDetect(gyro->busDev)) { | ||
busDeviceDeInit(gyro->busDev); | ||
return false; | ||
} | ||
|
||
// Magic number for ACC detection to indicate that we have detected MPU6000 gyro | ||
mpuContextData_t * ctx = busDeviceGetScratchpadMemory(gyro->busDev); | ||
ctx->chipMagicNumber = 0x50D1; | ||
|
||
gyro->initFn = icm20689AccAndGyroInit; | ||
gyro->readFn = mpuGyroReadScratchpad; | ||
gyro->intStatusFn = gyroCheckDataReady; | ||
gyro->temperatureFn = mpuTemperatureReadScratchpad; | ||
gyro->scale = 1.0f / 16.4f; // 16.4 dps/lsb scalefactor | ||
|
||
return true; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* This file is part of iNavFlight. | ||
* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "drivers/bus.h" | ||
|
||
#define ICM20689_BIT_RESET (0x80) | ||
|
||
#if (defined(USE_GYRO_ICM20689) || defined(USE_ACC_ICM20689)) | ||
|
||
bool icm20689AccDetect(accDev_t *acc); | ||
bool icm20689GyroDetect(gyroDev_t *gyro); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ typedef enum { | |
GYRO_MPU6500, | ||
GYRO_MPU9250, | ||
GYRO_BMI160, | ||
GYRO_ICM20689, | ||
GYRO_FAKE | ||
} gyroSensor_e; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of INAV. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* Alternatively, the contents of this file may be used under the terms | ||
* of the GNU General Public License Version 3, as described below: | ||
* | ||
* This file is free software: you may copy, redistribute and/or modify | ||
* it 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 file 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 program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
|
||
#include <platform.h> | ||
#include "drivers/io.h" | ||
#include "drivers/pwm_mapping.h" | ||
#include "drivers/timer.h" | ||
#include "drivers/bus.h" | ||
|
||
BUSDEV_REGISTER_SPI_TAG(busdev_icm20689, DEVHW_ICM20689, ICM20689_SPI_BUS, ICM20689_CS_PIN, ICM20689_EXTI_PIN, 0, DEVFLAGS_NONE); | ||
|
||
const timerHardware_t timerHardware[] = { | ||
{ TIM1, IO_TAG(PE13), TIM_CHANNEL_3, 0, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_PPM }, // PPM | ||
|
||
{ TIM3, IO_TAG(PB0), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_1 | ||
{ TIM3, IO_TAG(PB1), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_2 | ||
{ TIM1, IO_TAG(PE9), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_3 | ||
{ TIM1, IO_TAG(PE11), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_4 | ||
{ TIM8, IO_TAG(PC9), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_5 | ||
{ TIM5, IO_TAG(PA3), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_6 | ||
|
||
{ TIM4, IO_TAG(PD12), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_LED } | ||
}; | ||
|
||
const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); |
Oops, something went wrong.