#ifndef BMI088_H
#define BMI088_H

/* Includes ----------------------------------------------------------------- */
#include <stdbool.h>
#include <stdint.h>

#include "ahrs.h"
#include "device\device.h"


typedef struct {
  struct {
    float x;
    float y;
    float z;
  } gyro_offset; /* 陀螺仪偏置 */
} BMI088_Cali_t; /* BMI088校准数据 */

typedef struct {
  AHRS_Accl_t accl;
  AHRS_Gyro_t gyro;

  float temp; /* 温度 */
	
	AHRS_Accl_t filtered_accl;
  AHRS_Gyro_t filtered_gyro;

const  BMI088_Cali_t *cali;
} BMI088_t;


typedef struct {
  struct {
    float x;
    float y;
    float z;
  } magn_offset; /* 磁力计偏置 */

  struct {
    float x;
    float y;
    float z;
  } magn_scale;   /* 磁力计缩放 */
} IST8310_Cali_t; /* IST8310校准数据 */

typedef struct {
  AHRS_Magn_t magn;
  const IST8310_Cali_t *cali;
} IST8310_t;


/* Exported functions prototypes -------------------------------------------- */
int8_t BMI088_Init(BMI088_t *bmi088,const BMI088_Cali_t *cali);
int8_t BMI088_Restart(void);
 void BMI088_AcclIntCallback(void);
 void BMI088_GyroIntCallback(void);
bool BMI088_GyroStable(AHRS_Gyro_t *gyro);

/* Sensor use right-handed coordinate system. */
/*
                x < R(logo)
                        y
                UP is z
        All implementation should follow this rule.
 */
uint32_t BMI088_WaitNew(void);

/*
  BMI088的Accl和Gyro共用同一个DMA通道，所以一次只能读一个传感器。
  即BMI088_AcclStartDmaRecv() 和 BMI088_AcclWaitDmaCplt() 中间不能
  出现 BMI088_GyroStartDmaRecv()。
*/
int8_t   BMI088_AcclStartDmaRecv(void);
uint32_t BMI088_AcclWaitDmaCplt(void);
int8_t   BMI088_GyroStartDmaRecv(void);
uint32_t BMI088_GyroWaitDmaCplt(void);
int8_t   BMI088_ParseAccl(BMI088_t *bmi088);
int8_t   BMI088_ParseGyro(BMI088_t *bmi088);
float    BMI088_GetUpdateFreq(BMI088_t *bmi088);
int8_t BMI088_calibration(BMI088_t *bmi088);
int8_t BMI088_Waiting_Temp_Ready(BMI088_t *bmi088);
uint32_t BMI088_TempWaitCplt(void);
#endif
