MPU6050 MPU DATA READY // gyro sync activated
MPU6050 gets DATA READY pin based interrupt instad of i2c SPI targets are still getting interrupt from SPI
This commit is contained in:
parent
60053d5ea5
commit
c45d3e1fdd
|
@ -165,7 +165,9 @@ static void mpu6050AccInit(void);
|
||||||
static bool mpu6050AccRead(int16_t *accData);
|
static bool mpu6050AccRead(int16_t *accData);
|
||||||
static void mpu6050GyroInit(void);
|
static void mpu6050GyroInit(void);
|
||||||
static bool mpu6050GyroRead(int16_t *gyroADC);
|
static bool mpu6050GyroRead(int16_t *gyroADC);
|
||||||
static void checkMPU6050Interrupt(bool *gyroIsUpdated);
|
static void checkMPU6050DataReady(bool *mpuDataReadyPtr);
|
||||||
|
|
||||||
|
static bool mpuDataReady;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MPU_6050_HALF_RESOLUTION,
|
MPU_6050_HALF_RESOLUTION,
|
||||||
|
@ -184,6 +186,8 @@ void MPU_DATA_READY_EXTI_Handler(void)
|
||||||
|
|
||||||
EXTI_ClearITPendingBit(mpu6050Config->exti_line);
|
EXTI_ClearITPendingBit(mpu6050Config->exti_line);
|
||||||
|
|
||||||
|
mpuDataReady = true;
|
||||||
|
|
||||||
#ifdef DEBUG_MPU_DATA_READY_INTERRUPT
|
#ifdef DEBUG_MPU_DATA_READY_INTERRUPT
|
||||||
// Measure the delta in micro seconds between calls to the interrupt handler
|
// Measure the delta in micro seconds between calls to the interrupt handler
|
||||||
static uint32_t lastCalledAt = 0;
|
static uint32_t lastCalledAt = 0;
|
||||||
|
@ -358,7 +362,7 @@ bool mpu6050GyroDetect(const mpu6050Config_t *configToUse, gyro_t *gyro, uint16_
|
||||||
|
|
||||||
gyro->init = mpu6050GyroInit;
|
gyro->init = mpu6050GyroInit;
|
||||||
gyro->read = mpu6050GyroRead;
|
gyro->read = mpu6050GyroRead;
|
||||||
gyro->intStatus = checkMPU6050Interrupt;
|
gyro->intStatus = checkMPU6050DataReady;
|
||||||
|
|
||||||
// 16.4 dps/lsb scalefactor
|
// 16.4 dps/lsb scalefactor
|
||||||
gyro->scale = 1.0f / 16.4f;
|
gyro->scale = 1.0f / 16.4f;
|
||||||
|
@ -458,12 +462,11 @@ static bool mpu6050GyroRead(int16_t *gyroADC)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkMPU6050Interrupt(bool *gyroIsUpdated) {
|
void checkMPU6050DataReady(bool *mpuDataReadyPtr) {
|
||||||
uint8_t mpuIntStatus;
|
if (mpuDataReady) {
|
||||||
|
*mpuDataReadyPtr = true;
|
||||||
i2cRead(MPU6050_ADDRESS, MPU_RA_INT_STATUS, 1, &mpuIntStatus);
|
mpuDataReady= false;
|
||||||
|
} else {
|
||||||
delayMicroseconds(5);
|
*mpuDataReadyPtr = false;
|
||||||
|
}
|
||||||
(mpuIntStatus) ? (*gyroIsUpdated= true) : (*gyroIsUpdated= false);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,16 +31,16 @@ extern gyro_t gyro;
|
||||||
uint32_t targetLooptime;
|
uint32_t targetLooptime;
|
||||||
static uint8_t mpuDivider;
|
static uint8_t mpuDivider;
|
||||||
|
|
||||||
bool getMpuInterrupt(gyro_t *gyro)
|
bool getMpuDataStatus(gyro_t *gyro)
|
||||||
{
|
{
|
||||||
bool gyroIsUpdated;
|
bool mpuDataStatus;
|
||||||
|
|
||||||
gyro->intStatus(&gyroIsUpdated);
|
gyro->intStatus(&mpuDataStatus);
|
||||||
return gyroIsUpdated;
|
return mpuDataStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gyroSyncCheckUpdate(void) {
|
bool gyroSyncCheckUpdate(void) {
|
||||||
return getMpuInterrupt(&gyro);
|
return getMpuDataStatus(&gyro);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gyroUpdateSampleRate(uint32_t looptime, uint8_t lpf, uint8_t syncGyroToLoop) {
|
void gyroUpdateSampleRate(uint32_t looptime, uint8_t lpf, uint8_t syncGyroToLoop) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ enum {
|
||||||
#define VBATINTERVAL (6 * 3500)
|
#define VBATINTERVAL (6 * 3500)
|
||||||
/* IBat monitoring interval (in microseconds) - 6 default looptimes */
|
/* IBat monitoring interval (in microseconds) - 6 default looptimes */
|
||||||
#define IBATINTERVAL (6 * 3500)
|
#define IBATINTERVAL (6 * 3500)
|
||||||
#define GYRO_WATCHDOG_DELAY 150 // Watchdog for boards without interrupt for gyro
|
#define GYRO_WATCHDOG_DELAY 100 // Watchdog for boards without interrupt for gyro
|
||||||
|
|
||||||
uint32_t currentTime = 0;
|
uint32_t currentTime = 0;
|
||||||
uint32_t previousTime = 0;
|
uint32_t previousTime = 0;
|
||||||
|
@ -738,6 +738,21 @@ void filterRc(void){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function for loop trigger
|
||||||
|
bool runLoop(uint32_t loopTime) {
|
||||||
|
bool loopTrigger = false;
|
||||||
|
|
||||||
|
if (masterConfig.syncGyroToLoop) {
|
||||||
|
if (gyroSyncCheckUpdate() || (int32_t)(currentTime - (loopTime + GYRO_WATCHDOG_DELAY)) >= 0) {
|
||||||
|
loopTrigger = true;
|
||||||
|
}
|
||||||
|
} else if ((int32_t)(currentTime - loopTime) >= 0){
|
||||||
|
loopTrigger = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return loopTrigger;
|
||||||
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
static uint32_t loopTime;
|
static uint32_t loopTime;
|
||||||
|
@ -784,7 +799,7 @@ void loop(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTime = micros();
|
currentTime = micros();
|
||||||
if ((!masterConfig.syncGyroToLoop && masterConfig.looptime == 0) || ((int32_t)(currentTime - loopTime) >= 0)) {
|
if (runLoop(loopTime)) {
|
||||||
|
|
||||||
loopTime = currentTime + targetLooptime;
|
loopTime = currentTime + targetLooptime;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue